1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/run_loop.h"
10 #include "base/message_loop/message_pump_dispatcher.h"
16 : loop_(MessageLoop::current()),
17 previous_run_loop_(NULL),
22 quit_when_idle_received_(false),
30 RunLoop::RunLoop(MessagePumpDispatcher* dispatcher)
31 : loop_(MessageLoop::current()),
32 previous_run_loop_(NULL),
33 dispatcher_(dispatcher),
38 quit_when_idle_received_(false),
53 void RunLoop::RunUntilIdle() {
54 quit_when_idle_received_ = true;
58 void RunLoop::Quit() {
60 if (running_ && loop_->run_loop_ == this) {
61 // This is the inner-most RunLoop, so quit now.
66 base::Closure RunLoop::QuitClosure() {
67 return base::Bind(&RunLoop::Quit, weak_factory_.GetWeakPtr());
70 bool RunLoop::BeforeRun() {
74 // Allow Quit to be called before Run.
78 // Push RunLoop stack:
79 previous_run_loop_ = loop_->run_loop_;
80 run_depth_ = previous_run_loop_? previous_run_loop_->run_depth_ + 1 : 1;
81 loop_->run_loop_ = this;
87 void RunLoop::AfterRun() {
91 loop_->run_loop_ = previous_run_loop_;
93 // Execute deferred QuitNow, if any:
94 if (previous_run_loop_ && previous_run_loop_->quit_called_)