OLD | NEW |
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/nqe/network_quality_estimator.h" | 5 #include "net/nqe/network_quality_estimator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <utility> | 10 #include <utility> |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 : NetworkQualityEstimator(std::move(external_estimates_provider), | 213 : NetworkQualityEstimator(std::move(external_estimates_provider), |
214 variation_params, | 214 variation_params, |
215 false, | 215 false, |
216 false) {} | 216 false) {} |
217 | 217 |
218 NetworkQualityEstimator::NetworkQualityEstimator( | 218 NetworkQualityEstimator::NetworkQualityEstimator( |
219 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, | 219 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, |
220 const std::map<std::string, std::string>& variation_params, | 220 const std::map<std::string, std::string>& variation_params, |
221 bool use_local_host_requests_for_tests, | 221 bool use_local_host_requests_for_tests, |
222 bool use_smaller_responses_for_tests) | 222 bool use_smaller_responses_for_tests) |
| 223 : NetworkQualityEstimator(std::move(external_estimates_provider), |
| 224 variation_params, |
| 225 use_local_host_requests_for_tests, |
| 226 use_smaller_responses_for_tests, |
| 227 true) {} |
| 228 |
| 229 NetworkQualityEstimator::NetworkQualityEstimator( |
| 230 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, |
| 231 const std::map<std::string, std::string>& variation_params, |
| 232 bool use_local_host_requests_for_tests, |
| 233 bool use_smaller_responses_for_tests, |
| 234 bool add_default_platform_observations) |
223 : algorithm_name_to_enum_({{"HttpRTTAndDownstreamThroughput", | 235 : algorithm_name_to_enum_({{"HttpRTTAndDownstreamThroughput", |
224 EffectiveConnectionTypeAlgorithm:: | 236 EffectiveConnectionTypeAlgorithm:: |
225 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, | 237 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, |
226 {"TransportRTTOrDownstreamThroughput", | 238 {"TransportRTTOrDownstreamThroughput", |
227 EffectiveConnectionTypeAlgorithm:: | 239 EffectiveConnectionTypeAlgorithm:: |
228 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}), | 240 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}), |
229 use_localhost_requests_(use_local_host_requests_for_tests), | 241 use_localhost_requests_(use_local_host_requests_for_tests), |
230 use_small_responses_(use_smaller_responses_for_tests), | 242 use_small_responses_(use_smaller_responses_for_tests), |
| 243 add_default_platform_observations_(add_default_platform_observations), |
231 weight_multiplier_per_second_( | 244 weight_multiplier_per_second_( |
232 nqe::internal::GetWeightMultiplierPerSecond(variation_params)), | 245 nqe::internal::GetWeightMultiplierPerSecond(variation_params)), |
233 effective_connection_type_algorithm_( | 246 effective_connection_type_algorithm_( |
234 algorithm_name_to_enum_.find( | 247 algorithm_name_to_enum_.find( |
235 net::nqe::internal::GetEffectiveConnectionTypeAlgorithm( | 248 net::nqe::internal::GetEffectiveConnectionTypeAlgorithm( |
236 variation_params)) == algorithm_name_to_enum_.end() | 249 variation_params)) == algorithm_name_to_enum_.end() |
237 ? kDefaultEffectiveConnectionTypeAlgorithm | 250 ? kDefaultEffectiveConnectionTypeAlgorithm |
238 : algorithm_name_to_enum_ | 251 : algorithm_name_to_enum_ |
239 .find( | 252 .find( |
240 net::nqe::internal::GetEffectiveConnectionTypeAlgorithm( | 253 net::nqe::internal::GetEffectiveConnectionTypeAlgorithm( |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 nqe::internal::ObtainDefaultObservations(variation_params, | 328 nqe::internal::ObtainDefaultObservations(variation_params, |
316 default_observations_); | 329 default_observations_); |
317 nqe::internal::ObtainEffectiveConnectionTypeModelParams( | 330 nqe::internal::ObtainEffectiveConnectionTypeModelParams( |
318 variation_params, connection_thresholds_); | 331 variation_params, connection_thresholds_); |
319 nqe::internal::ObtainTypicalNetworkQuality(typical_network_quality_); | 332 nqe::internal::ObtainTypicalNetworkQuality(typical_network_quality_); |
320 } | 333 } |
321 | 334 |
322 void NetworkQualityEstimator::AddDefaultEstimates() { | 335 void NetworkQualityEstimator::AddDefaultEstimates() { |
323 DCHECK(thread_checker_.CalledOnValidThread()); | 336 DCHECK(thread_checker_.CalledOnValidThread()); |
324 | 337 |
| 338 if (!add_default_platform_observations_) |
| 339 return; |
| 340 |
325 if (default_observations_[current_network_id_.type].http_rtt() != | 341 if (default_observations_[current_network_id_.type].http_rtt() != |
326 nqe::internal::InvalidRTT()) { | 342 nqe::internal::InvalidRTT()) { |
327 RttObservation rtt_observation( | 343 RttObservation rtt_observation( |
328 default_observations_[current_network_id_.type].http_rtt(), | 344 default_observations_[current_network_id_.type].http_rtt(), |
329 tick_clock_->NowTicks(), | 345 tick_clock_->NowTicks(), |
330 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM); | 346 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM); |
331 rtt_observations_.AddObservation(rtt_observation); | 347 rtt_observations_.AddObservation(rtt_observation); |
332 NotifyObserversOfRTT(rtt_observation); | 348 NotifyObserversOfRTT(rtt_observation); |
333 } | 349 } |
334 | 350 |
| 351 if (default_observations_[current_network_id_.type].transport_rtt() != |
| 352 nqe::internal::InvalidRTT()) { |
| 353 RttObservation rtt_observation( |
| 354 default_observations_[current_network_id_.type].transport_rtt(), |
| 355 tick_clock_->NowTicks(), |
| 356 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM); |
| 357 rtt_observations_.AddObservation(rtt_observation); |
| 358 NotifyObserversOfRTT(rtt_observation); |
| 359 } |
| 360 |
335 if (default_observations_[current_network_id_.type] | 361 if (default_observations_[current_network_id_.type] |
336 .downstream_throughput_kbps() != nqe::internal::kInvalidThroughput) { | 362 .downstream_throughput_kbps() != nqe::internal::kInvalidThroughput) { |
337 ThroughputObservation throughput_observation( | 363 ThroughputObservation throughput_observation( |
338 default_observations_[current_network_id_.type] | 364 default_observations_[current_network_id_.type] |
339 .downstream_throughput_kbps(), | 365 .downstream_throughput_kbps(), |
340 tick_clock_->NowTicks(), | 366 tick_clock_->NowTicks(), |
341 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM); | 367 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM); |
342 downstream_throughput_kbps_observations_.AddObservation( | 368 downstream_throughput_kbps_observations_.AddObservation( |
343 throughput_observation); | 369 throughput_observation); |
344 NotifyObserversOfThroughput(throughput_observation); | 370 NotifyObserversOfThroughput(throughput_observation); |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 GetHistogram("RTT.Percentile50.", current_network_id_.type, 10 * 1000); | 850 GetHistogram("RTT.Percentile50.", current_network_id_.type, 10 * 1000); |
825 rtt_percentile->Add(rtt.InMilliseconds()); | 851 rtt_percentile->Add(rtt.InMilliseconds()); |
826 | 852 |
827 // Add the remaining percentile values. | 853 // Add the remaining percentile values. |
828 static const int kPercentiles[] = {0, 10, 90, 100}; | 854 static const int kPercentiles[] = {0, 10, 90, 100}; |
829 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; | 855 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; |
830 disallowed_observation_sources.push_back( | 856 disallowed_observation_sources.push_back( |
831 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP); | 857 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP); |
832 disallowed_observation_sources.push_back( | 858 disallowed_observation_sources.push_back( |
833 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); | 859 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); |
| 860 disallowed_observation_sources.push_back( |
| 861 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE); |
| 862 disallowed_observation_sources.push_back( |
| 863 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM); |
834 for (size_t i = 0; i < arraysize(kPercentiles); ++i) { | 864 for (size_t i = 0; i < arraysize(kPercentiles); ++i) { |
835 rtt = GetRTTEstimateInternal(disallowed_observation_sources, | 865 rtt = GetRTTEstimateInternal(disallowed_observation_sources, |
836 base::TimeTicks(), kPercentiles[i]); | 866 base::TimeTicks(), kPercentiles[i]); |
837 | 867 |
838 rtt_percentile = GetHistogram( | 868 rtt_percentile = GetHistogram( |
839 "RTT.Percentile" + base::IntToString(kPercentiles[i]) + ".", | 869 "RTT.Percentile" + base::IntToString(kPercentiles[i]) + ".", |
840 current_network_id_.type, 10 * 1000); // 10 seconds | 870 current_network_id_.type, 10 * 1000); // 10 seconds |
841 rtt_percentile->Add(rtt.InMilliseconds()); | 871 rtt_percentile->Add(rtt.InMilliseconds()); |
842 } | 872 } |
843 } | 873 } |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 | 1218 |
1189 bool NetworkQualityEstimator::GetRecentHttpRTT( | 1219 bool NetworkQualityEstimator::GetRecentHttpRTT( |
1190 const base::TimeTicks& start_time, | 1220 const base::TimeTicks& start_time, |
1191 base::TimeDelta* rtt) const { | 1221 base::TimeDelta* rtt) const { |
1192 DCHECK(thread_checker_.CalledOnValidThread()); | 1222 DCHECK(thread_checker_.CalledOnValidThread()); |
1193 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; | 1223 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; |
1194 disallowed_observation_sources.push_back( | 1224 disallowed_observation_sources.push_back( |
1195 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP); | 1225 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP); |
1196 disallowed_observation_sources.push_back( | 1226 disallowed_observation_sources.push_back( |
1197 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); | 1227 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); |
| 1228 disallowed_observation_sources.push_back( |
| 1229 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE); |
| 1230 disallowed_observation_sources.push_back( |
| 1231 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM); |
1198 *rtt = GetRTTEstimateInternal(disallowed_observation_sources, start_time, 50); | 1232 *rtt = GetRTTEstimateInternal(disallowed_observation_sources, start_time, 50); |
1199 return (*rtt != nqe::internal::InvalidRTT()); | 1233 return (*rtt != nqe::internal::InvalidRTT()); |
1200 } | 1234 } |
1201 | 1235 |
1202 bool NetworkQualityEstimator::GetRecentTransportRTT( | 1236 bool NetworkQualityEstimator::GetRecentTransportRTT( |
1203 const base::TimeTicks& start_time, | 1237 const base::TimeTicks& start_time, |
1204 base::TimeDelta* rtt) const { | 1238 base::TimeDelta* rtt) const { |
1205 DCHECK(thread_checker_.CalledOnValidThread()); | 1239 DCHECK(thread_checker_.CalledOnValidThread()); |
1206 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; | 1240 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; |
1207 disallowed_observation_sources.push_back( | 1241 disallowed_observation_sources.push_back( |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 void NetworkQualityEstimator::OnPrefsRead( | 1592 void NetworkQualityEstimator::OnPrefsRead( |
1559 const std::map<nqe::internal::NetworkID, | 1593 const std::map<nqe::internal::NetworkID, |
1560 nqe::internal::CachedNetworkQuality> read_prefs) { | 1594 nqe::internal::CachedNetworkQuality> read_prefs) { |
1561 DCHECK(thread_checker_.CalledOnValidThread()); | 1595 DCHECK(thread_checker_.CalledOnValidThread()); |
1562 UMA_HISTOGRAM_COUNTS("NQE.Prefs.ReadSize", read_prefs.size()); | 1596 UMA_HISTOGRAM_COUNTS("NQE.Prefs.ReadSize", read_prefs.size()); |
1563 // TODO(tbansal): crbug.com/490870. Incorporate the network quality into the | 1597 // TODO(tbansal): crbug.com/490870. Incorporate the network quality into the |
1564 // current estimates. | 1598 // current estimates. |
1565 } | 1599 } |
1566 | 1600 |
1567 } // namespace net | 1601 } // namespace net |
OLD | NEW |