| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // These functions can only be called on the same thread that the task queue | 109 // These functions can only be called on the same thread that the task queue |
| 110 // manager executes its tasks on. | 110 // manager executes its tasks on. |
| 111 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer); | 111 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer); |
| 112 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer); | 112 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer); |
| 113 | 113 |
| 114 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source); | 114 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source); |
| 115 | 115 |
| 116 private: | 116 private: |
| 117 friend class internal::TaskQueue; | 117 friend class internal::TaskQueue; |
| 118 | 118 |
| 119 enum class WorkQueueUpdateEventType { BEFORE_WAKEUP, AFTER_WAKEUP }; | |
| 120 | |
| 121 // Called by the task queue to register a new pending task and allocate a | 119 // Called by the task queue to register a new pending task and allocate a |
| 122 // sequence number for it. | 120 // sequence number for it. |
| 123 void DidQueueTask(base::PendingTask* pending_task); | 121 void DidQueueTask(base::PendingTask* pending_task); |
| 124 | 122 |
| 125 // Post a task to call DoWork() on the main task runner. Only one pending | 123 // 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 | 124 // DoWork is allowed from the main thread, to prevent an explosion of pending |
| 127 // DoWorks. | 125 // DoWorks. |
| 128 void MaybePostDoWorkOnMainRunner(); | 126 void MaybePostDoWorkOnMainRunner(); |
| 129 | 127 |
| 130 // Use the selector to choose a pending task and run it. | 128 // Use the selector to choose a pending task and run it. |
| 131 void DoWork(bool posted_from_main_thread); | 129 void DoWork(bool posted_from_main_thread); |
| 132 | 130 |
| 133 // Reloads any empty work queues which have automatic pumping enabled and | 131 // Reloads any empty work queues which have automatic pumping enabled and |
| 134 // which are eligible to be auto pumped at the given |event_type|. | 132 // which are eligible to be auto pumped based on the |previous_task| which was |
| 135 // Returns true if any work queue has tasks after doing this. | 133 // run. Call with an empty |previous_task| if no task was just run. Returns |
| 134 // true if any work queue has tasks after doing this. |
| 136 // |next_pending_delayed_task| should be the time of the next known delayed | 135 // |next_pending_delayed_task| should be the time of the next known delayed |
| 137 // task. It is updated if any task is found which should run earlier. | 136 // task. It is updated if any task is found which should run earlier. |
| 138 bool UpdateWorkQueues(base::TimeTicks* next_pending_delayed_task, | 137 bool UpdateWorkQueues(base::TimeTicks* next_pending_delayed_task, |
| 139 WorkQueueUpdateEventType event_type); | 138 const base::PendingTask& previous_task); |
| 140 | 139 |
| 141 // Chooses the next work queue to service. Returns true if |out_queue_index| | 140 // Chooses the next work queue to service. Returns true if |out_queue_index| |
| 142 // indicates the queue from which the next task should be run, false to | 141 // indicates the queue from which the next task should be run, false to |
| 143 // avoid running any tasks. | 142 // avoid running any tasks. |
| 144 bool SelectWorkQueueToService(size_t* out_queue_index); | 143 bool SelectWorkQueueToService(size_t* out_queue_index); |
| 145 | 144 |
| 146 // Runs a single nestable task from the work queue designated by | 145 // Runs a single nestable task from the work queue designated by |
| 147 // |queue_index|. If |has_previous_task| is true, |previous_task| should | 146 // |queue_index|. If |has_previous_task| is true, |previous_task| should |
| 148 // contain the previous task in this work batch. Non-nestable task are | 147 // contain the previous task in this work batch. Non-nestable task are |
| 149 // reposted on the run loop. The queue must not be empty. | 148 // reposted on the run loop. The queue must not be empty. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 ObserverList<base::MessageLoop::TaskObserver> task_observers_; | 185 ObserverList<base::MessageLoop::TaskObserver> task_observers_; |
| 187 | 186 |
| 188 base::WeakPtrFactory<TaskQueueManager> weak_factory_; | 187 base::WeakPtrFactory<TaskQueueManager> weak_factory_; |
| 189 | 188 |
| 190 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); | 189 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); |
| 191 }; | 190 }; |
| 192 | 191 |
| 193 } // namespace content | 192 } // namespace content |
| 194 | 193 |
| 195 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ | 194 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ |
| OLD | NEW |