| Index: net/base/network_quality_estimator.cc
|
| diff --git a/net/base/network_quality_estimator.cc b/net/base/network_quality_estimator.cc
|
| index fdd2212adfb1b4c4853d6be76456ce0e990ef8a7..a7cb838b00cde0cea6af444544f37e14a11ace02 100644
|
| --- a/net/base/network_quality_estimator.cc
|
| +++ b/net/base/network_quality_estimator.cc
|
| @@ -140,7 +140,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,
|
| @@ -154,8 +155,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",
|
| + 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();
|
| }
|
| @@ -226,6 +236,7 @@ NetworkQualityEstimator::~NetworkQualityEstimator() {
|
| void NetworkQualityEstimator::NotifyHeadersReceived(const URLRequest& request) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| + MaybeQueryExternalEstimateProvider();
|
| if (!RequestProvidesUsefulObservations(request))
|
| return;
|
|
|
| @@ -276,6 +287,7 @@ void NetworkQualityEstimator::NotifyRequestCompleted(
|
| const URLRequest& request) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| + MaybeQueryExternalEstimateProvider();
|
| if (!RequestProvidesUsefulObservations(request))
|
| return;
|
|
|
| @@ -500,6 +512,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())
|
| @@ -507,9 +521,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;
|
| @@ -518,10 +533,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;
|
| @@ -532,18 +547,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);
|
| }
|
| @@ -774,8 +793,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() {
|
|
|