| 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 THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_IDLE_HELPER_H_ | 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_IDLE_HELPER_H_ |
| 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_IDLE_HELPER_H_ | 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_IDLE_HELPER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "platform/PlatformExport.h" |
| 10 #include "platform/scheduler/base/cancelable_closure_holder.h" | 11 #include "platform/scheduler/base/cancelable_closure_holder.h" |
| 11 #include "platform/scheduler/base/task_queue_selector.h" | 12 #include "platform/scheduler/base/task_queue_selector.h" |
| 12 #include "platform/scheduler/child/scheduler_helper.h" | 13 #include "platform/scheduler/child/scheduler_helper.h" |
| 13 #include "public/platform/scheduler/child/single_thread_idle_task_runner.h" | 14 #include "public/platform/scheduler/child/single_thread_idle_task_runner.h" |
| 14 #include "public/platform/WebCommon.h" | |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 namespace scheduler { | 17 namespace scheduler { |
| 18 | 18 |
| 19 class SchedulerHelper; | 19 class SchedulerHelper; |
| 20 | 20 |
| 21 // The job of the IdleHelper is to run idle tasks when the system is otherwise | 21 // The job of the IdleHelper is to run idle tasks when the system is otherwise |
| 22 // idle. Idle tasks should be optional work, with no guarantee they will be run | 22 // idle. Idle tasks should be optional work, with no guarantee they will be run |
| 23 // at all. Idle tasks are subject to three levels of throttling: | 23 // at all. Idle tasks are subject to three levels of throttling: |
| 24 // | 24 // |
| 25 // 1. Both idle queues are run a BEST_EFFORT priority (i.e. only selected if | 25 // 1. Both idle queues are run a BEST_EFFORT priority (i.e. only selected if |
| 26 // there is nothing else to do. | 26 // there is nothing else to do. |
| 27 // 2. The idle queues are only enabled during an idle period. | 27 // 2. The idle queues are only enabled during an idle period. |
| 28 // 3. Idle tasks posted from within an idle task run in the next idle period. | 28 // 3. Idle tasks posted from within an idle task run in the next idle period. |
| 29 // This is achieved by inserting a fence into the queue. | 29 // This is achieved by inserting a fence into the queue. |
| 30 // | 30 // |
| 31 // There are two types of idle periods: | 31 // There are two types of idle periods: |
| 32 // 1. Short idle period - typically less than 10ms run after begin main frame | 32 // 1. Short idle period - typically less than 10ms run after begin main frame |
| 33 // has finished, with the idle period ending at the compositor provided | 33 // has finished, with the idle period ending at the compositor provided |
| 34 // deadline. | 34 // deadline. |
| 35 // 2. Long idle periods - typically up to 50ms when no frames are being | 35 // 2. Long idle periods - typically up to 50ms when no frames are being |
| 36 // produced. | 36 // produced. |
| 37 // | 37 // |
| 38 // Idle tasks are supplied a deadline, and should endeavor to finished before it | 38 // Idle tasks are supplied a deadline, and should endeavor to finished before it |
| 39 // ends to avoid jank. | 39 // ends to avoid jank. |
| 40 class BLINK_PLATFORM_EXPORT IdleHelper | 40 class PLATFORM_EXPORT IdleHelper : public base::MessageLoop::TaskObserver, |
| 41 : public base::MessageLoop::TaskObserver, | 41 public SingleThreadIdleTaskRunner::Delegate { |
| 42 public SingleThreadIdleTaskRunner::Delegate { | |
| 43 public: | 42 public: |
| 44 // Used to by scheduler implementations to customize idle behaviour. | 43 // Used to by scheduler implementations to customize idle behaviour. |
| 45 class BLINK_PLATFORM_EXPORT Delegate { | 44 class PLATFORM_EXPORT Delegate { |
| 46 public: | 45 public: |
| 47 Delegate(); | 46 Delegate(); |
| 48 virtual ~Delegate(); | 47 virtual ~Delegate(); |
| 49 | 48 |
| 50 // If it's ok to enter a long idle period, return true. Otherwise return | 49 // If it's ok to enter a long idle period, return true. Otherwise return |
| 51 // false and set next_long_idle_period_delay_out so we know when to try | 50 // false and set next_long_idle_period_delay_out so we know when to try |
| 52 // again. | 51 // again. |
| 53 virtual bool CanEnterLongIdlePeriod( | 52 virtual bool CanEnterLongIdlePeriod( |
| 54 base::TimeTicks now, | 53 base::TimeTicks now, |
| 55 base::TimeDelta* next_long_idle_period_delay_out) = 0; | 54 base::TimeDelta* next_long_idle_period_delay_out) = 0; |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 base::WeakPtr<IdleHelper> weak_idle_helper_ptr_; | 239 base::WeakPtr<IdleHelper> weak_idle_helper_ptr_; |
| 241 base::WeakPtrFactory<IdleHelper> weak_factory_; | 240 base::WeakPtrFactory<IdleHelper> weak_factory_; |
| 242 | 241 |
| 243 DISALLOW_COPY_AND_ASSIGN(IdleHelper); | 242 DISALLOW_COPY_AND_ASSIGN(IdleHelper); |
| 244 }; | 243 }; |
| 245 | 244 |
| 246 } // namespace scheduler | 245 } // namespace scheduler |
| 247 } // namespace blink | 246 } // namespace blink |
| 248 | 247 |
| 249 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_IDLE_HELPER_H_ | 248 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_IDLE_HELPER_H_ |
| OLD | NEW |