| 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_WIN) | |
| 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(OS_WIN) | |
| 35 explicit RunLoop(MessagePumpDispatcher* dispatcher); | |
| 36 #endif | |
| 37 ~RunLoop(); | 30 ~RunLoop(); |
| 38 | 31 |
| 39 // Run the current MessageLoop. This blocks until Quit is called. Before | 32 // Run the current MessageLoop. This blocks until Quit is called. Before |
| 40 // calling Run, be sure to grab an AsWeakPtr or the QuitClosure in order to | 33 // calling Run, be sure to grab an AsWeakPtr or the QuitClosure in order to |
| 41 // stop the MessageLoop asynchronously. MessageLoop::Quit and QuitNow will | 34 // stop the MessageLoop asynchronously. MessageLoop::Quit and QuitNow will |
| 42 // also trigger a return from Run, but those are deprecated. | 35 // also trigger a return from Run, but those are deprecated. |
| 43 void Run(); | 36 void Run(); |
| 44 | 37 |
| 45 // Run the current MessageLoop until it doesn't find any tasks or messages in | 38 // Run the current MessageLoop until it doesn't find any tasks or messages in |
| 46 // the queue (it goes idle). WARNING: This may never return! Only use this | 39 // the queue (it goes idle). WARNING: This may never return! Only use this |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 79 |
| 87 // Return false to abort the Run. | 80 // Return false to abort the Run. |
| 88 bool BeforeRun(); | 81 bool BeforeRun(); |
| 89 void AfterRun(); | 82 void AfterRun(); |
| 90 | 83 |
| 91 MessageLoop* loop_; | 84 MessageLoop* loop_; |
| 92 | 85 |
| 93 // Parent RunLoop or NULL if this is the top-most RunLoop. | 86 // Parent RunLoop or NULL if this is the top-most RunLoop. |
| 94 RunLoop* previous_run_loop_; | 87 RunLoop* previous_run_loop_; |
| 95 | 88 |
| 96 #if defined(OS_WIN) | |
| 97 MessagePumpDispatcher* dispatcher_; | |
| 98 #endif | |
| 99 | |
| 100 // Used to count how many nested Run() invocations are on the stack. | 89 // Used to count how many nested Run() invocations are on the stack. |
| 101 int run_depth_; | 90 int run_depth_; |
| 102 | 91 |
| 103 bool run_called_; | 92 bool run_called_; |
| 104 bool quit_called_; | 93 bool quit_called_; |
| 105 bool running_; | 94 bool running_; |
| 106 | 95 |
| 107 // Used to record that QuitWhenIdle() was called on the MessageLoop, meaning | 96 // Used to record that QuitWhenIdle() was called on the MessageLoop, meaning |
| 108 // that we should quit Run once it becomes idle. | 97 // that we should quit Run once it becomes idle. |
| 109 bool quit_when_idle_received_; | 98 bool quit_when_idle_received_; |
| 110 | 99 |
| 111 // WeakPtrFactory for QuitClosure safety. | 100 // WeakPtrFactory for QuitClosure safety. |
| 112 base::WeakPtrFactory<RunLoop> weak_factory_; | 101 base::WeakPtrFactory<RunLoop> weak_factory_; |
| 113 | 102 |
| 114 DISALLOW_COPY_AND_ASSIGN(RunLoop); | 103 DISALLOW_COPY_AND_ASSIGN(RunLoop); |
| 115 }; | 104 }; |
| 116 | 105 |
| 117 } // namespace base | 106 } // namespace base |
| 118 | 107 |
| 119 #endif // BASE_RUN_LOOP_H_ | 108 #endif // BASE_RUN_LOOP_H_ |
| OLD | NEW |