OLD | NEW |
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" | |
13 #include "base/pending_task.h" | 12 #include "base/pending_task.h" |
14 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
15 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
16 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
17 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
18 | 17 |
19 namespace base { | 18 namespace base { |
20 namespace trace_event { | 19 namespace trace_event { |
21 class ConvertableToTraceFormat; | 20 class ConvertableToTraceFormat; |
22 class TracedValue; | 21 class TracedValue; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // Set the name |queue_index| for tracing purposes. |name| must be a pointer | 83 // Set the name |queue_index| for tracing purposes. |name| must be a pointer |
85 // to a static string. | 84 // to a static string. |
86 void SetQueueName(size_t queue_index, const char* name); | 85 void SetQueueName(size_t queue_index, const char* name); |
87 | 86 |
88 // Set the number of tasks executed in a single invocation of the task queue | 87 // Set the number of tasks executed in a single invocation of the task queue |
89 // manager. Increasing the batch size can reduce the overhead of yielding | 88 // manager. Increasing the batch size can reduce the overhead of yielding |
90 // back to the main message loop -- at the cost of potentially delaying other | 89 // back to the main message loop -- at the cost of potentially delaying other |
91 // tasks posted to the main loop. The batch size is 1 by default. | 90 // tasks posted to the main loop. The batch size is 1 by default. |
92 void SetWorkBatchSize(int work_batch_size); | 91 void SetWorkBatchSize(int work_batch_size); |
93 | 92 |
94 // These functions can only be called on the same thread that the task queue | |
95 // manager executes its tasks on. | |
96 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer); | |
97 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer); | |
98 | |
99 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source); | 93 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source); |
100 | 94 |
101 private: | 95 private: |
102 friend class internal::TaskQueue; | 96 friend class internal::TaskQueue; |
103 | 97 |
104 // Called by the task queue to register a new pending task and allocate a | 98 // Called by the task queue to register a new pending task and allocate a |
105 // sequence number for it. | 99 // sequence number for it. |
106 void DidQueueTask(base::PendingTask* pending_task); | 100 void DidQueueTask(base::PendingTask* pending_task); |
107 | 101 |
108 // Post a task to call DoWork() on the main task runner. Only one pending | 102 // Post a task to call DoWork() on the main task runner. Only one pending |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 base::WeakPtr<TaskQueueManager> task_queue_manager_weak_ptr_; | 148 base::WeakPtr<TaskQueueManager> task_queue_manager_weak_ptr_; |
155 | 149 |
156 // The pending_dowork_count_ is only tracked on the main thread since that's | 150 // The pending_dowork_count_ is only tracked on the main thread since that's |
157 // where re-entrant problems happen. | 151 // where re-entrant problems happen. |
158 int pending_dowork_count_; | 152 int pending_dowork_count_; |
159 | 153 |
160 int work_batch_size_; | 154 int work_batch_size_; |
161 | 155 |
162 scoped_refptr<cc::TestNowSource> time_source_; | 156 scoped_refptr<cc::TestNowSource> time_source_; |
163 | 157 |
164 ObserverList<base::MessageLoop::TaskObserver> task_observers_; | |
165 | |
166 base::WeakPtrFactory<TaskQueueManager> weak_factory_; | 158 base::WeakPtrFactory<TaskQueueManager> weak_factory_; |
167 | 159 |
168 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); | 160 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); |
169 }; | 161 }; |
170 | 162 |
171 } // namespace content | 163 } // namespace content |
172 | 164 |
173 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ | 165 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ |
OLD | NEW |