Chromium Code Reviews| Index: net/base/network_quality_estimator.cc |
| diff --git a/net/base/network_quality_estimator.cc b/net/base/network_quality_estimator.cc |
| index e012a99d72fdcc752cf4e9406f8e61651315598a..43285e06187fc0e2e6622ac0750324801bd35f5d 100644 |
| --- a/net/base/network_quality_estimator.cc |
| +++ b/net/base/network_quality_estimator.cc |
| @@ -6,6 +6,7 @@ |
| #include <string> |
| +#include "base/logging.h" |
| #include "base/metrics/histogram.h" |
| #include "net/base/net_util.h" |
| #include "net/base/network_quality.h" |
| @@ -35,18 +36,23 @@ NetworkQualityEstimator::~NetworkQualityEstimator() { |
| NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| } |
| -void NetworkQualityEstimator::NotifyDataReceived(const URLRequest& request, |
| - int64_t prefilter_bytes_read) { |
| +void NetworkQualityEstimator::NotifyDataReceived( |
| + const URLRequest& request, |
| + int64_t cummulative_prefilter_bytes_read, |
| + int64_t prefiltered_bytes_read) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - DCHECK_GT(prefilter_bytes_read, 0); |
| + DCHECK_GT(cummulative_prefilter_bytes_read, 0); |
| + DCHECK_GT(prefiltered_bytes_read, 0); |
| if (!request.url().is_valid() || |
| (!allow_localhost_requests_ && IsLocalhost(request.url().host())) || |
| !request.url().SchemeIsHTTPOrHTTPS() || |
| // Verify that response headers are received, so it can be ensured that |
| // response is not cached. |
| - request.response_info().response_time.is_null() || request.was_cached()) |
| + request.response_info().response_time.is_null() || request.was_cached() || |
| + request.creation_time() < last_connection_change_) { |
| return; |
| + } |
| base::TimeTicks now = base::TimeTicks::Now(); |
| base::TimeDelta request_duration = now - request.creation_time(); |
| @@ -58,16 +64,22 @@ void NetworkQualityEstimator::NotifyDataReceived(const URLRequest& request, |
| if (request_duration < fastest_RTT_since_last_connection_change_) |
| fastest_RTT_since_last_connection_change_ = request_duration; |
| + // Only add RTT sample if this is the first read for this response. |
| + if (cummulative_prefilter_bytes_read == prefiltered_bytes_read) |
| + rtt_msec_.AddSample(request_duration.InMilliseconds()); |
| + |
| // Ignore tiny transfers which will not produce accurate rates. |
| // Ignore short duration transfers. |
| - if (prefilter_bytes_read >= kMinTransferSizeInBytes && |
| + if (cummulative_prefilter_bytes_read >= kMinTransferSizeInBytes && |
| request_duration >= |
| - base::TimeDelta::FromMicroseconds(kMinRequestDurationMicroseconds) && |
| - request.creation_time() > last_connection_change_) { |
| - uint64_t kbps = static_cast<uint64_t>(prefilter_bytes_read * 8 * 1000 / |
| - request_duration.InMicroseconds()); |
| + base::TimeDelta::FromMicroseconds(kMinRequestDurationMicroseconds)) { |
| + uint64_t kbps = |
| + static_cast<uint64_t>(cummulative_prefilter_bytes_read * 8 * 1000 / |
| + request_duration.InMicroseconds()); |
| if (kbps > peak_kbps_since_last_connection_change_) |
| peak_kbps_since_last_connection_change_ = kbps; |
| + |
| + kbps_.AddSample(kbps); |
| } |
| } |
| @@ -160,7 +172,7 @@ void NetworkQualityEstimator::OnConnectionTypeChanged( |
| current_connection_type_ = type; |
| } |
| -NetworkQuality NetworkQualityEstimator::GetEstimate() const { |
| +NetworkQuality NetworkQualityEstimator::GetPeakEstimate() const { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| if (!bytes_read_since_last_connection_change_) { |
| @@ -175,4 +187,29 @@ NetworkQuality NetworkQualityEstimator::GetEstimate() const { |
| peak_kbps_since_last_connection_change_, 0.1); |
|
mmenke
2015/06/03 18:31:39
This seems a bit silly. Suggest just always retur
tbansal1
2015/06/05 01:50:08
Done.
|
| } |
| +NetworkQualityEstimator::Sample::Sample(int value) |
| + : value_(value), timestamp_(base::TimeTicks::Now()) { |
| + DCHECK_GE(value_, 0); |
| +} |
| + |
| +NetworkQualityEstimator::Sample::~Sample() { |
| +} |
| + |
| +NetworkQualityEstimator::RingBuffer::RingBuffer() { |
| + DCHECK_GT(kMaximumSamples, 0U); |
|
mmenke
2015/06/03 18:31:39
If you think this is necessary, should use static_
tbansal1
2015/06/05 01:50:08
Done.
|
| +} |
| + |
| +NetworkQualityEstimator::RingBuffer::~RingBuffer() { |
| +} |
| + |
| +void NetworkQualityEstimator::RingBuffer::AddSample(int value) { |
| + DCHECK_LE(samples_.size(), kMaximumSamples); |
| + // Pop the oldest element if the buffer is already full. |
| + if (samples_.size() >= kMaximumSamples) |
| + samples_.pop_front(); |
| + |
| + samples_.push_back(Sample(value)); |
| + DCHECK_LE(samples_.size(), kMaximumSamples); |
| +} |
| + |
| } // namespace net |