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 #include "components/scheduler/base/task_queue_manager_delegate.h" |
9 #include "components/scheduler/base/time_domain.h" | 9 #include "components/scheduler/base/time_domain.h" |
10 #include "components/scheduler/base/work_queue.h" | 10 #include "components/scheduler/base/work_queue.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 TaskType task_type) { | 179 TaskType task_type) { |
180 DCHECK_GT(delay, base::TimeDelta()); | 180 DCHECK_GT(delay, base::TimeDelta()); |
181 if (base::PlatformThread::CurrentId() == thread_id_) { | 181 if (base::PlatformThread::CurrentId() == thread_id_) { |
182 // Lock-free fast path for delayed tasks posted from the main thread. | 182 // Lock-free fast path for delayed tasks posted from the main thread. |
183 if (!main_thread_only().task_queue_manager) | 183 if (!main_thread_only().task_queue_manager) |
184 return false; | 184 return false; |
185 | 185 |
186 EnqueueOrder sequence_number = | 186 EnqueueOrder sequence_number = |
187 main_thread_only().task_queue_manager->GetNextSequenceNumber(); | 187 main_thread_only().task_queue_manager->GetNextSequenceNumber(); |
188 | 188 |
189 base::TimeTicks now = main_thread_only().time_domain->Now(); | 189 base::TimeTicks time_domain_now = main_thread_only().time_domain->Now(); |
| 190 base::TimeTicks time_domain_delayed_run_time = |
| 191 main_thread_only().time_domain->ComputeDelayedRunTime(time_domain_now, |
| 192 delay); |
190 PushOntoDelayedIncomingQueueFromMainThread( | 193 PushOntoDelayedIncomingQueueFromMainThread( |
191 Task(from_here, task, now + delay, sequence_number, | 194 Task(from_here, task, time_domain_delayed_run_time, sequence_number, |
192 task_type != TaskType::NON_NESTABLE), | 195 task_type != TaskType::NON_NESTABLE), |
193 now); | 196 time_domain_now); |
194 } else { | 197 } else { |
195 // NOTE posting a delayed task from a different thread is not expected to | 198 // NOTE posting a delayed task from a different thread is not expected to |
196 // be common. This pathway is less optimal than perhaps it could be | 199 // be common. This pathway is less optimal than perhaps it could be |
197 // because it causes two main thread tasks to be run. Should this | 200 // because it causes two main thread tasks to be run. Should this |
198 // assumption prove to be false in future, we may need to revisit this. | 201 // assumption prove to be false in future, we may need to revisit this. |
199 base::AutoLock lock(any_thread_lock_); | 202 base::AutoLock lock(any_thread_lock_); |
200 if (!any_thread().task_queue_manager) | 203 if (!any_thread().task_queue_manager) |
201 return false; | 204 return false; |
202 | 205 |
203 EnqueueOrder sequence_number = | 206 EnqueueOrder sequence_number = |
204 any_thread().task_queue_manager->GetNextSequenceNumber(); | 207 any_thread().task_queue_manager->GetNextSequenceNumber(); |
205 | 208 |
| 209 base::TimeTicks time_domain_now = any_thread().time_domain->Now(); |
| 210 base::TimeTicks time_domain_delayed_run_time = |
| 211 any_thread().time_domain->ComputeDelayedRunTime(time_domain_now, delay); |
206 PushOntoDelayedIncomingQueueLocked( | 212 PushOntoDelayedIncomingQueueLocked( |
207 Task(from_here, task, any_thread().time_domain->Now() + delay, | 213 Task(from_here, task, time_domain_delayed_run_time, sequence_number, |
208 sequence_number, task_type != TaskType::NON_NESTABLE)); | 214 task_type != TaskType::NON_NESTABLE)); |
209 } | 215 } |
210 return true; | 216 return true; |
211 } | 217 } |
212 | 218 |
213 void TaskQueueImpl::PushOntoDelayedIncomingQueueFromMainThread( | 219 void TaskQueueImpl::PushOntoDelayedIncomingQueueFromMainThread( |
214 Task&& pending_task, | 220 Task&& pending_task, |
215 base::TimeTicks now) { | 221 base::TimeTicks now) { |
216 main_thread_only().task_queue_manager->DidQueueTask(pending_task); | 222 main_thread_only().task_queue_manager->DidQueueTask(pending_task); |
217 | 223 |
218 // Schedule a later call to MoveReadyDelayedTasksToDelayedWorkQueue. | 224 // Schedule a later call to MoveReadyDelayedTasksToDelayedWorkQueue. |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 state->SetBoolean("nestable", task.nestable); | 679 state->SetBoolean("nestable", task.nestable); |
674 state->SetBoolean("is_high_res", task.is_high_res); | 680 state->SetBoolean("is_high_res", task.is_high_res); |
675 state->SetDouble( | 681 state->SetDouble( |
676 "delayed_run_time", | 682 "delayed_run_time", |
677 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); | 683 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); |
678 state->EndDictionary(); | 684 state->EndDictionary(); |
679 } | 685 } |
680 | 686 |
681 } // namespace internal | 687 } // namespace internal |
682 } // namespace scheduler | 688 } // namespace scheduler |
OLD | NEW |