Index: net/quic/quic_sustained_bandwidth_recorder.cc |
diff --git a/net/quic/quic_sustained_bandwidth_recorder.cc b/net/quic/quic_sustained_bandwidth_recorder.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9045014b40ddf1f4b7ab568eaac4434537560235 |
--- /dev/null |
+++ b/net/quic/quic_sustained_bandwidth_recorder.cc |
@@ -0,0 +1,59 @@ |
+// 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. |
+ |
+#include "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 { |
+ |
+QuicSustainedBandwidthRecorder::QuicSustainedBandwidthRecorder() |
+ : has_estimate_(false), |
+ is_recording_(false), |
+ bandwidth_estimate_(QuicBandwidth::Zero()), |
+ max_bandwidth_estimate_(QuicBandwidth::Zero()), |
+ max_bandwidth_timestamp_(0), |
+ start_time_(QuicTime::Zero()) {} |
+ |
+void QuicSustainedBandwidthRecorder::RecordEstimate(bool is_reliable_estimate, |
+ QuicBandwidth bandwidth, |
+ QuicTime estimate_time, |
+ QuicWallTime wall_time, |
+ QuicTime::Delta srtt) { |
+ if (!is_reliable_estimate) { |
+ is_recording_ = false; |
+ DVLOG(1) << "Stopped recording due to unreliable estimate at: " |
+ << estimate_time.ToDebuggingValue(); |
+ return; |
+ } |
+ |
+ if (!is_recording_) { |
+ // This is the first estimate of a new recording period. |
+ start_time_ = estimate_time; |
+ is_recording_ = true; |
+ DVLOG(1) << "Started recording at: " << start_time_.ToDebuggingValue(); |
+ return; |
+ } |
+ |
+ // If we have been recording for at least 3 * srtt, then record the latest |
+ // bandwidth estimate as a valid sustained bandwidth estimate. |
+ if (estimate_time.Subtract(start_time_) >= srtt.Multiply(3)) { |
+ has_estimate_ = true; |
+ bandwidth_estimate_ = bandwidth; |
+ DVLOG(1) << "New sustained bandwidth estimate (KBytes/s): " |
+ << bandwidth_estimate_.ToKBytesPerSecond(); |
+ } |
+ |
+ // Check for an increase in max bandwidth. |
+ if (bandwidth > max_bandwidth_estimate_) { |
+ max_bandwidth_estimate_ = bandwidth; |
+ max_bandwidth_timestamp_ = wall_time.ToUNIXSeconds(); |
+ DVLOG(1) << "New max bandwidth estimate (KBytes/s): " |
+ << max_bandwidth_estimate_.ToKBytesPerSecond(); |
+ } |
+} |
+ |
+} // namespace net |