Commit 80575da0 authored by tapted's avatar tapted Committed by Commit bot

Filter run loop modes in message_pump_mac.mm

There's a non-trivial overhead for the machinery to run posted tasks in
a given run loop mode. Only observe modes known to be run for a particular
thread.

BUG=640466, 724076

Review-Url: https://codereview.chromium.org/2889293002
Cr-Commit-Position: refs/heads/master@{#473391}
parent bd5768e5
......@@ -79,26 +79,29 @@ typedef NSAutoreleasePool AutoreleasePoolType;
#endif // !defined(__OBJC__) || __has_feature(objc_arc)
class BASE_EXPORT MessagePumpCFRunLoopBase : public MessagePump {
public:
// MessagePump:
void Run(Delegate* delegate) override;
void ScheduleWork() override;
void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override;
void SetTimerSlack(TimerSlack timer_slack) override;
protected:
// Needs access to CreateAutoreleasePool.
friend class MessagePumpScopedAutoreleasePool;
friend class TestMessagePumpCFRunLoopBase;
public:
MessagePumpCFRunLoopBase();
// Tasks will be pumped in the run loop modes described by |mode_mask|, which
// maps bits to the index of an internal array of run loop mode identifiers.
explicit MessagePumpCFRunLoopBase(int mode_mask);
~MessagePumpCFRunLoopBase() override;
// Subclasses should implement the work they need to do in MessagePump::Run
// in the DoRun method. MessagePumpCFRunLoopBase::Run calls DoRun directly.
// This arrangement is used because MessagePumpCFRunLoopBase needs to set
// up and tear down things before and after the "meat" of DoRun.
void Run(Delegate* delegate) override;
virtual void DoRun(Delegate* delegate) = 0;
void ScheduleWork() override;
void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override;
void SetTimerSlack(TimerSlack timer_slack) override;
protected:
// Accessors for private data members to be used by subclasses.
CFRunLoopRef run_loop() const { return run_loop_; }
int nesting_level() const { return nesting_level_; }
......@@ -114,6 +117,11 @@ class BASE_EXPORT MessagePumpCFRunLoopBase : public MessagePump {
// objects autoreleased by work to fall into the current autorelease pool.
virtual AutoreleasePoolType* CreateAutoreleasePool();
// Invokes function(run_loop_, arg, mode) for all the modes in |mode_mask_|.
template <typename Argument>
void InvokeForEnabledModes(void function(CFRunLoopRef, Argument, CFStringRef),
Argument argument);
private:
// Marking timers as invalid at the right time helps significantly reduce
// power use (see the comment in RunDelayedWorkTimer()), however there is no
......@@ -190,6 +198,9 @@ class BASE_EXPORT MessagePumpCFRunLoopBase : public MessagePump {
// The thread's run loop.
CFRunLoopRef run_loop_;
// Bitmask controlling the run loop modes in which posted tasks may run.
const int mode_mask_;
// The timer, sources, and observers are described above alongside their
// callbacks.
CFRunLoopTimerRef delayed_work_timer_;
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment