| 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_RENDERER_THROTTLING_HELPER_H_ | 5 #ifndef COMPONENTS_SCHEDULER_RENDERER_THROTTLING_HELPER_H_ |
| 6 #define COMPONENTS_SCHEDULER_RENDERER_THROTTLING_HELPER_H_ | 6 #define COMPONENTS_SCHEDULER_RENDERER_THROTTLING_HELPER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "components/scheduler/base/cancelable_closure_holder.h" | 11 #include "components/scheduler/base/cancelable_closure_holder.h" |
| 12 #include "components/scheduler/base/time_domain.h" | 12 #include "components/scheduler/base/time_domain.h" |
| 13 #include "components/scheduler/scheduler_export.h" | 13 #include "components/scheduler/scheduler_export.h" |
| 14 #include "third_party/WebKit/public/platform/WebViewScheduler.h" | 14 #include "third_party/WebKit/public/platform/WebViewScheduler.h" |
| 15 | 15 |
| 16 namespace scheduler { | 16 namespace scheduler { |
| 17 | 17 |
| 18 class RendererSchedulerImpl; | 18 class RendererSchedulerImpl; |
| 19 class VirtualTimeDomain; | 19 class ThrottledTimeDomain; |
| 20 class WebFrameSchedulerImpl; | 20 class WebFrameSchedulerImpl; |
| 21 | 21 |
| 22 class SCHEDULER_EXPORT ThrottlingHelper : public TimeDomain::Observer { | 22 class SCHEDULER_EXPORT ThrottlingHelper : public TimeDomain::Observer { |
| 23 public: | 23 public: |
| 24 ThrottlingHelper(RendererSchedulerImpl* renderer_scheduler, | 24 ThrottlingHelper(RendererSchedulerImpl* renderer_scheduler, |
| 25 const char* tracing_category); | 25 const char* tracing_category); |
| 26 | 26 |
| 27 ~ThrottlingHelper() override; | 27 ~ThrottlingHelper() override; |
| 28 | 28 |
| 29 // TimeDomain::Observer implementation: | 29 // TimeDomain::Observer implementation: |
| 30 void OnTimeDomainHasImmediateWork() override; | 30 void OnTimeDomainHasImmediateWork() override; |
| 31 void OnTimeDomainHasDelayedWork() override; | 31 void OnTimeDomainHasDelayedWork() override; |
| 32 | 32 |
| 33 void Throttle(TaskQueue* task_queue); | 33 void Throttle(TaskQueue* task_queue); |
| 34 void Unthrottle(TaskQueue* task_queue); | 34 void Unthrottle(TaskQueue* task_queue); |
| 35 | 35 |
| 36 const VirtualTimeDomain* time_domain() const { return time_domain_.get(); } | 36 const ThrottledTimeDomain* time_domain() const { return time_domain_.get(); } |
| 37 | 37 |
| 38 static base::TimeTicks ThrottledRunTime(base::TimeTicks unthrottled_runtime); | 38 static base::TimeTicks ThrottledRunTime(base::TimeTicks unthrottled_runtime); |
| 39 | 39 |
| 40 const scoped_refptr<TaskQueue>& task_runner() const { return task_runner_; } | 40 const scoped_refptr<TaskQueue>& task_runner() const { return task_runner_; } |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 void PumpThrottledTasks(); | 43 void PumpThrottledTasks(); |
| 44 void MaybeSchedulePumpThrottledTasksLocked( | 44 void MaybeSchedulePumpThrottledTasksLocked( |
| 45 const tracked_objects::Location& from_here, | 45 const tracked_objects::Location& from_here, |
| 46 base::TimeTicks now, | 46 base::TimeTicks now, |
| 47 base::TimeTicks unthrottled_runtime); | 47 base::TimeTicks unthrottled_runtime); |
| 48 | 48 |
| 49 std::set<TaskQueue*> throttled_queues_; | 49 std::set<TaskQueue*> throttled_queues_; |
| 50 base::Closure forward_immediate_work_closure_; | 50 base::Closure forward_immediate_work_closure_; |
| 51 scoped_refptr<TaskQueue> task_runner_; | 51 scoped_refptr<TaskQueue> task_runner_; |
| 52 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED | 52 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED |
| 53 base::TickClock* tick_clock_; // NOT OWNED | 53 base::TickClock* tick_clock_; // NOT OWNED |
| 54 const char* tracing_category_; // NOT OWNED | 54 const char* tracing_category_; // NOT OWNED |
| 55 scoped_ptr<VirtualTimeDomain> time_domain_; | 55 scoped_ptr<ThrottledTimeDomain> time_domain_; |
| 56 | 56 |
| 57 CancelableClosureHolder suspend_timers_when_backgrounded_closure_; | 57 CancelableClosureHolder suspend_timers_when_backgrounded_closure_; |
| 58 base::TimeTicks pending_pump_throttled_tasks_runtime_; | 58 base::TimeTicks pending_pump_throttled_tasks_runtime_; |
| 59 | 59 |
| 60 base::WeakPtrFactory<ThrottlingHelper> weak_factory_; | 60 base::WeakPtrFactory<ThrottlingHelper> weak_factory_; |
| 61 | 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(ThrottlingHelper); | 62 DISALLOW_COPY_AND_ASSIGN(ThrottlingHelper); |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 } // namespace scheduler | 65 } // namespace scheduler |
| 66 | 66 |
| 67 #endif // COMPONENTS_SCHEDULER_RENDERER_THROTTLING_HELPER_H_ | 67 #endif // COMPONENTS_SCHEDULER_RENDERER_THROTTLING_HELPER_H_ |
| OLD | NEW |