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

Side by Side Diff: components/scheduler/base/task_queue_impl.h

Issue 1441073006: Move throttling of background timers into the renderer scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Last few changes Sami requested Created 5 years 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
« no previous file with comments | « components/scheduler/base/task_queue.cc ('k') | components/scheduler/base/task_queue_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ 5 #ifndef CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_
6 #define CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ 6 #define CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/pending_task.h" 10 #include "base/pending_task.h"
11 #include "base/threading/thread_checker.h" 11 #include "base/threading/thread_checker.h"
12 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
13 #include "base/trace_event/trace_event_argument.h" 13 #include "base/trace_event/trace_event_argument.h"
14 #include "components/scheduler/base/task_queue.h" 14 #include "components/scheduler/base/task_queue.h"
15 #include "components/scheduler/scheduler_export.h" 15 #include "components/scheduler/scheduler_export.h"
16 16
17 namespace scheduler { 17 namespace scheduler {
18 class LazyNow; 18 class LazyNow;
19 class TimeDomain; 19 class TimeDomain;
20 class TaskQueueManager; 20 class TaskQueueManager;
21 21
22 namespace internal { 22 namespace internal {
23 class SCHEDULER_EXPORT TaskQueueImpl final : public TaskQueue { 23 class SCHEDULER_EXPORT TaskQueueImpl final : public TaskQueue {
24 public: 24 public:
25 TaskQueueImpl(TaskQueueManager* task_queue_manager, 25 TaskQueueImpl(TaskQueueManager* task_queue_manager,
26 const scoped_refptr<TimeDomain>& time_domain, 26 TimeDomain* time_domain,
27 const Spec& spec, 27 const Spec& spec,
28 const char* disabled_by_default_tracing_category, 28 const char* disabled_by_default_tracing_category,
29 const char* disabled_by_default_verbose_tracing_category); 29 const char* disabled_by_default_verbose_tracing_category);
30 30
31 class SCHEDULER_EXPORT Task : public base::PendingTask { 31 class SCHEDULER_EXPORT Task : public base::PendingTask {
32 public: 32 public:
33 Task(); 33 Task();
34 Task(const tracked_objects::Location& posted_from, 34 Task(const tracked_objects::Location& posted_from,
35 const base::Closure& task, 35 const base::Closure& task,
36 int sequence_number, 36 int sequence_number,
(...skipping 26 matching lines...) Expand all
63 63
64 // TaskQueue implementation. 64 // TaskQueue implementation.
65 void UnregisterTaskQueue() override; 65 void UnregisterTaskQueue() override;
66 bool RunsTasksOnCurrentThread() const override; 66 bool RunsTasksOnCurrentThread() const override;
67 bool PostDelayedTask(const tracked_objects::Location& from_here, 67 bool PostDelayedTask(const tracked_objects::Location& from_here,
68 const base::Closure& task, 68 const base::Closure& task,
69 base::TimeDelta delay) override; 69 base::TimeDelta delay) override;
70 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 70 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
71 const base::Closure& task, 71 const base::Closure& task,
72 base::TimeDelta delay) override; 72 base::TimeDelta delay) override;
73 bool PostDelayedTaskAt(const tracked_objects::Location& from_here,
74 const base::Closure& task,
75 base::TimeTicks desired_run_time) override;
76 73
77 bool IsQueueEnabled() const override; 74 bool IsQueueEnabled() const override;
78 QueueState GetQueueState() const override; 75 QueueState GetQueueState() const override;
79 void SetQueuePriority(QueuePriority priority) override; 76 void SetQueuePriority(QueuePriority priority) override;
80 void PumpQueue() override; 77 void PumpQueue() override;
81 void SetPumpPolicy(PumpPolicy pump_policy) override; 78 void SetPumpPolicy(PumpPolicy pump_policy) override;
82 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; 79 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override;
83 void RemoveTaskObserver( 80 void RemoveTaskObserver(
84 base::MessageLoop::TaskObserver* task_observer) override; 81 base::MessageLoop::TaskObserver* task_observer) override;
85 void SetTimeDomain(const scoped_refptr<TimeDomain>& time_domain) override; 82 void SetTimeDomain(TimeDomain* time_domain) override;
86 83
87 void UpdateWorkQueue(LazyNow* lazy_now, 84 void UpdateWorkQueue(LazyNow* lazy_now,
88 bool should_trigger_wakeup, 85 bool should_trigger_wakeup,
89 const Task* previous_task); 86 const Task* previous_task);
90 Task TakeTaskFromWorkQueue(); 87 Task TakeTaskFromWorkQueue();
91 88
92 std::queue<Task>& work_queue() { return main_thread_only().work_queue; } 89 std::queue<Task>& work_queue() { return main_thread_only().work_queue; }
93 90
94 WakeupPolicy wakeup_policy() const { 91 WakeupPolicy wakeup_policy() const {
95 DCHECK(main_thread_checker_.CalledOnValidThread()); 92 DCHECK(main_thread_checker_.CalledOnValidThread());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 144
148 private: 145 private:
149 enum class TaskType { 146 enum class TaskType {
150 NORMAL, 147 NORMAL,
151 NON_NESTABLE, 148 NON_NESTABLE,
152 }; 149 };
153 150
154 struct AnyThread { 151 struct AnyThread {
155 AnyThread(TaskQueueManager* task_queue_manager, 152 AnyThread(TaskQueueManager* task_queue_manager,
156 PumpPolicy pump_policy, 153 PumpPolicy pump_policy,
157 const scoped_refptr<TimeDomain>& time_domain); 154 TimeDomain* time_domain);
158 ~AnyThread(); 155 ~AnyThread();
159 156
160 // TaskQueueManager is maintained in two copies: inside AnyThread and inside 157 // TaskQueueManager is maintained in two copies: inside AnyThread and inside
161 // MainThreadOnly. It can be changed only from main thread, so it should be 158 // MainThreadOnly. It can be changed only from main thread, so it should be
162 // locked before accessing from other threads. 159 // locked before accessing from other threads.
163 TaskQueueManager* task_queue_manager; 160 TaskQueueManager* task_queue_manager;
164 161
165 std::queue<Task> incoming_queue; 162 std::queue<Task> incoming_queue;
166 PumpPolicy pump_policy; 163 PumpPolicy pump_policy;
167 std::priority_queue<Task> delayed_task_queue; 164 std::priority_queue<Task> delayed_task_queue;
168 scoped_refptr<TimeDomain> time_domain; 165 TimeDomain* time_domain;
169 }; 166 };
170 167
171 struct MainThreadOnly { 168 struct MainThreadOnly {
172 MainThreadOnly(TaskQueueManager* task_queue_manager); 169 MainThreadOnly(TaskQueueManager* task_queue_manager);
173 ~MainThreadOnly(); 170 ~MainThreadOnly();
174 171
175 // Another copy of TaskQueueManager for lock-free access from the main 172 // Another copy of TaskQueueManager for lock-free access from the main
176 // thread. See description inside struct AnyThread for details. 173 // thread. See description inside struct AnyThread for details.
177 TaskQueueManager* task_queue_manager; 174 TaskQueueManager* task_queue_manager;
178 175
179 std::queue<Task> work_queue; 176 std::queue<Task> work_queue;
180 base::ObserverList<base::MessageLoop::TaskObserver> task_observers; 177 base::ObserverList<base::MessageLoop::TaskObserver> task_observers;
181 size_t set_index; 178 size_t set_index;
182 }; 179 };
183 180
184 ~TaskQueueImpl() override; 181 ~TaskQueueImpl() override;
185 182
186 bool PostDelayedTaskImpl(const tracked_objects::Location& from_here, 183 bool PostDelayedTaskImpl(const tracked_objects::Location& from_here,
187 const base::Closure& task, 184 const base::Closure& task,
188 base::TimeDelta delay, 185 base::TimeDelta delay,
189 TaskType task_type); 186 TaskType task_type);
190 bool PostDelayedTaskLocked(LazyNow* lazy_now, 187 bool PostDelayedTaskLocked(LazyNow* lazy_now,
191 const tracked_objects::Location& from_here, 188 const tracked_objects::Location& from_here,
192 const base::Closure& task, 189 const base::Closure& task,
193 base::TimeTicks desired_run_time, 190 base::TimeTicks desired_run_time,
194 TaskType task_type); 191 TaskType task_type);
195 void ScheduleDelayedWorkTask(const scoped_refptr<TimeDomain> time_domain, 192 void ScheduleDelayedWorkTask(TimeDomain* time_domain,
196 base::TimeTicks desired_run_time); 193 base::TimeTicks desired_run_time);
197 194
198 // Enqueues any delayed tasks which should be run now on the incoming_queue_. 195 // Enqueues any delayed tasks which should be run now on the incoming_queue_.
199 // Must be called with |any_thread_lock_| locked. 196 // Must be called with |any_thread_lock_| locked.
200 void MoveReadyDelayedTasksToIncomingQueueLocked(LazyNow* lazy_now); 197 void MoveReadyDelayedTasksToIncomingQueueLocked(LazyNow* lazy_now);
201 198
202 void PumpQueueLocked(); 199 void PumpQueueLocked();
203 bool TaskIsOlderThanQueuedTasks(const Task* task); 200 bool TaskIsOlderThanQueuedTasks(const Task* task);
204 bool ShouldAutoPumpQueueLocked(bool should_trigger_wakeup, 201 bool ShouldAutoPumpQueueLocked(bool should_trigger_wakeup,
205 const Task* previous_task); 202 const Task* previous_task);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 const bool should_monitor_quiescence_; 250 const bool should_monitor_quiescence_;
254 const bool should_notify_observers_; 251 const bool should_notify_observers_;
255 252
256 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl); 253 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl);
257 }; 254 };
258 255
259 } // namespace internal 256 } // namespace internal
260 } // namespace scheduler 257 } // namespace scheduler
261 258
262 #endif // CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ 259 #endif // CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_
OLDNEW
« no previous file with comments | « components/scheduler/base/task_queue.cc ('k') | components/scheduler/base/task_queue_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698