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

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/base/task_queue_manager.cc

Issue 2353473003: Revert of Prevent redundant DoWorks due to canceled delayed tasks (Closed)
Patch Set: Created 4 years, 3 months 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 "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
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 // Only request the wake up if, either there are no wake ups scheduled, or if 193 // De-duplicate DoWork posts.
194 // its sooner than any previously requested wake up.
195 base::TimeTicks run_time = now + delay; 194 base::TimeTicks run_time = now + delay;
196 if (!main_thread_pending_wakeups_.empty() && 195 if (!main_thread_pending_wakeups_.insert(run_time).second)
197 *main_thread_pending_wakeups_.begin() <= run_time) {
198 return; 196 return;
199 }
200 main_thread_pending_wakeups_.insert(run_time);
201 delegate_->PostDelayedTask( 197 delegate_->PostDelayedTask(
202 from_here, base::Bind(&TaskQueueManager::DoWork, 198 from_here, base::Bind(&TaskQueueManager::DoWork,
203 weak_factory_.GetWeakPtr(), run_time, true), 199 weak_factory_.GetWeakPtr(), run_time, true),
204 delay); 200 delay);
205 } 201 }
206 202
207 void TaskQueueManager::DoWork(base::TimeTicks run_time, bool from_main_thread) { 203 void TaskQueueManager::DoWork(base::TimeTicks run_time, bool from_main_thread) {
208 DCHECK(main_thread_checker_.CalledOnValidThread()); 204 DCHECK(main_thread_checker_.CalledOnValidThread());
209 TRACE_EVENT1(tracing_category_, "TaskQueueManager::DoWork", 205 TRACE_EVENT1(tracing_category_, "TaskQueueManager::DoWork",
210 "from_main_thread", from_main_thread); 206 "from_main_thread", from_main_thread);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 DCHECK(main_thread_checker_.CalledOnValidThread()); 458 DCHECK(main_thread_checker_.CalledOnValidThread());
463 DCHECK(!work_queue->Empty()); 459 DCHECK(!work_queue->Empty());
464 if (observer_) { 460 if (observer_) {
465 observer_->OnTriedToExecuteBlockedTask(*work_queue->task_queue(), 461 observer_->OnTriedToExecuteBlockedTask(*work_queue->task_queue(),
466 *work_queue->GetFrontTask()); 462 *work_queue->GetFrontTask());
467 } 463 }
468 } 464 }
469 465
470 } // namespace scheduler 466 } // namespace scheduler
471 } // namespace blink 467 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698