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

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

Issue 2798563003: [scheduler] Add TaskQueue::Observer (Closed)
Patch Set: 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 #include "platform/scheduler/base/time_domain.h" 5 #include "platform/scheduler/base/time_domain.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "platform/scheduler/base/task_queue_impl.h" 9 #include "platform/scheduler/base/task_queue_impl.h"
10 #include "platform/scheduler/base/task_queue_manager_delegate.h" 10 #include "platform/scheduler/base/task_queue_manager_delegate.h"
11 #include "platform/scheduler/base/work_queue.h" 11 #include "platform/scheduler/base/work_queue.h"
12 12
13 namespace blink { 13 namespace blink {
14 namespace scheduler { 14 namespace scheduler {
15 15
16 TimeDomain::TimeDomain(Observer* observer) : observer_(observer) {} 16 TimeDomain::TimeDomain() {}
17 17
18 TimeDomain::~TimeDomain() { 18 TimeDomain::~TimeDomain() {
19 DCHECK(main_thread_checker_.CalledOnValidThread()); 19 DCHECK(main_thread_checker_.CalledOnValidThread());
20 } 20 }
21 21
22 void TimeDomain::RegisterQueue(internal::TaskQueueImpl* queue) { 22 void TimeDomain::RegisterQueue(internal::TaskQueueImpl* queue) {
23 DCHECK(main_thread_checker_.CalledOnValidThread()); 23 DCHECK(main_thread_checker_.CalledOnValidThread());
24 DCHECK_EQ(queue->GetTimeDomain(), this); 24 DCHECK_EQ(queue->GetTimeDomain(), this);
25 } 25 }
26 26
(...skipping 21 matching lines...) Expand all
48 } else { 48 } else {
49 // O(log n) 49 // O(log n)
50 delayed_wakeup_queue_.insert({wake_up, queue}); 50 delayed_wakeup_queue_.insert({wake_up, queue});
51 } 51 }
52 52
53 queue->set_scheduled_time_domain_wakeup(wake_up.time); 53 queue->set_scheduled_time_domain_wakeup(wake_up.time);
54 54
55 // If |queue| is the first wakeup then request the wakeup. 55 // If |queue| is the first wakeup then request the wakeup.
56 if (delayed_wakeup_queue_.min().queue == queue) 56 if (delayed_wakeup_queue_.min().queue == queue)
57 RequestWakeupAt(now, wake_up.time); 57 RequestWakeupAt(now, wake_up.time);
58
59 if (observer_)
60 observer_->OnTimeDomainHasDelayedWork(queue);
61 }
62
63 void TimeDomain::OnQueueHasImmediateWork(internal::TaskQueueImpl* queue) {
64 if (observer_)
65 observer_->OnTimeDomainHasImmediateWork(queue);
66 } 58 }
67 59
68 void TimeDomain::CancelDelayedWork(internal::TaskQueueImpl* queue) { 60 void TimeDomain::CancelDelayedWork(internal::TaskQueueImpl* queue) {
69 DCHECK(main_thread_checker_.CalledOnValidThread()); 61 DCHECK(main_thread_checker_.CalledOnValidThread());
70 DCHECK_EQ(queue->GetTimeDomain(), this); 62 DCHECK_EQ(queue->GetTimeDomain(), this);
71 63
72 // If no wakeup has been requested then bail out. 64 // If no wakeup has been requested then bail out.
73 if (!queue->heap_handle().IsValid()) 65 if (!queue->heap_handle().IsValid())
74 return; 66 return;
75 67
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 if (!delayed_wakeup_queue_.empty()) { 128 if (!delayed_wakeup_queue_.empty()) {
137 base::TimeDelta delay = delayed_wakeup_queue_.min().wake_up.time - Now(); 129 base::TimeDelta delay = delayed_wakeup_queue_.min().wake_up.time - Now();
138 state->SetDouble("next_delay_ms", delay.InMillisecondsF()); 130 state->SetDouble("next_delay_ms", delay.InMillisecondsF());
139 } 131 }
140 AsValueIntoInternal(state); 132 AsValueIntoInternal(state);
141 state->EndDictionary(); 133 state->EndDictionary();
142 } 134 }
143 135
144 } // namespace scheduler 136 } // namespace scheduler
145 } // namespace blink 137 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698