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

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

Issue 2028433004: Fix a bug with throttling and timer queue suspension (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make sure this works in general. 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 // If |task_queue| is throttled then the ThrottlingHelper remembers the
34 // |enabled| setting. In addition if |enabled| is false then the queue is
35 // immediatly disabled. Otherwise if |task_queue| not throttled then
36 // TaskQueue::SetEnabled(enabled) is called.
37 void SetQueueEnabled(TaskQueue* task_queue, bool enabled);
38
33 // Increments the throttled refcount and causes |task_queue| to be throttled 39 // Increments the throttled refcount and causes |task_queue| to be throttled
34 // if its not already throttled. 40 // if its not already throttled.
35 void IncreaseThrottleRefCount(TaskQueue* task_queue); 41 void IncreaseThrottleRefCount(TaskQueue* task_queue);
36 42
37 // If the refcouint is non-zero it's decremented. If the throttled refcount 43 // 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 44 // becomes zero then |task_queue| is unthrottled. If the refcount was already
39 // zero this function does nothing. 45 // zero this function does nothing.
40 void DecreaseThrottleRefCount(TaskQueue* task_queue); 46 void DecreaseThrottleRefCount(TaskQueue* task_queue);
41 47
42 // Removes |task_queue| from |throttled_queues_|. 48 // Removes |task_queue| from |throttled_queues_|.
43 void UnregisterTaskQueue(TaskQueue* task_queue); 49 void UnregisterTaskQueue(TaskQueue* task_queue);
44 50
45 const ThrottledTimeDomain* time_domain() const { return time_domain_.get(); } 51 const ThrottledTimeDomain* time_domain() const { return time_domain_.get(); }
46 52
47 static base::TimeTicks ThrottledRunTime(base::TimeTicks unthrottled_runtime); 53 static base::TimeTicks ThrottledRunTime(base::TimeTicks unthrottled_runtime);
48 54
49 const scoped_refptr<TaskQueue>& task_runner() const { return task_runner_; } 55 const scoped_refptr<TaskQueue>& task_runner() const { return task_runner_; }
50 56
51 private: 57 private:
52 using TaskQueueMap = std::map<TaskQueue*, size_t>; 58 struct Metadata {
59 Metadata() : throttling_ref_count(0), enabled(false) {}
60
61 Metadata(size_t ref_count, bool is_enabled)
62 : throttling_ref_count(ref_count), enabled(is_enabled) {}
63
64 size_t throttling_ref_count;
65 bool enabled;
66 };
67 using TaskQueueMap = std::map<TaskQueue*, Metadata>;
53 68
54 void PumpThrottledTasks(); 69 void PumpThrottledTasks();
55 70
56 // Note |unthrottled_runtime| might be in the past. When this happens we 71 // 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 72 // compute the delay to the next runtime based on now rather than
58 // unthrottled_runtime. 73 // unthrottled_runtime.
59 void MaybeSchedulePumpThrottledTasksLocked( 74 void MaybeSchedulePumpThrottledTasksLocked(
60 const tracked_objects::Location& from_here, 75 const tracked_objects::Location& from_here,
61 base::TimeTicks now, 76 base::TimeTicks now,
62 base::TimeTicks unthrottled_runtime); 77 base::TimeTicks unthrottled_runtime);
(...skipping 10 matching lines...) Expand all
73 base::TimeTicks pending_pump_throttled_tasks_runtime_; 88 base::TimeTicks pending_pump_throttled_tasks_runtime_;
74 89
75 base::WeakPtrFactory<ThrottlingHelper> weak_factory_; 90 base::WeakPtrFactory<ThrottlingHelper> weak_factory_;
76 91
77 DISALLOW_COPY_AND_ASSIGN(ThrottlingHelper); 92 DISALLOW_COPY_AND_ASSIGN(ThrottlingHelper);
78 }; 93 };
79 94
80 } // namespace scheduler 95 } // namespace scheduler
81 96
82 #endif // COMPONENTS_SCHEDULER_RENDERER_THROTTLING_HELPER_H_ 97 #endif // COMPONENTS_SCHEDULER_RENDERER_THROTTLING_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698