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 708a13c2bbf5cec591f882e6adf4d49ee9045d56..dc26cc556b5f4ed9971b097013b7bb95dcf8351c 100644 |
| --- a/net/base/network_quality_estimator.cc |
| +++ b/net/base/network_quality_estimator.cc |
| @@ -178,7 +178,8 @@ NetworkQualityEstimator::NetworkQualityEstimator( |
| downstream_throughput_kbps_observations_( |
| GetWeightMultiplierPerSecond(variation_params)), |
| rtt_msec_observations_(GetWeightMultiplierPerSecond(variation_params)), |
| - external_estimates_provider_(external_estimates_provider.Pass()) { |
| + external_estimate_provider_(external_estimates_provider.Pass()), |
| + external_estimate_request_time_(base::TimeTicks()) { |
| static_assert(kMinRequestDurationMicroseconds > 0, |
| "Minimum request duration must be > 0"); |
| static_assert(kDefaultHalfLifeSeconds > 0, |
| @@ -192,8 +193,17 @@ NetworkQualityEstimator::NetworkQualityEstimator( |
| ObtainOperatingParams(variation_params); |
| NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| - if (external_estimates_provider_) |
| - external_estimates_provider_->SetUpdatedEstimateDelegate(this); |
| + if (external_estimate_provider_) { |
| + UMA_HISTOGRAM_ENUMERATION("NQE.ExternalEstimateProviderStatus", |
|
Alexei Svitkine (slow)
2015/09/08 21:33:10
Please make a helper function that logs this histo
tbansal1
2015/09/08 22:29:30
Made the helper function. Had to move the enum def
|
| + EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, |
| + EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY); |
| + external_estimate_provider_->SetUpdatedEstimateDelegate(this); |
| + QueryExternalEstimateProvider(); |
| + } else { |
| + UMA_HISTOGRAM_ENUMERATION("NQE.ExternalEstimateProviderStatus", |
| + EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, |
| + EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY); |
| + } |
| current_network_id_ = GetCurrentNetworkID(); |
| AddDefaultEstimates(); |
| } |
| @@ -264,6 +274,7 @@ NetworkQualityEstimator::~NetworkQualityEstimator() { |
| void NetworkQualityEstimator::NotifyHeadersReceived(const URLRequest& request) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| + MaybeQueryExternalEstimateProvider(); |
| if (!RequestProvidesUsefulObservations(request)) |
| return; |
| @@ -314,6 +325,7 @@ void NetworkQualityEstimator::NotifyRequestCompleted( |
| const URLRequest& request) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| + MaybeQueryExternalEstimateProvider(); |
| if (!RequestProvidesUsefulObservations(request)) |
| return; |
| @@ -538,6 +550,8 @@ void NetworkQualityEstimator::OnConnectionTypeChanged( |
| rtt_msec_observations_.Clear(); |
| current_network_id_ = GetCurrentNetworkID(); |
| + QueryExternalEstimateProvider(); |
| + |
| // Read any cached estimates for the new network. If cached estimates are |
| // unavailable, add the default estimates. |
| if (!ReadCachedNetworkQualityEstimate()) |
| @@ -545,9 +559,10 @@ void NetworkQualityEstimator::OnConnectionTypeChanged( |
| estimated_median_network_quality_ = NetworkQuality(); |
| } |
| -bool NetworkQualityEstimator::GetRTTEstimate(base::TimeDelta* rtt) const { |
| +bool NetworkQualityEstimator::GetRTTEstimate(base::TimeDelta* rtt) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK(rtt); |
| + MaybeQueryExternalEstimateProvider(); |
| if (rtt_msec_observations_.Size() == 0) { |
| *rtt = InvalidRTT(); |
| return false; |
| @@ -556,10 +571,10 @@ bool NetworkQualityEstimator::GetRTTEstimate(base::TimeDelta* rtt) const { |
| return (*rtt != InvalidRTT()); |
| } |
| -bool NetworkQualityEstimator::GetDownlinkThroughputKbpsEstimate( |
| - int32_t* kbps) const { |
| +bool NetworkQualityEstimator::GetDownlinkThroughputKbpsEstimate(int32_t* kbps) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK(kbps); |
| + MaybeQueryExternalEstimateProvider(); |
| if (downstream_throughput_kbps_observations_.Size() == 0) { |
| *kbps = kInvalidThroughput; |
| return false; |
| @@ -570,18 +585,22 @@ bool NetworkQualityEstimator::GetDownlinkThroughputKbpsEstimate( |
| bool NetworkQualityEstimator::GetRecentMedianRTT( |
| const base::TimeTicks& begin_timestamp, |
| - base::TimeDelta* rtt) const { |
| + base::TimeDelta* rtt) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK(rtt); |
| + |
| + MaybeQueryExternalEstimateProvider(); |
| *rtt = GetRTTEstimateInternal(begin_timestamp, 50); |
| return (*rtt != InvalidRTT()); |
| } |
| bool NetworkQualityEstimator::GetRecentMedianDownlinkThroughputKbps( |
| const base::TimeTicks& begin_timestamp, |
| - int32_t* kbps) const { |
| + int32_t* kbps) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK(kbps); |
| + |
| + MaybeQueryExternalEstimateProvider(); |
| *kbps = GetDownlinkThroughputKbpsEstimateInternal(begin_timestamp, 50); |
| return (*kbps != kInvalidThroughput); |
| } |
| @@ -812,8 +831,64 @@ bool NetworkQualityEstimator::ReadCachedNetworkQualityEstimate() { |
| void NetworkQualityEstimator::OnUpdatedEstimateAvailable() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - DCHECK(external_estimates_provider_); |
| - // TODO(tbansal): Query provider for the recent value. |
| + DCHECK(external_estimate_provider_); |
| + |
| + UMA_HISTOGRAM_ENUMERATION("NQE.ExternalEstimateProviderStatus", |
| + EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, |
| + EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY); |
| + |
| + QueryExternalEstimateProvider(); |
| +} |
| + |
| +void NetworkQualityEstimator::MaybeQueryExternalEstimateProvider() { |
| + if (base::TimeTicks::Now() - external_estimate_request_time_ >= |
| + base::TimeDelta::FromMilliseconds( |
| + kExternalEstimateProviderQueryIntervalMsec)) { |
| + QueryExternalEstimateProvider(); |
| + } |
| +} |
| + |
| +void NetworkQualityEstimator::QueryExternalEstimateProvider() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + |
| + if (!external_estimate_provider_) |
| + return; |
| + UMA_HISTOGRAM_ENUMERATION("NQE.ExternalEstimateProviderStatus", |
| + EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, |
| + EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY); |
| + |
| + external_estimate_request_time_ = base::TimeTicks::Now(); |
| + |
| + base::TimeDelta time_since_last_update; |
| + if (!external_estimate_provider_->GetTimeSinceLastUpdate( |
| + &time_since_last_update) || |
| + time_since_last_update > |
| + base::TimeDelta::FromMilliseconds( |
| + kExternalEstimateProviderQueryIntervalMsec)) { |
| + // Request the external estimate provider for updated estimates. When the |
| + // updates estimates are available, OnUpdatedEstimateAvailable() will get |
| + // called. |
| + external_estimate_provider_->RequestUpdate(); |
| + return; |
| + } |
| + |
| + UMA_HISTOGRAM_ENUMERATION("NQE.ExternalEstimateProviderStatus", |
| + EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, |
| + EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY); |
| + |
| + base::TimeDelta rtt; |
| + if (external_estimate_provider_->GetRTT(&rtt)) { |
| + rtt_msec_observations_.AddObservation(Observation( |
| + rtt.InMilliseconds(), base::TimeTicks::Now() - time_since_last_update)); |
| + } |
| + |
| + int32_t downstream_throughput_kbps; |
| + if (external_estimate_provider_->GetDownstreamThroughputKbps( |
| + &downstream_throughput_kbps)) { |
| + downstream_throughput_kbps_observations_.AddObservation( |
| + Observation(downstream_throughput_kbps, |
| + base::TimeTicks::Now() - time_since_last_update)); |
| + } |
| } |
| void NetworkQualityEstimator::CacheNetworkQualityEstimate() { |