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

Side by Side Diff: content/renderer/scheduler/task_queue_manager.h

Issue 922733002: scheduler: Implement task observers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Build fix. Created 5 years, 10 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 #ifndef CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ 5 #ifndef CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_
6 #define CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ 6 #define CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_
7 7
8 #include "base/atomic_sequence_num.h" 8 #include "base/atomic_sequence_num.h"
9 #include "base/debug/task_annotator.h" 9 #include "base/debug/task_annotator.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/message_loop/message_loop.h"
12 #include "base/pending_task.h" 13 #include "base/pending_task.h"
13 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
14 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
15 #include "base/threading/thread_checker.h" 16 #include "base/threading/thread_checker.h"
16 #include "content/common/content_export.h" 17 #include "content/common/content_export.h"
17 18
18 namespace base { 19 namespace base {
19 namespace trace_event { 20 namespace trace_event {
20 class ConvertableToTraceFormat; 21 class ConvertableToTraceFormat;
21 class TracedValue; 22 class TracedValue;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // Set the name |queue_index| for tracing purposes. |name| must be a pointer 99 // Set the name |queue_index| for tracing purposes. |name| must be a pointer
99 // to a static string. 100 // to a static string.
100 void SetQueueName(size_t queue_index, const char* name); 101 void SetQueueName(size_t queue_index, const char* name);
101 102
102 // Set the number of tasks executed in a single invocation of the task queue 103 // Set the number of tasks executed in a single invocation of the task queue
103 // manager. Increasing the batch size can reduce the overhead of yielding 104 // manager. Increasing the batch size can reduce the overhead of yielding
104 // back to the main message loop -- at the cost of potentially delaying other 105 // back to the main message loop -- at the cost of potentially delaying other
105 // tasks posted to the main loop. The batch size is 1 by default. 106 // tasks posted to the main loop. The batch size is 1 by default.
106 void SetWorkBatchSize(int work_batch_size); 107 void SetWorkBatchSize(int work_batch_size);
107 108
109 // These functions can only be called on the same thread that the task queue
110 // manager executes its tasks on.
111 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer);
112 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer);
113
108 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source); 114 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source);
109 115
110 private: 116 private:
111 friend class internal::TaskQueue; 117 friend class internal::TaskQueue;
112 118
113 enum WorkQueueUpdateEventType { 119 enum WorkQueueUpdateEventType {
114 BEFORE_WAKEUP_EVENT_TYPE, 120 BEFORE_WAKEUP_EVENT_TYPE,
115 AFTER_WAKEUP_EVENT_TYPE 121 AFTER_WAKEUP_EVENT_TYPE
116 }; 122 };
117 123
(...skipping 16 matching lines...) Expand all
134 // task. It is updated if any task is found which should run earlier. 140 // task. It is updated if any task is found which should run earlier.
135 bool UpdateWorkQueues(base::TimeTicks* next_pending_delayed_task, 141 bool UpdateWorkQueues(base::TimeTicks* next_pending_delayed_task,
136 WorkQueueUpdateEventType event_type); 142 WorkQueueUpdateEventType event_type);
137 143
138 // Chooses the next work queue to service. Returns true if |out_queue_index| 144 // Chooses the next work queue to service. Returns true if |out_queue_index|
139 // indicates the queue from which the next task should be run, false to 145 // indicates the queue from which the next task should be run, false to
140 // avoid running any tasks. 146 // avoid running any tasks.
141 bool SelectWorkQueueToService(size_t* out_queue_index); 147 bool SelectWorkQueueToService(size_t* out_queue_index);
142 148
143 // Runs a single nestable task from the work queue designated by 149 // Runs a single nestable task from the work queue designated by
144 // |queue_index|. Non-nestable task are reposted on the run loop. 150 // |queue_index|. If |has_previous_task| is true, |previous_task| should
145 // The queue must not be empty. 151 // contain the previous task in this work batch. Non-nestable task are
146 void ProcessTaskFromWorkQueue(size_t queue_index); 152 // reposted on the run loop. The queue must not be empty.
153 void ProcessTaskFromWorkQueue(size_t queue_index,
154 bool has_previous_task,
155 base::PendingTask* previous_task);
147 156
148 bool RunsTasksOnCurrentThread() const; 157 bool RunsTasksOnCurrentThread() const;
149 bool PostDelayedTask(const tracked_objects::Location& from_here, 158 bool PostDelayedTask(const tracked_objects::Location& from_here,
150 const base::Closure& task, 159 const base::Closure& task,
151 base::TimeDelta delay); 160 base::TimeDelta delay);
152 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 161 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
153 const base::Closure& task, 162 const base::Closure& task,
154 base::TimeDelta delay); 163 base::TimeDelta delay);
155 internal::TaskQueue* Queue(size_t queue_index) const; 164 internal::TaskQueue* Queue(size_t queue_index) const;
156 165
(...skipping 13 matching lines...) Expand all
170 base::WeakPtr<TaskQueueManager> task_queue_manager_weak_ptr_; 179 base::WeakPtr<TaskQueueManager> task_queue_manager_weak_ptr_;
171 180
172 // The pending_dowork_count_ is only tracked on the main thread since that's 181 // The pending_dowork_count_ is only tracked on the main thread since that's
173 // where re-entrant problems happen. 182 // where re-entrant problems happen.
174 int pending_dowork_count_; 183 int pending_dowork_count_;
175 184
176 int work_batch_size_; 185 int work_batch_size_;
177 186
178 scoped_refptr<cc::TestNowSource> time_source_; 187 scoped_refptr<cc::TestNowSource> time_source_;
179 188
189 ObserverList<base::MessageLoop::TaskObserver> task_observers_;
190
180 base::WeakPtrFactory<TaskQueueManager> weak_factory_; 191 base::WeakPtrFactory<TaskQueueManager> weak_factory_;
181 192
182 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); 193 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager);
183 }; 194 };
184 195
185 } // namespace content 196 } // namespace content
186 197
187 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ 198 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_
OLDNEW
« no previous file with comments | « content/renderer/scheduler/renderer_scheduler_impl.cc ('k') | content/renderer/scheduler/task_queue_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698