| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 class TracedValue; | 22 class TracedValue; |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace cc { | 26 namespace cc { |
| 27 class TestNowSource; | 27 class TestNowSource; |
| 28 } | 28 } |
| 29 | 29 |
| 30 namespace content { | 30 namespace content { |
| 31 namespace internal { | 31 namespace internal { |
| 32 class LazyNow; |
| 32 class TaskQueue; | 33 class TaskQueue; |
| 33 } | 34 } |
| 34 class TaskQueueSelector; | 35 class TaskQueueSelector; |
| 35 class NestableSingleThreadTaskRunner; | 36 class NestableSingleThreadTaskRunner; |
| 36 | 37 |
| 37 // The task queue manager provides N task queues and a selector interface for | 38 // The task queue manager provides N task queues and a selector interface for |
| 38 // choosing which task queue to service next. Each task queue consists of two | 39 // choosing which task queue to service next. Each task queue consists of two |
| 39 // sub queues: | 40 // sub queues: |
| 40 // | 41 // |
| 41 // 1. Incoming task queue. Tasks that are posted get immediately appended here. | 42 // 1. Incoming task queue. Tasks that are posted get immediately appended here. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 void SetWorkBatchSize(int work_batch_size); | 110 void SetWorkBatchSize(int work_batch_size); |
| 110 | 111 |
| 111 // These functions can only be called on the same thread that the task queue | 112 // These functions can only be called on the same thread that the task queue |
| 112 // manager executes its tasks on. | 113 // manager executes its tasks on. |
| 113 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer); | 114 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer); |
| 114 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer); | 115 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer); |
| 115 | 116 |
| 116 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source); | 117 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source); |
| 117 | 118 |
| 118 private: | 119 private: |
| 120 friend class internal::LazyNow; |
| 119 friend class internal::TaskQueue; | 121 friend class internal::TaskQueue; |
| 120 | 122 |
| 121 // Called by the task queue to register a new pending task and allocate a | 123 // Called by the task queue to register a new pending task and allocate a |
| 122 // sequence number for it. | 124 // sequence number for it. |
| 123 void DidQueueTask(base::PendingTask* pending_task); | 125 void DidQueueTask(base::PendingTask* pending_task); |
| 124 | 126 |
| 125 // Post a task to call DoWork() on the main task runner. Only one pending | 127 // Post a task to call DoWork() on the main task runner. Only one pending |
| 126 // DoWork is allowed from the main thread, to prevent an explosion of pending | 128 // DoWork is allowed from the main thread, to prevent an explosion of pending |
| 127 // DoWorks. | 129 // DoWorks. |
| 128 void MaybePostDoWorkOnMainRunner(); | 130 void MaybePostDoWorkOnMainRunner(); |
| 129 | 131 |
| 130 // Use the selector to choose a pending task and run it. | 132 // Use the selector to choose a pending task and run it. |
| 131 void DoWork(bool posted_from_main_thread); | 133 void DoWork(bool posted_from_main_thread); |
| 132 | 134 |
| 135 // Delayed Tasks with run_times <= Now() are enqueued onto their work queues. |
| 133 // Reloads any empty work queues which have automatic pumping enabled and | 136 // Reloads any empty work queues which have automatic pumping enabled and |
| 134 // which are eligible to be auto pumped based on the |previous_task| which was | 137 // which are eligible to be auto pumped based on the |previous_task| which was |
| 135 // run. Call with an empty |previous_task| if no task was just run. Returns | 138 // run. Call with an empty |previous_task| if no task was just run. Returns |
| 136 // true if any work queue has tasks after doing this. | 139 // true if any work queue has tasks after doing this. |
| 137 // |next_pending_delayed_task| should be the time of the next known delayed | 140 // |next_pending_delayed_task| should be the time of the next known delayed |
| 138 // task. It is updated if any task is found which should run earlier. | 141 // task. It is updated if any task is found which should run earlier. |
| 139 bool UpdateWorkQueues(base::TimeTicks* next_pending_delayed_task, | 142 bool UpdateWorkQueues(const base::PendingTask* previous_task); |
| 140 const base::PendingTask* previous_task); | |
| 141 | 143 |
| 142 // 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| |
| 143 // 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 |
| 144 // avoid running any tasks. | 146 // avoid running any tasks. |
| 145 bool SelectWorkQueueToService(size_t* out_queue_index); | 147 bool SelectWorkQueueToService(size_t* out_queue_index); |
| 146 | 148 |
| 147 // Runs a single nestable task from the work queue designated by | 149 // Runs a single nestable task from the work queue designated by |
| 148 // |queue_index|. If |has_previous_task| is true, |previous_task| should | 150 // |queue_index|. If |has_previous_task| is true, |previous_task| should |
| 149 // contain the previous task in this work batch. Non-nestable task are | 151 // contain the previous task in this work batch. Non-nestable task are |
| 150 // reposted on the run loop. The queue must not be empty. | 152 // reposted on the run loop. The queue must not be empty. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 ObserverList<base::MessageLoop::TaskObserver> task_observers_; | 189 ObserverList<base::MessageLoop::TaskObserver> task_observers_; |
| 188 | 190 |
| 189 base::WeakPtrFactory<TaskQueueManager> weak_factory_; | 191 base::WeakPtrFactory<TaskQueueManager> weak_factory_; |
| 190 | 192 |
| 191 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); | 193 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); |
| 192 }; | 194 }; |
| 193 | 195 |
| 194 } // namespace content | 196 } // namespace content |
| 195 | 197 |
| 196 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ | 198 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ |
| OLD | NEW |