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

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

Issue 2080563003: (Merge m52) Fix a bug with throttling and timer queue suspension (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 6 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
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"
(...skipping 12 matching lines...) Expand all
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 // The purpose of this method is to make sure thottling 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
33 // Increments the throttled refcount and causes |task_queue| to be throttled 41 // Increments the throttled refcount and causes |task_queue| to be throttled
34 // if its not already throttled. 42 // if its not already throttled.
35 void IncreaseThrottleRefCount(TaskQueue* task_queue); 43 void IncreaseThrottleRefCount(TaskQueue* task_queue);
36 44
37 // If the refcouint is non-zero it's decremented. If the throttled refcount 45 // If the refcouint is non-zero it's decremented. If the throttled refcount
38 // becomes zero then |task_queue| is unthrottled. If the refcount was already 46 // becomes zero then |task_queue| is unthrottled. If the refcount was already
39 // zero this function does nothing. 47 // zero this function does nothing.
40 void DecreaseThrottleRefCount(TaskQueue* task_queue); 48 void DecreaseThrottleRefCount(TaskQueue* task_queue);
41 49
42 // Removes |task_queue| from |throttled_queues_|. 50 // Removes |task_queue| from |throttled_queues_|.
43 void UnregisterTaskQueue(TaskQueue* task_queue); 51 void UnregisterTaskQueue(TaskQueue* task_queue);
44 52
45 const ThrottledTimeDomain* time_domain() const { return time_domain_.get(); } 53 const ThrottledTimeDomain* time_domain() const { return time_domain_.get(); }
46 54
47 static base::TimeTicks ThrottledRunTime(base::TimeTicks unthrottled_runtime); 55 static base::TimeTicks ThrottledRunTime(base::TimeTicks unthrottled_runtime);
48 56
49 const scoped_refptr<TaskQueue>& task_runner() const { return task_runner_; } 57 const scoped_refptr<TaskQueue>& task_runner() const { return task_runner_; }
50 58
51 private: 59 private:
52 using TaskQueueMap = std::map<TaskQueue*, size_t>; 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>;
53 70
54 void PumpThrottledTasks(); 71 void PumpThrottledTasks();
55 72
56 // Note |unthrottled_runtime| might be in the past. When this happens we 73 // Note |unthrottled_runtime| might be in the past. When this happens we
57 // compute the delay to the next runtime based on now rather than 74 // compute the delay to the next runtime based on now rather than
58 // unthrottled_runtime. 75 // unthrottled_runtime.
59 void MaybeSchedulePumpThrottledTasksLocked( 76 void MaybeSchedulePumpThrottledTasksLocked(
60 const tracked_objects::Location& from_here, 77 const tracked_objects::Location& from_here,
61 base::TimeTicks now, 78 base::TimeTicks now,
62 base::TimeTicks unthrottled_runtime); 79 base::TimeTicks unthrottled_runtime);
(...skipping 10 matching lines...) Expand all
73 base::TimeTicks pending_pump_throttled_tasks_runtime_; 90 base::TimeTicks pending_pump_throttled_tasks_runtime_;
74 91
75 base::WeakPtrFactory<ThrottlingHelper> weak_factory_; 92 base::WeakPtrFactory<ThrottlingHelper> weak_factory_;
76 93
77 DISALLOW_COPY_AND_ASSIGN(ThrottlingHelper); 94 DISALLOW_COPY_AND_ASSIGN(ThrottlingHelper);
78 }; 95 };
79 96
80 } // namespace scheduler 97 } // namespace scheduler
81 98
82 #endif // COMPONENTS_SCHEDULER_RENDERER_THROTTLING_HELPER_H_ 99 #endif // COMPONENTS_SCHEDULER_RENDERER_THROTTLING_HELPER_H_
OLDNEW
« no previous file with comments | « components/scheduler/renderer/renderer_scheduler_impl_unittest.cc ('k') | components/scheduler/renderer/throttling_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698