Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/base/time_domain.h

Issue 2812703002: Revert of [scheduler] Add TaskQueue::Observer (Closed)
Patch Set: Manual Revert Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 13 matching lines...) Expand all
24 } // internal 24 } // internal
25 class TaskQueueManager; 25 class TaskQueueManager;
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 wake task queues up when their next delayed tasks
28 // are due to fire. TaskQueues request a wake up via ScheduleDelayedWork, when 28 // are due to fire. TaskQueues request a wake up via ScheduleDelayedWork, when
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 wakeup 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 TimeDomain(); 39 class BLINK_PLATFORM_EXPORT Observer {
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);
40 virtual ~TimeDomain(); 55 virtual ~TimeDomain();
41 56
42 // Returns a LazyNow that evaluate this TimeDomain's Now. Can be called from 57 // Returns a LazyNow that evaluate this TimeDomain's Now. Can be called from
43 // any thread. 58 // any thread.
44 // TODO(alexclarke): Make this main thread only. 59 // TODO(alexclarke): Make this main thread only.
45 virtual LazyNow CreateLazyNow() const = 0; 60 virtual LazyNow CreateLazyNow() const = 0;
46 61
47 // Evaluate this TimeDomain's Now. Can be called from any thread. 62 // Evaluate this TimeDomain's Now. Can be called from any thread.
48 virtual base::TimeTicks Now() const = 0; 63 virtual base::TimeTicks Now() const = 0;
49 64
(...skipping 14 matching lines...) Expand all
64 protected: 79 protected:
65 friend class internal::TaskQueueImpl; 80 friend class internal::TaskQueueImpl;
66 friend class TaskQueueManager; 81 friend class TaskQueueManager;
67 82
68 void AsValueInto(base::trace_event::TracedValue* state) const; 83 void AsValueInto(base::trace_event::TracedValue* state) const;
69 84
70 // If there is a scheduled delayed task, |out_task_queue| is set to the queue 85 // If there is a scheduled delayed task, |out_task_queue| is set to the queue
71 // the next task was posted to and it returns true. Returns false otherwise. 86 // the next task was posted to and it returns true. Returns false otherwise.
72 bool NextScheduledTaskQueue(TaskQueue** out_task_queue) const; 87 bool NextScheduledTaskQueue(TaskQueue** out_task_queue) const;
73 88
89 // Notifies the time domain observer (if any) that |queue| has incoming
90 // immediate work.
91 void OnQueueHasImmediateWork(internal::TaskQueueImpl* queue);
92
74 // Schedules a call to TaskQueueImpl::WakeUpForDelayedWork when this 93 // Schedules a call to TaskQueueImpl::WakeUpForDelayedWork when this
75 // TimeDomain reaches |delayed_run_time|. This supersedes any previously 94 // TimeDomain reaches |delayed_run_time|. This supersedes any previously
76 // registered wake-up for |queue|. 95 // registered wakeup for |queue|.
77 void ScheduleDelayedWork(internal::TaskQueueImpl* queue, 96 void ScheduleDelayedWork(internal::TaskQueueImpl* queue,
78 internal::TaskQueueImpl::DelayedWakeUp wake_up, 97 internal::TaskQueueImpl::DelayedWakeUp wake_up,
79 base::TimeTicks now); 98 base::TimeTicks now);
80 99
81 // Cancels any scheduled calls to TaskQueueImpl::WakeUpForDelayedWork for 100 // Cancels any scheduled calls to TaskQueueImpl::WakeUpForDelayedWork for
82 // |queue|. 101 // |queue|.
83 void CancelDelayedWork(internal::TaskQueueImpl* queue); 102 void CancelDelayedWork(internal::TaskQueueImpl* queue);
84 103
85 // Registers the |queue|. 104 // Registers the |queue|.
86 void RegisterQueue(internal::TaskQueueImpl* queue); 105 void RegisterQueue(internal::TaskQueueImpl* queue);
87 106
88 // Removes |queue| from all internal data structures. 107 // Removes |queue| from all internal data structures.
89 void UnregisterQueue(internal::TaskQueueImpl* queue); 108 void UnregisterQueue(internal::TaskQueueImpl* queue);
90 109
91 // Called by the TaskQueueManager when the TimeDomain is registered. 110 // Called by the TaskQueueManager when the TimeDomain is registered.
92 virtual void OnRegisterWithTaskQueueManager( 111 virtual void OnRegisterWithTaskQueueManager(
93 TaskQueueManager* task_queue_manager) = 0; 112 TaskQueueManager* task_queue_manager) = 0;
94 113
95 // The implementation will schedule task processing to run at time |run_time| 114 // The implementation will schedule task processing to run at time |run_time|
96 // within the TimeDomain's time line. Only called from the main thread. 115 // within the TimeDomain's time line. Only called from the main thread.
97 // NOTE this is only called by ScheduleDelayedWork if the scheduled runtime 116 // NOTE this is only called by ScheduleDelayedWork if the scheduled runtime
98 // is sooner than any previously sheduled work or if there is no other 117 // is sooner than any previously sheduled work or if there is no other
99 // scheduled work. 118 // scheduled work.
100 virtual void RequestWakeUpAt(base::TimeTicks now, 119 virtual void RequestWakeupAt(base::TimeTicks now,
101 base::TimeTicks run_time) = 0; 120 base::TimeTicks run_time) = 0;
102 121
103 // The implementation will cancel a wake up previously requested by 122 // The implementation will cancel a wake up previously requested by
104 // RequestWakeUpAt. It's expected this will be a NOP for most virtual time 123 // RequestWakeupAt. It's expected this will be a NOP for most virtual time
105 // domains. 124 // domains.
106 virtual void CancelWakeUpAt(base::TimeTicks run_time) = 0; 125 virtual void CancelWakeupAt(base::TimeTicks run_time) = 0;
107 126
108 // For implementation specific tracing. 127 // For implementation specific tracing.
109 virtual void AsValueIntoInternal( 128 virtual void AsValueIntoInternal(
110 base::trace_event::TracedValue* state) const = 0; 129 base::trace_event::TracedValue* state) const = 0;
111 130
112 // Call TaskQueueImpl::UpdateDelayedWorkQueue for each queue where the delay 131 // Call TaskQueueImpl::UpdateDelayedWorkQueue for each queue where the delay
113 // has elapsed. 132 // has elapsed.
114 void WakeUpReadyDelayedQueues(LazyNow* lazy_now); 133 void WakeupReadyDelayedQueues(LazyNow* lazy_now);
115 134
116 size_t NumberOfScheduledWakeUps() const { 135 size_t NumberOfScheduledWakeups() const {
117 return delayed_wake_up_queue_.size(); 136 return delayed_wakeup_queue_.size();
118 } 137 }
119 138
120 private: 139 private:
121 struct ScheduledDelayedWakeUp { 140 struct ScheduledDelayedWakeUp {
122 internal::TaskQueueImpl::DelayedWakeUp wake_up; 141 internal::TaskQueueImpl::DelayedWakeUp wake_up;
123 internal::TaskQueueImpl* queue; 142 internal::TaskQueueImpl* queue;
124 143
125 bool operator<=(const ScheduledDelayedWakeUp& other) const { 144 bool operator<=(const ScheduledDelayedWakeUp& other) const {
126 return wake_up <= other.wake_up; 145 return wake_up <= other.wake_up;
127 } 146 }
128 147
129 void SetHeapHandle(HeapHandle handle) { 148 void SetHeapHandle(HeapHandle handle) {
130 DCHECK(handle.IsValid()); 149 DCHECK(handle.IsValid());
131 queue->set_heap_handle(handle); 150 queue->set_heap_handle(handle);
132 } 151 }
133 152
134 void ClearHeapHandle() { 153 void ClearHeapHandle() {
135 DCHECK(queue->heap_handle().IsValid()); 154 DCHECK(queue->heap_handle().IsValid());
136 queue->set_heap_handle(HeapHandle()); 155 queue->set_heap_handle(HeapHandle());
137 156
138 DCHECK_NE(queue->scheduled_time_domain_wake_up(), base::TimeTicks()); 157 DCHECK_NE(queue->scheduled_time_domain_wakeup(), base::TimeTicks());
139 queue->set_scheduled_time_domain_wake_up(base::TimeTicks()); 158 queue->set_scheduled_time_domain_wakeup(base::TimeTicks());
140 } 159 }
141 }; 160 };
142 161
143 IntrusiveHeap<ScheduledDelayedWakeUp> delayed_wake_up_queue_; 162 IntrusiveHeap<ScheduledDelayedWakeUp> delayed_wakeup_queue_;
163
164 Observer* const observer_; // NOT OWNED.
144 165
145 base::ThreadChecker main_thread_checker_; 166 base::ThreadChecker main_thread_checker_;
146 167
147 DISALLOW_COPY_AND_ASSIGN(TimeDomain); 168 DISALLOW_COPY_AND_ASSIGN(TimeDomain);
148 }; 169 };
149 170
150 } // namespace scheduler 171 } // namespace scheduler
151 } // namespace blink 172 } // namespace blink
152 173
153 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ 174 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698