2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_BROWSER_THREAD_UTIL_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_THREAD_UTIL_H_
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "base/location.h"
|
|
|
|
#include "base/logging.h"
|
2018-08-09 22:18:24 +02:00
|
|
|
#include "base/task/post_task.h"
|
2019-03-13 22:27:37 +01:00
|
|
|
#include "base/threading/scoped_blocking_call.h"
|
2018-03-20 21:15:08 +01:00
|
|
|
#include "base/threading/thread_restrictions.h"
|
2018-10-02 14:14:11 +02:00
|
|
|
#include "content/public/browser/browser_task_traits.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
|
|
|
|
#define CEF_UIT content::BrowserThread::UI
|
|
|
|
#define CEF_IOT content::BrowserThread::IO
|
|
|
|
|
|
|
|
#define CEF_CURRENTLY_ON(id) content::BrowserThread::CurrentlyOn(id)
|
|
|
|
#define CEF_CURRENTLY_ON_UIT() CEF_CURRENTLY_ON(CEF_UIT)
|
|
|
|
#define CEF_CURRENTLY_ON_IOT() CEF_CURRENTLY_ON(CEF_IOT)
|
|
|
|
|
|
|
|
#define CEF_REQUIRE(id) DCHECK(CEF_CURRENTLY_ON(id))
|
|
|
|
#define CEF_REQUIRE_UIT() CEF_REQUIRE(CEF_UIT)
|
|
|
|
#define CEF_REQUIRE_IOT() CEF_REQUIRE(CEF_IOT)
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
#define CEF_REQUIRE_RETURN(id, var) \
|
|
|
|
if (!CEF_CURRENTLY_ON(id)) { \
|
2012-04-03 03:34:16 +02:00
|
|
|
NOTREACHED() << "called on invalid thread"; \
|
2017-05-17 11:29:28 +02:00
|
|
|
return var; \
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
#define CEF_REQUIRE_UIT_RETURN(var) CEF_REQUIRE_RETURN(CEF_UIT, var)
|
|
|
|
#define CEF_REQUIRE_IOT_RETURN(var) CEF_REQUIRE_RETURN(CEF_IOT, var)
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
#define CEF_REQUIRE_RETURN_VOID(id) \
|
|
|
|
if (!CEF_CURRENTLY_ON(id)) { \
|
2012-04-03 03:34:16 +02:00
|
|
|
NOTREACHED() << "called on invalid thread"; \
|
2017-05-17 11:29:28 +02:00
|
|
|
return; \
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
#define CEF_REQUIRE_UIT_RETURN_VOID() CEF_REQUIRE_RETURN_VOID(CEF_UIT)
|
|
|
|
#define CEF_REQUIRE_IOT_RETURN_VOID() CEF_REQUIRE_RETURN_VOID(CEF_IOT)
|
|
|
|
|
2018-10-02 14:14:11 +02:00
|
|
|
#define CEF_POST_TASK(id, task) base::PostTaskWithTraits(FROM_HERE, {id}, task)
|
|
|
|
#define CEF_POST_DELAYED_TASK(id, task, delay_ms) \
|
|
|
|
base::PostDelayedTaskWithTraits(FROM_HERE, {id}, task, \
|
|
|
|
base::TimeDelta::FromMilliseconds(delay_ms))
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
// Post a blocking task with the specified |priority|. Tasks that have not
|
|
|
|
// started executing at shutdown will never run. However, any task that has
|
|
|
|
// already begun executing when shutdown is invoked will be allowed to continue
|
|
|
|
// and will block shutdown until completion.
|
|
|
|
// Tasks posted with this method are not guaranteed to run sequentially. Use
|
|
|
|
// base::CreateSequencedTaskRunnerWithTraits instead if sequence is important.
|
|
|
|
// Sequenced runners at various priorities that always execute all pending tasks
|
|
|
|
// before shutdown are available via CefContentBrowserClient::*_task_runner()
|
|
|
|
// and exposed by the CEF API.
|
|
|
|
#define CEF_POST_BLOCKING_TASK(priority, task) \
|
|
|
|
base::PostTaskWithTraits( \
|
|
|
|
FROM_HERE, \
|
|
|
|
{priority, base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN, \
|
|
|
|
base::MayBlock()}, \
|
|
|
|
task)
|
|
|
|
|
|
|
|
// Post a blocking task that affects UI or responsiveness of future user
|
|
|
|
// interactions. Do not use if an immediate response to a user interaction is
|
|
|
|
// expected.
|
|
|
|
#define CEF_POST_USER_VISIBLE_TASK(task) \
|
|
|
|
CEF_POST_BLOCKING_TASK(base::TaskPriority::USER_VISIBLE, task)
|
|
|
|
|
|
|
|
// Post a blocking task where the user won't notice if it takes an arbitrarily
|
|
|
|
// long time to complete.
|
|
|
|
#define CEF_POST_BACKGROUND_TASK(task) \
|
2018-07-31 21:21:39 +02:00
|
|
|
CEF_POST_BLOCKING_TASK(base::TaskPriority::BEST_EFFORT, task)
|
2018-03-20 21:15:08 +01:00
|
|
|
|
|
|
|
// Assert that blocking is allowed on the current thread.
|
2019-03-13 22:27:37 +01:00
|
|
|
#define CEF_REQUIRE_BLOCKING() \
|
|
|
|
base::ScopedBlockingCall scoped_blocking_call( \
|
|
|
|
FROM_HERE, base::BlockingType::WILL_BLOCK)
|
2018-03-20 21:15:08 +01:00
|
|
|
|
2016-03-16 03:55:59 +01:00
|
|
|
// Same as IMPLEMENT_REFCOUNTING() but using the specified Destructor.
|
2017-05-17 11:29:28 +02:00
|
|
|
#define IMPLEMENT_REFCOUNTING_EX(ClassName, Destructor) \
|
|
|
|
public: \
|
|
|
|
void AddRef() const OVERRIDE { ref_count_.AddRef(); } \
|
|
|
|
bool Release() const OVERRIDE { \
|
|
|
|
if (ref_count_.Release()) { \
|
|
|
|
Destructor::Destruct(this); \
|
|
|
|
return true; \
|
|
|
|
} \
|
|
|
|
return false; \
|
|
|
|
} \
|
|
|
|
bool HasOneRef() const OVERRIDE { return ref_count_.HasOneRef(); } \
|
2018-08-09 22:18:24 +02:00
|
|
|
bool HasAtLeastOneRef() const OVERRIDE { \
|
|
|
|
return ref_count_.HasAtLeastOneRef(); \
|
|
|
|
} \
|
2017-05-17 11:29:28 +02:00
|
|
|
\
|
|
|
|
private: \
|
2019-03-13 22:27:37 +01:00
|
|
|
CefRefCount ref_count_
|
2016-03-16 03:55:59 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
#define IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(ClassName) \
|
|
|
|
IMPLEMENT_REFCOUNTING_EX(ClassName, content::BrowserThread::DeleteOnUIThread)
|
2016-03-16 03:55:59 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
#define IMPLEMENT_REFCOUNTING_DELETE_ON_IOT(ClassName) \
|
|
|
|
IMPLEMENT_REFCOUNTING_EX(ClassName, content::BrowserThread::DeleteOnIOThread)
|
2016-03-16 03:55:59 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#endif // CEF_LIBCEF_BROWSER_THREAD_UTIL_H_
|