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 19 matching lines...) Expand all Loading... |
30 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_MAC_H_ | 30 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_MAC_H_ |
31 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_MAC_H_ | 31 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_MAC_H_ |
32 | 32 |
33 #include "base/message_loop/message_pump.h" | 33 #include "base/message_loop/message_pump.h" |
34 | 34 |
35 #include "base/basictypes.h" | 35 #include "base/basictypes.h" |
36 | 36 |
37 #include <CoreFoundation/CoreFoundation.h> | 37 #include <CoreFoundation/CoreFoundation.h> |
38 | 38 |
39 #include "base/memory/weak_ptr.h" | 39 #include "base/memory/weak_ptr.h" |
| 40 #include "base/message_loop/timer_slack.h" |
40 | 41 |
41 #if defined(__OBJC__) | 42 #if defined(__OBJC__) |
42 #if defined(OS_IOS) | 43 #if defined(OS_IOS) |
43 #import <Foundation/Foundation.h> | 44 #import <Foundation/Foundation.h> |
44 #else | 45 #else |
45 #import <AppKit/AppKit.h> | 46 #import <AppKit/AppKit.h> |
46 | 47 |
47 // Clients must subclass NSApplication and implement this protocol if they use | 48 // Clients must subclass NSApplication and implement this protocol if they use |
48 // MessagePumpMac. | 49 // MessagePumpMac. |
49 @protocol CrAppProtocol | 50 @protocol CrAppProtocol |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 87 |
87 // Subclasses should implement the work they need to do in MessagePump::Run | 88 // Subclasses should implement the work they need to do in MessagePump::Run |
88 // in the DoRun method. MessagePumpCFRunLoopBase::Run calls DoRun directly. | 89 // in the DoRun method. MessagePumpCFRunLoopBase::Run calls DoRun directly. |
89 // This arrangement is used because MessagePumpCFRunLoopBase needs to set | 90 // This arrangement is used because MessagePumpCFRunLoopBase needs to set |
90 // up and tear down things before and after the "meat" of DoRun. | 91 // up and tear down things before and after the "meat" of DoRun. |
91 virtual void Run(Delegate* delegate) OVERRIDE; | 92 virtual void Run(Delegate* delegate) OVERRIDE; |
92 virtual void DoRun(Delegate* delegate) = 0; | 93 virtual void DoRun(Delegate* delegate) = 0; |
93 | 94 |
94 virtual void ScheduleWork() OVERRIDE; | 95 virtual void ScheduleWork() OVERRIDE; |
95 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) OVERRIDE; | 96 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) OVERRIDE; |
| 97 virtual void SetTimerSlack(TimerSlack timer_slack) OVERRIDE; |
96 | 98 |
97 protected: | 99 protected: |
98 // Accessors for private data members to be used by subclasses. | 100 // Accessors for private data members to be used by subclasses. |
99 CFRunLoopRef run_loop() const { return run_loop_; } | 101 CFRunLoopRef run_loop() const { return run_loop_; } |
100 int nesting_level() const { return nesting_level_; } | 102 int nesting_level() const { return nesting_level_; } |
101 int run_nesting_level() const { return run_nesting_level_; } | 103 int run_nesting_level() const { return run_nesting_level_; } |
102 | 104 |
103 // Sets this pump's delegate. Signals the appropriate sources if | 105 // Sets this pump's delegate. Signals the appropriate sources if |
104 // |delegateless_work_| is true. |delegate| can be NULL. | 106 // |delegateless_work_| is true. |delegate| can be NULL. |
105 void SetDelegate(Delegate* delegate); | 107 void SetDelegate(Delegate* delegate); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 190 |
189 // (weak) Delegate passed as an argument to the innermost Run call. | 191 // (weak) Delegate passed as an argument to the innermost Run call. |
190 Delegate* delegate_; | 192 Delegate* delegate_; |
191 | 193 |
192 // The time that delayed_work_timer_ is scheduled to fire. This is tracked | 194 // The time that delayed_work_timer_ is scheduled to fire. This is tracked |
193 // independently of CFRunLoopTimerGetNextFireDate(delayed_work_timer_) | 195 // independently of CFRunLoopTimerGetNextFireDate(delayed_work_timer_) |
194 // to be able to reset the timer properly after waking from system sleep. | 196 // to be able to reset the timer properly after waking from system sleep. |
195 // See PowerStateNotification. | 197 // See PowerStateNotification. |
196 CFAbsoluteTime delayed_work_fire_time_; | 198 CFAbsoluteTime delayed_work_fire_time_; |
197 | 199 |
| 200 base::TimerSlack timer_slack_; |
| 201 |
198 // The recursion depth of the currently-executing CFRunLoopRun loop on the | 202 // The recursion depth of the currently-executing CFRunLoopRun loop on the |
199 // run loop's thread. 0 if no run loops are running inside of whatever scope | 203 // run loop's thread. 0 if no run loops are running inside of whatever scope |
200 // the object was created in. | 204 // the object was created in. |
201 int nesting_level_; | 205 int nesting_level_; |
202 | 206 |
203 // The recursion depth (calculated in the same way as nesting_level_) of the | 207 // The recursion depth (calculated in the same way as nesting_level_) of the |
204 // innermost executing CFRunLoopRun loop started by a call to Run. | 208 // innermost executing CFRunLoopRun loop started by a call to Run. |
205 int run_nesting_level_; | 209 int run_nesting_level_; |
206 | 210 |
207 // The deepest (numerically highest) recursion depth encountered since the | 211 // The deepest (numerically highest) recursion depth encountered since the |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 static bool IsHandlingSendEvent(); | 346 static bool IsHandlingSendEvent(); |
343 #endif // !defined(OS_IOS) | 347 #endif // !defined(OS_IOS) |
344 | 348 |
345 private: | 349 private: |
346 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac); | 350 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac); |
347 }; | 351 }; |
348 | 352 |
349 } // namespace base | 353 } // namespace base |
350 | 354 |
351 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_MAC_H_ | 355 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_MAC_H_ |
OLD | NEW |