OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef COMPONENTS_SCHEDULER_BASE_TASK_QUEUE_H_ | 5 #ifndef COMPONENTS_SCHEDULER_BASE_TASK_QUEUE_H_ |
6 #define COMPONENTS_SCHEDULER_BASE_TASK_QUEUE_H_ | 6 #define COMPONENTS_SCHEDULER_BASE_TASK_QUEUE_H_ |
7 | 7 |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "components/scheduler/scheduler_export.h" | 10 #include "components/scheduler/scheduler_export.h" |
11 | 11 |
12 namespace scheduler { | 12 namespace scheduler { |
13 class DelayedTaskDelegate; | |
13 | 14 |
14 class SCHEDULER_EXPORT TaskQueue : public base::SingleThreadTaskRunner { | 15 class SCHEDULER_EXPORT TaskQueue : public base::SingleThreadTaskRunner { |
15 public: | 16 public: |
16 TaskQueue() {} | 17 TaskQueue() {} |
17 | 18 |
18 // Unregisters the task queue after which no tasks posted to it will run and | 19 // Unregisters the task queue after which no tasks posted to it will run and |
19 // the TaskQueueManager's reference to it will be released soon. | 20 // the TaskQueueManager's reference to it will be released soon. |
20 virtual void UnregisterTaskQueue() = 0; | 21 virtual void UnregisterTaskQueue() = 0; |
21 | 22 |
22 // Post a delayed task at an absolute desired run time instead of a time | 23 // Post a delayed task at an absolute desired run time instead of a time |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 // Options for constructing a TaskQueue. Once set the |name|, | 96 // Options for constructing a TaskQueue. Once set the |name|, |
96 // |should_monitor_quiescence| and |wakeup_policy| are immutable. The | 97 // |should_monitor_quiescence| and |wakeup_policy| are immutable. The |
97 // |pump_policy| can be mutated with |SetPumpPolicy()|. | 98 // |pump_policy| can be mutated with |SetPumpPolicy()|. |
98 struct Spec { | 99 struct Spec { |
99 // Note |name| must have application lifetime. | 100 // Note |name| must have application lifetime. |
100 explicit Spec(const char* name) | 101 explicit Spec(const char* name) |
101 : name(name), | 102 : name(name), |
102 should_monitor_quiescence(false), | 103 should_monitor_quiescence(false), |
103 pump_policy(TaskQueue::PumpPolicy::AUTO), | 104 pump_policy(TaskQueue::PumpPolicy::AUTO), |
104 wakeup_policy(TaskQueue::WakeupPolicy::CAN_WAKE_OTHER_QUEUES), | 105 wakeup_policy(TaskQueue::WakeupPolicy::CAN_WAKE_OTHER_QUEUES), |
106 delayed_task_delegate(nullptr), | |
105 should_notify_observers(true) {} | 107 should_notify_observers(true) {} |
106 | 108 |
107 Spec SetShouldMonitorQuiescence(bool should_monitor) { | 109 Spec SetShouldMonitorQuiescence(bool should_monitor) { |
108 should_monitor_quiescence = should_monitor; | 110 should_monitor_quiescence = should_monitor; |
109 return *this; | 111 return *this; |
110 } | 112 } |
111 | 113 |
112 Spec SetPumpPolicy(PumpPolicy policy) { | 114 Spec SetPumpPolicy(PumpPolicy policy) { |
113 pump_policy = policy; | 115 pump_policy = policy; |
114 return *this; | 116 return *this; |
115 } | 117 } |
116 | 118 |
117 Spec SetWakeupPolicy(WakeupPolicy policy) { | 119 Spec SetWakeupPolicy(WakeupPolicy policy) { |
118 wakeup_policy = policy; | 120 wakeup_policy = policy; |
119 return *this; | 121 return *this; |
120 } | 122 } |
121 | 123 |
122 Spec SetShouldNotifyObservers(bool run_observers) { | 124 Spec SetShouldNotifyObservers(bool run_observers) { |
123 should_notify_observers = run_observers; | 125 should_notify_observers = run_observers; |
124 return *this; | 126 return *this; |
125 } | 127 } |
126 | 128 |
129 Spec SetDelayedTaskDelegate(DelayedTaskDelegate* delegate) { | |
130 delayed_task_delegate = delegate; | |
131 return *this; | |
132 } | |
133 | |
127 const char* name; | 134 const char* name; |
128 bool should_monitor_quiescence; | 135 bool should_monitor_quiescence; |
129 TaskQueue::PumpPolicy pump_policy; | 136 TaskQueue::PumpPolicy pump_policy; |
130 TaskQueue::WakeupPolicy wakeup_policy; | 137 TaskQueue::WakeupPolicy wakeup_policy; |
138 DelayedTaskDelegate* delayed_task_delegate; | |
Sami
2015/11/17 10:31:06
Should this be a scoped_refptr?
alex clarke (OOO till 29th)
2015/11/18 15:30:15
Its a bit of a pain to do that since suddenly the
| |
131 bool should_notify_observers; | 139 bool should_notify_observers; |
132 }; | 140 }; |
133 | 141 |
134 // Returns true if the queue priority is not | 142 // Returns true if the queue priority is not |
135 // TaskQueueSelector::DISABLED_PRIORITY. NOTE this must be called on the | 143 // TaskQueueSelector::DISABLED_PRIORITY. NOTE this must be called on the |
136 // thread this TaskQueue was created by. | 144 // thread this TaskQueue was created by. |
137 virtual bool IsQueueEnabled() const = 0; | 145 virtual bool IsQueueEnabled() const = 0; |
138 | 146 |
139 // Returns true if there no tasks in either the work or incoming task queue. | 147 // Returns true if there no tasks in either the work or incoming task queue. |
140 // Note that this function involves taking a lock, so calling it has some | 148 // Note that this function involves taking a lock, so calling it has some |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 | 183 |
176 protected: | 184 protected: |
177 ~TaskQueue() override {} | 185 ~TaskQueue() override {} |
178 | 186 |
179 DISALLOW_COPY_AND_ASSIGN(TaskQueue); | 187 DISALLOW_COPY_AND_ASSIGN(TaskQueue); |
180 }; | 188 }; |
181 | 189 |
182 } // namespace scheduler | 190 } // namespace scheduler |
183 | 191 |
184 #endif // COMPONENTS_SCHEDULER_BASE_TASK_QUEUE_H_ | 192 #endif // COMPONENTS_SCHEDULER_BASE_TASK_QUEUE_H_ |
OLD | NEW |