OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/quic/congestion_control/leaky_bucket.h" | 5 #include "net/quic/congestion_control/leaky_bucket.h" |
6 | 6 |
7 #include "base/time.h" | 7 #include "base/time.h" |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 | 10 |
11 LeakyBucket::LeakyBucket(const QuicClock* clock, int bytes_per_second) | 11 LeakyBucket::LeakyBucket(const QuicClock* clock, int bytes_per_second) |
12 : clock_(clock), | 12 : clock_(clock), |
13 bytes_(0), | 13 bytes_(0), |
| 14 time_last_updated_(QuicTime::Zero()), |
14 draining_rate_bytes_per_s_(bytes_per_second) { | 15 draining_rate_bytes_per_s_(bytes_per_second) { |
15 } | 16 } |
16 | 17 |
17 void LeakyBucket::SetDrainingRate(int bytes_per_second) { | 18 void LeakyBucket::SetDrainingRate(int bytes_per_second) { |
18 Update(); | 19 Update(); |
19 draining_rate_bytes_per_s_ = bytes_per_second; | 20 draining_rate_bytes_per_s_ = bytes_per_second; |
20 } | 21 } |
21 | 22 |
22 void LeakyBucket::Add(size_t bytes) { | 23 void LeakyBucket::Add(size_t bytes) { |
23 Update(); | 24 Update(); |
(...skipping 19 matching lines...) Expand all Loading... |
43 base::Time::kMicrosecondsPerSecond; | 44 base::Time::kMicrosecondsPerSecond; |
44 if (bytes_cleared >= bytes_) { | 45 if (bytes_cleared >= bytes_) { |
45 bytes_ = 0; | 46 bytes_ = 0; |
46 } else { | 47 } else { |
47 bytes_ -= bytes_cleared; | 48 bytes_ -= bytes_cleared; |
48 } | 49 } |
49 time_last_updated_ = clock_->Now(); | 50 time_last_updated_ = clock_->Now(); |
50 } | 51 } |
51 | 52 |
52 } // namespace net | 53 } // namespace net |
OLD | NEW |