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

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

Issue 2889293002: Filter run loop modes in message_pump_mac.mm (Closed)
Patch Set: respond to comments, sort methods Created 3 years, 7 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
« no previous file with comments | « no previous file | 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // Objective-C TUs, it is a type alias for NSAutoreleasePool. In all cases, a 72 // Objective-C TUs, it is a type alias for NSAutoreleasePool. In all cases, a
73 // method that takes or returns an NSAutoreleasePool* can use 73 // method that takes or returns an NSAutoreleasePool* can use
74 // AutoreleasePoolType* instead. 74 // AutoreleasePoolType* instead.
75 #if !defined(__OBJC__) || __has_feature(objc_arc) 75 #if !defined(__OBJC__) || __has_feature(objc_arc)
76 class AutoreleasePoolType; 76 class AutoreleasePoolType;
77 #else // !defined(__OBJC__) || __has_feature(objc_arc) 77 #else // !defined(__OBJC__) || __has_feature(objc_arc)
78 typedef NSAutoreleasePool AutoreleasePoolType; 78 typedef NSAutoreleasePool AutoreleasePoolType;
79 #endif // !defined(__OBJC__) || __has_feature(objc_arc) 79 #endif // !defined(__OBJC__) || __has_feature(objc_arc)
80 80
81 class BASE_EXPORT MessagePumpCFRunLoopBase : public MessagePump { 81 class BASE_EXPORT MessagePumpCFRunLoopBase : public MessagePump {
82 public:
83 // MessagePump:
84 void Run(Delegate* delegate) override;
85 void ScheduleWork() override;
86 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override;
87 void SetTimerSlack(TimerSlack timer_slack) override;
88
89 protected:
82 // Needs access to CreateAutoreleasePool. 90 // Needs access to CreateAutoreleasePool.
83 friend class MessagePumpScopedAutoreleasePool; 91 friend class MessagePumpScopedAutoreleasePool;
84 friend class TestMessagePumpCFRunLoopBase; 92 friend class TestMessagePumpCFRunLoopBase;
85 93
86 public: 94 // Tasks will be pumped in the run loop modes described by |mode_mask|, which
87 MessagePumpCFRunLoopBase(); 95 // maps bits to the index of an internal array of run loop mode identifiers.
96 explicit MessagePumpCFRunLoopBase(int mode_mask);
88 ~MessagePumpCFRunLoopBase() override; 97 ~MessagePumpCFRunLoopBase() override;
89 98
90 // Subclasses should implement the work they need to do in MessagePump::Run 99 // Subclasses should implement the work they need to do in MessagePump::Run
91 // in the DoRun method. MessagePumpCFRunLoopBase::Run calls DoRun directly. 100 // in the DoRun method. MessagePumpCFRunLoopBase::Run calls DoRun directly.
92 // This arrangement is used because MessagePumpCFRunLoopBase needs to set 101 // This arrangement is used because MessagePumpCFRunLoopBase needs to set
93 // up and tear down things before and after the "meat" of DoRun. 102 // up and tear down things before and after the "meat" of DoRun.
94 void Run(Delegate* delegate) override;
95 virtual void DoRun(Delegate* delegate) = 0; 103 virtual void DoRun(Delegate* delegate) = 0;
96 104
97 void ScheduleWork() override;
98 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override;
99 void SetTimerSlack(TimerSlack timer_slack) override;
100
101 protected:
102 // Accessors for private data members to be used by subclasses. 105 // Accessors for private data members to be used by subclasses.
103 CFRunLoopRef run_loop() const { return run_loop_; } 106 CFRunLoopRef run_loop() const { return run_loop_; }
104 int nesting_level() const { return nesting_level_; } 107 int nesting_level() const { return nesting_level_; }
105 int run_nesting_level() const { return run_nesting_level_; } 108 int run_nesting_level() const { return run_nesting_level_; }
106 109
107 // Sets this pump's delegate. Signals the appropriate sources if 110 // Sets this pump's delegate. Signals the appropriate sources if
108 // |delegateless_work_| is true. |delegate| can be NULL. 111 // |delegateless_work_| is true. |delegate| can be NULL.
109 void SetDelegate(Delegate* delegate); 112 void SetDelegate(Delegate* delegate);
110 113
111 // Return an autorelease pool to wrap around any work being performed. 114 // Return an autorelease pool to wrap around any work being performed.
112 // In some cases, CreateAutoreleasePool may return nil intentionally to 115 // In some cases, CreateAutoreleasePool may return nil intentionally to
113 // preventing an autorelease pool from being created, allowing any 116 // preventing an autorelease pool from being created, allowing any
114 // objects autoreleased by work to fall into the current autorelease pool. 117 // objects autoreleased by work to fall into the current autorelease pool.
115 virtual AutoreleasePoolType* CreateAutoreleasePool(); 118 virtual AutoreleasePoolType* CreateAutoreleasePool();
116 119
120 // Invokes function(run_loop_, arg, mode) for all the modes in |mode_mask_|.
121 template <typename Argument>
122 void InvokeForEnabledModes(void function(CFRunLoopRef, Argument, CFStringRef),
123 Argument argument);
124
117 private: 125 private:
118 // Marking timers as invalid at the right time helps significantly reduce 126 // Marking timers as invalid at the right time helps significantly reduce
119 // power use (see the comment in RunDelayedWorkTimer()), however there is no 127 // power use (see the comment in RunDelayedWorkTimer()), however there is no
120 // public API for doing so. CFRuntime.h states that CFRuntimeBase, upon which 128 // public API for doing so. CFRuntime.h states that CFRuntimeBase, upon which
121 // the above timer invalidation functions are based, can change from release 129 // the above timer invalidation functions are based, can change from release
122 // to release and should not be accessed directly (this struct last changed at 130 // to release and should not be accessed directly (this struct last changed at
123 // least in 2008 in CF-476). 131 // least in 2008 in CF-476).
124 // 132 //
125 // This function uses private API to modify a test timer's valid state and 133 // This function uses private API to modify a test timer's valid state and
126 // uses public API to confirm that the private API changed the right bit. 134 // uses public API to confirm that the private API changed the right bit.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 CFRunLoopActivity activity, void* info); 191 CFRunLoopActivity activity, void* info);
184 192
185 // Called by EnterExitObserver after performing maintenance on nesting_level_. 193 // Called by EnterExitObserver after performing maintenance on nesting_level_.
186 // This allows subclasses an opportunity to perform additional processing on 194 // This allows subclasses an opportunity to perform additional processing on
187 // the basis of run loops starting and stopping. 195 // the basis of run loops starting and stopping.
188 virtual void EnterExitRunLoop(CFRunLoopActivity activity); 196 virtual void EnterExitRunLoop(CFRunLoopActivity activity);
189 197
190 // The thread's run loop. 198 // The thread's run loop.
191 CFRunLoopRef run_loop_; 199 CFRunLoopRef run_loop_;
192 200
201 // Bitmask controlling the run loop modes in which posted tasks may run.
202 const int mode_mask_;
203
193 // The timer, sources, and observers are described above alongside their 204 // The timer, sources, and observers are described above alongside their
194 // callbacks. 205 // callbacks.
195 CFRunLoopTimerRef delayed_work_timer_; 206 CFRunLoopTimerRef delayed_work_timer_;
196 CFRunLoopSourceRef work_source_; 207 CFRunLoopSourceRef work_source_;
197 CFRunLoopSourceRef idle_work_source_; 208 CFRunLoopSourceRef idle_work_source_;
198 CFRunLoopSourceRef nesting_deferred_work_source_; 209 CFRunLoopSourceRef nesting_deferred_work_source_;
199 CFRunLoopObserverRef pre_wait_observer_; 210 CFRunLoopObserverRef pre_wait_observer_;
200 CFRunLoopObserverRef pre_source_observer_; 211 CFRunLoopObserverRef pre_source_observer_;
201 CFRunLoopObserverRef enter_exit_observer_; 212 CFRunLoopObserverRef enter_exit_observer_;
202 213
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac); 373 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac);
363 }; 374 };
364 375
365 // Tasks posted to the message loop are posted under this mode, as well 376 // Tasks posted to the message loop are posted under this mode, as well
366 // as kCFRunLoopCommonModes. 377 // as kCFRunLoopCommonModes.
367 extern const CFStringRef BASE_EXPORT kMessageLoopExclusiveRunLoopMode; 378 extern const CFStringRef BASE_EXPORT kMessageLoopExclusiveRunLoopMode;
368 379
369 } // namespace base 380 } // namespace base
370 381
371 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_MAC_H_ 382 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_MAC_H_
OLDNEW
« no previous file with comments | « no previous file | base/message_loop/message_pump_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698