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

Side by Side Diff: components/scheduler/base/task_queue_manager.cc

Issue 1411843008: Make blink platform time consistent with the timer virtual time (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix CachingCorrectnessTest Created 5 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/scheduler/base/task_queue_manager.h" 5 #include "components/scheduler/base/task_queue_manager.h"
6 6
7 #include <queue> 7 #include <queue>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 newly_updatable_.pop_back(); 164 newly_updatable_.pop_back();
165 } 165 }
166 } 166 }
167 167
168 void TaskQueueManager::UpdateWorkQueues( 168 void TaskQueueManager::UpdateWorkQueues(
169 bool should_trigger_wakeup, 169 bool should_trigger_wakeup,
170 const internal::TaskQueueImpl::Task* previous_task) { 170 const internal::TaskQueueImpl::Task* previous_task) {
171 DCHECK(main_thread_checker_.CalledOnValidThread()); 171 DCHECK(main_thread_checker_.CalledOnValidThread());
172 TRACE_EVENT0(disabled_by_default_tracing_category_, 172 TRACE_EVENT0(disabled_by_default_tracing_category_,
173 "TaskQueueManager::UpdateWorkQueues"); 173 "TaskQueueManager::UpdateWorkQueues");
174 internal::LazyNow lazy_now(tick_clock()); 174 internal::LazyNow lazy_now(delegate().get());
175 175
176 // Move any ready delayed tasks into the incomming queues. 176 // Move any ready delayed tasks into the incomming queues.
177 WakeupReadyDelayedQueues(&lazy_now); 177 WakeupReadyDelayedQueues(&lazy_now);
178 178
179 MoveNewlyUpdatableQueuesIntoUpdatableQueueSet(); 179 MoveNewlyUpdatableQueuesIntoUpdatableQueueSet();
180 180
181 auto iter = updatable_queue_set_.begin(); 181 auto iter = updatable_queue_set_.begin();
182 while (iter != updatable_queue_set_.end()) { 182 while (iter != updatable_queue_set_.end()) {
183 internal::TaskQueueImpl* queue = *iter++; 183 internal::TaskQueueImpl* queue = *iter++;
184 // NOTE Update work queue may erase itself from |updatable_queue_set_|. 184 // NOTE Update work queue may erase itself from |updatable_queue_set_|.
185 // This is fine, erasing an element won't invalidate any interator, as long 185 // This is fine, erasing an element won't invalidate any interator, as long
186 // as the iterator isn't the element being delated. 186 // as the iterator isn't the element being delated.
187 if (queue->work_queue().empty()) 187 if (queue->work_queue().empty())
188 queue->UpdateWorkQueue(&lazy_now, should_trigger_wakeup, previous_task); 188 queue->UpdateWorkQueue(&lazy_now, should_trigger_wakeup, previous_task);
189 } 189 }
190 } 190 }
191 191
192 void TaskQueueManager::ScheduleDelayedWorkTask( 192 void TaskQueueManager::ScheduleDelayedWorkTask(
193 scoped_refptr<internal::TaskQueueImpl> queue, 193 scoped_refptr<internal::TaskQueueImpl> queue,
194 base::TimeTicks delayed_run_time) { 194 base::TimeTicks delayed_run_time) {
195 internal::LazyNow lazy_now(tick_clock()); 195 internal::LazyNow lazy_now(delegate().get());
196 ScheduleDelayedWork(queue.get(), delayed_run_time, &lazy_now); 196 ScheduleDelayedWork(queue.get(), delayed_run_time, &lazy_now);
197 } 197 }
198 198
199 void TaskQueueManager::ScheduleDelayedWork(internal::TaskQueueImpl* queue, 199 void TaskQueueManager::ScheduleDelayedWork(internal::TaskQueueImpl* queue,
200 base::TimeTicks delayed_run_time, 200 base::TimeTicks delayed_run_time,
201 internal::LazyNow* lazy_now) { 201 internal::LazyNow* lazy_now) {
202 if (!delegate_->BelongsToCurrentThread()) { 202 if (!delegate_->BelongsToCurrentThread()) {
203 // NOTE posting a delayed task from a different thread is not expected to be 203 // NOTE posting a delayed task from a different thread is not expected to be
204 // common. This pathway is less optimal than perhaps it could be because 204 // common. This pathway is less optimal than perhaps it could be because
205 // it causes two main thread tasks to be run. Should this assumption prove 205 // it causes two main thread tasks to be run. Should this assumption prove
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 DCHECK(main_thread_checker_.CalledOnValidThread()); 393 DCHECK(main_thread_checker_.CalledOnValidThread());
394 task_observers_.RemoveObserver(task_observer); 394 task_observers_.RemoveObserver(task_observer);
395 } 395 }
396 396
397 bool TaskQueueManager::GetAndClearSystemIsQuiescentBit() { 397 bool TaskQueueManager::GetAndClearSystemIsQuiescentBit() {
398 bool task_was_run = task_was_run_on_quiescence_monitored_queue_; 398 bool task_was_run = task_was_run_on_quiescence_monitored_queue_;
399 task_was_run_on_quiescence_monitored_queue_ = false; 399 task_was_run_on_quiescence_monitored_queue_ = false;
400 return !task_was_run; 400 return !task_was_run;
401 } 401 }
402 402
403 base::TickClock* TaskQueueManager::tick_clock() const { 403 const scoped_refptr<TaskQueueManagerDelegate>& TaskQueueManager::delegate()
404 return delegate_.get(); 404 const {
405 return delegate_;
405 } 406 }
406 407
407 int TaskQueueManager::GetNextSequenceNumber() { 408 int TaskQueueManager::GetNextSequenceNumber() {
408 return task_sequence_num_.GetNext(); 409 return task_sequence_num_.GetNext();
409 } 410 }
410 411
411 scoped_refptr<base::trace_event::ConvertableToTraceFormat> 412 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
412 TaskQueueManager::AsValueWithSelectorResult( 413 TaskQueueManager::AsValueWithSelectorResult(
413 bool should_run, 414 bool should_run,
414 internal::TaskQueueImpl* selected_queue) const { 415 internal::TaskQueueImpl* selected_queue) const {
(...skipping 18 matching lines...) Expand all
433 } 434 }
434 435
435 void TaskQueueManager::OnTaskQueueEnabled(internal::TaskQueueImpl* queue) { 436 void TaskQueueManager::OnTaskQueueEnabled(internal::TaskQueueImpl* queue) {
436 DCHECK(main_thread_checker_.CalledOnValidThread()); 437 DCHECK(main_thread_checker_.CalledOnValidThread());
437 // Only schedule DoWork if there's something to do. 438 // Only schedule DoWork if there's something to do.
438 if (!queue->work_queue().empty()) 439 if (!queue->work_queue().empty())
439 MaybePostDoWorkOnMainRunner(); 440 MaybePostDoWorkOnMainRunner();
440 } 441 }
441 442
442 } // namespace scheduler 443 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/base/task_queue_manager.h ('k') | components/scheduler/base/task_queue_manager_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698