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 THIRD_PARTY_WEBKIT_PUBLIC_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_H_ | 5 #ifndef THIRD_PARTY_WEBKIT_PUBLIC_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_H_ |
6 #define THIRD_PARTY_WEBKIT_PUBLIC_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_H_ | 6 #define THIRD_PARTY_WEBKIT_PUBLIC_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/trace_event/trace_event.h" | |
12 #include "public/platform/WebCommon.h" | 11 #include "public/platform/WebCommon.h" |
13 | 12 |
14 namespace base { | 13 namespace base { |
15 namespace trace_event { | 14 namespace trace_event { |
16 class BlameContext; | 15 class BlameContext; |
17 } | 16 } |
18 } | 17 } |
19 | 18 |
20 namespace blink { | 19 namespace blink { |
21 namespace scheduler { | 20 namespace scheduler { |
| 21 namespace internal { |
| 22 class TaskQueueImpl; |
| 23 } // namespace internal |
| 24 class FakeWebTaskRunner; |
22 class LazyNow; | 25 class LazyNow; |
23 class TimeDomain; | 26 class TimeDomain; |
24 | 27 |
25 class BLINK_PLATFORM_EXPORT TaskQueue : public base::SingleThreadTaskRunner { | 28 class BLINK_PLATFORM_EXPORT TaskQueue : public base::SingleThreadTaskRunner { |
26 public: | 29 public: |
27 TaskQueue() {} | 30 TaskQueue() {} |
28 | 31 |
29 // Unregisters the task queue after which no tasks posted to it will run and | 32 // Unregisters the task queue after which no tasks posted to it will run and |
30 // the TaskQueueManager's reference to it will be released soon. | 33 // the TaskQueueManager's reference to it will be released soon. |
31 virtual void UnregisterTaskQueue() = 0; | 34 virtual void UnregisterTaskQueue() = 0; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 132 |
130 const char* name; | 133 const char* name; |
131 bool should_monitor_quiescence; | 134 bool should_monitor_quiescence; |
132 TaskQueue::PumpPolicy pump_policy; | 135 TaskQueue::PumpPolicy pump_policy; |
133 TaskQueue::WakeupPolicy wakeup_policy; | 136 TaskQueue::WakeupPolicy wakeup_policy; |
134 TimeDomain* time_domain; | 137 TimeDomain* time_domain; |
135 bool should_notify_observers; | 138 bool should_notify_observers; |
136 bool should_report_when_execution_blocked; | 139 bool should_report_when_execution_blocked; |
137 }; | 140 }; |
138 | 141 |
| 142 // Intended to be used as an opaque handle to a task posted by |
| 143 // PostCancellableDelayedTask. |
| 144 class BLINK_PLATFORM_EXPORT TaskHandle { |
| 145 public: |
| 146 TaskHandle(); |
| 147 |
| 148 // Returns false if the handle is equivalent to TaskHandle(), i.e. the |
| 149 // handle doesn't represent a task that got posted. |
| 150 operator bool() const; |
| 151 |
| 152 private: |
| 153 friend internal::TaskQueueImpl; |
| 154 friend FakeWebTaskRunner; |
| 155 |
| 156 // For immediate tasks. |
| 157 TaskHandle(TaskQueue* task_queue, uint64_t enqueue_order); |
| 158 |
| 159 // For delayed tasks. |
| 160 TaskHandle(TaskQueue* task_queue, |
| 161 base::TimeTicks scheduled_run_time, |
| 162 int sequence_number); |
| 163 |
| 164 uint64_t enqueue_order_; |
| 165 base::TimeTicks scheduled_run_time_; |
| 166 #if DCHECK_IS_ON() |
| 167 TaskQueue* task_queue_; |
| 168 #endif |
| 169 int sequence_number_; |
| 170 }; |
| 171 |
| 172 // Posts the given task to be run after |delay| has passed. Returns a handle |
| 173 // which can be passed to CancelTask to cancel the task before it has run. |
| 174 // NOTE this must be called on the thread this TaskQueue was created by. |
| 175 virtual TaskHandle PostCancellableDelayedTask( |
| 176 const tracked_objects::Location& from_here, |
| 177 const base::Closure& task, |
| 178 base::TimeDelta delay) = 0; |
| 179 |
| 180 // Attempts to cancel a task posted by PostCancellableDelayedTask. Returns |
| 181 // true on success or false otherwise. NOTE this must be called on the thread |
| 182 // this TaskQueue was created by. |
| 183 virtual bool CancelTask(const TaskHandle& handle) = 0; |
| 184 |
139 // Enable or disable task execution for this queue. NOTE this must be called | 185 // Enable or disable task execution for this queue. NOTE this must be called |
140 // on the thread this TaskQueue was created by. | 186 // on the thread this TaskQueue was created by. |
141 virtual void SetQueueEnabled(bool enabled) = 0; | 187 virtual void SetQueueEnabled(bool enabled) = 0; |
142 | 188 |
143 // NOTE this must be called on the thread this TaskQueue was created by. | 189 // NOTE this must be called on the thread this TaskQueue was created by. |
144 virtual bool IsQueueEnabled() const = 0; | 190 virtual bool IsQueueEnabled() const = 0; |
145 | 191 |
146 // Returns true if the queue is completely empty. | 192 // Returns true if the queue is completely empty. |
147 virtual bool IsEmpty() const = 0; | 193 virtual bool IsEmpty() const = 0; |
148 | 194 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 protected: | 255 protected: |
210 ~TaskQueue() override {} | 256 ~TaskQueue() override {} |
211 | 257 |
212 DISALLOW_COPY_AND_ASSIGN(TaskQueue); | 258 DISALLOW_COPY_AND_ASSIGN(TaskQueue); |
213 }; | 259 }; |
214 | 260 |
215 } // namespace scheduler | 261 } // namespace scheduler |
216 } // namespace blink | 262 } // namespace blink |
217 | 263 |
218 #endif // THIRD_PARTY_WEBKIT_PUBLIC_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_H_ | 264 #endif // THIRD_PARTY_WEBKIT_PUBLIC_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_H_ |
OLD | NEW |