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" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 return *this; | 84 return *this; |
85 } | 85 } |
86 | 86 |
87 const char* name; | 87 const char* name; |
88 bool should_monitor_quiescence; | 88 bool should_monitor_quiescence; |
89 TimeDomain* time_domain; | 89 TimeDomain* time_domain; |
90 bool should_notify_observers; | 90 bool should_notify_observers; |
91 bool should_report_when_execution_blocked; | 91 bool should_report_when_execution_blocked; |
92 }; | 92 }; |
93 | 93 |
| 94 // Intended to be used as an opaque handle to a task posted by |
| 95 // PostCancellableDelayedTask. |
| 96 class BLINK_PLATFORM_EXPORT TaskHandle { |
| 97 public: |
| 98 TaskHandle(); |
| 99 |
| 100 // Returns false if the handle is equivalent to TaskHandle(), i.e. the |
| 101 // handle doesn't represent a task that got posted. |
| 102 operator bool() const; |
| 103 |
| 104 private: |
| 105 friend internal::TaskQueueImpl; |
| 106 friend FakeWebTaskRunner; |
| 107 |
| 108 // For immediate tasks. |
| 109 TaskHandle(TaskQueue* task_queue, uint64_t enqueue_order); |
| 110 |
| 111 // For delayed tasks. |
| 112 TaskHandle(TaskQueue* task_queue, |
| 113 base::TimeTicks scheduled_run_time, |
| 114 int sequence_number); |
| 115 |
| 116 uint64_t enqueue_order_; |
| 117 base::TimeTicks scheduled_run_time_; |
| 118 #if DCHECK_IS_ON() |
| 119 TaskQueue* task_queue_; |
| 120 #endif |
| 121 int sequence_number_; |
| 122 }; |
| 123 |
| 124 // Posts the given task to be run after |delay| has passed. Returns a handle |
| 125 // which can be passed to CancelTask to cancel the task before it has run. |
| 126 // NOTE this must be called on the thread this TaskQueue was created by. |
| 127 virtual TaskHandle PostCancellableDelayedTask( |
| 128 const tracked_objects::Location& from_here, |
| 129 const base::Closure& task, |
| 130 base::TimeDelta delay) = 0; |
| 131 |
| 132 // Attempts to cancel a task posted by PostCancellableDelayedTask. Returns |
| 133 // true on success or false otherwise. NOTE this must be called on the thread |
| 134 // this TaskQueue was created by. |
| 135 virtual bool CancelTask(const TaskHandle& handle) = 0; |
| 136 |
94 // Enable or disable task execution for this queue. NOTE this must be called | 137 // Enable or disable task execution for this queue. NOTE this must be called |
95 // on the thread this TaskQueue was created by. | 138 // on the thread this TaskQueue was created by. |
96 virtual void SetQueueEnabled(bool enabled) = 0; | 139 virtual void SetQueueEnabled(bool enabled) = 0; |
97 | 140 |
98 // NOTE this must be called on the thread this TaskQueue was created by. | 141 // NOTE this must be called on the thread this TaskQueue was created by. |
99 virtual bool IsQueueEnabled() const = 0; | 142 virtual bool IsQueueEnabled() const = 0; |
100 | 143 |
101 // Returns true if the queue is completely empty. | 144 // Returns true if the queue is completely empty. |
102 virtual bool IsEmpty() const = 0; | 145 virtual bool IsEmpty() const = 0; |
103 | 146 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 protected: | 194 protected: |
152 ~TaskQueue() override {} | 195 ~TaskQueue() override {} |
153 | 196 |
154 DISALLOW_COPY_AND_ASSIGN(TaskQueue); | 197 DISALLOW_COPY_AND_ASSIGN(TaskQueue); |
155 }; | 198 }; |
156 | 199 |
157 } // namespace scheduler | 200 } // namespace scheduler |
158 } // namespace blink | 201 } // namespace blink |
159 | 202 |
160 #endif // THIRD_PARTY_WEBKIT_PUBLIC_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_H_ | 203 #endif // THIRD_PARTY_WEBKIT_PUBLIC_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_H_ |
OLD | NEW |