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_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ | 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ |
6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ | 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "platform/scheduler/base/lazy_now.h" | 16 #include "platform/scheduler/base/lazy_now.h" |
17 #include "platform/scheduler/base/task_queue_impl.h" | 17 #include "platform/scheduler/base/task_queue_impl.h" |
18 | 18 |
19 namespace blink { | 19 namespace blink { |
20 namespace scheduler { | 20 namespace scheduler { |
21 namespace internal { | 21 namespace internal { |
22 class TaskQueueImpl; | 22 class TaskQueueImpl; |
23 } // internal | 23 } // internal |
24 class TaskQueueManager; | 24 class TaskQueueManager; |
25 class TaskQueueManagerDelegate; | 25 class TaskQueueManagerDelegate; |
26 | 26 |
27 // The TimeDomain's job is to keep track of moments when delayed tasks have been | 27 // The TimeDomain's job is to wake task queues up when their next delayed tasks |
28 // scheduled to fire and to notify their TaskQueues via UpdateDelayedWorkQueue. | 28 // are due to fire. TaskQueues request a wake up via ScheduleDelayedWork, when |
| 29 // the WakeUp is due the TimeDomain calls TaskQueue::WakeUpForDelayedWork which |
| 30 // schedules the next non-canceled wakeup. |
29 // | 31 // |
30 // The time domain keeps track of the next wakeup required to pump delayed tasks | 32 // To prevent spurious wake-ups for canceled tasks the TaskQueue should only |
31 // and issues |RequestWakeup| calls to the subclass as needed. Where possible | 33 // have a single wake up registered with its TimeDomain. If should call |
32 // it tried to de-dupe these wakeups. Ideally it would be possible to cancel | 34 // CancelDelayedWork as needed to ensure this. The TimeDomain communicates with |
33 // them, but that's not currently supported by the base message loop. | 35 // the TaskQueueManager to actually schedule the wake-ups on the underlying |
| 36 // base::MessageLoop. Various levels of de-duping are employed to prevent |
| 37 // unnecessary posting of TaskQueueManager::DoWork. |
34 // | 38 // |
35 // The clock itself is provided by subclasses of the TimeDomain and it may be | 39 // The clock itself is provided by subclasses of the TimeDomain and it may be |
36 // the real wall clock or a synthetic (virtual) time base. | 40 // the real wall clock or a synthetic (virtual) time base. |
37 class BLINK_PLATFORM_EXPORT TimeDomain { | 41 class BLINK_PLATFORM_EXPORT TimeDomain { |
38 public: | 42 public: |
39 class BLINK_PLATFORM_EXPORT Observer { | 43 class BLINK_PLATFORM_EXPORT Observer { |
40 public: | 44 public: |
41 virtual ~Observer() {} | 45 virtual ~Observer() {} |
42 | 46 |
43 // Called when an empty TaskQueue registered with this TimeDomain has a task | 47 // Called when an empty TaskQueue registered with this TimeDomain has a task |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 TimeDomain* destination_time_domain); | 86 TimeDomain* destination_time_domain); |
83 | 87 |
84 // If there is a scheduled delayed task, |out_task_queue| is set to the queue | 88 // If there is a scheduled delayed task, |out_task_queue| is set to the queue |
85 // the next task was posted to and it returns true. Returns false otherwise. | 89 // the next task was posted to and it returns true. Returns false otherwise. |
86 bool NextScheduledTaskQueue(TaskQueue** out_task_queue) const; | 90 bool NextScheduledTaskQueue(TaskQueue** out_task_queue) const; |
87 | 91 |
88 // Adds |queue| to the set of task queues that UpdateWorkQueues calls | 92 // Adds |queue| to the set of task queues that UpdateWorkQueues calls |
89 // UpdateWorkQueue on. | 93 // UpdateWorkQueue on. |
90 void RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue); | 94 void RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue); |
91 | 95 |
92 // Schedules a call to TaskQueueImpl::MoveReadyDelayedTasksToDelayedWorkQueue | 96 // Schedules a call to TaskQueueImpl::WakeUpForDelayedWork |
93 // when this TimeDomain reaches |delayed_run_time|. | 97 // when this TimeDomain reaches |delayed_run_time|. |
94 void ScheduleDelayedWork(internal::TaskQueueImpl* queue, | 98 void ScheduleDelayedWork(internal::TaskQueueImpl* queue, |
95 base::TimeTicks delayed_run_time, | 99 base::TimeTicks delayed_run_time, |
96 base::TimeTicks now); | 100 base::TimeTicks now); |
97 | 101 |
98 // Cancels a call to TaskQueueImpl::MoveReadyDelayedTasksToDelayedWorkQueue | 102 // Cancels a call to TaskQueueImpl::WakeUpForDelayedWork |
99 // previously requested with ScheduleDelayedWork. Note this only works if | 103 // previously requested with ScheduleDelayedWork. Note this only works if |
100 // delayed_run_time is _not_ the next scheduled run time. | 104 // delayed_run_time is _not_ the next scheduled run time. |
101 void CancelDelayedWork(internal::TaskQueueImpl* queue, | 105 void CancelDelayedWork(internal::TaskQueueImpl* queue, |
102 base::TimeTicks delayed_run_time); | 106 base::TimeTicks delayed_run_time); |
103 | 107 |
104 // Registers the |queue|. | 108 // Registers the |queue|. |
105 void RegisterQueue(internal::TaskQueueImpl* queue); | 109 void RegisterQueue(internal::TaskQueueImpl* queue); |
106 | 110 |
107 // Removes |queue| from the set of task queues that UpdateWorkQueues calls | 111 // Removes |queue| from the set of task queues that UpdateWorkQueues calls |
108 // UpdateWorkQueue on. Returns true if |queue| was updatable. | 112 // UpdateWorkQueue on. Returns true if |queue| was updatable. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 164 |
161 base::ThreadChecker main_thread_checker_; | 165 base::ThreadChecker main_thread_checker_; |
162 | 166 |
163 DISALLOW_COPY_AND_ASSIGN(TimeDomain); | 167 DISALLOW_COPY_AND_ASSIGN(TimeDomain); |
164 }; | 168 }; |
165 | 169 |
166 } // namespace scheduler | 170 } // namespace scheduler |
167 } // namespace blink | 171 } // namespace blink |
168 | 172 |
169 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ | 173 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ |
OLD | NEW |