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

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: The reset was 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
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..e3d548be07ed8562efb39e3e3ca3bff8a0a0a339 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,23 @@ void MessageLoop::BindToCurrentThread() {
incoming_task_queue_->StartScheduling();
task_runner_->BindToCurrentThread();
- thread_task_runner_handle_.reset(new ThreadTaskRunnerHandle(task_runner_));
+ SwapTaskRunner(task_runner_);
danakj 2015/06/29 19:07:23 Why do we want to support both: 1. SwapTaskRunner
danakj 2015/06/29 19:07:23 can we DCHECK that the return from this is null?
alex clarke (OOO till 29th) 2015/06/30 10:51:43 I don't know, and Sami is currently OOO so I can't
alex clarke (OOO till 29th) 2015/06/30 10:51:43 Done.
+}
+
+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.
danakj 2015/06/29 19:07:23 We're not calling Get() here.. can you expand the
alex clarke (OOO till 29th) 2015/06/30 10:51:43 It's there because in the original review kinuko a
+ 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() {

Powered by Google App Engine
This is Rietveld 408576698