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()),
13 previous_run_loop_(NULL
),
18 quit_when_idle_received_(false),
20 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) && \
21 !defined(USE_GTK_MESSAGE_PUMP)
26 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) && \
27 !defined(USE_GTK_MESSAGE_PUMP)
28 RunLoop::RunLoop(MessageLoop::Dispatcher
* dispatcher
)
29 : loop_(MessageLoop::current()),
30 previous_run_loop_(NULL
),
31 dispatcher_(dispatcher
),
36 quit_when_idle_received_(false),
51 void RunLoop::RunUntilIdle() {
52 quit_when_idle_received_
= true;
56 void RunLoop::Quit() {
58 if (running_
&& loop_
->run_loop_
== this) {
59 // This is the inner-most RunLoop, so quit now.
64 base::Closure
RunLoop::QuitClosure() {
65 return base::Bind(&RunLoop::Quit
, weak_factory_
.GetWeakPtr());
68 bool RunLoop::BeforeRun() {
72 // Allow Quit to be called before Run.
76 // Push RunLoop stack:
77 previous_run_loop_
= loop_
->run_loop_
;
78 run_depth_
= previous_run_loop_
? previous_run_loop_
->run_depth_
+ 1 : 1;
79 loop_
->run_loop_
= this;
85 void RunLoop::AfterRun() {
89 loop_
->run_loop_
= previous_run_loop_
;
91 // Execute deferred QuitNow, if any:
92 if (previous_run_loop_
&& previous_run_loop_
->quit_called_
)