Chromium Code Reviews| Index: net/base/network_stream_throttler.cc |
| diff --git a/net/base/network_stream_throttler.cc b/net/base/network_stream_throttler.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..14593138edad19234f4b475d60db13fa96f0c81e |
| --- /dev/null |
| +++ b/net/base/network_stream_throttler.cc |
| @@ -0,0 +1,70 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "net/base/network_stream_throttler.h" |
| + |
| +namespace net { |
| + |
| +// Currently this is a null implementation that does no throttling; |
| +// all entries are created in the unthrottled state, and no throttle state |
| +// change notifications are transmitted. |
| + |
| +NetworkStreamThrottler::Throttle::~Throttle() { |
| + if (throttler_) |
| + throttler_->OnStreamDestroyed(this); |
| +} |
| + |
| +void NetworkStreamThrottler::Throttle::SetPriority(RequestPriority priority) { |
| + RequestPriority old_priority = priority_; |
| + priority_ = priority; |
| + if (throttler_) |
| + throttler_->OnStreamPriorityChanged(this, old_priority, priority); |
| +} |
| + |
| +NetworkStreamThrottler::Throttle::Throttle( |
| + bool throttled, |
| + RequestPriority priority, |
| + base::WeakPtr<NetworkStreamThrottler> throttler) |
| + : throttled_(throttled), |
| + priority_(priority), |
| + delegate_(nullptr), |
| + throttler_(throttler) {} |
| + |
| +void NetworkStreamThrottler::Throttle::NotifyThrottleStateChanged( |
| + bool new_throttle_state) { |
| + throttled_ = new_throttle_state; |
| + // TODO(rdsmith): Figure out if/how this needs to be made asynchronous. |
| + if (delegate_) |
| + delegate_->OnThrottleStateChanged(); |
| +} |
| + |
| +NetworkStreamThrottler::NetworkStreamThrottler() |
| + : priority_queue_(MAXIMUM_PRIORITY + 1), factory_(this) {} |
| + |
| +NetworkStreamThrottler::~NetworkStreamThrottler() {} |
| + |
| +std::unique_ptr<NetworkStreamThrottler::Throttle> |
| +NetworkStreamThrottler::CreateThrottle(RequestPriority priority, |
| + bool ignore_limits) { |
| + std::unique_ptr<Throttle> stream( |
| + new Throttle(false, priority, factory_.GetWeakPtr())); |
| + |
| + stream->set_queue_pointer(priority_queue_.Insert(stream.get(), priority)); |
| + |
| + return stream; |
| +} |
| + |
| +void NetworkStreamThrottler::OnStreamPriorityChanged( |
| + Throttle* stream, |
| + RequestPriority old_priority, |
|
mmenke
2016/04/29 16:57:28
I don't think we need old_priority as an argument?
Randy Smith (Not in Mondays)
2016/05/08 00:46:30
Ah, confusing implementations in my head. Priorit
|
| + RequestPriority new_priority) { |
| + priority_queue_.Erase(stream->queue_pointer()); |
| + stream->set_queue_pointer(priority_queue_.Insert(stream, new_priority)); |
| +} |
| + |
| +void NetworkStreamThrottler::OnStreamDestroyed(Throttle* stream) { |
| + priority_queue_.Erase(stream->queue_pointer()); |
| +} |
| + |
| +} // namespace net |