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

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

Issue 2637463002: Add an idle task to periodically sweep canceled delayed tasks (Closed)
Patch Set: Clarify test Created 3 years, 11 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 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 "platform/scheduler/base/task_queue_impl.h" 5 #include "platform/scheduler/base/task_queue_impl.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/trace_event/blame_context.h" 10 #include "base/trace_event/blame_context.h"
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 } 807 }
808 } 808 }
809 809
810 std::unique_ptr<TaskQueueImpl::QueueEnabledVoter> 810 std::unique_ptr<TaskQueueImpl::QueueEnabledVoter>
811 TaskQueueImpl::CreateQueueEnabledVoter() { 811 TaskQueueImpl::CreateQueueEnabledVoter() {
812 main_thread_only().voter_refcount++; 812 main_thread_only().voter_refcount++;
813 main_thread_only().is_enabled_refcount++; 813 main_thread_only().is_enabled_refcount++;
814 return base::MakeUnique<QueueEnabledVoterImpl>(this); 814 return base::MakeUnique<QueueEnabledVoterImpl>(this);
815 } 815 }
816 816
817 void TaskQueueImpl::SweepCanceledDelayedTasks(base::TimeTicks now) {
818 if (main_thread_only().delayed_incoming_queue.empty())
819 return;
820
821 base::TimeTicks first_task_runtime =
822 main_thread_only().delayed_incoming_queue.top().delayed_run_time;
823
824 // TODO(alexclarke): Let this remove all tasks once the DoWork refactor has
825 // landed.
826 std::priority_queue<Task> swept;
Sami 2017/01/13 19:00:30 nit: How about |remaining_tasks| since the others
alex clarke (OOO till 29th) 2017/01/13 19:04:40 Done.
827 while (!main_thread_only().delayed_incoming_queue.empty()) {
828 if (!main_thread_only().delayed_incoming_queue.top().task.IsCancelled() ||
829 main_thread_only().delayed_incoming_queue.top().delayed_run_time ==
830 first_task_runtime) {
831 swept.push(std::move(
832 const_cast<Task&>(main_thread_only().delayed_incoming_queue.top())));
833 }
834 main_thread_only().delayed_incoming_queue.pop();
835 }
836 main_thread_only().delayed_incoming_queue = std::move(swept);
837 }
838
817 } // namespace internal 839 } // namespace internal
818 } // namespace scheduler 840 } // namespace scheduler
819 } // namespace blink 841 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698