OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_RUN_LOOP_H_ | 5 #ifndef BASE_RUN_LOOP_H_ |
6 #define BASE_RUN_LOOP_H_ | 6 #define BASE_RUN_LOOP_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 #if defined(OS_ANDROID) | 14 #if defined(OS_ANDROID) |
15 class MessagePumpForUI; | 15 class MessagePumpForUI; |
16 #endif | 16 #endif |
17 | 17 |
18 #if defined(USE_AURA) | |
19 class MessagePumpDispatcher; | |
20 #endif | |
21 | |
22 #if defined(OS_IOS) | 18 #if defined(OS_IOS) |
23 class MessagePumpUIApplication; | 19 class MessagePumpUIApplication; |
24 #endif | 20 #endif |
25 | 21 |
26 // Helper class to Run a nested MessageLoop. Please do not use nested | 22 // Helper class to Run a nested MessageLoop. Please do not use nested |
27 // MessageLoops in production code! If you must, use this class instead of | 23 // MessageLoops in production code! If you must, use this class instead of |
28 // calling MessageLoop::Run/Quit directly. RunLoop::Run can only be called once | 24 // calling MessageLoop::Run/Quit directly. RunLoop::Run can only be called once |
29 // per RunLoop lifetime. Create a RunLoop on the stack and call Run/Quit to run | 25 // per RunLoop lifetime. Create a RunLoop on the stack and call Run/Quit to run |
30 // a nested MessageLoop. | 26 // a nested MessageLoop. |
31 class BASE_EXPORT RunLoop { | 27 class BASE_EXPORT RunLoop { |
32 public: | 28 public: |
33 RunLoop(); | 29 RunLoop(); |
34 #if defined(USE_AURA) | 30 #if defined(USE_AURA) |
35 explicit RunLoop(MessagePumpDispatcher* dispatcher); | 31 explicit RunLoop(MessageLoop::Dispatcher* dispatcher); |
36 #endif | 32 #endif |
37 ~RunLoop(); | 33 ~RunLoop(); |
38 | 34 |
39 #if defined(USE_AURA) | 35 #if defined(USE_AURA) |
40 void set_dispatcher(MessagePumpDispatcher* dispatcher) { | 36 void set_dispatcher(MessageLoop::Dispatcher* dispatcher) { |
41 dispatcher_ = dispatcher; | 37 dispatcher_ = dispatcher; |
42 } | 38 } |
43 #endif | 39 #endif |
44 | 40 |
45 // Run the current MessageLoop. This blocks until Quit is called. Before | 41 // Run the current MessageLoop. This blocks until Quit is called. Before |
46 // calling Run, be sure to grab an AsWeakPtr or the QuitClosure in order to | 42 // calling Run, be sure to grab an AsWeakPtr or the QuitClosure in order to |
47 // stop the MessageLoop asynchronously. MessageLoop::Quit and QuitNow will | 43 // stop the MessageLoop asynchronously. MessageLoop::Quit and QuitNow will |
48 // also trigger a return from Run, but those are deprecated. | 44 // also trigger a return from Run, but those are deprecated. |
49 void Run(); | 45 void Run(); |
50 | 46 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // Return false to abort the Run. | 89 // Return false to abort the Run. |
94 bool BeforeRun(); | 90 bool BeforeRun(); |
95 void AfterRun(); | 91 void AfterRun(); |
96 | 92 |
97 MessageLoop* loop_; | 93 MessageLoop* loop_; |
98 | 94 |
99 // Parent RunLoop or NULL if this is the top-most RunLoop. | 95 // Parent RunLoop or NULL if this is the top-most RunLoop. |
100 RunLoop* previous_run_loop_; | 96 RunLoop* previous_run_loop_; |
101 | 97 |
102 #if defined(USE_AURA) | 98 #if defined(USE_AURA) |
103 MessagePumpDispatcher* dispatcher_; | 99 MessageLoop::Dispatcher* dispatcher_; |
104 #endif | 100 #endif |
105 | 101 |
106 // Used to count how many nested Run() invocations are on the stack. | 102 // Used to count how many nested Run() invocations are on the stack. |
107 int run_depth_; | 103 int run_depth_; |
108 | 104 |
109 bool run_called_; | 105 bool run_called_; |
110 bool quit_called_; | 106 bool quit_called_; |
111 bool running_; | 107 bool running_; |
112 | 108 |
113 // Used to record that QuitWhenIdle() was called on the MessageLoop, meaning | 109 // Used to record that QuitWhenIdle() was called on the MessageLoop, meaning |
114 // that we should quit Run once it becomes idle. | 110 // that we should quit Run once it becomes idle. |
115 bool quit_when_idle_received_; | 111 bool quit_when_idle_received_; |
116 | 112 |
117 // WeakPtrFactory for QuitClosure safety. | 113 // WeakPtrFactory for QuitClosure safety. |
118 base::WeakPtrFactory<RunLoop> weak_factory_; | 114 base::WeakPtrFactory<RunLoop> weak_factory_; |
119 | 115 |
120 DISALLOW_COPY_AND_ASSIGN(RunLoop); | 116 DISALLOW_COPY_AND_ASSIGN(RunLoop); |
121 }; | 117 }; |
122 | 118 |
123 } // namespace base | 119 } // namespace base |
124 | 120 |
125 #endif // BASE_RUN_LOOP_H_ | 121 #endif // BASE_RUN_LOOP_H_ |
OLD | NEW |