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

Side by Side Diff: content/renderer/scheduler/renderer_task_queue_selector.cc

Issue 985813002: Experimental: Remove chromium shared timers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More tests Created 5 years, 9 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "content/renderer/scheduler/renderer_task_queue_selector.h" 5 #include "content/renderer/scheduler/renderer_task_queue_selector.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/pending_task.h" 8 #include "base/pending_task.h"
9 #include "base/trace_event/trace_event_argument.h" 9 #include "base/trace_event/trace_event_argument.h"
10 10
11 namespace content { 11 namespace content {
12 12
13 RendererTaskQueueSelector::RendererTaskQueueSelector() : starvation_count_(0) { 13 RendererTaskQueueSelector::RendererTaskQueueSelector()
14 : starvation_count_(0), task_queue_selector_observer_(nullptr) {
14 } 15 }
15 16
16 RendererTaskQueueSelector::~RendererTaskQueueSelector() { 17 RendererTaskQueueSelector::~RendererTaskQueueSelector() {
17 } 18 }
18 19
19 void RendererTaskQueueSelector::RegisterWorkQueues( 20 void RendererTaskQueueSelector::RegisterWorkQueues(
20 const std::vector<const base::TaskQueue*>& work_queues) { 21 const std::vector<const base::TaskQueue*>& work_queues) {
21 DCHECK(main_thread_checker_.CalledOnValidThread()); 22 DCHECK(main_thread_checker_.CalledOnValidThread());
22 work_queues_ = work_queues; 23 work_queues_ = work_queues;
23 for (auto& queue_priority : queue_priorities_) { 24 for (auto& queue_priority : queue_priorities_) {
24 queue_priority.clear(); 25 queue_priority.clear();
25 } 26 }
26 27
27 // By default, all work queues are set to normal priority. 28 // By default, all work queues are set to normal priority.
28 for (size_t i = 0; i < work_queues.size(); i++) { 29 for (size_t i = 0; i < work_queues.size(); i++) {
29 queue_priorities_[NORMAL_PRIORITY].insert(i); 30 queue_priorities_[NORMAL_PRIORITY].insert(i);
30 } 31 }
31 } 32 }
32 33
33 void RendererTaskQueueSelector::SetQueuePriority(size_t queue_index, 34 void RendererTaskQueueSelector::SetQueuePriority(size_t queue_index,
34 QueuePriority priority) { 35 QueuePriority priority) {
35 DCHECK(main_thread_checker_.CalledOnValidThread()); 36 DCHECK(main_thread_checker_.CalledOnValidThread());
36 DCHECK_LT(queue_index, work_queues_.size()); 37 DCHECK_LT(queue_index, work_queues_.size());
37 DCHECK_LT(priority, QUEUE_PRIORITY_COUNT); 38 DCHECK_LT(priority, QUEUE_PRIORITY_COUNT);
38 DisableQueue(queue_index); 39 bool previously_enabled = DisableQueue(queue_index);
39 queue_priorities_[priority].insert(queue_index); 40 queue_priorities_[priority].insert(queue_index);
41 if (task_queue_selector_observer_ && !previously_enabled)
42 task_queue_selector_observer_->OnTaskQueueEnabled();
40 } 43 }
41 44
42 void RendererTaskQueueSelector::EnableQueue(size_t queue_index, 45 void RendererTaskQueueSelector::EnableQueue(size_t queue_index,
43 QueuePriority priority) { 46 QueuePriority priority) {
44 SetQueuePriority(queue_index, priority); 47 SetQueuePriority(queue_index, priority);
45 } 48 }
46 49
47 void RendererTaskQueueSelector::DisableQueue(size_t queue_index) { 50 bool RendererTaskQueueSelector::DisableQueue(size_t queue_index) {
48 DCHECK(main_thread_checker_.CalledOnValidThread()); 51 DCHECK(main_thread_checker_.CalledOnValidThread());
49 DCHECK_LT(queue_index, work_queues_.size()); 52 DCHECK_LT(queue_index, work_queues_.size());
53 bool previously_enabled = false;
50 for (auto& queue_priority : queue_priorities_) { 54 for (auto& queue_priority : queue_priorities_) {
51 queue_priority.erase(queue_index); 55 if (queue_priority.erase(queue_index))
56 previously_enabled = true;
52 } 57 }
58 return previously_enabled;
53 } 59 }
54 60
55 bool RendererTaskQueueSelector::IsQueueEnabled(size_t queue_index) const { 61 bool RendererTaskQueueSelector::IsQueueEnabled(size_t queue_index) const {
56 DCHECK(main_thread_checker_.CalledOnValidThread()); 62 DCHECK(main_thread_checker_.CalledOnValidThread());
57 DCHECK_LT(queue_index, work_queues_.size()); 63 DCHECK_LT(queue_index, work_queues_.size());
58 for (const auto& queue_priority : queue_priorities_) { 64 for (const auto& queue_priority : queue_priorities_) {
59 if (queue_priority.find(queue_index) != queue_priority.end()) 65 if (queue_priority.find(queue_index) != queue_priority.end())
60 return true; 66 return true;
61 } 67 }
62 return false; 68 return false;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 priority < QUEUE_PRIORITY_COUNT; priority = NextPriority(priority)) { 173 priority < QUEUE_PRIORITY_COUNT; priority = NextPriority(priority)) {
168 state->BeginArray(PriorityToString(priority)); 174 state->BeginArray(PriorityToString(priority));
169 for (size_t queue_index : queue_priorities_[priority]) 175 for (size_t queue_index : queue_priorities_[priority])
170 state->AppendInteger(queue_index); 176 state->AppendInteger(queue_index);
171 state->EndArray(); 177 state->EndArray();
172 } 178 }
173 state->EndDictionary(); 179 state->EndDictionary();
174 state->SetInteger("starvation_count", starvation_count_); 180 state->SetInteger("starvation_count", starvation_count_);
175 } 181 }
176 182
183 void RendererTaskQueueSelector::RegisterTaskQueueObserver(
184 TaskQueueSelectorObserver* observer) {
185 task_queue_selector_observer_ = observer;
186 }
187
177 } // namespace content 188 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698