Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Unified Diff: base/message_loop/message_loop.cc

Issue 1206893003: base: Make it possible to replace the MessageLoop's task runner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change in media/blink/webmediaplayer_impl.cc is not needed Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/message_loop/message_loop.h ('k') | base/message_loop/message_loop_task_runner.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_loop/message_loop.cc
diff --git a/base/message_loop/message_loop.cc b/base/message_loop/message_loop.cc
index 74bfdb6f4ef6c2d16f66891c8189f8a5ffb76613..219d520f6d9e52e1bd50983d86f17ea62ee628b1 100644
--- a/base/message_loop/message_loop.cc
+++ b/base/message_loop/message_loop.cc
@@ -367,6 +367,7 @@ bool MessageLoop::IsIdleForTesting() {
//------------------------------------------------------------------------------
+// static
scoped_ptr<MessageLoop> MessageLoop::CreateUnbound(
Type type, MessagePumpFactoryCallback pump_factory) {
return make_scoped_ptr(new MessageLoop(type, pump_factory));
@@ -403,7 +404,25 @@ void MessageLoop::BindToCurrentThread() {
incoming_task_queue_->StartScheduling();
task_runner_->BindToCurrentThread();
- thread_task_runner_handle_.reset(new ThreadTaskRunnerHandle(task_runner_));
+ scoped_refptr<BindableSingleThreadTaskRunner> previous_task_runner =
+ SwapTaskRunner(task_runner_.Pass());
+ DCHECK(previous_task_runner == NULL);
+}
+
+scoped_refptr<BindableSingleThreadTaskRunner> MessageLoop::SwapTaskRunner(
+ scoped_refptr<BindableSingleThreadTaskRunner> task_runner) {
+ // If this message loop was already bound to a thread, ensure the task runner
+ // belongs to the same thread and update the thread task runner handle.
+ // Otherwise the task runner will be bound later in BindToCurrentThread().
+ if (pump_) {
+ DCHECK_EQ(this, current());
+ DCHECK(task_runner->BelongsToCurrentThread());
+ // This reset() is needed or ThreadTaskRunnerHandle::Get() will crash.
+ thread_task_runner_handle_.reset();
+ thread_task_runner_handle_.reset(new ThreadTaskRunnerHandle(task_runner));
+ }
+ task_runner_.swap(task_runner);
+ return task_runner;
}
void MessageLoop::RunHandler() {
« no previous file with comments | « base/message_loop/message_loop.h ('k') | base/message_loop/message_loop_task_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698