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

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

Issue 1424053002: Adds a flag to support "Virtual Time" to the blink scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a test Created 5 years, 1 month 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_BASE_TASK_QUEUE_MANAGER_H_ 5 #ifndef CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_
6 #define CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ 6 #define CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/atomic_sequence_num.h" 10 #include "base/atomic_sequence_num.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // manager. Increasing the batch size can reduce the overhead of yielding 71 // manager. Increasing the batch size can reduce the overhead of yielding
72 // back to the main message loop -- at the cost of potentially delaying other 72 // back to the main message loop -- at the cost of potentially delaying other
73 // tasks posted to the main loop. The batch size is 1 by default. 73 // tasks posted to the main loop. The batch size is 1 by default.
74 void SetWorkBatchSize(int work_batch_size); 74 void SetWorkBatchSize(int work_batch_size);
75 75
76 // These functions can only be called on the same thread that the task queue 76 // These functions can only be called on the same thread that the task queue
77 // manager executes its tasks on. 77 // manager executes its tasks on.
78 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer); 78 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer);
79 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer); 79 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer);
80 80
81 void SetTimeSourceForTesting(scoped_ptr<base::TickClock> time_source);
82
83 // Returns true if any task from a monitored task queue was was run since the 81 // Returns true if any task from a monitored task queue was was run since the
84 // last call to GetAndClearSystemIsQuiescentBit. 82 // last call to GetAndClearSystemIsQuiescentBit.
85 bool GetAndClearSystemIsQuiescentBit(); 83 bool GetAndClearSystemIsQuiescentBit();
86 84
87 // Creates a task queue with the given |spec|. Must be called on the thread 85 // Creates a task queue with the given |spec|. Must be called on the thread
88 // this class was created on. 86 // this class was created on.
89 scoped_refptr<internal::TaskQueueImpl> NewTaskQueue( 87 scoped_refptr<internal::TaskQueueImpl> NewTaskQueue(
90 const TaskQueue::Spec& spec); 88 const TaskQueue::Spec& spec);
91 89
92 class SCHEDULER_EXPORT Observer { 90 class SCHEDULER_EXPORT Observer {
93 public: 91 public:
94 virtual ~Observer() {} 92 virtual ~Observer() {}
95 93
96 // Called when |queue| is unregistered. 94 // Called when |queue| is unregistered.
97 virtual void OnUnregisterTaskQueue( 95 virtual void OnUnregisterTaskQueue(
98 const scoped_refptr<internal::TaskQueueImpl>& queue) = 0; 96 const scoped_refptr<internal::TaskQueueImpl>& queue) = 0;
99 }; 97 };
100 98
101 // Called once to set the Observer. This function is called on the main 99 // Called once to set the Observer. This function is called on the main
102 // thread. If |observer| is null, then no callbacks will occur. 100 // thread. If |observer| is null, then no callbacks will occur.
103 // Note |observer| is expected to outlive the SchedulerHelper. 101 // Note |observer| is expected to outlive the SchedulerHelper.
104 void SetObserver(Observer* observer); 102 void SetObserver(Observer* observer);
105 103
104 // Returns the TickClock used by the TaskQueueManager.
105 base::TickClock* tick_clock() const;
106
106 private: 107 private:
107 friend class internal::LazyNow; 108 friend class internal::LazyNow;
108 friend class internal::TaskQueueImpl; 109 friend class internal::TaskQueueImpl;
109 friend class TaskQueueManagerTest; 110 friend class TaskQueueManagerTest;
110 111
111 class DeletionSentinel : public base::RefCounted<DeletionSentinel> { 112 class DeletionSentinel : public base::RefCounted<DeletionSentinel> {
112 private: 113 private:
113 friend class base::RefCounted<DeletionSentinel>; 114 friend class base::RefCounted<DeletionSentinel>;
114 ~DeletionSentinel() {} 115 ~DeletionSentinel() {}
115 }; 116 };
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 internal::TaskQueueImpl::Task* out_previous_task); 161 internal::TaskQueueImpl::Task* out_previous_task);
161 162
162 bool RunsTasksOnCurrentThread() const; 163 bool RunsTasksOnCurrentThread() const;
163 bool PostDelayedTask(const tracked_objects::Location& from_here, 164 bool PostDelayedTask(const tracked_objects::Location& from_here,
164 const base::Closure& task, 165 const base::Closure& task,
165 base::TimeDelta delay); 166 base::TimeDelta delay);
166 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 167 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
167 const base::Closure& task, 168 const base::Closure& task,
168 base::TimeDelta delay); 169 base::TimeDelta delay);
169 170
170 base::TimeTicks Now() const;
171
172 int GetNextSequenceNumber(); 171 int GetNextSequenceNumber();
173 172
174 scoped_refptr<base::trace_event::ConvertableToTraceFormat> 173 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
175 AsValueWithSelectorResult(bool should_run, 174 AsValueWithSelectorResult(bool should_run,
176 internal::TaskQueueImpl* selected_queue) const; 175 internal::TaskQueueImpl* selected_queue) const;
177 176
178 // Causes DoWork to start calling UpdateWorkQueue for |queue|. Can be called 177 // Causes DoWork to start calling UpdateWorkQueue for |queue|. Can be called
179 // from any thread. 178 // from any thread.
180 void RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue); 179 void RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue);
181 180
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 base::Closure delayed_queue_wakeup_closure_; 235 base::Closure delayed_queue_wakeup_closure_;
237 236
238 bool task_was_run_on_quiescence_monitored_queue_; 237 bool task_was_run_on_quiescence_monitored_queue_;
239 238
240 // The pending_dowork_count_ is only tracked on the main thread since that's 239 // The pending_dowork_count_ is only tracked on the main thread since that's
241 // where re-entrant problems happen. 240 // where re-entrant problems happen.
242 int pending_dowork_count_; 241 int pending_dowork_count_;
243 242
244 int work_batch_size_; 243 int work_batch_size_;
245 244
246 scoped_ptr<base::TickClock> time_source_;
247
248 base::ObserverList<base::MessageLoop::TaskObserver> task_observers_; 245 base::ObserverList<base::MessageLoop::TaskObserver> task_observers_;
249 246
250 const char* tracing_category_; 247 const char* tracing_category_;
251 const char* disabled_by_default_tracing_category_; 248 const char* disabled_by_default_tracing_category_;
252 const char* disabled_by_default_verbose_tracing_category_; 249 const char* disabled_by_default_verbose_tracing_category_;
253 250
254 Observer* observer_; // NOT OWNED 251 Observer* observer_; // NOT OWNED
255 scoped_refptr<DeletionSentinel> deletion_sentinel_; 252 scoped_refptr<DeletionSentinel> deletion_sentinel_;
256 base::WeakPtrFactory<TaskQueueManager> weak_factory_; 253 base::WeakPtrFactory<TaskQueueManager> weak_factory_;
257 254
258 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); 255 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager);
259 }; 256 };
260 257
261 } // namespace scheduler 258 } // namespace scheduler
262 259
263 #endif // CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ 260 #endif // CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698