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 20 matching lines...) Expand all Loading... |
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 | 40 |
41 #if !defined(__OBJC__) | 41 #if defined(__OBJC__) |
42 class NSAutoreleasePool; | |
43 #else // !defined(__OBJC__) | |
44 #if defined(OS_IOS) | 42 #if defined(OS_IOS) |
45 #import <Foundation/Foundation.h> | 43 #import <Foundation/Foundation.h> |
46 #else | 44 #else |
47 #import <AppKit/AppKit.h> | 45 #import <AppKit/AppKit.h> |
48 | 46 |
49 // Clients must subclass NSApplication and implement this protocol if they use | 47 // Clients must subclass NSApplication and implement this protocol if they use |
50 // MessagePumpMac. | 48 // MessagePumpMac. |
51 @protocol CrAppProtocol | 49 @protocol CrAppProtocol |
52 // Must return true if -[NSApplication sendEvent:] is currently on the stack. | 50 // Must return true if -[NSApplication sendEvent:] is currently on the stack. |
53 // See the comment for |CreateAutoreleasePool()| in the cc file for why this is | 51 // See the comment for |CreateAutoreleasePool()| in the cc file for why this is |
54 // necessary. | 52 // necessary. |
55 - (BOOL)isHandlingSendEvent; | 53 - (BOOL)isHandlingSendEvent; |
56 @end | 54 @end |
57 #endif // !defined(OS_IOS) | 55 #endif // !defined(OS_IOS) |
58 #endif // !defined(__OBJC__) | 56 #endif // defined(__OBJC__) |
59 | 57 |
60 namespace base { | 58 namespace base { |
61 | 59 |
62 class MessagePumpInstrumentation; | 60 class MessagePumpInstrumentation; |
63 class RunLoop; | 61 class RunLoop; |
64 class TimeTicks; | 62 class TimeTicks; |
65 | 63 |
| 64 // 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 // 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 // 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 // "NSAutoreleasePool" in such TUs. Finally, in Manual Retain Release (MRR) |
| 71 // Objective-C TUs, it is a type alias for NSAutoreleasePool. In all cases, a |
| 72 // method that takes or returns an NSAutoreleasePool* can use |
| 73 // AutoreleasePoolType* instead. |
| 74 #if !defined(__OBJC__) || __has_feature(objc_arc) |
| 75 class AutoreleasePoolType; |
| 76 #else // !defined(__OBJC__) || __has_feature(objc_arc) |
| 77 typedef NSAutoreleasePool AutoreleasePoolType; |
| 78 #endif // !defined(__OBJC__) || __has_feature(objc_arc) |
| 79 |
66 class MessagePumpCFRunLoopBase : public MessagePump { | 80 class MessagePumpCFRunLoopBase : public MessagePump { |
67 // Needs access to CreateAutoreleasePool. | 81 // Needs access to CreateAutoreleasePool. |
68 friend class MessagePumpScopedAutoreleasePool; | 82 friend class MessagePumpScopedAutoreleasePool; |
69 public: | 83 public: |
70 MessagePumpCFRunLoopBase(); | 84 MessagePumpCFRunLoopBase(); |
71 virtual ~MessagePumpCFRunLoopBase(); | 85 virtual ~MessagePumpCFRunLoopBase(); |
72 | 86 |
73 // Subclasses should implement the work they need to do in MessagePump::Run | 87 // Subclasses should implement the work they need to do in MessagePump::Run |
74 // in the DoRun method. MessagePumpCFRunLoopBase::Run calls DoRun directly. | 88 // in the DoRun method. MessagePumpCFRunLoopBase::Run calls DoRun directly. |
75 // This arrangement is used because MessagePumpCFRunLoopBase needs to set | 89 // This arrangement is used because MessagePumpCFRunLoopBase needs to set |
(...skipping 11 matching lines...) Expand all Loading... |
87 int run_nesting_level() const { return run_nesting_level_; } | 101 int run_nesting_level() const { return run_nesting_level_; } |
88 | 102 |
89 // Sets this pump's delegate. Signals the appropriate sources if | 103 // Sets this pump's delegate. Signals the appropriate sources if |
90 // |delegateless_work_| is true. |delegate| can be NULL. | 104 // |delegateless_work_| is true. |delegate| can be NULL. |
91 void SetDelegate(Delegate* delegate); | 105 void SetDelegate(Delegate* delegate); |
92 | 106 |
93 // Return an autorelease pool to wrap around any work being performed. | 107 // Return an autorelease pool to wrap around any work being performed. |
94 // In some cases, CreateAutoreleasePool may return nil intentionally to | 108 // In some cases, CreateAutoreleasePool may return nil intentionally to |
95 // preventing an autorelease pool from being created, allowing any | 109 // preventing an autorelease pool from being created, allowing any |
96 // objects autoreleased by work to fall into the current autorelease pool. | 110 // objects autoreleased by work to fall into the current autorelease pool. |
97 virtual NSAutoreleasePool* CreateAutoreleasePool(); | 111 virtual AutoreleasePoolType* CreateAutoreleasePool(); |
98 | 112 |
99 // Enables instrumentation of the MessagePump. See MessagePumpInstrumentation | 113 // Enables instrumentation of the MessagePump. See MessagePumpInstrumentation |
100 // in the implementation for details. | 114 // in the implementation for details. |
101 void EnableInstrumentation(); | 115 void EnableInstrumentation(); |
102 WeakPtr<MessagePumpInstrumentation> instrumentation_; | 116 WeakPtr<MessagePumpInstrumentation> instrumentation_; |
103 | 117 |
104 private: | 118 private: |
105 // Timer callback scheduled by ScheduleDelayedWork. This does not do any | 119 // Timer callback scheduled by ScheduleDelayedWork. This does not do any |
106 // work, but it signals work_source_ so that delayed work can be performed | 120 // work, but it signals work_source_ so that delayed work can be performed |
107 // within the appropriate priority constraints. | 121 // within the appropriate priority constraints. |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 }; | 303 }; |
290 | 304 |
291 class MessagePumpCrApplication : public MessagePumpNSApplication { | 305 class MessagePumpCrApplication : public MessagePumpNSApplication { |
292 public: | 306 public: |
293 MessagePumpCrApplication(); | 307 MessagePumpCrApplication(); |
294 virtual ~MessagePumpCrApplication(); | 308 virtual ~MessagePumpCrApplication(); |
295 | 309 |
296 protected: | 310 protected: |
297 // Returns nil if NSApp is currently in the middle of calling | 311 // Returns nil if NSApp is currently in the middle of calling |
298 // -sendEvent. Requires NSApp implementing CrAppProtocol. | 312 // -sendEvent. Requires NSApp implementing CrAppProtocol. |
299 virtual NSAutoreleasePool* CreateAutoreleasePool() OVERRIDE; | 313 virtual AutoreleasePoolType* CreateAutoreleasePool() OVERRIDE; |
300 | 314 |
301 private: | 315 private: |
302 DISALLOW_COPY_AND_ASSIGN(MessagePumpCrApplication); | 316 DISALLOW_COPY_AND_ASSIGN(MessagePumpCrApplication); |
303 }; | 317 }; |
304 #endif // !defined(OS_IOS) | 318 #endif // !defined(OS_IOS) |
305 | 319 |
306 class MessagePumpMac { | 320 class MessagePumpMac { |
307 public: | 321 public: |
308 // If not on the main thread, returns a new instance of | 322 // If not on the main thread, returns a new instance of |
309 // MessagePumpNSRunLoop. | 323 // MessagePumpNSRunLoop. |
(...skipping 18 matching lines...) Expand all Loading... |
328 BASE_EXPORT static bool IsHandlingSendEvent(); | 342 BASE_EXPORT static bool IsHandlingSendEvent(); |
329 #endif // !defined(OS_IOS) | 343 #endif // !defined(OS_IOS) |
330 | 344 |
331 private: | 345 private: |
332 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac); | 346 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac); |
333 }; | 347 }; |
334 | 348 |
335 } // namespace base | 349 } // namespace base |
336 | 350 |
337 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_MAC_H_ | 351 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_MAC_H_ |
OLD | NEW |