Chromium Code Reviews| Index: net/quic/quic_sustained_bandwidth_recorder.h |
| diff --git a/net/quic/quic_sustained_bandwidth_recorder.h b/net/quic/quic_sustained_bandwidth_recorder.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..402640920cb254ae3c15b51a594647aa1453bf33 |
| --- /dev/null |
| +++ b/net/quic/quic_sustained_bandwidth_recorder.h |
| @@ -0,0 +1,76 @@ |
| +// Copyright (c) 2014 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. |
| + |
| +#ifndef NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_ |
| +#define NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_ |
| + |
| +#include "base/logging.h" |
| +#include "net/quic/quic_bandwidth.h" |
| +#include "net/quic/quic_time.h" |
| + |
| +namespace net { |
| + |
| +// This class keeps track of a sustained bandwidth estimate to ultimately send |
| +// to the client in a server config update message. A sustained bandwidth |
| +// estimate is only marked as valid if the QuicSustainedBandwidthRecorder has |
| +// been given uninterrupted reliable estimates over a certain period of time. |
| +class NET_EXPORT_PRIVATE QuicSustainedBandwidthRecorder { |
| + public: |
| + QuicSustainedBandwidthRecorder(); |
| + |
| + // As long as |is_reliable_estimate| is consistently true, multiple calls to |
| + // this method over a 3 * srtt period results in storage of a valid sustained |
| + // bandwidth estimate. |
| + // |time_now| is used as a max bandwidth timestamp if needed. |
| + void RecordEstimate(bool is_reliable_estimate, |
| + QuicBandwidth bandwidth, |
| + QuicTime estimate_time, |
| + QuicWallTime wall_time, |
| + QuicTime::Delta srtt); |
| + |
| + bool HasEstimate() const { |
| + return has_estimate_; |
| + } |
| + |
| + QuicBandwidth BandwidthEstimate() const { |
| + DCHECK(has_estimate_); |
| + return bandwidth_estimate_; |
| + } |
| + |
| + QuicBandwidth MaxBandwidthEstimate() const { |
| + DCHECK(has_estimate_); |
| + return max_bandwidth_estimate_; |
| + } |
| + |
| + int32 MaxBandwidthTimestamp() const { |
|
ramant (doing other things)
2014/08/15 02:35:35
rjshade@: should we use int64 instead of int32?
Robbie Shade
2014/08/15 12:08:38
Yep, thanks!
ramant (doing other things)
2014/08/15 17:54:18
Great. Will submit the change to the internal sour
|
| + DCHECK(has_estimate_); |
| + return max_bandwidth_timestamp_; |
| + } |
| + |
| + private: |
| + // True if we have been able to calculate sustained bandwidth, over at least |
| + // one recording period (3 * rtt). |
| + bool has_estimate_; |
| + |
| + // True if the last call to RecordEstimate had a reliable estimate. |
| + bool is_recording_; |
| + |
| + // The latest sustained bandwidth estimate. |
| + QuicBandwidth bandwidth_estimate_; |
| + |
| + // The maximum sustained bandwidth seen over the lifetime of the connection. |
| + QuicBandwidth max_bandwidth_estimate_; |
| + |
| + // Timestamp indicating when the max_bandwidth_estimate_ was seen. |
| + int32 max_bandwidth_timestamp_; |
| + |
| + // Timestamp marking the beginning of the latest recording period. |
| + QuicTime start_time_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(QuicSustainedBandwidthRecorder); |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_ |