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

Unified Diff: base/message_loop/message_loop.cc

Issue 998063002: base: Make it possible to replace the MessageLoop's task runner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix data race (see https://codereview.chromium.org/1232573002/) Created 5 years, 5 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_unittest.cc » ('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 785287fcf6189a202115c168a5a085508a0f4c9b..6dfc5c551db0b2e2dff034716ab0188c95062176 100644
--- a/base/message_loop/message_loop.cc
+++ b/base/message_loop/message_loop.cc
@@ -171,6 +171,7 @@ MessageLoop::~MessageLoop() {
// Tell the incoming queue that we are dying.
incoming_task_queue_->WillDestroyCurrentMessageLoop();
incoming_task_queue_ = NULL;
+ unbound_task_runner_ = NULL;
task_runner_ = NULL;
// OK, now make it so that no one can find us.
@@ -368,6 +369,7 @@ bool MessageLoop::IsIdleForTesting() {
//------------------------------------------------------------------------------
+// static
scoped_ptr<MessageLoop> MessageLoop::CreateUnbound(
Type type, MessagePumpFactoryCallback pump_factory) {
return make_scoped_ptr(new MessageLoop(type, pump_factory));
@@ -387,7 +389,9 @@ MessageLoop::MessageLoop(Type type, MessagePumpFactoryCallback pump_factory)
message_histogram_(NULL),
run_loop_(NULL),
incoming_task_queue_(new internal::IncomingTaskQueue(this)),
- task_runner_(new internal::MessageLoopTaskRunner(incoming_task_queue_)) {
+ unbound_task_runner_(
+ new internal::MessageLoopTaskRunner(incoming_task_queue_)),
+ task_runner_(unbound_task_runner_) {
// If type is TYPE_CUSTOM non-null pump_factory must be given.
DCHECK_EQ(type_ == TYPE_CUSTOM, !pump_factory_.is_null());
}
@@ -403,7 +407,25 @@ void MessageLoop::BindToCurrentThread() {
lazy_tls_ptr.Pointer()->Set(this);
incoming_task_queue_->StartScheduling();
- task_runner_->BindToCurrentThread();
+ unbound_task_runner_->BindToCurrentThread();
+ unbound_task_runner_ = nullptr;
+ SetThreadTaskRunnerHandle();
+}
+
+void MessageLoop::SetTaskRunner(
+ scoped_refptr<SingleThreadTaskRunner> task_runner) {
+ DCHECK_EQ(this, current());
+ DCHECK(task_runner->BelongsToCurrentThread());
+ DCHECK(!unbound_task_runner_);
+ task_runner_ = task_runner.Pass();
+ SetThreadTaskRunnerHandle();
+}
+
+void MessageLoop::SetThreadTaskRunnerHandle() {
+ DCHECK_EQ(this, current());
+ // Clear the previous thread task runner first because only one can exist at
+ // a time.
+ thread_task_runner_handle_.reset();
thread_task_runner_handle_.reset(new ThreadTaskRunnerHandle(task_runner_));
}
« no previous file with comments | « base/message_loop/message_loop.h ('k') | base/message_loop/message_loop_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698