| 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 #include "platform/scheduler/renderer/task_queue_throttler.h" | 5 #include "platform/scheduler/renderer/task_queue_throttler.h" |
| 6 | 6 |
| 7 #include <cstdint> | 7 #include <cstdint> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 TaskQueueThrottler::TimeBudgetPool::~TimeBudgetPool() {} | 81 TaskQueueThrottler::TimeBudgetPool::~TimeBudgetPool() {} |
| 82 | 82 |
| 83 void TaskQueueThrottler::TimeBudgetPool::SetTimeBudget(base::TimeTicks now, | 83 void TaskQueueThrottler::TimeBudgetPool::SetTimeBudget(base::TimeTicks now, |
| 84 double cpu_percentage) { | 84 double cpu_percentage) { |
| 85 Advance(now); | 85 Advance(now); |
| 86 cpu_percentage_ = cpu_percentage; | 86 cpu_percentage_ = cpu_percentage; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void TaskQueueThrottler::TimeBudgetPool::AddQueue(base::TimeTicks now, | 89 void TaskQueueThrottler::TimeBudgetPool::AddQueue(base::TimeTicks now, |
| 90 TaskQueue* queue) { | 90 TaskQueue* queue) { |
| 91 Metadata& metadata = task_queue_throttler_->queue_details_[queue]; | 91 std::pair<TaskQueueMap::iterator, bool> insert_result = |
| 92 task_queue_throttler_->queue_details_.insert( |
| 93 std::make_pair(queue, Metadata(0, queue->IsQueueEnabled()))); |
| 94 Metadata& metadata = insert_result.first->second; |
| 92 DCHECK(!metadata.time_budget_pool); | 95 DCHECK(!metadata.time_budget_pool); |
| 93 metadata.time_budget_pool = this; | 96 metadata.time_budget_pool = this; |
| 94 | 97 |
| 95 associated_task_queues_.insert(queue); | 98 associated_task_queues_.insert(queue); |
| 96 | 99 |
| 97 if (!metadata.IsThrottled()) | 100 if (!is_enabled_ || !metadata.IsThrottled()) |
| 98 return; | 101 return; |
| 99 | 102 |
| 100 queue->SetQueueEnabled(false); | 103 queue->SetQueueEnabled(false); |
| 101 | 104 |
| 102 task_queue_throttler_->MaybeSchedulePumpQueue(FROM_HERE, now, queue, | 105 task_queue_throttler_->MaybeSchedulePumpQueue(FROM_HERE, now, queue, |
| 103 GetNextAllowedRunTime()); | 106 GetNextAllowedRunTime()); |
| 104 } | 107 } |
| 105 | 108 |
| 106 void TaskQueueThrottler::TimeBudgetPool::RemoveQueue(base::TimeTicks now, | 109 void TaskQueueThrottler::TimeBudgetPool::RemoveQueue(base::TimeTicks now, |
| 107 TaskQueue* queue) { | 110 TaskQueue* queue) { |
| 108 auto find_it = task_queue_throttler_->queue_details_.find(queue); | 111 auto find_it = task_queue_throttler_->queue_details_.find(queue); |
| 109 DCHECK(find_it != task_queue_throttler_->queue_details_.end() && | 112 DCHECK(find_it != task_queue_throttler_->queue_details_.end() && |
| 110 find_it->second.time_budget_pool == this); | 113 find_it->second.time_budget_pool == this); |
| 111 find_it->second.time_budget_pool = nullptr; | 114 find_it->second.time_budget_pool = nullptr; |
| 112 bool is_throttled = find_it->second.IsThrottled(); | 115 bool is_throttled = find_it->second.IsThrottled(); |
| 113 | 116 |
| 114 task_queue_throttler_->MaybeDeleteQueueMetadata(find_it); | 117 task_queue_throttler_->MaybeDeleteQueueMetadata(find_it); |
| 115 associated_task_queues_.erase(queue); | 118 associated_task_queues_.erase(queue); |
| 116 | 119 |
| 117 if (is_throttled) | 120 if (!is_enabled_ || !is_throttled) |
| 118 return; | 121 return; |
| 119 | 122 |
| 120 task_queue_throttler_->MaybeSchedulePumpQueue(FROM_HERE, now, queue, | 123 task_queue_throttler_->MaybeSchedulePumpQueue(FROM_HERE, now, queue, |
| 121 base::nullopt); | 124 base::nullopt); |
| 122 } | 125 } |
| 123 | 126 |
| 124 void TaskQueueThrottler::TimeBudgetPool::EnableThrottling(LazyNow* lazy_now) { | 127 void TaskQueueThrottler::TimeBudgetPool::EnableThrottling(LazyNow* lazy_now) { |
| 125 if (is_enabled_) | 128 if (is_enabled_) |
| 126 return; | 129 return; |
| 127 is_enabled_ = true; | 130 is_enabled_ = true; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 void TaskQueueThrottler::SetQueueEnabled(TaskQueue* task_queue, bool enabled) { | 262 void TaskQueueThrottler::SetQueueEnabled(TaskQueue* task_queue, bool enabled) { |
| 260 TaskQueueMap::iterator find_it = queue_details_.find(task_queue); | 263 TaskQueueMap::iterator find_it = queue_details_.find(task_queue); |
| 261 | 264 |
| 262 if (find_it == queue_details_.end()) { | 265 if (find_it == queue_details_.end()) { |
| 263 task_queue->SetQueueEnabled(enabled); | 266 task_queue->SetQueueEnabled(enabled); |
| 264 return; | 267 return; |
| 265 } | 268 } |
| 266 | 269 |
| 267 find_it->second.enabled = enabled; | 270 find_it->second.enabled = enabled; |
| 268 | 271 |
| 269 if (!find_it->second.IsThrottled()) | 272 if (!find_it->second.IsThrottled()) { |
| 273 task_queue->SetQueueEnabled(enabled); |
| 270 return; | 274 return; |
| 275 } |
| 271 | 276 |
| 272 // We don't enable the queue here because it's throttled and there might be | 277 // We don't enable the queue here because it's throttled and there might be |
| 273 // tasks in it's work queue that would execute immediatly rather than after | 278 // tasks in it's work queue that would execute immediatly rather than after |
| 274 // PumpThrottledTasks runs. | 279 // PumpThrottledTasks runs. |
| 275 if (!enabled) { | 280 if (!enabled) { |
| 276 task_queue->SetQueueEnabled(false); | 281 task_queue->SetQueueEnabled(false); |
| 277 MaybeSchedulePumpQueue(FROM_HERE, tick_clock_->NowTicks(), task_queue, | 282 MaybeSchedulePumpQueue(FROM_HERE, tick_clock_->NowTicks(), task_queue, |
| 278 base::nullopt); | 283 base::nullopt); |
| 279 } | 284 } |
| 280 } | 285 } |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 return std::max(now, time_budget_pool->GetNextAllowedRunTime()); | 571 return std::max(now, time_budget_pool->GetNextAllowedRunTime()); |
| 567 } | 572 } |
| 568 | 573 |
| 569 void TaskQueueThrottler::MaybeDeleteQueueMetadata(TaskQueueMap::iterator it) { | 574 void TaskQueueThrottler::MaybeDeleteQueueMetadata(TaskQueueMap::iterator it) { |
| 570 if (!it->second.IsThrottled() && !it->second.time_budget_pool) | 575 if (!it->second.IsThrottled() && !it->second.time_budget_pool) |
| 571 queue_details_.erase(it); | 576 queue_details_.erase(it); |
| 572 } | 577 } |
| 573 | 578 |
| 574 } // namespace scheduler | 579 } // namespace scheduler |
| 575 } // namespace blink | 580 } // namespace blink |
| OLD | NEW |