Fix task runner checking

This commit is contained in:
Marshall Greenblatt 2017-09-21 13:57:40 +02:00
parent f23a512bed
commit f60fdc6d87
12 changed files with 39 additions and 33 deletions

View File

@ -14,6 +14,7 @@
#include "libcef/browser/thread_util.h"
#include "libcef/common/request_impl.h"
#include "libcef/common/response_impl.h"
#include "libcef/common/task_runner_impl.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
@ -75,7 +76,7 @@ class CefURLFetcherResponseWriter : public net::URLFetcherResponseWriter {
base::Bind(&CefURLFetcherResponseWriter::WriteOnClientThread,
url_request_, scoped_refptr<net::IOBuffer>(buffer),
num_bytes, callback,
base::MessageLoop::current()->task_runner()));
CefTaskRunnerImpl::GetCurrentTaskRunner()));
return net::ERR_IO_PENDING;
}
return num_bytes;
@ -135,7 +136,7 @@ class CefBrowserURLRequest::Context
request_(request),
client_(client),
request_context_(request_context),
task_runner_(base::MessageLoop::current()->task_runner()),
task_runner_(CefTaskRunnerImpl::GetCurrentTaskRunner()),
status_(UR_IO_PENDING),
error_code_(ERR_NONE),
upload_data_size_(0),
@ -391,7 +392,7 @@ CefURLFetcherDelegate::~CefURLFetcherDelegate() {}
void CefURLFetcherDelegate::OnURLFetchComplete(const net::URLFetcher* source) {
// Complete asynchronously so as not to delete the URLFetcher while it's still
// in the call stack.
base::MessageLoop::current()->task_runner()->PostTask(
CefTaskRunnerImpl::GetCurrentTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&CefBrowserURLRequest::Context::OnComplete, context_));
}

View File

@ -11,6 +11,7 @@
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h"
#include "libcef/browser/net/network_delegate.h"
#include "libcef/common/task_runner_impl.h"
#include "libcef/common/time_util.h"
#include "base/bind.h"
@ -144,7 +145,7 @@ void CefCookieManagerImpl::GetCookieStore(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const CookieStoreCallback& callback) {
if (!task_runner.get())
task_runner = base::MessageLoop::current()->task_runner();
task_runner = CefTaskRunnerImpl::GetCurrentTaskRunner();
if (!CEF_CURRENTLY_ON_IOT()) {
CEF_POST_TASK(CEF_IOT, base::Bind(&CefCookieManagerImpl::GetCookieStore,

View File

@ -8,6 +8,7 @@
#include <vector>
#include "libcef/browser/thread_util.h"
#include "libcef/common/task_runner_impl.h"
#include "base/bind.h"
#include "base/logging.h"
@ -793,7 +794,7 @@ void CefMenuModelImpl::MouseOutsideMenu(const gfx::Point& screen_point) {
// Allow the callstack to unwind before notifying the delegate since it may
// result in the menu being destroyed.
base::MessageLoop::current()->task_runner()->PostTask(
CefTaskRunnerImpl::GetCurrentTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&CefMenuModelImpl::OnMouseOutsideMenu, this, screen_point));
}
@ -804,7 +805,7 @@ void CefMenuModelImpl::UnhandledOpenSubmenu(bool is_rtl) {
// Allow the callstack to unwind before notifying the delegate since it may
// result in the menu being destroyed.
base::MessageLoop::current()->task_runner()->PostTask(
CefTaskRunnerImpl::GetCurrentTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&CefMenuModelImpl::OnUnhandledOpenSubmenu, this, is_rtl));
}
@ -815,7 +816,7 @@ void CefMenuModelImpl::UnhandledCloseSubmenu(bool is_rtl) {
// Allow the callstack to unwind before notifying the delegate since it may
// result in the menu being destroyed.
base::MessageLoop::current()->task_runner()->PostTask(
CefTaskRunnerImpl::GetCurrentTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&CefMenuModelImpl::OnUnhandledCloseSubmenu, this, is_rtl));
}
@ -891,7 +892,7 @@ void CefMenuModelImpl::MenuWillClose() {
// Due to how menus work on the different platforms, ActivatedAt will be
// called after this. It's more convenient for the delegate to be called
// afterwards, though, so post a task.
base::MessageLoop::current()->task_runner()->PostTask(
CefTaskRunnerImpl::GetCurrentTaskRunner()->PostTask(
FROM_HERE, base::Bind(&CefMenuModelImpl::OnMenuClosed, this));
}

View File

@ -11,6 +11,7 @@
#include "libcef/browser/extensions/extension_system.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/extensions/extensions_util.h"
#include "libcef/common/task_runner_impl.h"
#include "libcef/common/values_impl.h"
#include "base/atomic_sequence_num.h"
@ -184,7 +185,7 @@ void CefRequestContextImpl::GetBrowserContext(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const BrowserContextCallback& callback) {
if (!task_runner.get())
task_runner = base::MessageLoop::current()->task_runner();
task_runner = CefTaskRunnerImpl::GetCurrentTaskRunner();
GetBrowserContextOnUIThread(task_runner, callback);
}
@ -192,7 +193,7 @@ void CefRequestContextImpl::GetRequestContextImpl(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const RequestContextCallback& callback) {
if (!task_runner.get())
task_runner = base::MessageLoop::current()->task_runner();
task_runner = CefTaskRunnerImpl::GetCurrentTaskRunner();
if (request_context_getter_impl_) {
// The browser context already exists.
DCHECK(browser_context());

View File

@ -19,7 +19,7 @@ using content::BrowserThread;
// static
CefRefPtr<CefTaskRunner> CefTaskRunner::GetForCurrentThread() {
scoped_refptr<base::SequencedTaskRunner> task_runner =
scoped_refptr<base::SingleThreadTaskRunner> task_runner =
CefTaskRunnerImpl::GetCurrentTaskRunner();
if (task_runner.get())
return new CefTaskRunnerImpl(task_runner);
@ -28,7 +28,7 @@ CefRefPtr<CefTaskRunner> CefTaskRunner::GetForCurrentThread() {
// static
CefRefPtr<CefTaskRunner> CefTaskRunner::GetForThread(CefThreadId threadId) {
scoped_refptr<base::SequencedTaskRunner> task_runner =
scoped_refptr<base::SingleThreadTaskRunner> task_runner =
CefTaskRunnerImpl::GetTaskRunner(threadId);
if (task_runner.get())
return new CefTaskRunnerImpl(task_runner);
@ -40,13 +40,13 @@ CefRefPtr<CefTaskRunner> CefTaskRunner::GetForThread(CefThreadId threadId) {
// CefTaskRunnerImpl
CefTaskRunnerImpl::CefTaskRunnerImpl(
scoped_refptr<base::SequencedTaskRunner> task_runner)
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: task_runner_(task_runner) {
DCHECK(task_runner_.get());
}
// static
scoped_refptr<base::SequencedTaskRunner> CefTaskRunnerImpl::GetTaskRunner(
scoped_refptr<base::SingleThreadTaskRunner> CefTaskRunnerImpl::GetTaskRunner(
CefThreadId threadId) {
// Render process.
if (threadId == TID_RENDERER) {
@ -95,9 +95,9 @@ scoped_refptr<base::SequencedTaskRunner> CefTaskRunnerImpl::GetTaskRunner(
}
// static
scoped_refptr<base::SequencedTaskRunner>
scoped_refptr<base::SingleThreadTaskRunner>
CefTaskRunnerImpl::GetCurrentTaskRunner() {
scoped_refptr<base::SequencedTaskRunner> task_runner;
scoped_refptr<base::SingleThreadTaskRunner> task_runner;
// For named browser process threads return the same TaskRunner as
// GetTaskRunner(). Otherwise BelongsToThread() will return incorrect results.
@ -133,7 +133,7 @@ bool CefTaskRunnerImpl::BelongsToCurrentThread() {
}
bool CefTaskRunnerImpl::BelongsToThread(CefThreadId threadId) {
scoped_refptr<base::SequencedTaskRunner> task_runner =
scoped_refptr<base::SingleThreadTaskRunner> task_runner =
GetTaskRunner(threadId);
return (task_runner_ == task_runner);
}

View File

@ -8,18 +8,18 @@
#include "include/cef_task.h"
#include "base/sequenced_task_runner.h"
#include "base/single_thread_task_runner.h"
class CefTaskRunnerImpl : public CefTaskRunner {
public:
explicit CefTaskRunnerImpl(
scoped_refptr<base::SequencedTaskRunner> task_runner);
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
// Returns the task runner associated with |threadId|.
static scoped_refptr<base::SequencedTaskRunner> GetTaskRunner(
static scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner(
CefThreadId threadId);
// Returns the current task runner.
static scoped_refptr<base::SequencedTaskRunner> GetCurrentTaskRunner();
static scoped_refptr<base::SingleThreadTaskRunner> GetCurrentTaskRunner();
// CefTaskRunner methods:
bool IsSame(CefRefPtr<CefTaskRunner> that) override;
@ -29,7 +29,7 @@ class CefTaskRunnerImpl : public CefTaskRunner {
bool PostDelayedTask(CefRefPtr<CefTask> task, int64 delay_ms) override;
private:
scoped_refptr<base::SequencedTaskRunner> task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
IMPLEMENT_REFCOUNTING(CefTaskRunnerImpl);
DISALLOW_COPY_AND_ASSIGN(CefTaskRunnerImpl);

View File

@ -5,6 +5,7 @@
#include "include/cef_urlrequest.h"
#include "libcef/browser/browser_urlrequest_impl.h"
#include "libcef/common/content_client.h"
#include "libcef/common/task_runner_impl.h"
#include "libcef/renderer/render_urlrequest_impl.h"
#include "base/logging.h"
@ -21,7 +22,7 @@ CefRefPtr<CefURLRequest> CefURLRequest::Create(
return NULL;
}
if (!base::MessageLoop::current()) {
if (!CefTaskRunnerImpl::GetCurrentTaskRunner()) {
NOTREACHED() << "called on invalid thread";
return NULL;
}

View File

@ -350,7 +350,7 @@ void CefContentRendererClient::DevToolsAgentDetached() {
}
}
scoped_refptr<base::SequencedTaskRunner>
scoped_refptr<base::SingleThreadTaskRunner>
CefContentRendererClient::GetCurrentTaskRunner() {
// Check if currently on the render thread.
if (CEF_CURRENTLY_ON_RT())

View File

@ -66,7 +66,7 @@ class CefContentRendererClient : public content::ContentRendererClient,
void OnGuestViewDestroyed(CefGuestView* guest_view);
// Render thread task runner.
base::SequencedTaskRunner* render_task_runner() const {
base::SingleThreadTaskRunner* render_task_runner() const {
return render_task_runner_.get();
}
@ -82,7 +82,7 @@ class CefContentRendererClient : public content::ContentRendererClient,
// Returns the task runner for the current thread. Returns NULL if the current
// thread is not the main render process thread.
scoped_refptr<base::SequencedTaskRunner> GetCurrentTaskRunner();
scoped_refptr<base::SingleThreadTaskRunner> GetCurrentTaskRunner();
// Perform cleanup work that needs to occur before shutdown when running in
// single-process mode. Blocks until cleanup is complete.
@ -145,7 +145,7 @@ class CefContentRendererClient : public content::ContentRendererClient,
// Perform cleanup work for single-process mode.
void RunSingleProcessCleanupOnUIThread();
scoped_refptr<base::SequencedTaskRunner> render_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> render_task_runner_;
std::unique_ptr<CefRenderThreadObserver> observer_;
std::unique_ptr<web_cache::WebCacheImpl> web_cache_impl_;
std::unique_ptr<SpellCheck> spellcheck_;

View File

@ -8,6 +8,7 @@
#include "libcef/common/request_impl.h"
#include "libcef/common/response_impl.h"
#include "libcef/common/task_runner_impl.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
@ -68,7 +69,7 @@ class CefRenderURLRequest::Context
: url_request_(url_request),
request_(request),
client_(client),
task_runner_(base::MessageLoop::current()->task_runner()),
task_runner_(CefTaskRunnerImpl::GetCurrentTaskRunner()),
status_(UR_IO_PENDING),
error_code_(ERR_NONE),
upload_data_size_(0),

View File

@ -152,7 +152,7 @@ class CefV8IsolateManager {
}
v8::Isolate* isolate() const { return isolate_; }
scoped_refptr<base::SequencedTaskRunner> task_runner() const {
scoped_refptr<base::SingleThreadTaskRunner> task_runner() const {
return task_runner_;
}
@ -162,7 +162,7 @@ class CefV8IsolateManager {
private:
v8::Isolate* isolate_;
scoped_refptr<base::SequencedTaskRunner> task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
typedef std::map<int, scoped_refptr<CefV8ContextState>> ContextMap;
ContextMap context_map_;

View File

@ -14,7 +14,7 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/sequenced_task_runner.h"
#include "base/single_thread_task_runner.h"
#include "v8/include/v8.h"
class CefTrackNode;
@ -103,7 +103,7 @@ class CefV8HandleBase
bool BelongsToCurrentThread() const;
v8::Isolate* isolate() const { return isolate_; }
scoped_refptr<base::SequencedTaskRunner> task_runner() const {
scoped_refptr<base::SingleThreadTaskRunner> task_runner() const {
return task_runner_;
}
@ -120,7 +120,7 @@ class CefV8HandleBase
protected:
v8::Isolate* isolate_;
scoped_refptr<base::SequencedTaskRunner> task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
scoped_refptr<CefV8ContextState> context_state_;
};