| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/time/tick_clock.h" | 11 #include "base/time/tick_clock.h" |
| 12 #include "components/scheduler/base/task_queue_manager.h" | 12 #include "components/scheduler/base/task_queue_manager.h" |
| 13 #include "components/scheduler/base/task_queue_selector.h" | 13 #include "components/scheduler/base/task_queue_selector.h" |
| 14 #include "components/scheduler/base/task_time_tracker.h" |
| 14 #include "components/scheduler/scheduler_export.h" | 15 #include "components/scheduler/scheduler_export.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 class TickClock; | 18 class TickClock; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace scheduler { | 21 namespace scheduler { |
| 21 | 22 |
| 22 class SchedulerTqmDelegate; | 23 class SchedulerTqmDelegate; |
| 23 | 24 |
| 24 // Common scheduler functionality for default tasks. | 25 // Common scheduler functionality for default tasks. |
| 25 class SCHEDULER_EXPORT SchedulerHelper : public TaskQueueManager::Observer { | 26 class SCHEDULER_EXPORT SchedulerHelper |
| 27 : public TaskQueueManager::Observer, |
| 28 public TaskTimeTracker::TaskTimeObserver { |
| 26 public: | 29 public: |
| 27 // Category strings must have application lifetime (statics or | 30 // Category strings must have application lifetime (statics or |
| 28 // literals). They may not include " chars. | 31 // literals). They may not include " chars. |
| 29 SchedulerHelper( | 32 SchedulerHelper( |
| 30 scoped_refptr<SchedulerTqmDelegate> task_queue_manager_delegate, | 33 scoped_refptr<SchedulerTqmDelegate> task_queue_manager_delegate, |
| 31 const char* tracing_category, | 34 const char* tracing_category, |
| 32 const char* disabled_by_default_tracing_category, | 35 const char* disabled_by_default_tracing_category, |
| 33 const char* disabled_by_default_verbose_tracing_category); | 36 const char* disabled_by_default_verbose_tracing_category); |
| 34 ~SchedulerHelper() override; | 37 ~SchedulerHelper() override; |
| 35 | 38 |
| 36 // TaskQueueManager::Observer implementation: | 39 // TaskQueueManager::Observer implementation: |
| 37 void OnUnregisterTaskQueue(const scoped_refptr<TaskQueue>& queue) override; | 40 void OnUnregisterTaskQueue(const scoped_refptr<TaskQueue>& queue) override; |
| 38 void OnTriedToExecuteBlockedTask(const TaskQueue& queue, | 41 void OnTriedToExecuteBlockedTask(const TaskQueue& queue, |
| 39 const base::PendingTask& task) override; | 42 const base::PendingTask& task) override; |
| 40 | 43 |
| 44 // TaskTimeTracker::TaskTimeObserver implementation: |
| 45 void OnLongTask(base::TimeDelta long_task_time) override; |
| 46 |
| 41 // Returns the default task runner. | 47 // Returns the default task runner. |
| 42 scoped_refptr<TaskQueue> DefaultTaskRunner(); | 48 scoped_refptr<TaskQueue> DefaultTaskRunner(); |
| 43 | 49 |
| 44 // Returns the control task runner. Tasks posted to this runner are executed | 50 // Returns the control task runner. Tasks posted to this runner are executed |
| 45 // with the highest priority. Care must be taken to avoid starvation of other | 51 // with the highest priority. Care must be taken to avoid starvation of other |
| 46 // task queues. | 52 // task queues. |
| 47 scoped_refptr<TaskQueue> ControlTaskRunner(); | 53 scoped_refptr<TaskQueue> ControlTaskRunner(); |
| 48 | 54 |
| 49 // Returns the control task after wakeup runner. Tasks posted to this runner | 55 // Returns the control task after wakeup runner. Tasks posted to this runner |
| 50 // are executed with the highest priority but do not cause the scheduler to | 56 // are executed with the highest priority but do not cause the scheduler to |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 107 |
| 102 // Test helpers. | 108 // Test helpers. |
| 103 void SetWorkBatchSizeForTesting(size_t work_batch_size); | 109 void SetWorkBatchSizeForTesting(size_t work_batch_size); |
| 104 TaskQueueManager* GetTaskQueueManagerForTesting(); | 110 TaskQueueManager* GetTaskQueueManagerForTesting(); |
| 105 | 111 |
| 106 private: | 112 private: |
| 107 friend class SchedulerHelperTest; | 113 friend class SchedulerHelperTest; |
| 108 | 114 |
| 109 base::ThreadChecker thread_checker_; | 115 base::ThreadChecker thread_checker_; |
| 110 scoped_refptr<SchedulerTqmDelegate> task_queue_manager_delegate_; | 116 scoped_refptr<SchedulerTqmDelegate> task_queue_manager_delegate_; |
| 117 std::unique_ptr<TaskTimeTracker> task_time_tracker_; |
| 111 std::unique_ptr<TaskQueueManager> task_queue_manager_; | 118 std::unique_ptr<TaskQueueManager> task_queue_manager_; |
| 112 scoped_refptr<TaskQueue> control_task_runner_; | 119 scoped_refptr<TaskQueue> control_task_runner_; |
| 113 scoped_refptr<TaskQueue> control_after_wakeup_task_runner_; | 120 scoped_refptr<TaskQueue> control_after_wakeup_task_runner_; |
| 114 scoped_refptr<TaskQueue> default_task_runner_; | 121 scoped_refptr<TaskQueue> default_task_runner_; |
| 115 | 122 |
| 116 Observer* observer_; // NOT OWNED | 123 Observer* observer_; // NOT OWNED |
| 117 const char* tracing_category_; | 124 const char* tracing_category_; |
| 118 const char* disabled_by_default_tracing_category_; | 125 const char* disabled_by_default_tracing_category_; |
| 119 | 126 |
| 120 DISALLOW_COPY_AND_ASSIGN(SchedulerHelper); | 127 DISALLOW_COPY_AND_ASSIGN(SchedulerHelper); |
| 121 }; | 128 }; |
| 122 | 129 |
| 123 } // namespace scheduler | 130 } // namespace scheduler |
| 124 | 131 |
| 125 #endif // COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_ | 132 #endif // COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_ |
| OLD | NEW |