Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: components/scheduler/renderer/throttling_helper.h

Issue 2118903002: scheduler: Move the Blink scheduler into Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Another GYP fix Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_SCHEDULER_RENDERER_THROTTLING_HELPER_H_
6 #define COMPONENTS_SCHEDULER_RENDERER_THROTTLING_HELPER_H_
7
8 #include <set>
9
10 #include "base/macros.h"
11 #include "components/scheduler/base/cancelable_closure_holder.h"
12 #include "components/scheduler/base/time_domain.h"
13 #include "components/scheduler/scheduler_export.h"
14 #include "third_party/WebKit/public/platform/WebViewScheduler.h"
15
16 namespace scheduler {
17
18 class RendererSchedulerImpl;
19 class ThrottledTimeDomain;
20 class WebFrameSchedulerImpl;
21
22 class SCHEDULER_EXPORT ThrottlingHelper : public TimeDomain::Observer {
23 public:
24 ThrottlingHelper(RendererSchedulerImpl* renderer_scheduler,
25 const char* tracing_category);
26
27 ~ThrottlingHelper() override;
28
29 // TimeDomain::Observer implementation:
30 void OnTimeDomainHasImmediateWork() override;
31 void OnTimeDomainHasDelayedWork() override;
32
33 // The purpose of this method is to make sure throttling doesn't conflict with
34 // enabling/disabling the queue for policy reasons.
35 // If |task_queue| is throttled then the ThrottlingHelper remembers the
36 // |enabled| setting. In addition if |enabled| is false then the queue is
37 // immediatly disabled. Otherwise if |task_queue| not throttled then
38 // TaskQueue::SetEnabled(enabled) is called.
39 void SetQueueEnabled(TaskQueue* task_queue, bool enabled);
40
41 // Increments the throttled refcount and causes |task_queue| to be throttled
42 // if its not already throttled.
43 void IncreaseThrottleRefCount(TaskQueue* task_queue);
44
45 // 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
47 // zero this function does nothing.
48 void DecreaseThrottleRefCount(TaskQueue* task_queue);
49
50 // Removes |task_queue| from |throttled_queues_|.
51 void UnregisterTaskQueue(TaskQueue* task_queue);
52
53 const ThrottledTimeDomain* time_domain() const { return time_domain_.get(); }
54
55 static base::TimeTicks ThrottledRunTime(base::TimeTicks unthrottled_runtime);
56
57 const scoped_refptr<TaskQueue>& task_runner() const { return task_runner_; }
58
59 private:
60 struct Metadata {
61 Metadata() : throttling_ref_count(0), enabled(false) {}
62
63 Metadata(size_t ref_count, bool is_enabled)
64 : throttling_ref_count(ref_count), enabled(is_enabled) {}
65
66 size_t throttling_ref_count;
67 bool enabled;
68 };
69 using TaskQueueMap = std::map<TaskQueue*, Metadata>;
70
71 void PumpThrottledTasks();
72
73 // Note |unthrottled_runtime| might be in the past. When this happens we
74 // compute the delay to the next runtime based on now rather than
75 // unthrottled_runtime.
76 void MaybeSchedulePumpThrottledTasksLocked(
77 const tracked_objects::Location& from_here,
78 base::TimeTicks now,
79 base::TimeTicks unthrottled_runtime);
80
81 TaskQueueMap throttled_queues_;
82 base::Closure forward_immediate_work_closure_;
83 scoped_refptr<TaskQueue> task_runner_;
84 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED
85 base::TickClock* tick_clock_; // NOT OWNED
86 const char* tracing_category_; // NOT OWNED
87 std::unique_ptr<ThrottledTimeDomain> time_domain_;
88
89 CancelableClosureHolder suspend_timers_when_backgrounded_closure_;
90 base::TimeTicks pending_pump_throttled_tasks_runtime_;
91
92 base::WeakPtrFactory<ThrottlingHelper> weak_factory_;
93
94 DISALLOW_COPY_AND_ASSIGN(ThrottlingHelper);
95 };
96
97 } // namespace scheduler
98
99 #endif // COMPONENTS_SCHEDULER_RENDERER_THROTTLING_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698