| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
| 11 // MessagePump interface called CFRunLoopBase. CFRunLoopBase contains all | 11 // MessagePump interface called CFRunLoopBase. CFRunLoopBase contains all |
| (...skipping 15 matching lines...) Expand all Loading... |
| 27 // or NSRunLoop-based MessagePump subclass depending on which thread it is | 27 // or NSRunLoop-based MessagePump subclass depending on which thread it is |
| 28 // called on. | 28 // called on. |
| 29 | 29 |
| 30 #ifndef BASE_MESSAGE_PUMP_MAC_H_ | 30 #ifndef BASE_MESSAGE_PUMP_MAC_H_ |
| 31 #define BASE_MESSAGE_PUMP_MAC_H_ | 31 #define BASE_MESSAGE_PUMP_MAC_H_ |
| 32 #pragma once | 32 #pragma once |
| 33 | 33 |
| 34 #include "base/message_pump.h" | 34 #include "base/message_pump.h" |
| 35 | 35 |
| 36 #include <CoreFoundation/CoreFoundation.h> | 36 #include <CoreFoundation/CoreFoundation.h> |
| 37 #include <IOKit/IOKitLib.h> | |
| 38 | 37 |
| 39 #if !defined(__OBJC__) | 38 #if !defined(__OBJC__) |
| 40 class NSAutoreleasePool; | 39 class NSAutoreleasePool; |
| 41 #else // !defined(__OBJC__) | 40 #else // !defined(__OBJC__) |
| 42 #import <AppKit/AppKit.h> | 41 #import <AppKit/AppKit.h> |
| 43 | 42 |
| 44 // Clients must subclass NSApplication and implement this protocol if they use | 43 // Clients must subclass NSApplication and implement this protocol if they use |
| 45 // MessagePumpMac. | 44 // MessagePumpMac. |
| 46 @protocol CrAppProtocol | 45 @protocol CrAppProtocol |
| 47 // Must return true if -[NSApplication sendEvent:] is currently on the stack. | 46 // Must return true if -[NSApplication sendEvent:] is currently on the stack. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // beginning and end of calls to CFRunLoopRun. This is used to maintain | 134 // beginning and end of calls to CFRunLoopRun. This is used to maintain |
| 136 // nesting_level_. Associated with enter_exit_observer_. | 135 // nesting_level_. Associated with enter_exit_observer_. |
| 137 static void EnterExitObserver(CFRunLoopObserverRef observer, | 136 static void EnterExitObserver(CFRunLoopObserverRef observer, |
| 138 CFRunLoopActivity activity, void* info); | 137 CFRunLoopActivity activity, void* info); |
| 139 | 138 |
| 140 // Called by EnterExitObserver after performing maintenance on nesting_level_. | 139 // Called by EnterExitObserver after performing maintenance on nesting_level_. |
| 141 // This allows subclasses an opportunity to perform additional processing on | 140 // This allows subclasses an opportunity to perform additional processing on |
| 142 // the basis of run loops starting and stopping. | 141 // the basis of run loops starting and stopping. |
| 143 virtual void EnterExitRunLoop(CFRunLoopActivity activity); | 142 virtual void EnterExitRunLoop(CFRunLoopActivity activity); |
| 144 | 143 |
| 145 // IOKit power state change notification callback, called when the system | |
| 146 // enters and leaves the sleep state. | |
| 147 static void PowerStateNotification(void* info, io_service_t service, | |
| 148 uint32_t message_type, | |
| 149 void* message_argument); | |
| 150 | |
| 151 // The thread's run loop. | 144 // The thread's run loop. |
| 152 CFRunLoopRef run_loop_; | 145 CFRunLoopRef run_loop_; |
| 153 | 146 |
| 154 // The timer, sources, and observers are described above alongside their | 147 // The timer, sources, and observers are described above alongside their |
| 155 // callbacks. | 148 // callbacks. |
| 156 CFRunLoopTimerRef delayed_work_timer_; | 149 CFRunLoopTimerRef delayed_work_timer_; |
| 157 CFRunLoopSourceRef work_source_; | 150 CFRunLoopSourceRef work_source_; |
| 158 CFRunLoopSourceRef idle_work_source_; | 151 CFRunLoopSourceRef idle_work_source_; |
| 159 CFRunLoopSourceRef nesting_deferred_work_source_; | 152 CFRunLoopSourceRef nesting_deferred_work_source_; |
| 160 CFRunLoopObserverRef pre_wait_observer_; | 153 CFRunLoopObserverRef pre_wait_observer_; |
| 161 CFRunLoopObserverRef pre_source_observer_; | 154 CFRunLoopObserverRef pre_source_observer_; |
| 162 CFRunLoopObserverRef enter_exit_observer_; | 155 CFRunLoopObserverRef enter_exit_observer_; |
| 163 | 156 |
| 164 // Objects used for power state notification. See PowerStateNotification. | |
| 165 io_connect_t root_power_domain_; | |
| 166 IONotificationPortRef power_notification_port_; | |
| 167 io_object_t power_notification_object_; | |
| 168 | |
| 169 // (weak) Delegate passed as an argument to the innermost Run call. | 157 // (weak) Delegate passed as an argument to the innermost Run call. |
| 170 Delegate* delegate_; | 158 Delegate* delegate_; |
| 171 | 159 |
| 172 // The time that delayed_work_timer_ is scheduled to fire. This is tracked | 160 // The time that delayed_work_timer_ is scheduled to fire. This is tracked |
| 173 // independently of CFRunLoopTimerGetNextFireDate(delayed_work_timer_) | 161 // independently of CFRunLoopTimerGetNextFireDate(delayed_work_timer_) |
| 174 // to be able to reset the timer properly after waking from system sleep. | 162 // to be able to reset the timer properly after waking from system sleep. |
| 175 // See PowerStateNotification. | 163 // See PowerStateNotification. |
| 176 CFAbsoluteTime delayed_work_fire_time_; | 164 CFAbsoluteTime delayed_work_fire_time_; |
| 177 | 165 |
| 178 // The recursion depth of the currently-executing CFRunLoopRun loop on the | 166 // The recursion depth of the currently-executing CFRunLoopRun loop on the |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // thread. Otherwise, returns a new instance of MessagePumpNSRunLoop. | 255 // thread. Otherwise, returns a new instance of MessagePumpNSRunLoop. |
| 268 static MessagePump* Create(); | 256 static MessagePump* Create(); |
| 269 | 257 |
| 270 private: | 258 private: |
| 271 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac); | 259 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac); |
| 272 }; | 260 }; |
| 273 | 261 |
| 274 } // namespace base | 262 } // namespace base |
| 275 | 263 |
| 276 #endif // BASE_MESSAGE_PUMP_MAC_H_ | 264 #endif // BASE_MESSAGE_PUMP_MAC_H_ |
| OLD | NEW |