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