OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/base/network_stream_throttler.h" |
| 6 |
| 7 namespace net { |
| 8 |
| 9 // Currently this is a null implementation that does no throttling; |
| 10 // all entries are created in the unthrottled state, and no throttle state |
| 11 // change notifications are transmitted. |
| 12 |
| 13 NetworkStreamThrottler::Throttle::~Throttle() { |
| 14 if (throttler_) |
| 15 throttler_->OnStreamDestroyed(this); |
| 16 } |
| 17 |
| 18 void NetworkStreamThrottler::Throttle::SetPriority(RequestPriority priority) { |
| 19 RequestPriority old_priority = priority_; |
| 20 priority_ = priority; |
| 21 if (throttler_) |
| 22 throttler_->OnStreamPriorityChanged(this, old_priority, priority); |
| 23 } |
| 24 |
| 25 NetworkStreamThrottler::Throttle::Throttle( |
| 26 bool throttled, |
| 27 RequestPriority priority, |
| 28 base::WeakPtr<NetworkStreamThrottler> throttler) |
| 29 : throttled_(throttled), |
| 30 priority_(priority), |
| 31 delegate_(nullptr), |
| 32 throttler_(throttler) {} |
| 33 |
| 34 void NetworkStreamThrottler::Throttle::NotifyThrottleStateChanged( |
| 35 bool new_throttle_state) { |
| 36 throttled_ = new_throttle_state; |
| 37 // TODO(rdsmith): Figure out if/how this needs to be made asynchronous. |
| 38 if (delegate_) |
| 39 delegate_->OnThrottleStateChanged(); |
| 40 } |
| 41 |
| 42 NetworkStreamThrottler::NetworkStreamThrottler() |
| 43 : priority_queue_(MAXIMUM_PRIORITY + 1), factory_(this) {} |
| 44 |
| 45 NetworkStreamThrottler::~NetworkStreamThrottler() {} |
| 46 |
| 47 scoped_ptr<NetworkStreamThrottler::Throttle> |
| 48 NetworkStreamThrottler::CreateThrottle(RequestPriority priority) { |
| 49 scoped_ptr<Throttle> stream( |
| 50 new Throttle(false, priority, factory_.GetWeakPtr())); |
| 51 |
| 52 stream->set_queue_pointer(priority_queue_.Insert(stream.get(), priority)); |
| 53 |
| 54 return stream; |
| 55 } |
| 56 |
| 57 void NetworkStreamThrottler::OnStreamPriorityChanged( |
| 58 Throttle* stream, |
| 59 RequestPriority old_priority, |
| 60 RequestPriority new_priority) { |
| 61 priority_queue_.Erase(stream->queue_pointer()); |
| 62 stream->set_queue_pointer(priority_queue_.Insert(stream, new_priority)); |
| 63 } |
| 64 |
| 65 void NetworkStreamThrottler::OnStreamDestroyed(Throttle* stream) { |
| 66 priority_queue_.Erase(stream->queue_pointer()); |
| 67 } |
| 68 |
| 69 } // namespace net |
OLD | NEW |