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_RENDERER_THROTTLING_HELPER_ H_ | 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELPER_ H_ |
6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELPER_ H_ | 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_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 "platform/scheduler/base/cancelable_closure_holder.h" | 11 #include "platform/scheduler/base/cancelable_closure_holder.h" |
12 #include "platform/scheduler/base/time_domain.h" | 12 #include "platform/scheduler/base/time_domain.h" |
13 #include "public/platform/WebViewScheduler.h" | 13 #include "public/platform/WebViewScheduler.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 namespace scheduler { | 16 namespace scheduler { |
17 | 17 |
18 class RendererSchedulerImpl; | 18 class RendererSchedulerImpl; |
19 class ThrottledTimeDomain; | 19 class ThrottledTimeDomain; |
20 class WebFrameSchedulerImpl; | 20 class WebFrameSchedulerImpl; |
21 | 21 |
22 // The job of the ThrottlingHelper is to run tasks posted on throttled queues at | |
23 // most once per second. This is done by disabling throttled queues and running | |
24 // a special "heart beat" function |PumpThrottledTasks| which when run | |
25 // temporarily enables throttled queues and posts a task on them to disable | |
26 // themselves till next time. | |
27 // | |
28 // Of course the ThrottlingHelper isn't the only sub-system that wants to enable | |
29 // or disable queues. E.g. RendererSchedulerImpl also does this for policy | |
30 // reasons. To prevent the systems from fighting, clients of ThrottlingHelper | |
31 // must use SetQueueEnabled rather than calling the function directly on the | |
32 // queue. | |
33 // | |
34 // There may be more than one system that wishes to throttle a queue (e.g. | |
35 // renderer suspension vs level tab suspension) so the ThrottlingHelper keeps a | |
Sami
2016/08/25 15:54:13
Did you mean renderer level vs. tab level suspensi
alex clarke (OOO till 29th)
2016/08/26 13:29:09
Done.
| |
36 // count of the number of systems that wish a queue to be throttled. | |
37 // See IncreaseThrottleRefCount & DecreaseThrottleRefCount. | |
22 class BLINK_PLATFORM_EXPORT ThrottlingHelper : public TimeDomain::Observer { | 38 class BLINK_PLATFORM_EXPORT ThrottlingHelper : public TimeDomain::Observer { |
23 public: | 39 public: |
24 ThrottlingHelper(RendererSchedulerImpl* renderer_scheduler, | 40 ThrottlingHelper(RendererSchedulerImpl* renderer_scheduler, |
25 const char* tracing_category); | 41 const char* tracing_category); |
26 | 42 |
27 ~ThrottlingHelper() override; | 43 ~ThrottlingHelper() override; |
28 | 44 |
29 // TimeDomain::Observer implementation: | 45 // TimeDomain::Observer implementation: |
30 void OnTimeDomainHasImmediateWork() override; | 46 void OnTimeDomainHasImmediateWork() override; |
31 void OnTimeDomainHasDelayedWork() override; | 47 void OnTimeDomainHasDelayedWork() override; |
(...skipping 11 matching lines...) Expand all Loading... | |
43 void IncreaseThrottleRefCount(TaskQueue* task_queue); | 59 void IncreaseThrottleRefCount(TaskQueue* task_queue); |
44 | 60 |
45 // If the refcouint is non-zero it's decremented. If the throttled refcount | 61 // If the refcouint is non-zero it's decremented. If the throttled refcount |
46 // becomes zero then |task_queue| is unthrottled. If the refcount was already | 62 // becomes zero then |task_queue| is unthrottled. If the refcount was already |
47 // zero this function does nothing. | 63 // zero this function does nothing. |
48 void DecreaseThrottleRefCount(TaskQueue* task_queue); | 64 void DecreaseThrottleRefCount(TaskQueue* task_queue); |
49 | 65 |
50 // Removes |task_queue| from |throttled_queues_|. | 66 // Removes |task_queue| from |throttled_queues_|. |
51 void UnregisterTaskQueue(TaskQueue* task_queue); | 67 void UnregisterTaskQueue(TaskQueue* task_queue); |
52 | 68 |
69 // Returns true if the |task_queue| is throttled. | |
70 bool IsThrottled(TaskQueue* task_queue) const; | |
71 | |
53 // Tells the ThrottlingHelper we're using virtual time, which disables all | 72 // Tells the ThrottlingHelper we're using virtual time, which disables all |
54 // throttling. | 73 // throttling. |
55 void EnableVirtualTime(); | 74 void EnableVirtualTime(); |
56 | 75 |
57 const ThrottledTimeDomain* time_domain() const { return time_domain_.get(); } | 76 const ThrottledTimeDomain* time_domain() const { return time_domain_.get(); } |
58 | 77 |
59 static base::TimeTicks ThrottledRunTime(base::TimeTicks unthrottled_runtime); | 78 static base::TimeTicks ThrottledRunTime(base::TimeTicks unthrottled_runtime); |
60 | 79 |
61 const scoped_refptr<TaskQueue>& task_runner() const { return task_runner_; } | 80 const scoped_refptr<TaskQueue>& task_runner() const { return task_runner_; } |
62 | 81 |
63 private: | 82 private: |
64 struct Metadata { | 83 struct Metadata { |
65 Metadata() : throttling_ref_count(0), enabled(false) {} | 84 Metadata() : throttling_ref_count(0), enabled(false) {} |
66 | 85 |
67 Metadata(size_t ref_count, bool is_enabled) | 86 Metadata(size_t ref_count, bool is_enabled) |
68 : throttling_ref_count(ref_count), enabled(is_enabled) {} | 87 : throttling_ref_count(ref_count), enabled(is_enabled) {} |
69 | 88 |
70 size_t throttling_ref_count; | 89 size_t throttling_ref_count; |
71 bool enabled; | 90 bool enabled; |
72 }; | 91 }; |
73 using TaskQueueMap = std::map<TaskQueue*, Metadata>; | 92 using TaskQueueMap = std::map<TaskQueue*, Metadata>; |
74 | 93 |
75 void PumpThrottledTasks(); | 94 void PumpThrottledTasks(); |
95 void MaybeDisableQueue(TaskQueue* task_queue); | |
76 | 96 |
77 // Note |unthrottled_runtime| might be in the past. When this happens we | 97 // Note |unthrottled_runtime| might be in the past. When this happens we |
78 // compute the delay to the next runtime based on now rather than | 98 // compute the delay to the next runtime based on now rather than |
79 // unthrottled_runtime. | 99 // unthrottled_runtime. |
80 void MaybeSchedulePumpThrottledTasksLocked( | 100 void MaybeSchedulePumpThrottledTasksLocked( |
81 const tracked_objects::Location& from_here, | 101 const tracked_objects::Location& from_here, |
82 base::TimeTicks now, | 102 base::TimeTicks now, |
83 base::TimeTicks unthrottled_runtime); | 103 base::TimeTicks unthrottled_runtime); |
84 | 104 |
85 TaskQueueMap throttled_queues_; | 105 TaskQueueMap throttled_queues_; |
86 base::Closure forward_immediate_work_closure_; | 106 base::Closure forward_immediate_work_closure_; |
87 scoped_refptr<TaskQueue> task_runner_; | 107 scoped_refptr<TaskQueue> task_runner_; |
88 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED | 108 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED |
89 base::TickClock* tick_clock_; // NOT OWNED | 109 base::TickClock* tick_clock_; // NOT OWNED |
90 const char* tracing_category_; // NOT OWNED | 110 const char* tracing_category_; // NOT OWNED |
91 std::unique_ptr<ThrottledTimeDomain> time_domain_; | 111 std::unique_ptr<ThrottledTimeDomain> time_domain_; |
92 | 112 |
93 CancelableClosureHolder pump_throttled_tasks_closure_; | 113 CancelableClosureHolder pump_throttled_tasks_closure_; |
94 base::TimeTicks pending_pump_throttled_tasks_runtime_; | 114 base::TimeTicks pending_pump_throttled_tasks_runtime_; |
95 bool virtual_time_; | 115 bool virtual_time_; |
116 bool ignore_incoming_immediate_work_; | |
96 | 117 |
97 base::WeakPtrFactory<ThrottlingHelper> weak_factory_; | 118 base::WeakPtrFactory<ThrottlingHelper> weak_factory_; |
98 | 119 |
99 DISALLOW_COPY_AND_ASSIGN(ThrottlingHelper); | 120 DISALLOW_COPY_AND_ASSIGN(ThrottlingHelper); |
100 }; | 121 }; |
101 | 122 |
102 } // namespace scheduler | 123 } // namespace scheduler |
103 } // namespace blink | 124 } // namespace blink |
104 | 125 |
105 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELP ER_H_ | 126 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELP ER_H_ |
OLD | NEW |