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

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

Issue 2359493002: Prevent redundant DoWorks due to canceled delayed tasks (v2) (Closed)
Patch Set: Added a test and removed some code we probably don't need. Created 4 years, 2 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 DCHECK(main_thread_checker_.CalledOnValidThread()); 182 DCHECK(main_thread_checker_.CalledOnValidThread());
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
193 // De-duplicate DoWork posts. 192 // De-duplicate DoWork posts.
194 base::TimeTicks run_time = now + delay; 193 base::TimeTicks run_time = now + delay;
195 if (!main_thread_pending_wakeups_.insert(run_time).second) 194 if (!main_thread_pending_wakeups_.empty() &&
195 *main_thread_pending_wakeups_.begin() <= run_time) {
196 return; 196 return;
197 }
198 main_thread_pending_wakeups_.insert(run_time);
197 delegate_->PostDelayedTask( 199 delegate_->PostDelayedTask(
198 from_here, base::Bind(&TaskQueueManager::DoWork, 200 from_here, base::Bind(&TaskQueueManager::DoWork,
199 weak_factory_.GetWeakPtr(), run_time, true), 201 weak_factory_.GetWeakPtr(), run_time, true),
200 delay); 202 delay);
201 } 203 }
202 204
203 void TaskQueueManager::DoWork(base::TimeTicks run_time, bool from_main_thread) { 205 void TaskQueueManager::DoWork(base::TimeTicks run_time, bool from_main_thread) {
204 DCHECK(main_thread_checker_.CalledOnValidThread()); 206 DCHECK(main_thread_checker_.CalledOnValidThread());
205 TRACE_EVENT1(tracing_category_, "TaskQueueManager::DoWork", 207 TRACE_EVENT1(tracing_category_, "TaskQueueManager::DoWork",
206 "from_main_thread", from_main_thread); 208 "from_main_thread", from_main_thread);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 DCHECK(main_thread_checker_.CalledOnValidThread()); 460 DCHECK(main_thread_checker_.CalledOnValidThread());
459 DCHECK(!work_queue->Empty()); 461 DCHECK(!work_queue->Empty());
460 if (observer_) { 462 if (observer_) {
461 observer_->OnTriedToExecuteBlockedTask(*work_queue->task_queue(), 463 observer_->OnTriedToExecuteBlockedTask(*work_queue->task_queue(),
462 *work_queue->GetFrontTask()); 464 *work_queue->GetFrontTask());
463 } 465 }
464 } 466 }
465 467
466 } // namespace scheduler 468 } // namespace scheduler
467 } // namespace blink 469 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698