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