| Index: base/message_loop/message_loop.cc
|
| diff --git a/base/message_loop/message_loop.cc b/base/message_loop/message_loop.cc
|
| index 8991ff3a86f4fd7cce39fd4f32c439aed6d7ede3..5a755c6a4820c123879d4f3be9eacaf157ddf960 100644
|
| --- a/base/message_loop/message_loop.cc
|
| +++ b/base/message_loop/message_loop.cc
|
| @@ -97,7 +97,10 @@ MessageLoop::~MessageLoop() {
|
| // iOS just attaches to the loop, it doesn't Run it.
|
| // TODO(stuartmorgan): Consider wiring up a Detach().
|
| #if !defined(OS_IOS)
|
| - DCHECK(!run_loop_);
|
| + // There should be no active RunLoops on this thread, unless this MessageLoop
|
| + // isn't bound to the current thread (see other condition at the top of this
|
| + // method).
|
| + DCHECK((!pump_ && current() != this) || !GetTopMostRunLoop());
|
| #endif
|
|
|
| #if defined(OS_WIN)
|
| @@ -136,8 +139,6 @@ MessageLoop::~MessageLoop() {
|
| // OK, now make it so that no one can find us.
|
| if (current() == this)
|
| GetTLSMessageLoop()->Set(nullptr);
|
| -
|
| - RunLoop::ResetTLSState();
|
| }
|
|
|
| // static
|
| @@ -216,20 +217,14 @@ void MessageLoop::RemoveDestructionObserver(
|
|
|
| void MessageLoop::QuitWhenIdle() {
|
| DCHECK_EQ(this, current());
|
| - if (run_loop_) {
|
| - run_loop_->QuitWhenIdle();
|
| - } else {
|
| - NOTREACHED() << "Must be inside Run to call QuitWhenIdle";
|
| - }
|
| + DCHECK(GetTopMostRunLoop()) << "Must be inside Run to call QuitWhenIdle";
|
| + GetTopMostRunLoop()->QuitWhenIdle();
|
| }
|
|
|
| void MessageLoop::QuitNow() {
|
| DCHECK_EQ(this, current());
|
| - if (run_loop_) {
|
| - pump_->Quit();
|
| - } else {
|
| - NOTREACHED() << "Must be inside Run to call Quit";
|
| - }
|
| + DCHECK(GetTopMostRunLoop()) << "Must be inside Run to call Quit";
|
| + pump_->Quit();
|
| }
|
|
|
| bool MessageLoop::IsType(Type type) const {
|
| @@ -247,7 +242,7 @@ Closure MessageLoop::QuitWhenIdleClosure() {
|
|
|
| void MessageLoop::SetNestableTasksAllowed(bool allowed) {
|
| if (allowed) {
|
| - CHECK(base::RunLoop::IsNestingAllowedOnCurrentThread());
|
| + CHECK(RunLoop::IsNestingAllowedOnCurrentThread());
|
|
|
| // Kick the native pump just in case we enter a OS-driven nested message
|
| // loop.
|
| @@ -302,7 +297,6 @@ MessageLoop::MessageLoop(Type type, MessagePumpFactoryCallback pump_factory)
|
| #endif
|
| nestable_tasks_allowed_(true),
|
| pump_factory_(std::move(pump_factory)),
|
| - run_loop_(nullptr),
|
| current_pending_task_(nullptr),
|
| incoming_task_queue_(new internal::IncomingTaskQueue(this)),
|
| unbound_task_runner_(
|
| @@ -313,23 +307,6 @@ MessageLoop::MessageLoop(Type type, MessagePumpFactoryCallback pump_factory)
|
| DCHECK(type_ != TYPE_CUSTOM || !pump_factory_.is_null());
|
| }
|
|
|
| -void MessageLoop::BindToCurrentThread() {
|
| - DCHECK(!pump_);
|
| - if (!pump_factory_.is_null())
|
| - pump_ = std::move(pump_factory_).Run();
|
| - else
|
| - pump_ = CreateMessagePumpForType(type_);
|
| -
|
| - DCHECK(!current()) << "should only have one message loop per thread";
|
| - GetTLSMessageLoop()->Set(this);
|
| -
|
| - incoming_task_queue_->StartScheduling();
|
| - unbound_task_runner_->BindToCurrentThread();
|
| - unbound_task_runner_ = nullptr;
|
| - SetThreadTaskRunnerHandle();
|
| - thread_id_ = PlatformThread::CurrentId();
|
| -}
|
| -
|
| std::string MessageLoop::GetThreadName() const {
|
| DCHECK_NE(kInvalidThreadId, thread_id_)
|
| << "GetThreadName() must only be called after BindToCurrentThread()'s "
|
| @@ -354,6 +331,35 @@ void MessageLoop::ClearTaskRunnerForTesting() {
|
| thread_task_runner_handle_.reset();
|
| }
|
|
|
| +void MessageLoop::BindToCurrentThread() {
|
| + RunLoop::Delegate::BindToCurrentThread();
|
| +
|
| + DCHECK(!pump_);
|
| + if (!pump_factory_.is_null())
|
| + pump_ = std::move(pump_factory_).Run();
|
| + else
|
| + pump_ = CreateMessagePumpForType(type_);
|
| +
|
| + DCHECK(!current()) << "should only have one message loop per thread";
|
| + GetTLSMessageLoop()->Set(this);
|
| +
|
| + incoming_task_queue_->StartScheduling();
|
| + unbound_task_runner_->BindToCurrentThread();
|
| + unbound_task_runner_ = nullptr;
|
| + SetThreadTaskRunnerHandle();
|
| + thread_id_ = PlatformThread::CurrentId();
|
| +}
|
| +
|
| +void MessageLoop::Run() {
|
| + DCHECK_EQ(this, current());
|
| + pump_->Run(this);
|
| +}
|
| +
|
| +void MessageLoop::Quit() {
|
| + DCHECK_EQ(this, current());
|
| + QuitNow();
|
| +}
|
| +
|
| void MessageLoop::SetThreadTaskRunnerHandle() {
|
| DCHECK_EQ(this, current());
|
| // Clear the previous thread task runner first, because only one can exist at
|
| @@ -362,14 +368,8 @@ void MessageLoop::SetThreadTaskRunnerHandle() {
|
| thread_task_runner_handle_.reset(new ThreadTaskRunnerHandle(task_runner_));
|
| }
|
|
|
| -void MessageLoop::RunHandler() {
|
| - DCHECK_EQ(this, current());
|
| - DCHECK(run_loop_);
|
| - pump_->Run(this);
|
| -}
|
| -
|
| bool MessageLoop::ProcessNextDelayedNonNestableTask() {
|
| - if (is_nested_)
|
| + if (IsNested())
|
| return false;
|
|
|
| if (deferred_non_nestable_work_queue_.empty())
|
| @@ -411,7 +411,7 @@ void MessageLoop::RunTask(PendingTask* pending_task) {
|
| }
|
|
|
| bool MessageLoop::DeferOrRunPendingTask(PendingTask pending_task) {
|
| - if (pending_task.nestable || !is_nested_) {
|
| + if (pending_task.nestable || !IsNested()) {
|
| RunTask(&pending_task);
|
| // Show that we ran a task (Note: a new one might arrive as a
|
| // consequence!).
|
| @@ -546,7 +546,7 @@ bool MessageLoop::DoIdleWork() {
|
| if (ProcessNextDelayedNonNestableTask())
|
| return true;
|
|
|
| - if (run_loop_->quit_when_idle_received_)
|
| + if (GetTopMostRunLoop()->quit_when_idle_received_)
|
| pump_->Quit();
|
|
|
| // When we return we will do a kernel wait for more tasks.
|
|
|