| 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/optional.h" | 10 #include "base/optional.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "public/platform/WebCommon.h" | 13 #include "public/platform/WebCommon.h" |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 namespace trace_event { | 16 namespace trace_event { |
| 17 class BlameContext; | 17 class BlameContext; |
| 18 } | 18 } |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace blink { | 21 namespace blink { |
| 22 namespace scheduler { | 22 namespace scheduler { |
| 23 | 23 |
| 24 class TimeDomain; | 24 class TimeDomain; |
| 25 | 25 |
| 26 class BLINK_PLATFORM_EXPORT TaskQueue : public base::SingleThreadTaskRunner { | 26 class BLINK_PLATFORM_EXPORT TaskQueue : public base::SingleThreadTaskRunner { |
| 27 public: | 27 public: |
| 28 TaskQueue() {} | 28 TaskQueue() {} |
| 29 | 29 |
| 30 class BLINK_PLATFORM_EXPORT Observer { | |
| 31 public: | |
| 32 virtual ~Observer() {} | |
| 33 | |
| 34 // Notify observer that the time at which this queue wants to run | |
| 35 // the next task has changed. |next_wakeup| can be in the past | |
| 36 // (e.g. base::TimeTicks() can be used to notify about immediate work). | |
| 37 // Can be called on any thread | |
| 38 // All methods but SetObserver, SetTimeDomain and GetTimeDomain can be | |
| 39 // called on |queue|. | |
| 40 virtual void OnQueueNextWakeUpChanged(TaskQueue* queue, | |
| 41 base::TimeTicks next_wake_up) = 0; | |
| 42 }; | |
| 43 | |
| 44 // Unregisters the task queue after which no tasks posted to it will run and | 30 // Unregisters the task queue after which no tasks posted to it will run and |
| 45 // the TaskQueueManager's reference to it will be released soon. | 31 // the TaskQueueManager's reference to it will be released soon. |
| 46 virtual void UnregisterTaskQueue() = 0; | 32 virtual void UnregisterTaskQueue() = 0; |
| 47 | 33 |
| 48 enum QueuePriority { | 34 enum QueuePriority { |
| 49 // Queues with control priority will run before any other queue, and will | 35 // Queues with control priority will run before any other queue, and will |
| 50 // explicitly starve other queues. Typically this should only be used for | 36 // explicitly starve other queues. Typically this should only be used for |
| 51 // private queues which perform control operations. | 37 // private queues which perform control operations. |
| 52 CONTROL_PRIORITY, | 38 CONTROL_PRIORITY, |
| 53 // Queues with high priority will be selected preferentially over normal or | 39 // Queues with high priority will be selected preferentially over normal or |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 // Returns true if the queue is completely empty. | 143 // Returns true if the queue is completely empty. |
| 158 virtual bool IsEmpty() const = 0; | 144 virtual bool IsEmpty() const = 0; |
| 159 | 145 |
| 160 // Returns the number of pending tasks in the queue. | 146 // Returns the number of pending tasks in the queue. |
| 161 virtual size_t GetNumberOfPendingTasks() const = 0; | 147 virtual size_t GetNumberOfPendingTasks() const = 0; |
| 162 | 148 |
| 163 // Returns true if the queue has work that's ready to execute now. | 149 // Returns true if the queue has work that's ready to execute now. |
| 164 // NOTE: this must be called on the thread this TaskQueue was created by. | 150 // NOTE: this must be called on the thread this TaskQueue was created by. |
| 165 virtual bool HasPendingImmediateWork() const = 0; | 151 virtual bool HasPendingImmediateWork() const = 0; |
| 166 | 152 |
| 167 // Returns requested run time of next scheduled wake-up for a delayed task | 153 // Returns requested run time of next scheduled wakeup for a delayed task |
| 168 // which is not ready to run. If there are no such tasks or the queue is | 154 // which is not ready to run. If there are no such tasks or the queue is |
| 169 // disabled (by a QueueEnabledVoter) it returns base::nullopt. | 155 // disabled (by a QueueEnabledVoter) it returns base::nullopt. |
| 170 // NOTE: this must be called on the thread this TaskQueue was created by. | 156 // NOTE: this must be called on the thread this TaskQueue was created by. |
| 171 virtual base::Optional<base::TimeTicks> GetNextScheduledWakeUp() = 0; | 157 virtual base::Optional<base::TimeTicks> GetNextScheduledWakeUp() = 0; |
| 172 | 158 |
| 173 // Can be called on any thread. | 159 // Can be called on any thread. |
| 174 virtual QueueType GetQueueType() const = 0; | 160 virtual QueueType GetQueueType() const = 0; |
| 175 | 161 |
| 176 // Can be called on any thread. | 162 // Can be called on any thread. |
| 177 virtual const char* GetName() const = 0; | 163 virtual const char* GetName() const = 0; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 // Note: delayed tasks get their enqueue order set once their delay has | 201 // Note: delayed tasks get their enqueue order set once their delay has |
| 216 // expired, and non-delayed tasks get their enqueue order set when posted. | 202 // expired, and non-delayed tasks get their enqueue order set when posted. |
| 217 virtual void InsertFence(InsertFencePosition position) = 0; | 203 virtual void InsertFence(InsertFencePosition position) = 0; |
| 218 | 204 |
| 219 // Removes any previously added fence and unblocks execution of any tasks | 205 // Removes any previously added fence and unblocks execution of any tasks |
| 220 // blocked by it. | 206 // blocked by it. |
| 221 virtual void RemoveFence() = 0; | 207 virtual void RemoveFence() = 0; |
| 222 | 208 |
| 223 virtual bool BlockedByFence() const = 0; | 209 virtual bool BlockedByFence() const = 0; |
| 224 | 210 |
| 225 virtual void SetObserver(Observer* observer) = 0; | |
| 226 | |
| 227 protected: | 211 protected: |
| 228 ~TaskQueue() override {} | 212 ~TaskQueue() override {} |
| 229 | 213 |
| 230 DISALLOW_COPY_AND_ASSIGN(TaskQueue); | 214 DISALLOW_COPY_AND_ASSIGN(TaskQueue); |
| 231 }; | 215 }; |
| 232 | 216 |
| 233 } // namespace scheduler | 217 } // namespace scheduler |
| 234 } // namespace blink | 218 } // namespace blink |
| 235 | 219 |
| 236 #endif // THIRD_PARTY_WEBKIT_PUBLIC_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_H_ | 220 #endif // THIRD_PARTY_WEBKIT_PUBLIC_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_H_ |
| OLD | NEW |