| OLD | NEW |
| 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 #ifndef NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_ | 5 #ifndef NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_ |
| 6 #define NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_ | 6 #define NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_ |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "net/quic/quic_bandwidth.h" | 9 #include "net/quic/quic_bandwidth.h" |
| 10 #include "net/quic/quic_time.h" | 10 #include "net/quic/quic_time.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 namespace test { |
| 15 class QuicSustainedBandwidthRecorderPeer; |
| 16 } // namespace test |
| 17 |
| 14 // This class keeps track of a sustained bandwidth estimate to ultimately send | 18 // This class keeps track of a sustained bandwidth estimate to ultimately send |
| 15 // to the client in a server config update message. A sustained bandwidth | 19 // to the client in a server config update message. A sustained bandwidth |
| 16 // estimate is only marked as valid if the QuicSustainedBandwidthRecorder has | 20 // estimate is only marked as valid if the QuicSustainedBandwidthRecorder has |
| 17 // been given uninterrupted reliable estimates over a certain period of time. | 21 // been given uninterrupted reliable estimates over a certain period of time. |
| 18 class NET_EXPORT_PRIVATE QuicSustainedBandwidthRecorder { | 22 class NET_EXPORT_PRIVATE QuicSustainedBandwidthRecorder { |
| 19 public: | 23 public: |
| 20 QuicSustainedBandwidthRecorder(); | 24 QuicSustainedBandwidthRecorder(); |
| 21 | 25 |
| 22 // As long as |is_reliable_estimate| is consistently true, multiple calls to | 26 // As long as |in_recovery| is consistently false, multiple calls to this |
| 23 // this method over a 3 * srtt period results in storage of a valid sustained | 27 // method over a 3 * srtt period results in storage of a valid sustained |
| 24 // bandwidth estimate. | 28 // bandwidth estimate. |
| 25 // |time_now| is used as a max bandwidth timestamp if needed. | 29 // |time_now| is used as a max bandwidth timestamp if needed. |
| 26 void RecordEstimate(bool is_reliable_estimate, | 30 void RecordEstimate(bool in_recovery, |
| 27 bool in_slow_start, | 31 bool in_slow_start, |
| 28 QuicBandwidth bandwidth, | 32 QuicBandwidth bandwidth, |
| 29 QuicTime estimate_time, | 33 QuicTime estimate_time, |
| 30 QuicWallTime wall_time, | 34 QuicWallTime wall_time, |
| 31 QuicTime::Delta srtt); | 35 QuicTime::Delta srtt); |
| 32 | 36 |
| 33 bool HasEstimate() const { | 37 bool HasEstimate() const { |
| 34 return has_estimate_; | 38 return has_estimate_; |
| 35 } | 39 } |
| 36 | 40 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 48 DCHECK(has_estimate_); | 52 DCHECK(has_estimate_); |
| 49 return max_bandwidth_timestamp_; | 53 return max_bandwidth_timestamp_; |
| 50 } | 54 } |
| 51 | 55 |
| 52 bool EstimateRecordedDuringSlowStart() const { | 56 bool EstimateRecordedDuringSlowStart() const { |
| 53 DCHECK(has_estimate_); | 57 DCHECK(has_estimate_); |
| 54 return bandwidth_estimate_recorded_during_slow_start_; | 58 return bandwidth_estimate_recorded_during_slow_start_; |
| 55 } | 59 } |
| 56 | 60 |
| 57 private: | 61 private: |
| 62 friend class test::QuicSustainedBandwidthRecorderPeer; |
| 63 |
| 58 // True if we have been able to calculate sustained bandwidth, over at least | 64 // True if we have been able to calculate sustained bandwidth, over at least |
| 59 // one recording period (3 * rtt). | 65 // one recording period (3 * rtt). |
| 60 bool has_estimate_; | 66 bool has_estimate_; |
| 61 | 67 |
| 62 // True if the last call to RecordEstimate had a reliable estimate. | 68 // True if the last call to RecordEstimate had a reliable estimate. |
| 63 bool is_recording_; | 69 bool is_recording_; |
| 64 | 70 |
| 65 // True if the current sustained bandwidth estimate was generated while in | 71 // True if the current sustained bandwidth estimate was generated while in |
| 66 // slow start. | 72 // slow start. |
| 67 bool bandwidth_estimate_recorded_during_slow_start_; | 73 bool bandwidth_estimate_recorded_during_slow_start_; |
| 68 | 74 |
| 69 // The latest sustained bandwidth estimate. | 75 // The latest sustained bandwidth estimate. |
| 70 QuicBandwidth bandwidth_estimate_; | 76 QuicBandwidth bandwidth_estimate_; |
| 71 | 77 |
| 72 // The maximum sustained bandwidth seen over the lifetime of the connection. | 78 // The maximum sustained bandwidth seen over the lifetime of the connection. |
| 73 QuicBandwidth max_bandwidth_estimate_; | 79 QuicBandwidth max_bandwidth_estimate_; |
| 74 | 80 |
| 75 // Timestamp indicating when the max_bandwidth_estimate_ was seen. | 81 // Timestamp indicating when the max_bandwidth_estimate_ was seen. |
| 76 int32 max_bandwidth_timestamp_; | 82 int32 max_bandwidth_timestamp_; |
| 77 | 83 |
| 78 // Timestamp marking the beginning of the latest recording period. | 84 // Timestamp marking the beginning of the latest recording period. |
| 79 QuicTime start_time_; | 85 QuicTime start_time_; |
| 80 | 86 |
| 81 DISALLOW_COPY_AND_ASSIGN(QuicSustainedBandwidthRecorder); | 87 DISALLOW_COPY_AND_ASSIGN(QuicSustainedBandwidthRecorder); |
| 82 }; | 88 }; |
| 83 | 89 |
| 84 } // namespace net | 90 } // namespace net |
| 85 | 91 |
| 86 #endif // NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_ | 92 #endif // NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_ |
| OLD | NEW |