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/task_queue_manager.h" | 8 #include "components/scheduler/child/task_queue_manager.h" |
9 #include "components/scheduler/child/task_queue_selector.h" | 9 #include "components/scheduler/child/task_queue_selector.h" |
10 #include "components/scheduler/scheduler_export.h" | 10 #include "components/scheduler/scheduler_export.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 class TickClock; | 13 class TickClock; |
14 } | 14 } |
15 | 15 |
16 namespace scheduler { | 16 namespace scheduler { |
17 | 17 |
18 class SchedulerTaskRunnerDelegate; | 18 class SchedulerTaskRunnerDelegate; |
19 | 19 |
20 // Common scheduler functionality for default tasks. | 20 // Common scheduler functionality for default tasks. |
21 class SCHEDULER_EXPORT SchedulerHelper { | 21 class SCHEDULER_EXPORT SchedulerHelper : public TaskQueueManager::Observer { |
22 public: | 22 public: |
23 // Category strings must have application lifetime (statics or | 23 // Category strings must have application lifetime (statics or |
24 // literals). They may not include " chars. | 24 // literals). They may not include " chars. |
25 SchedulerHelper(scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner, | 25 SchedulerHelper(scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner, |
26 const char* tracing_category, | 26 const char* tracing_category, |
27 const char* disabled_by_default_tracing_category, | 27 const char* disabled_by_default_tracing_category, |
28 const char* disabled_by_default_verbose_tracing_category); | 28 const char* disabled_by_default_verbose_tracing_category); |
29 ~SchedulerHelper(); | 29 ~SchedulerHelper() override; |
30 | |
31 // TaskQueueManager::Observer implementation: | |
32 void OnUnregisterTaskQueue( | |
33 const scoped_refptr<internal::TaskQueueImpl>& queue) override; | |
30 | 34 |
31 // Returns the default task runner. | 35 // Returns the default task runner. |
32 scoped_refptr<TaskQueue> DefaultTaskRunner(); | 36 scoped_refptr<TaskQueue> DefaultTaskRunner(); |
33 | 37 |
34 // Returns the control task runner. Tasks posted to this runner are executed | 38 // Returns the control task runner. Tasks posted to this runner are executed |
35 // with the highest priority. Care must be taken to avoid starvation of other | 39 // with the highest priority. Care must be taken to avoid starvation of other |
36 // task queues. | 40 // task queues. |
37 scoped_refptr<TaskQueue> ControlTaskRunner(); | 41 scoped_refptr<TaskQueue> ControlTaskRunner(); |
38 | 42 |
39 // Returns the control task after wakeup runner. Tasks posted to this runner | 43 // Returns the control task after wakeup runner. Tasks posted to this runner |
(...skipping 15 matching lines...) Expand all Loading... | |
55 // Returns true if Shutdown() has been called. Otherwise returns false. | 59 // Returns true if Shutdown() has been called. Otherwise returns false. |
56 bool IsShutdown() const { return !task_queue_manager_.get(); } | 60 bool IsShutdown() const { return !task_queue_manager_.get(); } |
57 | 61 |
58 void CheckOnValidThread() const { | 62 void CheckOnValidThread() const { |
59 DCHECK(thread_checker_.CalledOnValidThread()); | 63 DCHECK(thread_checker_.CalledOnValidThread()); |
60 } | 64 } |
61 | 65 |
62 // Creates a new TaskQueue with the given |spec|. | 66 // Creates a new TaskQueue with the given |spec|. |
63 scoped_refptr<TaskQueue> NewTaskQueue(const TaskQueue::Spec& spec); | 67 scoped_refptr<TaskQueue> NewTaskQueue(const TaskQueue::Spec& spec); |
64 | 68 |
69 class SCHEDULER_EXPORT Observer { | |
70 public: | |
71 virtual ~Observer() {} | |
72 | |
73 // Called when |queue| is unregistered. | |
74 virtual void OnUnregisterTaskQueue( | |
75 const scoped_refptr<TaskQueue>& queue) = 0; | |
76 }; | |
77 | |
78 // Called once to set the Observer. This function is called on the main | |
79 // thread. If |observer| is null, then no callbacks will occur. | |
Sami
2015/09/10 15:10:23
nit: mention that the observer should outlive this
alex clarke (OOO till 29th)
2015/09/10 15:56:24
Done.
| |
80 void SetQueueObserver(Observer* observer); | |
81 | |
65 // Accessor methods. | 82 // Accessor methods. |
66 base::TimeTicks Now() const; | 83 base::TimeTicks Now() const; |
67 base::TimeTicks NextPendingDelayedTaskRunTime() const; | 84 base::TimeTicks NextPendingDelayedTaskRunTime() const; |
68 bool GetAndClearSystemIsQuiescentBit(); | 85 bool GetAndClearSystemIsQuiescentBit(); |
69 | 86 |
70 // Test helpers. | 87 // Test helpers. |
71 void SetTimeSourceForTesting(scoped_ptr<base::TickClock> time_source); | 88 void SetTimeSourceForTesting(scoped_ptr<base::TickClock> time_source); |
72 void SetWorkBatchSizeForTesting(size_t work_batch_size); | 89 void SetWorkBatchSizeForTesting(size_t work_batch_size); |
73 TaskQueueManager* GetTaskQueueManagerForTesting(); | 90 TaskQueueManager* GetTaskQueueManagerForTesting(); |
74 | 91 |
75 private: | 92 private: |
76 friend class SchedulerHelperTest; | 93 friend class SchedulerHelperTest; |
77 | 94 |
78 base::ThreadChecker thread_checker_; | 95 base::ThreadChecker thread_checker_; |
79 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner_; | 96 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner_; |
80 scoped_ptr<TaskQueueManager> task_queue_manager_; | 97 scoped_ptr<TaskQueueManager> task_queue_manager_; |
81 scoped_refptr<TaskQueue> control_task_runner_; | 98 scoped_refptr<TaskQueue> control_task_runner_; |
82 scoped_refptr<TaskQueue> control_after_wakeup_task_runner_; | 99 scoped_refptr<TaskQueue> control_after_wakeup_task_runner_; |
83 scoped_refptr<TaskQueue> default_task_runner_; | 100 scoped_refptr<TaskQueue> default_task_runner_; |
84 | 101 |
85 scoped_ptr<base::TickClock> time_source_; | 102 scoped_ptr<base::TickClock> time_source_; |
86 | 103 |
104 Observer* queue_observer_; // NOT OWNED | |
87 const char* tracing_category_; | 105 const char* tracing_category_; |
88 const char* disabled_by_default_tracing_category_; | 106 const char* disabled_by_default_tracing_category_; |
89 | 107 |
90 DISALLOW_COPY_AND_ASSIGN(SchedulerHelper); | 108 DISALLOW_COPY_AND_ASSIGN(SchedulerHelper); |
91 }; | 109 }; |
92 | 110 |
93 } // namespace scheduler | 111 } // namespace scheduler |
94 | 112 |
95 #endif // COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_ | 113 #endif // COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_ |
OLD | NEW |