Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: net/base/network_quality_estimator.cc

Issue 1316863006: Populate EEP estimate in NQE (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor fix Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/base/network_quality_estimator.h" 5 #include "net/base/network_quality_estimator.h"
6 6
7 #include <float.h> 7 #include <float.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <cmath> 9 #include <cmath>
10 #include <limits> 10 #include <limits>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/message_loop/message_loop.h"
14 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
15 #include "base/metrics/histogram_base.h" 17 #include "base/metrics/histogram_base.h"
16 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/task_runner.h"
17 #include "build/build_config.h" 20 #include "build/build_config.h"
18 #include "net/base/load_flags.h" 21 #include "net/base/load_flags.h"
19 #include "net/base/load_timing_info.h" 22 #include "net/base/load_timing_info.h"
20 #include "net/base/net_util.h" 23 #include "net/base/net_util.h"
21 #include "net/base/network_interfaces.h" 24 #include "net/base/network_interfaces.h"
22 #include "net/url_request/url_request.h" 25 #include "net/url_request/url_request.h"
23 #include "url/gurl.h" 26 #include "url/gurl.h"
24 27
25 #if defined(OS_ANDROID) 28 #if defined(OS_ANDROID)
26 #include "net/android/network_library.h" 29 #include "net/android/network_library.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 bool allow_smaller_responses_for_tests) 136 bool allow_smaller_responses_for_tests)
134 : allow_localhost_requests_(allow_local_host_requests_for_tests), 137 : allow_localhost_requests_(allow_local_host_requests_for_tests),
135 allow_small_responses_(allow_smaller_responses_for_tests), 138 allow_small_responses_(allow_smaller_responses_for_tests),
136 last_connection_change_(base::TimeTicks::Now()), 139 last_connection_change_(base::TimeTicks::Now()),
137 current_network_id_( 140 current_network_id_(
138 NetworkID(NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, 141 NetworkID(NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN,
139 std::string())), 142 std::string())),
140 downstream_throughput_kbps_observations_( 143 downstream_throughput_kbps_observations_(
141 GetWeightMultiplierPerSecond(variation_params)), 144 GetWeightMultiplierPerSecond(variation_params)),
142 rtt_msec_observations_(GetWeightMultiplierPerSecond(variation_params)), 145 rtt_msec_observations_(GetWeightMultiplierPerSecond(variation_params)),
143 external_estimates_provider_(external_estimates_provider.Pass()) { 146 external_estimates_provider_(external_estimates_provider.Pass()),
147 eep_queried_(base::TimeTicks()),
bengr 2015/09/02 20:27:56 Don't use eep.
tbansal1 2015/09/03 00:22:40 Done.
148 eep_delayed_task_posted_(false),
149 weak_factory_(this) {
144 static_assert(kMinRequestDurationMicroseconds > 0, 150 static_assert(kMinRequestDurationMicroseconds > 0,
145 "Minimum request duration must be > 0"); 151 "Minimum request duration must be > 0");
146 static_assert(kDefaultHalfLifeSeconds > 0, 152 static_assert(kDefaultHalfLifeSeconds > 0,
147 "Default half life duration must be > 0"); 153 "Default half life duration must be > 0");
148 static_assert(kMaximumNetworkQualityCacheSize > 0, 154 static_assert(kMaximumNetworkQualityCacheSize > 0,
149 "Size of the network quality cache must be > 0"); 155 "Size of the network quality cache must be > 0");
150 // This limit should not be increased unless the logic for removing the 156 // This limit should not be increased unless the logic for removing the
151 // oldest cache entry is rewritten to use a doubly-linked-list LRU queue. 157 // oldest cache entry is rewritten to use a doubly-linked-list LRU queue.
152 static_assert(kMaximumNetworkQualityCacheSize <= 10, 158 static_assert(kMaximumNetworkQualityCacheSize <= 10,
153 "Size of the network quality cache must <= 10"); 159 "Size of the network quality cache must <= 10");
154 160
155 ObtainOperatingParams(variation_params); 161 ObtainOperatingParams(variation_params);
156 NetworkChangeNotifier::AddConnectionTypeObserver(this); 162 NetworkChangeNotifier::AddConnectionTypeObserver(this);
157 if (external_estimates_provider_) 163 if (external_estimates_provider_) {
164 UMA_HISTOGRAM_ENUMERATION("NQE.ExternalEstimateProviderStatus",
165 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE,
166 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY);
158 external_estimates_provider_->SetUpdatedEstimateDelegate(this); 167 external_estimates_provider_->SetUpdatedEstimateDelegate(this);
168 QueryExternalEstimateProvider();
169 } else {
170 UMA_HISTOGRAM_ENUMERATION("NQE.ExternalEstimateProviderStatus",
171 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE,
172 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY);
173 }
159 current_network_id_ = GetCurrentNetworkID(); 174 current_network_id_ = GetCurrentNetworkID();
160 AddDefaultEstimates(); 175 AddDefaultEstimates();
161 } 176 }
162 177
163 // static 178 // static
164 const base::TimeDelta NetworkQualityEstimator::InvalidRTT() { 179 const base::TimeDelta NetworkQualityEstimator::InvalidRTT() {
165 return base::TimeDelta::Max(); 180 return base::TimeDelta::Max();
166 } 181 }
167 182
168 void NetworkQualityEstimator::ObtainOperatingParams( 183 void NetworkQualityEstimator::ObtainOperatingParams(
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 782
768 downstream_throughput_kbps_observations_.AddObservation(Observation( 783 downstream_throughput_kbps_observations_.AddObservation(Observation(
769 network_quality.downstream_throughput_kbps(), base::TimeTicks::Now())); 784 network_quality.downstream_throughput_kbps(), base::TimeTicks::Now()));
770 rtt_msec_observations_.AddObservation(Observation( 785 rtt_msec_observations_.AddObservation(Observation(
771 network_quality.rtt().InMilliseconds(), base::TimeTicks::Now())); 786 network_quality.rtt().InMilliseconds(), base::TimeTicks::Now()));
772 return true; 787 return true;
773 } 788 }
774 789
775 void NetworkQualityEstimator::OnUpdatedEstimateAvailable() { 790 void NetworkQualityEstimator::OnUpdatedEstimateAvailable() {
776 DCHECK(thread_checker_.CalledOnValidThread()); 791 DCHECK(thread_checker_.CalledOnValidThread());
792
793 UMA_HISTOGRAM_ENUMERATION("NQE.ExternalEstimateProviderStatus",
794 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK,
795 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY);
796
797 QueryExternalEstimateProvider();
798 }
799
800 void NetworkQualityEstimator::QueryExternalEstimateProvider() {
801 DCHECK(thread_checker_.CalledOnValidThread());
777 DCHECK(external_estimates_provider_); 802 DCHECK(external_estimates_provider_);
778 // TODO(tbansal): Query provider for the recent value. 803
804 UMA_HISTOGRAM_ENUMERATION("NQE.ExternalEstimateProviderStatus",
805 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED,
806 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY);
807
808 base::TimeDelta time_since_last_update;
809 if (!external_estimates_provider_->GetTimeSinceLastUpdate(
bengr 2015/09/02 20:27:56 external_estimate_provider_?
tbansal1 2015/09/03 00:22:40 Done.
810 &time_since_last_update)) {
811 external_estimates_provider_->RequestUpdate();
812 return;
813 }
814
815 eep_queried_ = base::TimeTicks::Now();
bengr 2015/09/02 20:27:56 external_estimate_request_time_. Also, is this use
tbansal1 2015/09/03 00:22:40 It is used now.
816
817 UMA_HISTOGRAM_ENUMERATION("NQE.ExternalEstimateProviderStatus",
818 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL,
819 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY);
820
821 base::TimeDelta rtt;
822 if (external_estimates_provider_->GetRTT(&rtt)) {
823 rtt_msec_observations_.AddObservation(Observation(
824 rtt.InMilliseconds(), base::TimeTicks::Now() - time_since_last_update));
825 }
826
827 int32_t downstream_throughput_kbps;
828 if (external_estimates_provider_->GetDownstreamThroughputKbps(
829 &downstream_throughput_kbps)) {
830 downstream_throughput_kbps_observations_.AddObservation(
831 Observation(downstream_throughput_kbps,
832 base::TimeTicks::Now() - time_since_last_update));
833 }
834
835 if (!eep_delayed_task_posted_ && base::MessageLoop::current()) {
bengr 2015/09/02 20:27:56 eep_delayed_task_posted_ -> external_estimate_pend
tbansal1 2015/09/03 00:22:40 Done.
836 base::MessageLoop::current()->task_runner()->PostDelayedTask(
837 FROM_HERE,
838 base::Bind(
839 &NetworkQualityEstimator::RunExternalEstimateProviderDelayedTask,
840 weak_factory_.GetWeakPtr()),
841 base::TimeDelta::FromMilliseconds(
842 kExternalEstimateProviderQueryIntervalMsec));
843 eep_delayed_task_posted_ = true;
844 }
845 }
846
847 void NetworkQualityEstimator::RunExternalEstimateProviderDelayedTask() {
bengr 2015/09/02 20:27:56 I don't understand the flow. Here's what I underst
tbansal1 2015/09/03 00:22:40 Updated to make it synchronous call. No posting of
848 DCHECK(thread_checker_.CalledOnValidThread());
849 DCHECK(eep_delayed_task_posted_);
850 eep_delayed_task_posted_ = false;
851 QueryExternalEstimateProvider();
779 } 852 }
780 853
781 void NetworkQualityEstimator::CacheNetworkQualityEstimate() { 854 void NetworkQualityEstimator::CacheNetworkQualityEstimate() {
782 DCHECK(thread_checker_.CalledOnValidThread()); 855 DCHECK(thread_checker_.CalledOnValidThread());
783 DCHECK_LE(cached_network_qualities_.size(), 856 DCHECK_LE(cached_network_qualities_.size(),
784 static_cast<size_t>(kMaximumNetworkQualityCacheSize)); 857 static_cast<size_t>(kMaximumNetworkQualityCacheSize));
785 858
786 // If the network name is unavailable, caching should not be performed. 859 // If the network name is unavailable, caching should not be performed.
787 if (current_network_id_.id.empty()) 860 if (current_network_id_.id.empty())
788 return; 861 return;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 930
858 NetworkQualityEstimator::NetworkQuality& 931 NetworkQualityEstimator::NetworkQuality&
859 NetworkQualityEstimator::NetworkQuality:: 932 NetworkQualityEstimator::NetworkQuality::
860 operator=(const NetworkQuality& other) { 933 operator=(const NetworkQuality& other) {
861 rtt_ = other.rtt_; 934 rtt_ = other.rtt_;
862 downstream_throughput_kbps_ = other.downstream_throughput_kbps_; 935 downstream_throughput_kbps_ = other.downstream_throughput_kbps_;
863 return *this; 936 return *this;
864 } 937 }
865 938
866 } // namespace net 939 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698