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 #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" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 delayed_run_time < delayed_wakeup_multimap_.begin()->first) { | 77 delayed_run_time < delayed_wakeup_multimap_.begin()->first) { |
78 base::TimeDelta delay = std::max(base::TimeDelta(), delayed_run_time - now); | 78 base::TimeDelta delay = std::max(base::TimeDelta(), delayed_run_time - now); |
79 RequestWakeup(now, delay); | 79 RequestWakeup(now, delay); |
80 } | 80 } |
81 | 81 |
82 delayed_wakeup_multimap_.insert(std::make_pair(delayed_run_time, queue)); | 82 delayed_wakeup_multimap_.insert(std::make_pair(delayed_run_time, queue)); |
83 if (observer_) | 83 if (observer_) |
84 observer_->OnTimeDomainHasDelayedWork(); | 84 observer_->OnTimeDomainHasDelayedWork(); |
85 } | 85 } |
86 | 86 |
87 void TimeDomain::CancelDelayedWork(internal::TaskQueueImpl* queue, | |
88 base::TimeTicks delayed_run_time) { | |
89 DCHECK(main_thread_checker_.CalledOnValidThread()); | |
90 | |
91 auto iterpair = delayed_wakeup_multimap_.equal_range(delayed_run_time); | |
92 for (auto it = iterpair.first; it != iterpair.second; ++it) { | |
93 if (it->second == queue) { | |
94 base::TimeTicks prev_first_wakeup = | |
95 delayed_wakeup_multimap_.begin()->first; | |
96 delayed_wakeup_multimap_.erase(it); | |
97 | |
98 if (delayed_wakeup_multimap_.empty()) | |
99 break; | |
100 | |
101 base::TimeTicks first_wakeup = delayed_wakeup_multimap_.begin()->first; | |
102 | |
103 if (first_wakeup == prev_first_wakeup) | |
haraken
2016/08/19 10:42:51
I'm just curious but what is this check doing?
alex clarke (OOO till 29th)
2016/08/19 11:02:59
I added a comment, it's checking if the first entr
| |
104 break; | |
105 | |
106 // The first wakeup has changed, we need to re-schedule. | |
107 base::TimeTicks now = Now(); | |
108 base::TimeDelta delay = std::max(base::TimeDelta(), first_wakeup - now); | |
109 RequestWakeup(now, delay); | |
110 break; | |
haraken
2016/08/19 10:42:51
This for loop finishes when it encounters the firs
alex clarke (OOO till 29th)
2016/08/19 11:02:59
I added a comment above but there might be other q
| |
111 } | |
112 } | |
113 | |
114 // Note since the base TaskRunner does not support cancellation there's no | |
115 // point trying to cancel a wakeup requested via RequestWakeup :( | |
116 } | |
117 | |
87 void TimeDomain::RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue) { | 118 void TimeDomain::RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue) { |
88 { | 119 { |
89 base::AutoLock lock(newly_updatable_lock_); | 120 base::AutoLock lock(newly_updatable_lock_); |
90 newly_updatable_.push_back(queue); | 121 newly_updatable_.push_back(queue); |
91 } | 122 } |
92 if (observer_) | 123 if (observer_) |
93 observer_->OnTimeDomainHasImmediateWork(); | 124 observer_->OnTimeDomainHasImmediateWork(); |
94 } | 125 } |
95 | 126 |
96 bool TimeDomain::UnregisterAsUpdatableTaskQueue( | 127 bool TimeDomain::UnregisterAsUpdatableTaskQueue( |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 if (!delayed_wakeup_multimap_.empty()) { | 244 if (!delayed_wakeup_multimap_.empty()) { |
214 base::TimeDelta delay = delayed_wakeup_multimap_.begin()->first - Now(); | 245 base::TimeDelta delay = delayed_wakeup_multimap_.begin()->first - Now(); |
215 state->SetDouble("next_delay_ms", delay.InMillisecondsF()); | 246 state->SetDouble("next_delay_ms", delay.InMillisecondsF()); |
216 } | 247 } |
217 AsValueIntoInternal(state); | 248 AsValueIntoInternal(state); |
218 state->EndDictionary(); | 249 state->EndDictionary(); |
219 } | 250 } |
220 | 251 |
221 } // namespace scheduler | 252 } // namespace scheduler |
222 } // namespace blink | 253 } // namespace blink |
OLD | NEW |