OLD | NEW |
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 "platform/scheduler/base/task_queue_manager.h" | 5 #include "platform/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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 DCHECK_GE(delay, base::TimeDelta()); | 183 DCHECK_GE(delay, base::TimeDelta()); |
184 | 184 |
185 // If there's a pending immediate DoWork then we rely on | 185 // If there's a pending immediate DoWork then we rely on |
186 // TryAdvanceTimeDomains getting the TimeDomain to call | 186 // TryAdvanceTimeDomains getting the TimeDomain to call |
187 // MaybeScheduleDelayedWork again when the immediate DoWork is complete. | 187 // MaybeScheduleDelayedWork again when the immediate DoWork is complete. |
188 if (main_thread_pending_wakeups_.find(base::TimeTicks()) != | 188 if (main_thread_pending_wakeups_.find(base::TimeTicks()) != |
189 main_thread_pending_wakeups_.end()) { | 189 main_thread_pending_wakeups_.end()) { |
190 return; | 190 return; |
191 } | 191 } |
192 | 192 |
193 // De-duplicate DoWork posts. | 193 // Only request the wake up if, either there are no wake ups scheduled, or if |
| 194 // its sooner than any previously requested wake up. |
194 base::TimeTicks run_time = now + delay; | 195 base::TimeTicks run_time = now + delay; |
195 if (!main_thread_pending_wakeups_.insert(run_time).second) | 196 if (!main_thread_pending_wakeups_.empty() && |
| 197 *main_thread_pending_wakeups_.begin() <= run_time) { |
196 return; | 198 return; |
| 199 } |
| 200 main_thread_pending_wakeups_.insert(run_time); |
197 delegate_->PostDelayedTask( | 201 delegate_->PostDelayedTask( |
198 from_here, base::Bind(&TaskQueueManager::DoWork, | 202 from_here, base::Bind(&TaskQueueManager::DoWork, |
199 weak_factory_.GetWeakPtr(), run_time, true), | 203 weak_factory_.GetWeakPtr(), run_time, true), |
200 delay); | 204 delay); |
201 } | 205 } |
202 | 206 |
203 void TaskQueueManager::DoWork(base::TimeTicks run_time, bool from_main_thread) { | 207 void TaskQueueManager::DoWork(base::TimeTicks run_time, bool from_main_thread) { |
204 DCHECK(main_thread_checker_.CalledOnValidThread()); | 208 DCHECK(main_thread_checker_.CalledOnValidThread()); |
205 TRACE_EVENT1(tracing_category_, "TaskQueueManager::DoWork", | 209 TRACE_EVENT1(tracing_category_, "TaskQueueManager::DoWork", |
206 "from_main_thread", from_main_thread); | 210 "from_main_thread", from_main_thread); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 DCHECK(main_thread_checker_.CalledOnValidThread()); | 462 DCHECK(main_thread_checker_.CalledOnValidThread()); |
459 DCHECK(!work_queue->Empty()); | 463 DCHECK(!work_queue->Empty()); |
460 if (observer_) { | 464 if (observer_) { |
461 observer_->OnTriedToExecuteBlockedTask(*work_queue->task_queue(), | 465 observer_->OnTriedToExecuteBlockedTask(*work_queue->task_queue(), |
462 *work_queue->GetFrontTask()); | 466 *work_queue->GetFrontTask()); |
463 } | 467 } |
464 } | 468 } |
465 | 469 |
466 } // namespace scheduler | 470 } // namespace scheduler |
467 } // namespace blink | 471 } // namespace blink |
OLD | NEW |