| 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_CHILD_SCHEDULER_H_ | 5 #ifndef COMPONENTS_SCHEDULER_CHILD_CHILD_SCHEDULER_H_ |
| 6 #define COMPONENTS_SCHEDULER_CHILD_CHILD_SCHEDULER_H_ | 6 #define COMPONENTS_SCHEDULER_CHILD_CHILD_SCHEDULER_H_ |
| 7 | 7 |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "components/scheduler/child/single_thread_idle_task_runner.h" | 9 #include "components/scheduler/child/single_thread_idle_task_runner.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 MessageLoop; | 13 class MessageLoop; |
| 14 } | 14 } |
| 15 | 15 |
| 16 namespace scheduler { | 16 namespace scheduler { |
| 17 | 17 |
| 18 class SCHEDULER_EXPORT ChildScheduler { | 18 class SCHEDULER_EXPORT ChildScheduler { |
| 19 public: | 19 public: |
| 20 virtual ~ChildScheduler() {} | 20 virtual ~ChildScheduler() {} |
| 21 | 21 |
| 22 // Returns the default task runner. | 22 // Returns the default task runner. |
| 23 virtual scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner() = 0; | 23 virtual scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner() = 0; |
| 24 | 24 |
| 25 // Returns the idle task runner. Tasks posted to this runner may be reordered | 25 // Returns the idle task runner. Tasks posted to this runner may be reordered |
| 26 // relative to other task types and may be starved for an arbitrarily long | 26 // relative to other task types and may be starved for an arbitrarily long |
| 27 // time if no idle time is available. | 27 // time if no idle time is available. |
| 28 virtual scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner() = 0; | 28 virtual scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner() = 0; |
| 29 | 29 |
| 30 // Returns the shutdown task runner. Intended for tasks that must be able to |
| 31 // run even after PreShutdown() is called. |
| 32 virtual scoped_refptr<base::SingleThreadTaskRunner> ShutdownTaskRunner() = 0; |
| 33 |
| 30 // Returns true if there is high priority work pending on the main thread | 34 // Returns true if there is high priority work pending on the main thread |
| 31 // and the caller should yield to let the scheduler service that work. Note | 35 // and the caller should yield to let the scheduler service that work. Note |
| 32 // that this is a stricter condition than |IsHighPriorityWorkAnticipated|, | 36 // that this is a stricter condition than |IsHighPriorityWorkAnticipated|, |
| 33 // restricted to the case where real work is pending. | 37 // restricted to the case where real work is pending. |
| 34 // Must be called from the thread this scheduler was created on. | 38 // Must be called from the thread this scheduler was created on. |
| 35 virtual bool ShouldYieldForHighPriorityWork() = 0; | 39 virtual bool ShouldYieldForHighPriorityWork() = 0; |
| 36 | 40 |
| 37 // Returns true if a currently running idle task could exceed its deadline | 41 // Returns true if a currently running idle task could exceed its deadline |
| 38 // without impacting user experience too much. This should only be used if | 42 // without impacting user experience too much. This should only be used if |
| 39 // there is a task which cannot be pre-empted and is likely to take longer | 43 // there is a task which cannot be pre-empted and is likely to take longer |
| 40 // than the largest expected idle task deadline. It should NOT be polled to | 44 // than the largest expected idle task deadline. It should NOT be polled to |
| 41 // check whether more work can be performed on the current idle task after | 45 // check whether more work can be performed on the current idle task after |
| 42 // its deadline has expired - post a new idle task for the continuation of the | 46 // its deadline has expired - post a new idle task for the continuation of the |
| 43 // work in this case. | 47 // work in this case. |
| 44 // Must be called from the thread this scheduler was created on. | 48 // Must be called from the thread this scheduler was created on. |
| 45 virtual bool CanExceedIdleDeadlineIfRequired() const = 0; | 49 virtual bool CanExceedIdleDeadlineIfRequired() const = 0; |
| 46 | 50 |
| 47 // Adds or removes a task observer from the scheduler. The observer will be | 51 // Adds or removes a task observer from the scheduler. The observer will be |
| 48 // notified before and after every executed task. These functions can only be | 52 // notified before and after every executed task. These functions can only be |
| 49 // called on the thread this scheduler was created on. | 53 // called on the thread this scheduler was created on. |
| 50 virtual void AddTaskObserver( | 54 virtual void AddTaskObserver( |
| 51 base::MessageLoop::TaskObserver* task_observer) = 0; | 55 base::MessageLoop::TaskObserver* task_observer) = 0; |
| 52 virtual void RemoveTaskObserver( | 56 virtual void RemoveTaskObserver( |
| 53 base::MessageLoop::TaskObserver* task_observer) = 0; | 57 base::MessageLoop::TaskObserver* task_observer) = 0; |
| 54 | 58 |
| 59 // Optional. This stops all queues except for the shutdown queue. Must be |
| 60 // called from the thread this scheduler was created on. |
| 61 virtual void PreShutdown() = 0; |
| 62 |
| 55 // Shuts down the scheduler by dropping any remaining pending work in the work | 63 // Shuts down the scheduler by dropping any remaining pending work in the work |
| 56 // queues. After this call any work posted to the task runners will be | 64 // queues. After this call any work posted to the task runners will be |
| 57 // silently dropped. | 65 // silently dropped. |
| 58 virtual void Shutdown() = 0; | 66 virtual void Shutdown() = 0; |
| 59 | 67 |
| 60 protected: | 68 protected: |
| 61 ChildScheduler() {} | 69 ChildScheduler() {} |
| 62 DISALLOW_COPY_AND_ASSIGN(ChildScheduler); | 70 DISALLOW_COPY_AND_ASSIGN(ChildScheduler); |
| 63 }; | 71 }; |
| 64 | 72 |
| 65 } // namespace scheduler | 73 } // namespace scheduler |
| 66 | 74 |
| 67 #endif // COMPONENTS_SCHEDULER_CHILD_CHILD_SCHEDULER_H_ | 75 #endif // COMPONENTS_SCHEDULER_CHILD_CHILD_SCHEDULER_H_ |
| OLD | NEW |