| 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 // The basis for all native run loops on the Mac is the CFRunLoop. It can be | 5 // The basis for all native run loops on the Mac is the CFRunLoop. It can be |
| 6 // used directly, it can be used as the driving force behind the similar | 6 // used directly, it can be used as the driving force behind the similar |
| 7 // Foundation NSRunLoop, and it can be used to implement higher-level event | 7 // Foundation NSRunLoop, and it can be used to implement higher-level event |
| 8 // loops such as the NSApplication event loop. | 8 // loops such as the NSApplication event loop. |
| 9 // | 9 // |
| 10 // This file introduces a basic CFRunLoop-based implementation of the | 10 // This file introduces a basic CFRunLoop-based implementation of the |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // Must return true if -[NSApplication sendEvent:] is currently on the stack. | 51 // Must return true if -[NSApplication sendEvent:] is currently on the stack. |
| 52 // See the comment for |CreateAutoreleasePool()| in the cc file for why this is | 52 // See the comment for |CreateAutoreleasePool()| in the cc file for why this is |
| 53 // necessary. | 53 // necessary. |
| 54 - (BOOL)isHandlingSendEvent; | 54 - (BOOL)isHandlingSendEvent; |
| 55 @end | 55 @end |
| 56 #endif // !defined(OS_IOS) | 56 #endif // !defined(OS_IOS) |
| 57 #endif // defined(__OBJC__) | 57 #endif // defined(__OBJC__) |
| 58 | 58 |
| 59 namespace base { | 59 namespace base { |
| 60 | 60 |
| 61 class MessagePumpInstrumentation; | |
| 62 class RunLoop; | 61 class RunLoop; |
| 63 class TimeTicks; | 62 class TimeTicks; |
| 64 | 63 |
| 65 // AutoreleasePoolType is a proxy type for autorelease pools. Its definition | 64 // AutoreleasePoolType is a proxy type for autorelease pools. Its definition |
| 66 // depends on the translation unit (TU) in which this header appears. In pure | 65 // depends on the translation unit (TU) in which this header appears. In pure |
| 67 // C++ TUs, it is defined as a forward C++ class declaration (that is never | 66 // C++ TUs, it is defined as a forward C++ class declaration (that is never |
| 68 // defined), because autorelease pools are an Objective-C concept. In Automatic | 67 // defined), because autorelease pools are an Objective-C concept. In Automatic |
| 69 // Reference Counting (ARC) Objective-C TUs, it is similarly defined as a | 68 // Reference Counting (ARC) Objective-C TUs, it is similarly defined as a |
| 70 // forward C++ class declaration, because clang will not allow the type | 69 // forward C++ class declaration, because clang will not allow the type |
| 71 // "NSAutoreleasePool" in such TUs. Finally, in Manual Retain Release (MRR) | 70 // "NSAutoreleasePool" in such TUs. Finally, in Manual Retain Release (MRR) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // Sets this pump's delegate. Signals the appropriate sources if | 104 // Sets this pump's delegate. Signals the appropriate sources if |
| 106 // |delegateless_work_| is true. |delegate| can be NULL. | 105 // |delegateless_work_| is true. |delegate| can be NULL. |
| 107 void SetDelegate(Delegate* delegate); | 106 void SetDelegate(Delegate* delegate); |
| 108 | 107 |
| 109 // Return an autorelease pool to wrap around any work being performed. | 108 // Return an autorelease pool to wrap around any work being performed. |
| 110 // In some cases, CreateAutoreleasePool may return nil intentionally to | 109 // In some cases, CreateAutoreleasePool may return nil intentionally to |
| 111 // preventing an autorelease pool from being created, allowing any | 110 // preventing an autorelease pool from being created, allowing any |
| 112 // objects autoreleased by work to fall into the current autorelease pool. | 111 // objects autoreleased by work to fall into the current autorelease pool. |
| 113 virtual AutoreleasePoolType* CreateAutoreleasePool(); | 112 virtual AutoreleasePoolType* CreateAutoreleasePool(); |
| 114 | 113 |
| 115 // Enables instrumentation of the MessagePump. See MessagePumpInstrumentation | |
| 116 // in the implementation for details. | |
| 117 void EnableInstrumentation(); | |
| 118 WeakPtr<MessagePumpInstrumentation> instrumentation_; | |
| 119 | |
| 120 private: | 114 private: |
| 121 // Timer callback scheduled by ScheduleDelayedWork. This does not do any | 115 // Timer callback scheduled by ScheduleDelayedWork. This does not do any |
| 122 // work, but it signals work_source_ so that delayed work can be performed | 116 // work, but it signals work_source_ so that delayed work can be performed |
| 123 // within the appropriate priority constraints. | 117 // within the appropriate priority constraints. |
| 124 static void RunDelayedWorkTimer(CFRunLoopTimerRef timer, void* info); | 118 static void RunDelayedWorkTimer(CFRunLoopTimerRef timer, void* info); |
| 125 | 119 |
| 126 // Perform highest-priority work. This is associated with work_source_ | 120 // Perform highest-priority work. This is associated with work_source_ |
| 127 // signalled by ScheduleWork or RunDelayedWorkTimer. The static method calls | 121 // signalled by ScheduleWork or RunDelayedWorkTimer. The static method calls |
| 128 // the instance method; the instance method returns true if it resignalled | 122 // the instance method; the instance method returns true if it resignalled |
| 129 // work_source_ to be called again from the loop. | 123 // work_source_ to be called again from the loop. |
| 130 static void RunWorkSource(void* info); | 124 static void RunWorkSource(void* info); |
| 131 bool RunWork(); | 125 bool RunWork(); |
| 132 | 126 |
| 133 // Perform idle-priority work. This is normally called by | 127 // Perform idle-priority work. This is normally called by PreWaitObserver, |
| 134 // StartOrEndWaitObserver, but is also associated with idle_work_source_. When | 128 // but is also associated with idle_work_source_. When this function |
| 135 // this function actually does perform idle work, it will resignal that | 129 // actually does perform idle work, it will resignal that source. The |
| 136 // source. The static method calls the instance method; the instance method | 130 // static method calls the instance method; the instance method returns |
| 137 // returns true if idle work was done. | 131 // true if idle work was done. |
| 138 static void RunIdleWorkSource(void* info); | 132 static void RunIdleWorkSource(void* info); |
| 139 bool RunIdleWork(); | 133 bool RunIdleWork(); |
| 140 | 134 |
| 141 // Perform work that may have been deferred because it was not runnable | 135 // Perform work that may have been deferred because it was not runnable |
| 142 // within a nested run loop. This is associated with | 136 // within a nested run loop. This is associated with |
| 143 // nesting_deferred_work_source_ and is signalled by | 137 // nesting_deferred_work_source_ and is signalled by |
| 144 // MaybeScheduleNestingDeferredWork when returning from a nested loop, | 138 // MaybeScheduleNestingDeferredWork when returning from a nested loop, |
| 145 // so that an outer loop will be able to perform the necessary tasks if it | 139 // so that an outer loop will be able to perform the necessary tasks if it |
| 146 // permits nestable tasks. | 140 // permits nestable tasks. |
| 147 static void RunNestingDeferredWorkSource(void* info); | 141 static void RunNestingDeferredWorkSource(void* info); |
| 148 bool RunNestingDeferredWork(); | 142 bool RunNestingDeferredWork(); |
| 149 | 143 |
| 150 // Schedules possible nesting-deferred work to be processed before the run | 144 // Schedules possible nesting-deferred work to be processed before the run |
| 151 // loop goes to sleep, exits, or begins processing sources at the top of its | 145 // loop goes to sleep, exits, or begins processing sources at the top of its |
| 152 // loop. If this function detects that a nested loop had run since the | 146 // loop. If this function detects that a nested loop had run since the |
| 153 // previous attempt to schedule nesting-deferred work, it will schedule a | 147 // previous attempt to schedule nesting-deferred work, it will schedule a |
| 154 // call to RunNestingDeferredWorkSource. | 148 // call to RunNestingDeferredWorkSource. |
| 155 void MaybeScheduleNestingDeferredWork(); | 149 void MaybeScheduleNestingDeferredWork(); |
| 156 | 150 |
| 157 // Observer callback responsible for performing idle-priority work, before | 151 // Observer callback responsible for performing idle-priority work, before |
| 158 // the run loop goes to sleep. Associated with idle_work_observer_. | 152 // the run loop goes to sleep. Associated with idle_work_observer_. |
| 159 static void StartOrEndWaitObserver(CFRunLoopObserverRef observer, | 153 static void PreWaitObserver(CFRunLoopObserverRef observer, |
| 160 CFRunLoopActivity activity, void* info); | 154 CFRunLoopActivity activity, void* info); |
| 161 | 155 |
| 162 // Observer callback called before the run loop processes any sources. | 156 // Observer callback called before the run loop processes any sources. |
| 163 // Associated with pre_source_observer_. | 157 // Associated with pre_source_observer_. |
| 164 static void PreSourceObserver(CFRunLoopObserverRef observer, | 158 static void PreSourceObserver(CFRunLoopObserverRef observer, |
| 165 CFRunLoopActivity activity, void* info); | 159 CFRunLoopActivity activity, void* info); |
| 166 | 160 |
| 167 // Observer callback called when the run loop starts and stops, at the | 161 // Observer callback called when the run loop starts and stops, at the |
| 168 // beginning and end of calls to CFRunLoopRun. This is used to maintain | 162 // beginning and end of calls to CFRunLoopRun. This is used to maintain |
| 169 // nesting_level_. Associated with enter_exit_observer_. | 163 // nesting_level_. Associated with enter_exit_observer_. |
| 170 static void EnterExitObserver(CFRunLoopObserverRef observer, | 164 static void EnterExitObserver(CFRunLoopObserverRef observer, |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac); | 344 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac); |
| 351 }; | 345 }; |
| 352 | 346 |
| 353 // Tasks posted to the message loop are posted under this mode, as well | 347 // Tasks posted to the message loop are posted under this mode, as well |
| 354 // as kCFRunLoopCommonModes. | 348 // as kCFRunLoopCommonModes. |
| 355 extern const CFStringRef BASE_EXPORT kMessageLoopExclusiveRunLoopMode; | 349 extern const CFStringRef BASE_EXPORT kMessageLoopExclusiveRunLoopMode; |
| 356 | 350 |
| 357 } // namespace base | 351 } // namespace base |
| 358 | 352 |
| 359 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_MAC_H_ | 353 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_MAC_H_ |
| OLD | NEW |