| 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 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 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" |
| 40 |
| 39 #if !defined(__OBJC__) | 41 #if !defined(__OBJC__) |
| 40 class NSAutoreleasePool; | 42 class NSAutoreleasePool; |
| 41 #else // !defined(__OBJC__) | 43 #else // !defined(__OBJC__) |
| 42 #if defined(OS_IOS) | 44 #if defined(OS_IOS) |
| 43 #import <Foundation/Foundation.h> | 45 #import <Foundation/Foundation.h> |
| 44 #else | 46 #else |
| 45 #import <AppKit/AppKit.h> | 47 #import <AppKit/AppKit.h> |
| 46 | 48 |
| 47 // Clients must subclass NSApplication and implement this protocol if they use | 49 // Clients must subclass NSApplication and implement this protocol if they use |
| 48 // MessagePumpMac. | 50 // MessagePumpMac. |
| 49 @protocol CrAppProtocol | 51 @protocol CrAppProtocol |
| 50 // Must return true if -[NSApplication sendEvent:] is currently on the stack. | 52 // Must return true if -[NSApplication sendEvent:] is currently on the stack. |
| 51 // See the comment for |CreateAutoreleasePool()| in the cc file for why this is | 53 // See the comment for |CreateAutoreleasePool()| in the cc file for why this is |
| 52 // necessary. | 54 // necessary. |
| 53 - (BOOL)isHandlingSendEvent; | 55 - (BOOL)isHandlingSendEvent; |
| 54 @end | 56 @end |
| 55 #endif // !defined(OS_IOS) | 57 #endif // !defined(OS_IOS) |
| 56 #endif // !defined(__OBJC__) | 58 #endif // !defined(__OBJC__) |
| 57 | 59 |
| 58 namespace base { | 60 namespace base { |
| 59 | 61 |
| 62 class MessagePumpInstrumentation; |
| 60 class RunLoop; | 63 class RunLoop; |
| 61 class TimeTicks; | 64 class TimeTicks; |
| 62 | 65 |
| 63 class MessagePumpCFRunLoopBase : public MessagePump { | 66 class MessagePumpCFRunLoopBase : public MessagePump { |
| 64 // Needs access to CreateAutoreleasePool. | 67 // Needs access to CreateAutoreleasePool. |
| 65 friend class MessagePumpScopedAutoreleasePool; | 68 friend class MessagePumpScopedAutoreleasePool; |
| 66 public: | 69 public: |
| 67 MessagePumpCFRunLoopBase(); | 70 MessagePumpCFRunLoopBase(); |
| 68 virtual ~MessagePumpCFRunLoopBase(); | 71 virtual ~MessagePumpCFRunLoopBase(); |
| 69 | 72 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 86 // Sets this pump's delegate. Signals the appropriate sources if | 89 // Sets this pump's delegate. Signals the appropriate sources if |
| 87 // |delegateless_work_| is true. |delegate| can be NULL. | 90 // |delegateless_work_| is true. |delegate| can be NULL. |
| 88 void SetDelegate(Delegate* delegate); | 91 void SetDelegate(Delegate* delegate); |
| 89 | 92 |
| 90 // Return an autorelease pool to wrap around any work being performed. | 93 // Return an autorelease pool to wrap around any work being performed. |
| 91 // In some cases, CreateAutoreleasePool may return nil intentionally to | 94 // In some cases, CreateAutoreleasePool may return nil intentionally to |
| 92 // preventing an autorelease pool from being created, allowing any | 95 // preventing an autorelease pool from being created, allowing any |
| 93 // objects autoreleased by work to fall into the current autorelease pool. | 96 // objects autoreleased by work to fall into the current autorelease pool. |
| 94 virtual NSAutoreleasePool* CreateAutoreleasePool(); | 97 virtual NSAutoreleasePool* CreateAutoreleasePool(); |
| 95 | 98 |
| 99 // Enables instrumentation of the MessagePump. See MessagePumpInstrumentation |
| 100 // in the implementation for details. |
| 101 void EnableInstrumentation(); |
| 102 WeakPtr<MessagePumpInstrumentation> instrumentation_; |
| 103 |
| 96 private: | 104 private: |
| 97 // Timer callback scheduled by ScheduleDelayedWork. This does not do any | 105 // Timer callback scheduled by ScheduleDelayedWork. This does not do any |
| 98 // work, but it signals work_source_ so that delayed work can be performed | 106 // work, but it signals work_source_ so that delayed work can be performed |
| 99 // within the appropriate priority constraints. | 107 // within the appropriate priority constraints. |
| 100 static void RunDelayedWorkTimer(CFRunLoopTimerRef timer, void* info); | 108 static void RunDelayedWorkTimer(CFRunLoopTimerRef timer, void* info); |
| 101 | 109 |
| 102 // Perform highest-priority work. This is associated with work_source_ | 110 // Perform highest-priority work. This is associated with work_source_ |
| 103 // signalled by ScheduleWork or RunDelayedWorkTimer. The static method calls | 111 // signalled by ScheduleWork or RunDelayedWorkTimer. The static method calls |
| 104 // the instance method; the instance method returns true if it resignalled | 112 // the instance method; the instance method returns true if it resignalled |
| 105 // work_source_ to be called again from the loop. | 113 // work_source_ to be called again from the loop. |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 BASE_EXPORT static bool IsHandlingSendEvent(); | 328 BASE_EXPORT static bool IsHandlingSendEvent(); |
| 321 #endif // !defined(OS_IOS) | 329 #endif // !defined(OS_IOS) |
| 322 | 330 |
| 323 private: | 331 private: |
| 324 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac); | 332 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac); |
| 325 }; | 333 }; |
| 326 | 334 |
| 327 } // namespace base | 335 } // namespace base |
| 328 | 336 |
| 329 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_MAC_H_ | 337 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_MAC_H_ |
| OLD | NEW |