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 | |
Sami
2016/08/26 14:37:03
No more task posting going on here.
alex clarke (OOO till 29th)
2016/08/26 16:33:14
Done.
| |
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 tab level suspension) so the ThrottlingHelper keeps a | |
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 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 | 115 |
97 base::WeakPtrFactory<ThrottlingHelper> weak_factory_; | 116 base::WeakPtrFactory<ThrottlingHelper> weak_factory_; |
98 | 117 |
99 DISALLOW_COPY_AND_ASSIGN(ThrottlingHelper); | 118 DISALLOW_COPY_AND_ASSIGN(ThrottlingHelper); |
100 }; | 119 }; |
101 | 120 |
102 } // namespace scheduler | 121 } // namespace scheduler |
103 } // namespace blink | 122 } // namespace blink |
104 | 123 |
105 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELP ER_H_ | 124 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELP ER_H_ |
OLD | NEW |