Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(993)

Side by Side Diff: base/message_loop/message_pump_mac.h

Issue 22911026: Add instrumentation to the MessagePumpMac family of classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add caveat Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/message_loop/message_pump.h ('k') | base/message_loop/message_pump_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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.
106 static void RunWorkSource(void* info); 114 static void RunWorkSource(void* info);
107 bool RunWork(); 115 bool RunWork();
108 116
109 // Perform idle-priority work. This is normally called by PreWaitObserver, 117 // Perform idle-priority work. This is normally called by
110 // but is also associated with idle_work_source_. When this function 118 // StartOrEndWaitObserver, but is also associated with idle_work_source_. When
111 // actually does perform idle work, it will resignal that source. The 119 // this function actually does perform idle work, it will resignal that
112 // static method calls the instance method; the instance method returns 120 // source. The static method calls the instance method; the instance method
113 // true if idle work was done. 121 // returns true if idle work was done.
114 static void RunIdleWorkSource(void* info); 122 static void RunIdleWorkSource(void* info);
115 bool RunIdleWork(); 123 bool RunIdleWork();
116 124
117 // Perform work that may have been deferred because it was not runnable 125 // Perform work that may have been deferred because it was not runnable
118 // within a nested run loop. This is associated with 126 // within a nested run loop. This is associated with
119 // nesting_deferred_work_source_ and is signalled by 127 // nesting_deferred_work_source_ and is signalled by
120 // MaybeScheduleNestingDeferredWork when returning from a nested loop, 128 // MaybeScheduleNestingDeferredWork when returning from a nested loop,
121 // so that an outer loop will be able to perform the necessary tasks if it 129 // so that an outer loop will be able to perform the necessary tasks if it
122 // permits nestable tasks. 130 // permits nestable tasks.
123 static void RunNestingDeferredWorkSource(void* info); 131 static void RunNestingDeferredWorkSource(void* info);
124 bool RunNestingDeferredWork(); 132 bool RunNestingDeferredWork();
125 133
126 // Schedules possible nesting-deferred work to be processed before the run 134 // Schedules possible nesting-deferred work to be processed before the run
127 // loop goes to sleep, exits, or begins processing sources at the top of its 135 // loop goes to sleep, exits, or begins processing sources at the top of its
128 // loop. If this function detects that a nested loop had run since the 136 // loop. If this function detects that a nested loop had run since the
129 // previous attempt to schedule nesting-deferred work, it will schedule a 137 // previous attempt to schedule nesting-deferred work, it will schedule a
130 // call to RunNestingDeferredWorkSource. 138 // call to RunNestingDeferredWorkSource.
131 void MaybeScheduleNestingDeferredWork(); 139 void MaybeScheduleNestingDeferredWork();
132 140
133 // Observer callback responsible for performing idle-priority work, before 141 // Observer callback responsible for performing idle-priority work, before
134 // the run loop goes to sleep. Associated with idle_work_observer_. 142 // the run loop goes to sleep. Associated with idle_work_observer_.
135 static void PreWaitObserver(CFRunLoopObserverRef observer, 143 static void StartOrEndWaitObserver(CFRunLoopObserverRef observer,
136 CFRunLoopActivity activity, void* info); 144 CFRunLoopActivity activity, void* info);
137 145
138 // Observer callback called before the run loop processes any sources. 146 // Observer callback called before the run loop processes any sources.
139 // Associated with pre_source_observer_. 147 // Associated with pre_source_observer_.
140 static void PreSourceObserver(CFRunLoopObserverRef observer, 148 static void PreSourceObserver(CFRunLoopObserverRef observer,
141 CFRunLoopActivity activity, void* info); 149 CFRunLoopActivity activity, void* info);
142 150
143 // Observer callback called when the run loop starts and stops, at the 151 // Observer callback called when the run loop starts and stops, at the
144 // beginning and end of calls to CFRunLoopRun. This is used to maintain 152 // beginning and end of calls to CFRunLoopRun. This is used to maintain
145 // nesting_level_. Associated with enter_exit_observer_. 153 // nesting_level_. Associated with enter_exit_observer_.
146 static void EnterExitObserver(CFRunLoopObserverRef observer, 154 static void EnterExitObserver(CFRunLoopObserverRef observer,
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_
OLDNEW
« no previous file with comments | « base/message_loop/message_pump.h ('k') | base/message_loop/message_pump_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698