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(OS_IOS) | 18 #if defined(OS_IOS) |
19 class MessagePumpUIApplication; | 19 class MessagePumpUIApplication; |
20 #endif | 20 #endif |
21 | 21 |
22 // 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 |
23 // 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 |
24 // 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 |
25 // 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 |
26 // a nested MessageLoop. | 26 // a nested MessageLoop. |
27 class BASE_EXPORT RunLoop { | 27 class BASE_EXPORT RunLoop { |
28 public: | 28 public: |
29 RunLoop(); | 29 RunLoop(); |
30 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 30 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) && \ |
| 31 !defined(USE_GTK_MESSAGE_PUMP) |
31 explicit RunLoop(MessageLoop::Dispatcher* dispatcher); | 32 explicit RunLoop(MessageLoop::Dispatcher* dispatcher); |
32 #endif | 33 #endif |
33 ~RunLoop(); | 34 ~RunLoop(); |
34 | 35 |
35 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 36 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) && \ |
| 37 !defined(USE_GTK_MESSAGE_PUMP) |
36 void set_dispatcher(MessageLoop::Dispatcher* dispatcher) { | 38 void set_dispatcher(MessageLoop::Dispatcher* dispatcher) { |
37 dispatcher_ = dispatcher; | 39 dispatcher_ = dispatcher; |
38 } | 40 } |
39 #endif | 41 #endif |
40 | 42 |
41 // Run the current MessageLoop. This blocks until Quit is called. Before | 43 // Run the current MessageLoop. This blocks until Quit is called. Before |
42 // calling Run, be sure to grab an AsWeakPtr or the QuitClosure in order to | 44 // calling Run, be sure to grab an AsWeakPtr or the QuitClosure in order to |
43 // stop the MessageLoop asynchronously. MessageLoop::Quit and QuitNow will | 45 // stop the MessageLoop asynchronously. MessageLoop::Quit and QuitNow will |
44 // also trigger a return from Run, but those are deprecated. | 46 // also trigger a return from Run, but those are deprecated. |
45 void Run(); | 47 void Run(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 void AfterRun(); | 93 void AfterRun(); |
92 | 94 |
93 MessageLoop* loop_; | 95 MessageLoop* loop_; |
94 | 96 |
95 // WeakPtrFactory for QuitClosure safety. | 97 // WeakPtrFactory for QuitClosure safety. |
96 base::WeakPtrFactory<RunLoop> weak_factory_; | 98 base::WeakPtrFactory<RunLoop> weak_factory_; |
97 | 99 |
98 // Parent RunLoop or NULL if this is the top-most RunLoop. | 100 // Parent RunLoop or NULL if this is the top-most RunLoop. |
99 RunLoop* previous_run_loop_; | 101 RunLoop* previous_run_loop_; |
100 | 102 |
101 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 103 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) && \ |
| 104 !defined(USE_GTK_MESSAGE_PUMP) |
102 MessageLoop::Dispatcher* dispatcher_; | 105 MessageLoop::Dispatcher* dispatcher_; |
103 #endif | 106 #endif |
104 | 107 |
105 // Used to count how many nested Run() invocations are on the stack. | 108 // Used to count how many nested Run() invocations are on the stack. |
106 int run_depth_; | 109 int run_depth_; |
107 | 110 |
108 bool run_called_; | 111 bool run_called_; |
109 bool quit_called_; | 112 bool quit_called_; |
110 bool running_; | 113 bool running_; |
111 | 114 |
112 // Used to record that QuitWhenIdle() was called on the MessageLoop, meaning | 115 // Used to record that QuitWhenIdle() was called on the MessageLoop, meaning |
113 // that we should quit Run once it becomes idle. | 116 // that we should quit Run once it becomes idle. |
114 bool quit_when_idle_received_; | 117 bool quit_when_idle_received_; |
115 | 118 |
116 DISALLOW_COPY_AND_ASSIGN(RunLoop); | 119 DISALLOW_COPY_AND_ASSIGN(RunLoop); |
117 }; | 120 }; |
118 | 121 |
119 } // namespace base | 122 } // namespace base |
120 | 123 |
121 #endif // BASE_RUN_LOOP_H_ | 124 #endif // BASE_RUN_LOOP_H_ |
OLD | NEW |