| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_ | 5 #ifndef COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_ |
| 6 #define COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_ | 6 #define COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_ |
| 7 | 7 |
| 8 #include "components/scheduler/child/cancelable_closure_holder.h" | 8 #include "components/scheduler/child/cancelable_closure_holder.h" |
| 9 #include "components/scheduler/child/prioritizing_task_queue_selector.h" | 9 #include "components/scheduler/child/prioritizing_task_queue_selector.h" |
| 10 #include "components/scheduler/child/single_thread_idle_task_runner.h" | 10 #include "components/scheduler/child/single_thread_idle_task_runner.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 ~SchedulerHelper(); | 54 ~SchedulerHelper(); |
| 55 | 55 |
| 56 // Returns the default task runner. | 56 // Returns the default task runner. |
| 57 scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner(); | 57 scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner(); |
| 58 | 58 |
| 59 // Returns the idle task runner. Tasks posted to this runner may be reordered | 59 // Returns the idle task runner. Tasks posted to this runner may be reordered |
| 60 // relative to other task types and may be starved for an arbitrarily long | 60 // relative to other task types and may be starved for an arbitrarily long |
| 61 // time if no idle time is available. | 61 // time if no idle time is available. |
| 62 scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner(); | 62 scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner(); |
| 63 | 63 |
| 64 // Returns the shutdown task runner. Intended for tasks that must be able to |
| 65 // run even after PreShutdown() is called. |
| 66 scoped_refptr<base::SingleThreadTaskRunner> ShutdownTaskRunner(); |
| 67 |
| 64 // Returns the control task runner. Tasks posted to this runner are executed | 68 // Returns the control task runner. Tasks posted to this runner are executed |
| 65 // with the highest priority. Care must be taken to avoid starvation of other | 69 // with the highest priority. Care must be taken to avoid starvation of other |
| 66 // task queues. | 70 // task queues. |
| 67 scoped_refptr<base::SingleThreadTaskRunner> ControlTaskRunner(); | 71 scoped_refptr<base::SingleThreadTaskRunner> ControlTaskRunner(); |
| 68 | 72 |
| 69 // Returns true if a currently running idle task could exceed its deadline | 73 // Returns true if a currently running idle task could exceed its deadline |
| 70 // without impacting user experience too much. This should only be used if | 74 // without impacting user experience too much. This should only be used if |
| 71 // there is a task which cannot be pre-empted and is likely to take longer | 75 // there is a task which cannot be pre-empted and is likely to take longer |
| 72 // than the largest expected idle task deadline. It should NOT be polled to | 76 // than the largest expected idle task deadline. It should NOT be polled to |
| 73 // check whether more work can be performed on the current idle task after | 77 // check whether more work can be performed on the current idle task after |
| 74 // its deadline has expired - post a new idle task for the continuation of the | 78 // its deadline has expired - post a new idle task for the continuation of the |
| 75 // work in this case. | 79 // work in this case. |
| 76 // Must be called from the thread this class was created on. | 80 // Must be called from the thread this class was created on. |
| 77 bool CanExceedIdleDeadlineIfRequired() const; | 81 bool CanExceedIdleDeadlineIfRequired() const; |
| 78 | 82 |
| 79 // Adds or removes a task observer from the scheduler. The observer will be | 83 // Adds or removes a task observer from the scheduler. The observer will be |
| 80 // notified before and after every executed task. These functions can only be | 84 // notified before and after every executed task. These functions can only be |
| 81 // called on the thread this class was created on. | 85 // called on the thread this class was created on. |
| 82 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer); | 86 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer); |
| 83 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer); | 87 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer); |
| 84 | 88 |
| 89 // Optional. This stops all queues except for the shutdown queue. Must be |
| 90 // called from the thread this class was created on. |
| 91 void PreShutdown(); |
| 92 |
| 85 // Shuts down the scheduler by dropping any remaining pending work in the work | 93 // Shuts down the scheduler by dropping any remaining pending work in the work |
| 86 // queues. After this call any work posted to the task runners will be | 94 // queues. After this call any work posted to the task runners will be |
| 87 // silently dropped. | 95 // silently dropped. |
| 88 void Shutdown(); | 96 void Shutdown(); |
| 89 | 97 |
| 90 // Returns true if Shutdown() has been called. Otherwise returns false. | 98 // Returns true if Shutdown() has been called. Otherwise returns false. |
| 91 bool IsShutdown() const { return !task_queue_manager_.get(); } | 99 bool IsShutdown() const { return !task_queue_manager_.get(); } |
| 92 | 100 |
| 93 // Keep SchedulerHelper::TaskQueueIdToString in sync with this enum. | 101 // Keep SchedulerHelper::TaskQueueIdToString in sync with this enum. |
| 94 enum QueueId { | 102 enum QueueId { |
| 95 DEFAULT_TASK_QUEUE, | 103 DEFAULT_TASK_QUEUE, |
| 96 IDLE_TASK_QUEUE, | 104 IDLE_TASK_QUEUE, |
| 105 SHUTDOWN_TASK_QUEUE, |
| 97 CONTROL_TASK_QUEUE, | 106 CONTROL_TASK_QUEUE, |
| 98 CONTROL_TASK_AFTER_WAKEUP_QUEUE, | 107 CONTROL_TASK_AFTER_WAKEUP_QUEUE, |
| 99 // Must be the last entry. | 108 // Must be the last entry. |
| 100 TASK_QUEUE_COUNT, | 109 TASK_QUEUE_COUNT, |
| 101 }; | 110 }; |
| 102 | 111 |
| 103 // Keep SchedulerHelper::IdlePeriodStateToString in sync with this enum. | 112 // Keep SchedulerHelper::IdlePeriodStateToString in sync with this enum. |
| 104 enum class IdlePeriodState { | 113 enum class IdlePeriodState { |
| 105 NOT_IN_IDLE_PERIOD, | 114 NOT_IN_IDLE_PERIOD, |
| 106 IN_SHORT_IDLE_PERIOD, | 115 IN_SHORT_IDLE_PERIOD, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 CancelableClosureHolder end_idle_period_closure_; | 197 CancelableClosureHolder end_idle_period_closure_; |
| 189 CancelableClosureHolder enable_next_long_idle_period_closure_; | 198 CancelableClosureHolder enable_next_long_idle_period_closure_; |
| 190 CancelableClosureHolder enable_next_long_idle_period_after_wakeup_closure_; | 199 CancelableClosureHolder enable_next_long_idle_period_after_wakeup_closure_; |
| 191 | 200 |
| 192 IdlePeriodState idle_period_state_; | 201 IdlePeriodState idle_period_state_; |
| 193 SchedulerHelperDelegate* scheduler_helper_delegate_; // NOT OWNED | 202 SchedulerHelperDelegate* scheduler_helper_delegate_; // NOT OWNED |
| 194 | 203 |
| 195 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_; | 204 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_; |
| 196 scoped_refptr<base::SingleThreadTaskRunner> control_task_after_wakeup_runner_; | 205 scoped_refptr<base::SingleThreadTaskRunner> control_task_after_wakeup_runner_; |
| 197 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; | 206 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; |
| 207 scoped_refptr<base::SingleThreadTaskRunner> shutdown_task_runner_; |
| 198 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; | 208 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; |
| 199 | 209 |
| 210 size_t total_task_queue_count_; |
| 211 bool in_preshutdown_; |
| 212 |
| 200 // A bitmap which controls the set of queues that are checked for quiescence | 213 // A bitmap which controls the set of queues that are checked for quiescence |
| 201 // before triggering a long idle period. | 214 // before triggering a long idle period. |
| 202 uint64 quiescence_monitored_task_queue_mask_; | 215 uint64 quiescence_monitored_task_queue_mask_; |
| 203 base::TimeDelta required_quiescence_duration_before_long_idle_period_; | 216 base::TimeDelta required_quiescence_duration_before_long_idle_period_; |
| 204 | 217 |
| 205 base::TimeTicks idle_period_deadline_; | 218 base::TimeTicks idle_period_deadline_; |
| 206 scoped_ptr<TimeSource> time_source_; | 219 scoped_ptr<TimeSource> time_source_; |
| 207 | 220 |
| 208 const char* tracing_category_; | 221 const char* tracing_category_; |
| 209 const char* disabled_by_default_tracing_category_; | 222 const char* disabled_by_default_tracing_category_; |
| 210 const char* idle_period_tracing_name_; | 223 const char* idle_period_tracing_name_; |
| 211 | 224 |
| 212 base::WeakPtr<SchedulerHelper> weak_scheduler_ptr_; | 225 base::WeakPtr<SchedulerHelper> weak_scheduler_ptr_; |
| 213 base::WeakPtrFactory<SchedulerHelper> weak_factory_; | 226 base::WeakPtrFactory<SchedulerHelper> weak_factory_; |
| 214 | 227 |
| 215 DISALLOW_COPY_AND_ASSIGN(SchedulerHelper); | 228 DISALLOW_COPY_AND_ASSIGN(SchedulerHelper); |
| 216 }; | 229 }; |
| 217 | 230 |
| 218 } // namespace scheduler | 231 } // namespace scheduler |
| 219 | 232 |
| 220 #endif // COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_ | 233 #endif // COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_ |
| OLD | NEW |