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