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 TU in which this header appears. In pure C++ TUs, it is | |
Mark Mentovai
2014/04/29 02:07:03
TU is not a commonly-understood abbreviation. Say
| |
66 // defined as a forward C++ class declaration (that is never defined), because | |
67 // autorelease pools are an Objective-C concept. In Automatic Reference Counting | |
68 // (ARC) Objective-C TUs, it is similarly defined as a forward C++ class | |
69 // declaration, because clang will not allow the type "NSAutoreleasePool" in | |
70 // such TUs. Finally, in Manual Retain Release (MRR) Objective-C TUs, it is a | |
71 // type alias for NSAutoreleasePool. In all cases, a method that takes or | |
72 // returns an NSAutoreleasePool* can use AutoreleasePoolType* instead. | |
73 #if !defined(__OBJC__) || __has_feature(objc_arc) | |
74 class AutoreleasePoolType; | |
75 #else // !defined(__OBJC__) || __has_feature(objc_arc) | |
76 typedef NSAutoreleasePool AutoreleasePoolType; | |
77 #endif // !defined(__OBJC__) || __has_feature(objc_arc) | |
78 | |
66 class MessagePumpCFRunLoopBase : public MessagePump { | 79 class MessagePumpCFRunLoopBase : public MessagePump { |
67 // Needs access to CreateAutoreleasePool. | 80 // Needs access to CreateAutoreleasePool. |
68 friend class MessagePumpScopedAutoreleasePool; | 81 friend class MessagePumpScopedAutoreleasePool; |
69 public: | 82 public: |
70 MessagePumpCFRunLoopBase(); | 83 MessagePumpCFRunLoopBase(); |
71 virtual ~MessagePumpCFRunLoopBase(); | 84 virtual ~MessagePumpCFRunLoopBase(); |
72 | 85 |
73 // Subclasses should implement the work they need to do in MessagePump::Run | 86 // Subclasses should implement the work they need to do in MessagePump::Run |
74 // in the DoRun method. MessagePumpCFRunLoopBase::Run calls DoRun directly. | 87 // in the DoRun method. MessagePumpCFRunLoopBase::Run calls DoRun directly. |
75 // This arrangement is used because MessagePumpCFRunLoopBase needs to set | 88 // 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_; } | 100 int run_nesting_level() const { return run_nesting_level_; } |
88 | 101 |
89 // Sets this pump's delegate. Signals the appropriate sources if | 102 // Sets this pump's delegate. Signals the appropriate sources if |
90 // |delegateless_work_| is true. |delegate| can be NULL. | 103 // |delegateless_work_| is true. |delegate| can be NULL. |
91 void SetDelegate(Delegate* delegate); | 104 void SetDelegate(Delegate* delegate); |
92 | 105 |
93 // Return an autorelease pool to wrap around any work being performed. | 106 // Return an autorelease pool to wrap around any work being performed. |
94 // In some cases, CreateAutoreleasePool may return nil intentionally to | 107 // In some cases, CreateAutoreleasePool may return nil intentionally to |
95 // preventing an autorelease pool from being created, allowing any | 108 // preventing an autorelease pool from being created, allowing any |
96 // objects autoreleased by work to fall into the current autorelease pool. | 109 // objects autoreleased by work to fall into the current autorelease pool. |
97 virtual NSAutoreleasePool* CreateAutoreleasePool(); | 110 virtual AutoreleasePoolType* CreateAutoreleasePool(); |
98 | 111 |
99 // Enables instrumentation of the MessagePump. See MessagePumpInstrumentation | 112 // Enables instrumentation of the MessagePump. See MessagePumpInstrumentation |
100 // in the implementation for details. | 113 // in the implementation for details. |
101 void EnableInstrumentation(); | 114 void EnableInstrumentation(); |
102 WeakPtr<MessagePumpInstrumentation> instrumentation_; | 115 WeakPtr<MessagePumpInstrumentation> instrumentation_; |
103 | 116 |
104 private: | 117 private: |
105 // Timer callback scheduled by ScheduleDelayedWork. This does not do any | 118 // Timer callback scheduled by ScheduleDelayedWork. This does not do any |
106 // work, but it signals work_source_ so that delayed work can be performed | 119 // work, but it signals work_source_ so that delayed work can be performed |
107 // within the appropriate priority constraints. | 120 // within the appropriate priority constraints. |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 }; | 302 }; |
290 | 303 |
291 class MessagePumpCrApplication : public MessagePumpNSApplication { | 304 class MessagePumpCrApplication : public MessagePumpNSApplication { |
292 public: | 305 public: |
293 MessagePumpCrApplication(); | 306 MessagePumpCrApplication(); |
294 virtual ~MessagePumpCrApplication(); | 307 virtual ~MessagePumpCrApplication(); |
295 | 308 |
296 protected: | 309 protected: |
297 // Returns nil if NSApp is currently in the middle of calling | 310 // Returns nil if NSApp is currently in the middle of calling |
298 // -sendEvent. Requires NSApp implementing CrAppProtocol. | 311 // -sendEvent. Requires NSApp implementing CrAppProtocol. |
299 virtual NSAutoreleasePool* CreateAutoreleasePool() OVERRIDE; | 312 virtual AutoreleasePoolType* CreateAutoreleasePool() OVERRIDE; |
300 | 313 |
301 private: | 314 private: |
302 DISALLOW_COPY_AND_ASSIGN(MessagePumpCrApplication); | 315 DISALLOW_COPY_AND_ASSIGN(MessagePumpCrApplication); |
303 }; | 316 }; |
304 #endif // !defined(OS_IOS) | 317 #endif // !defined(OS_IOS) |
305 | 318 |
306 class MessagePumpMac { | 319 class MessagePumpMac { |
307 public: | 320 public: |
308 // If not on the main thread, returns a new instance of | 321 // If not on the main thread, returns a new instance of |
309 // MessagePumpNSRunLoop. | 322 // MessagePumpNSRunLoop. |
(...skipping 18 matching lines...) Expand all Loading... | |
328 BASE_EXPORT static bool IsHandlingSendEvent(); | 341 BASE_EXPORT static bool IsHandlingSendEvent(); |
329 #endif // !defined(OS_IOS) | 342 #endif // !defined(OS_IOS) |
330 | 343 |
331 private: | 344 private: |
332 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac); | 345 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac); |
333 }; | 346 }; |
334 | 347 |
335 } // namespace base | 348 } // namespace base |
336 | 349 |
337 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_MAC_H_ | 350 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_MAC_H_ |
OLD | NEW |