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

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: selfnits 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Needs access to CreateAutoreleasePool. 82 // Needs access to CreateAutoreleasePool.
83 friend class MessagePumpScopedAutoreleasePool; 83 friend class MessagePumpScopedAutoreleasePool;
84 friend class TestMessagePumpCFRunLoopBase; 84 friend class TestMessagePumpCFRunLoopBase;
85 85
86 public: 86 public:
87 MessagePumpCFRunLoopBase(); 87 explicit MessagePumpCFRunLoopBase(int mode_mask);
Mark Mentovai 2017/05/19 03:29:13 Since you aren’t providing the enum that has masky
tapted 2017/05/19 06:28:15 Done. Made this constructor protected also and fix
88 ~MessagePumpCFRunLoopBase() override; 88 ~MessagePumpCFRunLoopBase() override;
89 89
90 // Subclasses should implement the work they need to do in MessagePump::Run 90 // Subclasses should implement the work they need to do in MessagePump::Run
91 // in the DoRun method. MessagePumpCFRunLoopBase::Run calls DoRun directly. 91 // in the DoRun method. MessagePumpCFRunLoopBase::Run calls DoRun directly.
92 // This arrangement is used because MessagePumpCFRunLoopBase needs to set 92 // This arrangement is used because MessagePumpCFRunLoopBase needs to set
93 // up and tear down things before and after the "meat" of DoRun. 93 // up and tear down things before and after the "meat" of DoRun.
94 void Run(Delegate* delegate) override; 94 void Run(Delegate* delegate) override;
95 virtual void DoRun(Delegate* delegate) = 0; 95 virtual void DoRun(Delegate* delegate) = 0;
96 96
97 void ScheduleWork() override; 97 void ScheduleWork() override;
98 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override; 98 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override;
99 void SetTimerSlack(TimerSlack timer_slack) override; 99 void SetTimerSlack(TimerSlack timer_slack) override;
100 100
101 protected: 101 protected:
102 // Accessors for private data members to be used by subclasses. 102 // Accessors for private data members to be used by subclasses.
103 CFRunLoopRef run_loop() const { return run_loop_; } 103 CFRunLoopRef run_loop() const { return run_loop_; }
104 int nesting_level() const { return nesting_level_; } 104 int nesting_level() const { return nesting_level_; }
105 int run_nesting_level() const { return run_nesting_level_; } 105 int run_nesting_level() const { return run_nesting_level_; }
106 106
107 // Sets this pump's delegate. Signals the appropriate sources if 107 // Sets this pump's delegate. Signals the appropriate sources if
108 // |delegateless_work_| is true. |delegate| can be NULL. 108 // |delegateless_work_| is true. |delegate| can be NULL.
109 void SetDelegate(Delegate* delegate); 109 void SetDelegate(Delegate* delegate);
110 110
111 // Return an autorelease pool to wrap around any work being performed. 111 // Return an autorelease pool to wrap around any work being performed.
112 // In some cases, CreateAutoreleasePool may return nil intentionally to 112 // In some cases, CreateAutoreleasePool may return nil intentionally to
113 // preventing an autorelease pool from being created, allowing any 113 // preventing an autorelease pool from being created, allowing any
114 // objects autoreleased by work to fall into the current autorelease pool. 114 // objects autoreleased by work to fall into the current autorelease pool.
115 virtual AutoreleasePoolType* CreateAutoreleasePool(); 115 virtual AutoreleasePoolType* CreateAutoreleasePool();
116 116
117 // Invokes method(run_loop_, arg, mode) for all the modes in |mode_mask_|.
118 template <typename Argument>
119 void InvokeForAllModes(void method(CFRunLoopRef, Argument, CFStringRef),
Mark Mentovai 2017/05/19 03:29:13 More a function than a method?
Mark Mentovai 2017/05/19 03:29:13 Since it’s restricted to mode_mask_, it shouldn’t
tapted 2017/05/19 06:28:15 Done.
tapted 2017/05/19 06:28:15 Done.
120 Argument argument);
121
117 private: 122 private:
118 // Marking timers as invalid at the right time helps significantly reduce 123 // Marking timers as invalid at the right time helps significantly reduce
119 // power use (see the comment in RunDelayedWorkTimer()), however there is no 124 // power use (see the comment in RunDelayedWorkTimer()), however there is no
120 // public API for doing so. CFRuntime.h states that CFRuntimeBase, upon which 125 // public API for doing so. CFRuntime.h states that CFRuntimeBase, upon which
121 // the above timer invalidation functions are based, can change from release 126 // 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 127 // to release and should not be accessed directly (this struct last changed at
123 // least in 2008 in CF-476). 128 // least in 2008 in CF-476).
124 // 129 //
125 // This function uses private API to modify a test timer's valid state and 130 // 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. 131 // 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); 188 CFRunLoopActivity activity, void* info);
184 189
185 // Called by EnterExitObserver after performing maintenance on nesting_level_. 190 // Called by EnterExitObserver after performing maintenance on nesting_level_.
186 // This allows subclasses an opportunity to perform additional processing on 191 // This allows subclasses an opportunity to perform additional processing on
187 // the basis of run loops starting and stopping. 192 // the basis of run loops starting and stopping.
188 virtual void EnterExitRunLoop(CFRunLoopActivity activity); 193 virtual void EnterExitRunLoop(CFRunLoopActivity activity);
189 194
190 // The thread's run loop. 195 // The thread's run loop.
191 CFRunLoopRef run_loop_; 196 CFRunLoopRef run_loop_;
192 197
198 // Bitmask controlling the run loop modes in which posted tasks may run.
199 const int mode_mask_;
200
193 // The timer, sources, and observers are described above alongside their 201 // The timer, sources, and observers are described above alongside their
194 // callbacks. 202 // callbacks.
195 CFRunLoopTimerRef delayed_work_timer_; 203 CFRunLoopTimerRef delayed_work_timer_;
196 CFRunLoopSourceRef work_source_; 204 CFRunLoopSourceRef work_source_;
197 CFRunLoopSourceRef idle_work_source_; 205 CFRunLoopSourceRef idle_work_source_;
198 CFRunLoopSourceRef nesting_deferred_work_source_; 206 CFRunLoopSourceRef nesting_deferred_work_source_;
199 CFRunLoopObserverRef pre_wait_observer_; 207 CFRunLoopObserverRef pre_wait_observer_;
200 CFRunLoopObserverRef pre_source_observer_; 208 CFRunLoopObserverRef pre_source_observer_;
201 CFRunLoopObserverRef enter_exit_observer_; 209 CFRunLoopObserverRef enter_exit_observer_;
202 210
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac); 370 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac);
363 }; 371 };
364 372
365 // Tasks posted to the message loop are posted under this mode, as well 373 // Tasks posted to the message loop are posted under this mode, as well
366 // as kCFRunLoopCommonModes. 374 // as kCFRunLoopCommonModes.
367 extern const CFStringRef BASE_EXPORT kMessageLoopExclusiveRunLoopMode; 375 extern const CFStringRef BASE_EXPORT kMessageLoopExclusiveRunLoopMode;
368 376
369 } // namespace base 377 } // namespace base
370 378
371 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_MAC_H_ 379 #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