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"
12 : loop_(MessageLoop::current()),
14 previous_run_loop_(NULL
),
19 quit_when_idle_received_(false) {
20 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
25 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
26 RunLoop::RunLoop(MessageLoop::Dispatcher
* dispatcher
)
27 : loop_(MessageLoop::current()),
29 previous_run_loop_(NULL
),
30 dispatcher_(dispatcher
),
35 quit_when_idle_received_(false) {
49 void RunLoop::RunUntilIdle() {
50 quit_when_idle_received_
= true;
54 void RunLoop::Quit() {
56 if (running_
&& loop_
->run_loop_
== this) {
57 // This is the inner-most RunLoop, so quit now.
62 base::Closure
RunLoop::QuitClosure() {
63 return base::Bind(&RunLoop::Quit
, weak_factory_
.GetWeakPtr());
66 bool RunLoop::BeforeRun() {
70 // Allow Quit to be called before Run.
74 // Push RunLoop stack:
75 previous_run_loop_
= loop_
->run_loop_
;
76 run_depth_
= previous_run_loop_
? previous_run_loop_
->run_depth_
+ 1 : 1;
77 loop_
->run_loop_
= this;
83 void RunLoop::AfterRun() {
87 loop_
->run_loop_
= previous_run_loop_
;
89 // Execute deferred QuitNow, if any:
90 if (previous_run_loop_
&& previous_run_loop_
->quit_called_
)