| 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 <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" |
| 11 #include "base/debug/task_annotator.h" | 11 #include "base/debug/task_annotator.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/pending_task.h" | 15 #include "base/pending_task.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
| 18 #include "components/scheduler/child/task_queue.h" | 18 #include "components/scheduler/child/task_queue_impl.h" |
| 19 #include "components/scheduler/child/task_queue_selector.h" | 19 #include "components/scheduler/child/task_queue_selector.h" |
| 20 #include "components/scheduler/scheduler_export.h" | 20 #include "components/scheduler/scheduler_export.h" |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 class TickClock; | 23 class TickClock; |
| 24 | 24 |
| 25 namespace trace_event { | 25 namespace trace_event { |
| 26 class ConvertableToTraceFormat; | 26 class ConvertableToTraceFormat; |
| 27 class TracedValue; | 27 class TracedValue; |
| 28 } // namespace trace_event | 28 } // namespace trace_event |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 class DeletionSentinel : public base::RefCounted<DeletionSentinel> { | 96 class DeletionSentinel : public base::RefCounted<DeletionSentinel> { |
| 97 private: | 97 private: |
| 98 friend class base::RefCounted<DeletionSentinel>; | 98 friend class base::RefCounted<DeletionSentinel>; |
| 99 ~DeletionSentinel() {} | 99 ~DeletionSentinel() {} |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 // TaskQueueSelector::Observer implementation: | 102 // TaskQueueSelector::Observer implementation: |
| 103 void OnTaskQueueEnabled() override; | 103 void OnTaskQueueEnabled() override; |
| 104 | 104 |
| 105 // Called by the task queue to register a new pending task. | 105 // Called by the task queue to register a new pending task. |
| 106 void DidQueueTask(const base::PendingTask& pending_task); | 106 void DidQueueTask(const internal::TaskQueueImpl::Task& pending_task); |
| 107 | 107 |
| 108 // Post a task to call DoWork() on the main task runner. Only one pending | 108 // Post a task to call DoWork() on the main task runner. Only one pending |
| 109 // DoWork is allowed from the main thread, to prevent an explosion of pending | 109 // DoWork is allowed from the main thread, to prevent an explosion of pending |
| 110 // DoWorks. | 110 // DoWorks. |
| 111 void MaybePostDoWorkOnMainRunner(); | 111 void MaybePostDoWorkOnMainRunner(); |
| 112 | 112 |
| 113 // Use the selector to choose a pending task and run it. | 113 // Use the selector to choose a pending task and run it. |
| 114 void DoWork(bool posted_from_main_thread); | 114 void DoWork(bool posted_from_main_thread); |
| 115 | 115 |
| 116 // Delayed Tasks with run_times <= Now() are enqueued onto the work queue. | 116 // Delayed Tasks with run_times <= Now() are enqueued onto the work queue. |
| 117 // Reloads any empty work queues which have automatic pumping enabled and | 117 // Reloads any empty work queues which have automatic pumping enabled and |
| 118 // which are eligible to be auto pumped based on the |previous_task| which was | 118 // which are eligible to be auto pumped based on the |previous_task| which was |
| 119 // run and |should_trigger_wakeup|. Call with an empty |previous_task| if no | 119 // run and |should_trigger_wakeup|. Call with an empty |previous_task| if no |
| 120 // task was just run. | 120 // task was just run. |
| 121 void UpdateWorkQueues(bool should_trigger_wakeup, | 121 void UpdateWorkQueues(bool should_trigger_wakeup, |
| 122 const base::PendingTask* previous_task); | 122 const internal::TaskQueueImpl::Task* previous_task); |
| 123 | 123 |
| 124 // Chooses the next work queue to service. Returns true if |out_queue| | 124 // Chooses the next work queue to service. Returns true if |out_queue| |
| 125 // indicates the queue from which the next task should be run, false to | 125 // indicates the queue from which the next task should be run, false to |
| 126 // avoid running any tasks. | 126 // avoid running any tasks. |
| 127 bool SelectQueueToService(internal::TaskQueueImpl** out_queue); | 127 bool SelectQueueToService(internal::TaskQueueImpl** out_queue); |
| 128 | 128 |
| 129 // Runs a single nestable task from the |queue|. On exit, |out_task| will | 129 // Runs a single nestable task from the |queue|. On exit, |out_task| will |
| 130 // contain the task which was executed. Non-nestable task are reposted on the | 130 // contain the task which was executed. Non-nestable task are reposted on the |
| 131 // run loop. The queue must not be empty. Returns true if the TaskQueueManager | 131 // run loop. The queue must not be empty. Returns true if the TaskQueueManager |
| 132 // got deleted, and false otherwise. | 132 // got deleted, and false otherwise. |
| 133 bool ProcessTaskFromWorkQueue(internal::TaskQueueImpl* queue, | 133 bool ProcessTaskFromWorkQueue( |
| 134 base::PendingTask* out_previous_task); | 134 internal::TaskQueueImpl* queue, |
| 135 internal::TaskQueueImpl::Task* out_previous_task); |
| 135 | 136 |
| 136 bool RunsTasksOnCurrentThread() const; | 137 bool RunsTasksOnCurrentThread() const; |
| 137 bool PostDelayedTask(const tracked_objects::Location& from_here, | 138 bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 138 const base::Closure& task, | 139 const base::Closure& task, |
| 139 base::TimeDelta delay); | 140 base::TimeDelta delay); |
| 140 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, | 141 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
| 141 const base::Closure& task, | 142 const base::Closure& task, |
| 142 base::TimeDelta delay); | 143 base::TimeDelta delay); |
| 143 | 144 |
| 144 base::TimeTicks Now() const; | 145 base::TimeTicks Now() const; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 196 |
| 196 scoped_refptr<DeletionSentinel> deletion_sentinel_; | 197 scoped_refptr<DeletionSentinel> deletion_sentinel_; |
| 197 base::WeakPtrFactory<TaskQueueManager> weak_factory_; | 198 base::WeakPtrFactory<TaskQueueManager> weak_factory_; |
| 198 | 199 |
| 199 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); | 200 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); |
| 200 }; | 201 }; |
| 201 | 202 |
| 202 } // namespace scheduler | 203 } // namespace scheduler |
| 203 | 204 |
| 204 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ | 205 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ |
| OLD | NEW |