| Index: base/message_loop/message_loop.cc | 
| diff --git a/base/message_loop/message_loop.cc b/base/message_loop/message_loop.cc | 
| index 4222c774dd58b20354d6b0e4c948efcbbf5abf1b..6bd6730cde34752a3e7db50ee8d2f153379013da 100644 | 
| --- a/base/message_loop/message_loop.cc | 
| +++ b/base/message_loop/message_loop.cc | 
| @@ -19,6 +19,7 @@ | 
| #include "base/thread_task_runner_handle.h" | 
| #include "base/threading/thread_local.h" | 
| #include "base/time/time.h" | 
| +#include "base/trace_event/trace_event.h" | 
| #include "base/tracked_objects.h" | 
|  | 
| #if defined(OS_MACOSX) | 
| @@ -170,7 +171,8 @@ MessageLoop::~MessageLoop() { | 
| // Tell the incoming queue that we are dying. | 
| incoming_task_queue_->WillDestroyCurrentMessageLoop(); | 
| incoming_task_queue_ = NULL; | 
| -  message_loop_proxy_ = NULL; | 
| +  unbound_task_runner_ = NULL; | 
| +  task_runner_ = NULL; | 
|  | 
| // OK, now make it so that no one can find us. | 
| lazy_tls_ptr.Pointer()->Set(NULL); | 
| @@ -257,27 +259,27 @@ void MessageLoop::RemoveDestructionObserver( | 
| void MessageLoop::PostTask( | 
| const tracked_objects::Location& from_here, | 
| const Closure& task) { | 
| -  message_loop_proxy_->PostTask(from_here, task); | 
| +  task_runner_->PostTask(from_here, task); | 
| } | 
|  | 
| void MessageLoop::PostDelayedTask( | 
| const tracked_objects::Location& from_here, | 
| const Closure& task, | 
| TimeDelta delay) { | 
| -  message_loop_proxy_->PostDelayedTask(from_here, task, delay); | 
| +  task_runner_->PostDelayedTask(from_here, task, delay); | 
| } | 
|  | 
| void MessageLoop::PostNonNestableTask( | 
| const tracked_objects::Location& from_here, | 
| const Closure& task) { | 
| -  message_loop_proxy_->PostNonNestableTask(from_here, task); | 
| +  task_runner_->PostNonNestableTask(from_here, task); | 
| } | 
|  | 
| void MessageLoop::PostNonNestableDelayedTask( | 
| const tracked_objects::Location& from_here, | 
| const Closure& task, | 
| TimeDelta delay) { | 
| -  message_loop_proxy_->PostNonNestableDelayedTask(from_here, task, delay); | 
| +  task_runner_->PostNonNestableDelayedTask(from_here, task, delay); | 
| } | 
|  | 
| void MessageLoop::Run() { | 
| @@ -367,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)); | 
| @@ -386,8 +389,9 @@ MessageLoop::MessageLoop(Type type, MessagePumpFactoryCallback pump_factory) | 
| message_histogram_(NULL), | 
| run_loop_(NULL), | 
| incoming_task_queue_(new internal::IncomingTaskQueue(this)), | 
| -      message_loop_proxy_( | 
| -          new internal::MessageLoopProxyImpl(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,9 +407,26 @@ void MessageLoop::BindToCurrentThread() { | 
| lazy_tls_ptr.Pointer()->Set(this); | 
|  | 
| incoming_task_queue_->StartScheduling(); | 
| -  message_loop_proxy_->BindToCurrentThread(); | 
| -  thread_task_runner_handle_.reset( | 
| -      new ThreadTaskRunnerHandle(message_loop_proxy_)); | 
| +  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_)); | 
| } | 
|  | 
| void MessageLoop::RunHandler() { | 
| @@ -453,10 +474,11 @@ void MessageLoop::RunTask(const PendingTask& pending_task) { | 
|  | 
| HistogramEvent(kTaskRunEvent); | 
|  | 
| +  TRACE_TASK_EXECUTION("toplevel", pending_task); | 
| + | 
| FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 
| WillProcessTask(pending_task)); | 
| -  task_annotator_.RunTask( | 
| -      "MessageLoop::PostTask", "MessageLoop::RunTask", pending_task); | 
| +  task_annotator_.RunTask("MessageLoop::PostTask", pending_task); | 
| FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 
| DidProcessTask(pending_task)); | 
|  | 
|  |