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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 // the wake up is due the TimeDomain calls TaskQueue::WakeUpForDelayedWork. | 29 // the wake up is due the TimeDomain calls TaskQueue::WakeUpForDelayedWork. |
30 // The TimeDomain communicates with the TaskQueueManager to actually schedule | 30 // The TimeDomain communicates with the TaskQueueManager to actually schedule |
31 // the wake-ups on the underlying base::MessageLoop. Various levels of de-duping | 31 // the wake-ups on the underlying base::MessageLoop. Various levels of de-duping |
32 // are employed to prevent unnecessary posting of TaskQueueManager::DoWork. | 32 // are employed to prevent unnecessary posting of TaskQueueManager::DoWork. |
33 // | 33 // |
34 // Note the TimeDomain only knows about the first wake-up per queue, it's the | 34 // Note the TimeDomain only knows about the first wake-up per queue, it's the |
35 // responsibility of TaskQueueImpl to keep the time domain up to date if this | 35 // responsibility of TaskQueueImpl to keep the time domain up to date if this |
36 // changes. | 36 // changes. |
37 class BLINK_PLATFORM_EXPORT TimeDomain { | 37 class BLINK_PLATFORM_EXPORT TimeDomain { |
38 public: | 38 public: |
39 class BLINK_PLATFORM_EXPORT Observer { | 39 TimeDomain(); |
40 public: | |
41 virtual ~Observer() {} | |
42 | |
43 // Called when an empty TaskQueue registered with this TimeDomain has a task | |
44 // enqueued. | |
45 // |task_queue| - task queue which has immediate work scheduled. | |
46 virtual void OnTimeDomainHasImmediateWork(TaskQueue* task_queue) = 0; | |
47 | |
48 // Called when a TaskQueue registered with this TimeDomain has a delayed | |
49 // task enqueued. | |
50 // |task_queue| - task queue which has delayed work scheduled. | |
51 virtual void OnTimeDomainHasDelayedWork(TaskQueue* task_queue) = 0; | |
52 }; | |
53 | |
54 explicit TimeDomain(Observer* observer); | |
55 virtual ~TimeDomain(); | 40 virtual ~TimeDomain(); |
56 | 41 |
57 // Returns a LazyNow that evaluate this TimeDomain's Now. Can be called from | 42 // Returns a LazyNow that evaluate this TimeDomain's Now. Can be called from |
58 // any thread. | 43 // any thread. |
59 // TODO(alexclarke): Make this main thread only. | 44 // TODO(alexclarke): Make this main thread only. |
60 virtual LazyNow CreateLazyNow() const = 0; | 45 virtual LazyNow CreateLazyNow() const = 0; |
61 | 46 |
62 // Evaluate this TimeDomain's Now. Can be called from any thread. | 47 // Evaluate this TimeDomain's Now. Can be called from any thread. |
63 virtual base::TimeTicks Now() const = 0; | 48 virtual base::TimeTicks Now() const = 0; |
64 | 49 |
(...skipping 14 matching lines...) Expand all Loading... |
79 protected: | 64 protected: |
80 friend class internal::TaskQueueImpl; | 65 friend class internal::TaskQueueImpl; |
81 friend class TaskQueueManager; | 66 friend class TaskQueueManager; |
82 | 67 |
83 void AsValueInto(base::trace_event::TracedValue* state) const; | 68 void AsValueInto(base::trace_event::TracedValue* state) const; |
84 | 69 |
85 // If there is a scheduled delayed task, |out_task_queue| is set to the queue | 70 // If there is a scheduled delayed task, |out_task_queue| is set to the queue |
86 // the next task was posted to and it returns true. Returns false otherwise. | 71 // the next task was posted to and it returns true. Returns false otherwise. |
87 bool NextScheduledTaskQueue(TaskQueue** out_task_queue) const; | 72 bool NextScheduledTaskQueue(TaskQueue** out_task_queue) const; |
88 | 73 |
89 // Notifies the time domain observer (if any) that |queue| has incoming | |
90 // immediate work. | |
91 void OnQueueHasImmediateWork(internal::TaskQueueImpl* queue); | |
92 | |
93 // Schedules a call to TaskQueueImpl::WakeUpForDelayedWork when this | 74 // Schedules a call to TaskQueueImpl::WakeUpForDelayedWork when this |
94 // TimeDomain reaches |delayed_run_time|. This supersedes any previously | 75 // TimeDomain reaches |delayed_run_time|. This supersedes any previously |
95 // registered wake-up for |queue|. | 76 // registered wake-up for |queue|. |
96 void ScheduleDelayedWork(internal::TaskQueueImpl* queue, | 77 void ScheduleDelayedWork(internal::TaskQueueImpl* queue, |
97 internal::TaskQueueImpl::DelayedWakeUp wake_up, | 78 internal::TaskQueueImpl::DelayedWakeUp wake_up, |
98 base::TimeTicks now); | 79 base::TimeTicks now); |
99 | 80 |
100 // Cancels any scheduled calls to TaskQueueImpl::WakeUpForDelayedWork for | 81 // Cancels any scheduled calls to TaskQueueImpl::WakeUpForDelayedWork for |
101 // |queue|. | 82 // |queue|. |
102 void CancelDelayedWork(internal::TaskQueueImpl* queue); | 83 void CancelDelayedWork(internal::TaskQueueImpl* queue); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 DCHECK(queue->heap_handle().IsValid()); | 135 DCHECK(queue->heap_handle().IsValid()); |
155 queue->set_heap_handle(HeapHandle()); | 136 queue->set_heap_handle(HeapHandle()); |
156 | 137 |
157 DCHECK_NE(queue->scheduled_time_domain_wake_up(), base::TimeTicks()); | 138 DCHECK_NE(queue->scheduled_time_domain_wake_up(), base::TimeTicks()); |
158 queue->set_scheduled_time_domain_wake_up(base::TimeTicks()); | 139 queue->set_scheduled_time_domain_wake_up(base::TimeTicks()); |
159 } | 140 } |
160 }; | 141 }; |
161 | 142 |
162 IntrusiveHeap<ScheduledDelayedWakeUp> delayed_wake_up_queue_; | 143 IntrusiveHeap<ScheduledDelayedWakeUp> delayed_wake_up_queue_; |
163 | 144 |
164 Observer* const observer_; // NOT OWNED. | |
165 | |
166 base::ThreadChecker main_thread_checker_; | 145 base::ThreadChecker main_thread_checker_; |
167 | 146 |
168 DISALLOW_COPY_AND_ASSIGN(TimeDomain); | 147 DISALLOW_COPY_AND_ASSIGN(TimeDomain); |
169 }; | 148 }; |
170 | 149 |
171 } // namespace scheduler | 150 } // namespace scheduler |
172 } // namespace blink | 151 } // namespace blink |
173 | 152 |
174 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ | 153 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ |
OLD | NEW |