| 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 "components/scheduler/base/task_queue_impl.h" | 5 #include "components/scheduler/base/task_queue_impl.h" |
| 6 | 6 |
| 7 #include "components/scheduler/base/task_queue_manager.h" | 7 #include "components/scheduler/base/task_queue_manager.h" |
| 8 | 8 |
| 9 namespace scheduler { | 9 namespace scheduler { |
| 10 namespace internal { | 10 namespace internal { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 return PostDelayedTaskImpl(from_here, task, delay, TaskType::NON_NESTABLE); | 96 return PostDelayedTaskImpl(from_here, task, delay, TaskType::NON_NESTABLE); |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool TaskQueueImpl::PostDelayedTaskAt( | 99 bool TaskQueueImpl::PostDelayedTaskAt( |
| 100 const tracked_objects::Location& from_here, | 100 const tracked_objects::Location& from_here, |
| 101 const base::Closure& task, | 101 const base::Closure& task, |
| 102 base::TimeTicks desired_run_time) { | 102 base::TimeTicks desired_run_time) { |
| 103 base::AutoLock lock(any_thread_lock_); | 103 base::AutoLock lock(any_thread_lock_); |
| 104 if (!any_thread().task_queue_manager) | 104 if (!any_thread().task_queue_manager) |
| 105 return false; | 105 return false; |
| 106 LazyNow lazy_now(any_thread().task_queue_manager); | 106 LazyNow lazy_now(any_thread().task_queue_manager->tick_clock()); |
| 107 return PostDelayedTaskLocked(&lazy_now, from_here, task, desired_run_time, | 107 return PostDelayedTaskLocked(&lazy_now, from_here, task, desired_run_time, |
| 108 TaskType::NORMAL); | 108 TaskType::NORMAL); |
| 109 } | 109 } |
| 110 | 110 |
| 111 bool TaskQueueImpl::PostDelayedTaskImpl( | 111 bool TaskQueueImpl::PostDelayedTaskImpl( |
| 112 const tracked_objects::Location& from_here, | 112 const tracked_objects::Location& from_here, |
| 113 const base::Closure& task, | 113 const base::Closure& task, |
| 114 base::TimeDelta delay, | 114 base::TimeDelta delay, |
| 115 TaskType task_type) { | 115 TaskType task_type) { |
| 116 base::AutoLock lock(any_thread_lock_); | 116 base::AutoLock lock(any_thread_lock_); |
| 117 if (!any_thread().task_queue_manager) | 117 if (!any_thread().task_queue_manager) |
| 118 return false; | 118 return false; |
| 119 LazyNow lazy_now(any_thread().task_queue_manager); | 119 LazyNow lazy_now(any_thread().task_queue_manager->tick_clock()); |
| 120 base::TimeTicks desired_run_time; | 120 base::TimeTicks desired_run_time; |
| 121 if (delay > base::TimeDelta()) | 121 if (delay > base::TimeDelta()) |
| 122 desired_run_time = lazy_now.Now() + delay; | 122 desired_run_time = lazy_now.Now() + delay; |
| 123 return PostDelayedTaskLocked(&lazy_now, from_here, task, desired_run_time, | 123 return PostDelayedTaskLocked(&lazy_now, from_here, task, desired_run_time, |
| 124 task_type); | 124 task_type); |
| 125 } | 125 } |
| 126 | 126 |
| 127 bool TaskQueueImpl::PostDelayedTaskLocked( | 127 bool TaskQueueImpl::PostDelayedTaskLocked( |
| 128 LazyNow* lazy_now, | 128 LazyNow* lazy_now, |
| 129 const tracked_objects::Location& from_here, | 129 const tracked_objects::Location& from_here, |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 any_thread().pump_policy != PumpPolicy::AUTO) { | 314 any_thread().pump_policy != PumpPolicy::AUTO) { |
| 315 PumpQueueLocked(); | 315 PumpQueueLocked(); |
| 316 } | 316 } |
| 317 any_thread().pump_policy = pump_policy; | 317 any_thread().pump_policy = pump_policy; |
| 318 } | 318 } |
| 319 | 319 |
| 320 void TaskQueueImpl::PumpQueueLocked() { | 320 void TaskQueueImpl::PumpQueueLocked() { |
| 321 if (!any_thread().task_queue_manager) | 321 if (!any_thread().task_queue_manager) |
| 322 return; | 322 return; |
| 323 | 323 |
| 324 LazyNow lazy_now(any_thread().task_queue_manager); | 324 LazyNow lazy_now(any_thread().task_queue_manager->tick_clock()); |
| 325 MoveReadyDelayedTasksToIncomingQueueLocked(&lazy_now); | 325 MoveReadyDelayedTasksToIncomingQueueLocked(&lazy_now); |
| 326 | 326 |
| 327 bool was_empty = main_thread_only().work_queue.empty(); | 327 bool was_empty = main_thread_only().work_queue.empty(); |
| 328 while (!any_thread().incoming_queue.empty()) { | 328 while (!any_thread().incoming_queue.empty()) { |
| 329 // TODO(alexclarke): consider std::move() when allowed. | 329 // TODO(alexclarke): consider std::move() when allowed. |
| 330 main_thread_only().work_queue.push(any_thread().incoming_queue.front()); | 330 main_thread_only().work_queue.push(any_thread().incoming_queue.front()); |
| 331 any_thread().incoming_queue.pop(); | 331 any_thread().incoming_queue.pop(); |
| 332 } | 332 } |
| 333 // |incoming_queue| is now empty so TaskQueueManager::UpdateQueues no longer | 333 // |incoming_queue| is now empty so TaskQueueManager::UpdateQueues no longer |
| 334 // needs to consider this queue for reloading. | 334 // needs to consider this queue for reloading. |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 state->SetBoolean("nestable", task.nestable); | 510 state->SetBoolean("nestable", task.nestable); |
| 511 state->SetBoolean("is_high_res", task.is_high_res); | 511 state->SetBoolean("is_high_res", task.is_high_res); |
| 512 state->SetDouble( | 512 state->SetDouble( |
| 513 "delayed_run_time", | 513 "delayed_run_time", |
| 514 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); | 514 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); |
| 515 state->EndDictionary(); | 515 state->EndDictionary(); |
| 516 } | 516 } |
| 517 | 517 |
| 518 } // namespace internal | 518 } // namespace internal |
| 519 } // namespace scheduler | 519 } // namespace scheduler |
| OLD | NEW |