OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 int run_nesting_level() const { return run_nesting_level_; } | 79 int run_nesting_level() const { return run_nesting_level_; } |
80 | 80 |
81 // Return an autorelease pool to wrap around any work being performed. | 81 // Return an autorelease pool to wrap around any work being performed. |
82 // In some cases, CreateAutoreleasePool may return nil intentionally to | 82 // In some cases, CreateAutoreleasePool may return nil intentionally to |
83 // preventing an autorelease pool from being created, allowing any | 83 // preventing an autorelease pool from being created, allowing any |
84 // objects autoreleased by work to fall into the current autorelease pool. | 84 // objects autoreleased by work to fall into the current autorelease pool. |
85 virtual NSAutoreleasePool* CreateAutoreleasePool(); | 85 virtual NSAutoreleasePool* CreateAutoreleasePool(); |
86 | 86 |
87 private: | 87 private: |
88 // Timer callback scheduled by ScheduleDelayedWork. This does not do any | 88 // Timer callback scheduled by ScheduleDelayedWork. This does not do any |
89 // work, but it signals delayed_work_source_ so that delayed work can be | 89 // work, but it signals work_source_ so that delayed work can be performed |
90 // performed within the appropriate priority constraints. | 90 // within the appropriate priority constraints. |
91 static void RunDelayedWorkTimer(CFRunLoopTimerRef timer, void* info); | 91 static void RunDelayedWorkTimer(CFRunLoopTimerRef timer, void* info); |
92 | 92 |
93 // Perform highest-priority work. This is associated with work_source_ | 93 // Perform highest-priority work. This is associated with work_source_ |
94 // signalled by ScheduleWork. The static method calls the instance method; | 94 // signalled by ScheduleWork or RunDelayedWorkTimer. The static method calls |
95 // the instance method returns true if work was done. | 95 // the instance method; the instance method returns true if it resignalled |
| 96 // work_source_ to be called again from the loop. |
96 static void RunWorkSource(void* info); | 97 static void RunWorkSource(void* info); |
97 bool RunWork(); | 98 bool RunWork(); |
98 | 99 |
99 // Perform delayed-priority work. This is associated with | |
100 // delayed_work_source_ signalled by RunDelayedWorkTimer, and is responsible | |
101 // for calling ScheduleDelayedWork again if appropriate. The static method | |
102 // calls the instance method; the instance method returns true if more | |
103 // delayed work is available. | |
104 static void RunDelayedWorkSource(void* info); | |
105 bool RunDelayedWork(); | |
106 | |
107 // Perform idle-priority work. This is normally called by PreWaitObserver, | 100 // Perform idle-priority work. This is normally called by PreWaitObserver, |
108 // but is also associated with idle_work_source_. When this function | 101 // but is also associated with idle_work_source_. When this function |
109 // actually does perform idle work, it will resignal that source. The | 102 // actually does perform idle work, it will resignal that source. The |
110 // static method calls the instance method; the instance method returns | 103 // static method calls the instance method; the instance method returns |
111 // true if idle work was done. | 104 // true if idle work was done. |
112 static void RunIdleWorkSource(void* info); | 105 static void RunIdleWorkSource(void* info); |
113 bool RunIdleWork(); | 106 bool RunIdleWork(); |
114 | 107 |
115 // Perform work that may have been deferred because it was not runnable | 108 // Perform work that may have been deferred because it was not runnable |
116 // within a nested run loop. This is associated with | 109 // within a nested run loop. This is associated with |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 uint32_t message_type, | 148 uint32_t message_type, |
156 void* message_argument); | 149 void* message_argument); |
157 | 150 |
158 // The thread's run loop. | 151 // The thread's run loop. |
159 CFRunLoopRef run_loop_; | 152 CFRunLoopRef run_loop_; |
160 | 153 |
161 // The timer, sources, and observers are described above alongside their | 154 // The timer, sources, and observers are described above alongside their |
162 // callbacks. | 155 // callbacks. |
163 CFRunLoopTimerRef delayed_work_timer_; | 156 CFRunLoopTimerRef delayed_work_timer_; |
164 CFRunLoopSourceRef work_source_; | 157 CFRunLoopSourceRef work_source_; |
165 CFRunLoopSourceRef delayed_work_source_; | |
166 CFRunLoopSourceRef idle_work_source_; | 158 CFRunLoopSourceRef idle_work_source_; |
167 CFRunLoopSourceRef nesting_deferred_work_source_; | 159 CFRunLoopSourceRef nesting_deferred_work_source_; |
168 CFRunLoopObserverRef pre_wait_observer_; | 160 CFRunLoopObserverRef pre_wait_observer_; |
169 CFRunLoopObserverRef pre_source_observer_; | 161 CFRunLoopObserverRef pre_source_observer_; |
170 CFRunLoopObserverRef enter_exit_observer_; | 162 CFRunLoopObserverRef enter_exit_observer_; |
171 | 163 |
172 // Objects used for power state notification. See PowerStateNotification. | 164 // Objects used for power state notification. See PowerStateNotification. |
173 io_connect_t root_power_domain_; | 165 io_connect_t root_power_domain_; |
174 IONotificationPortRef power_notification_port_; | 166 IONotificationPortRef power_notification_port_; |
175 io_object_t power_notification_object_; | 167 io_object_t power_notification_object_; |
(...skipping 19 matching lines...) Expand all Loading... |
195 // The deepest (numerically highest) recursion depth encountered since the | 187 // The deepest (numerically highest) recursion depth encountered since the |
196 // most recent attempt to run nesting-deferred work. | 188 // most recent attempt to run nesting-deferred work. |
197 int deepest_nesting_level_; | 189 int deepest_nesting_level_; |
198 | 190 |
199 // "Delegateless" work flags are set when work is ready to be performed but | 191 // "Delegateless" work flags are set when work is ready to be performed but |
200 // must wait until a delegate is available to process it. This can happen | 192 // must wait until a delegate is available to process it. This can happen |
201 // when a MessagePumpCFRunLoopBase is instantiated and work arrives without | 193 // when a MessagePumpCFRunLoopBase is instantiated and work arrives without |
202 // any call to Run on the stack. The Run method will check for delegateless | 194 // any call to Run on the stack. The Run method will check for delegateless |
203 // work on entry and redispatch it as needed once a delegate is available. | 195 // work on entry and redispatch it as needed once a delegate is available. |
204 bool delegateless_work_; | 196 bool delegateless_work_; |
205 bool delegateless_delayed_work_; | |
206 bool delegateless_idle_work_; | 197 bool delegateless_idle_work_; |
207 | 198 |
208 DISALLOW_COPY_AND_ASSIGN(MessagePumpCFRunLoopBase); | 199 DISALLOW_COPY_AND_ASSIGN(MessagePumpCFRunLoopBase); |
209 }; | 200 }; |
210 | 201 |
211 class MessagePumpCFRunLoop : public MessagePumpCFRunLoopBase { | 202 class MessagePumpCFRunLoop : public MessagePumpCFRunLoopBase { |
212 public: | 203 public: |
213 MessagePumpCFRunLoop(); | 204 MessagePumpCFRunLoop(); |
214 | 205 |
215 virtual void DoRun(Delegate* delegate); | 206 virtual void DoRun(Delegate* delegate); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 // thread. Otherwise, returns a new instance of MessagePumpNSRunLoop. | 267 // thread. Otherwise, returns a new instance of MessagePumpNSRunLoop. |
277 static MessagePump* Create(); | 268 static MessagePump* Create(); |
278 | 269 |
279 private: | 270 private: |
280 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac); | 271 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac); |
281 }; | 272 }; |
282 | 273 |
283 } // namespace base | 274 } // namespace base |
284 | 275 |
285 #endif // BASE_MESSAGE_PUMP_MAC_H_ | 276 #endif // BASE_MESSAGE_PUMP_MAC_H_ |
OLD | NEW |