| 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 15 matching lines...) Expand all Loading... |
| 26 #include "base/trace_event/trace_event.h" | 26 #include "base/trace_event/trace_event.h" |
| 27 #include "build/build_config.h" | 27 #include "build/build_config.h" |
| 28 #include "net/base/load_flags.h" | 28 #include "net/base/load_flags.h" |
| 29 #include "net/base/load_timing_info.h" | 29 #include "net/base/load_timing_info.h" |
| 30 #include "net/base/network_interfaces.h" | 30 #include "net/base/network_interfaces.h" |
| 31 #include "net/base/trace_constants.h" | 31 #include "net/base/trace_constants.h" |
| 32 #include "net/base/url_util.h" | 32 #include "net/base/url_util.h" |
| 33 #include "net/http/http_response_headers.h" | 33 #include "net/http/http_response_headers.h" |
| 34 #include "net/http/http_response_info.h" | 34 #include "net/http/http_response_info.h" |
| 35 #include "net/http/http_status_code.h" | 35 #include "net/http/http_status_code.h" |
| 36 #include "net/nqe/event_creator.h" |
| 36 #include "net/nqe/network_quality_estimator_params.h" | 37 #include "net/nqe/network_quality_estimator_params.h" |
| 37 #include "net/nqe/socket_watcher_factory.h" | 38 #include "net/nqe/socket_watcher_factory.h" |
| 38 #include "net/nqe/throughput_analyzer.h" | 39 #include "net/nqe/throughput_analyzer.h" |
| 39 #include "net/url_request/url_request.h" | 40 #include "net/url_request/url_request.h" |
| 40 #include "net/url_request/url_request_status.h" | 41 #include "net/url_request/url_request_status.h" |
| 41 #include "url/gurl.h" | 42 #include "url/gurl.h" |
| 42 | 43 |
| 43 #if defined(OS_ANDROID) | 44 #if defined(OS_ANDROID) |
| 44 #include "net/android/cellular_signal_strength.h" | 45 #include "net/android/cellular_signal_strength.h" |
| 45 #include "net/android/network_library.h" | 46 #include "net/android/network_library.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 histogram_name, 0, EFFECTIVE_CONNECTION_TYPE_LAST, | 202 histogram_name, 0, EFFECTIVE_CONNECTION_TYPE_LAST, |
| 202 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, | 203 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, |
| 203 base::HistogramBase::kUmaTargetedHistogramFlag); | 204 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 204 histogram->Add(std::abs(metric)); | 205 histogram->Add(std::abs(metric)); |
| 205 } | 206 } |
| 206 | 207 |
| 207 } // namespace | 208 } // namespace |
| 208 | 209 |
| 209 NetworkQualityEstimator::NetworkQualityEstimator( | 210 NetworkQualityEstimator::NetworkQualityEstimator( |
| 210 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, | 211 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, |
| 211 const std::map<std::string, std::string>& variation_params) | |
| 212 : NetworkQualityEstimator(std::move(external_estimates_provider), | |
| 213 variation_params, | |
| 214 false, | |
| 215 false) {} | |
| 216 | |
| 217 NetworkQualityEstimator::NetworkQualityEstimator( | |
| 218 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, | |
| 219 const std::map<std::string, std::string>& variation_params, | 212 const std::map<std::string, std::string>& variation_params, |
| 220 bool use_local_host_requests_for_tests, | 213 NetLog* net_log) |
| 221 bool use_smaller_responses_for_tests) | |
| 222 : NetworkQualityEstimator(std::move(external_estimates_provider), | 214 : NetworkQualityEstimator(std::move(external_estimates_provider), |
| 223 variation_params, | 215 variation_params, |
| 224 use_local_host_requests_for_tests, | 216 false, |
| 225 use_smaller_responses_for_tests, | 217 false, |
| 226 true) {} | 218 net_log) {} |
| 227 | 219 |
| 228 NetworkQualityEstimator::NetworkQualityEstimator( | 220 NetworkQualityEstimator::NetworkQualityEstimator( |
| 229 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, | 221 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, |
| 230 const std::map<std::string, std::string>& variation_params, | 222 const std::map<std::string, std::string>& variation_params, |
| 231 bool use_local_host_requests_for_tests, | 223 bool use_local_host_requests_for_tests, |
| 232 bool use_smaller_responses_for_tests, | 224 bool use_smaller_responses_for_tests, |
| 233 bool add_default_platform_observations) | 225 NetLog* net_log) |
| 226 : NetworkQualityEstimator( |
| 227 std::move(external_estimates_provider), |
| 228 variation_params, |
| 229 use_local_host_requests_for_tests, |
| 230 use_smaller_responses_for_tests, |
| 231 true, |
| 232 NetLogWithSource::Make( |
| 233 net_log, |
| 234 net::NetLogSourceType::NETWORK_QUALITY_ESTIMATOR)) {} |
| 235 |
| 236 NetworkQualityEstimator::NetworkQualityEstimator( |
| 237 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, |
| 238 const std::map<std::string, std::string>& variation_params, |
| 239 bool use_local_host_requests_for_tests, |
| 240 bool use_smaller_responses_for_tests, |
| 241 bool add_default_platform_observations, |
| 242 const NetLogWithSource& net_log) |
| 234 : algorithm_name_to_enum_({{"HttpRTTAndDownstreamThroughput", | 243 : algorithm_name_to_enum_({{"HttpRTTAndDownstreamThroughput", |
| 235 EffectiveConnectionTypeAlgorithm:: | 244 EffectiveConnectionTypeAlgorithm:: |
| 236 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, | 245 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, |
| 237 {"TransportRTTOrDownstreamThroughput", | 246 {"TransportRTTOrDownstreamThroughput", |
| 238 EffectiveConnectionTypeAlgorithm:: | 247 EffectiveConnectionTypeAlgorithm:: |
| 239 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}), | 248 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}), |
| 240 use_localhost_requests_(use_local_host_requests_for_tests), | 249 use_localhost_requests_(use_local_host_requests_for_tests), |
| 241 use_small_responses_(use_smaller_responses_for_tests), | 250 use_small_responses_(use_smaller_responses_for_tests), |
| 242 add_default_platform_observations_(add_default_platform_observations), | 251 add_default_platform_observations_(add_default_platform_observations), |
| 243 weight_multiplier_per_second_( | 252 weight_multiplier_per_second_( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 269 signal_strength_dbm_(INT32_MIN), | 278 signal_strength_dbm_(INT32_MIN), |
| 270 min_signal_strength_since_connection_change_(INT32_MAX), | 279 min_signal_strength_since_connection_change_(INT32_MAX), |
| 271 max_signal_strength_since_connection_change_(INT32_MIN), | 280 max_signal_strength_since_connection_change_(INT32_MIN), |
| 272 correlation_uma_logging_probability_( | 281 correlation_uma_logging_probability_( |
| 273 nqe::internal::correlation_uma_logging_probability(variation_params)), | 282 nqe::internal::correlation_uma_logging_probability(variation_params)), |
| 274 forced_effective_connection_type_set_( | 283 forced_effective_connection_type_set_( |
| 275 nqe::internal::forced_effective_connection_type_set( | 284 nqe::internal::forced_effective_connection_type_set( |
| 276 variation_params)), | 285 variation_params)), |
| 277 forced_effective_connection_type_( | 286 forced_effective_connection_type_( |
| 278 nqe::internal::forced_effective_connection_type(variation_params)), | 287 nqe::internal::forced_effective_connection_type(variation_params)), |
| 288 net_log_(net_log), |
| 279 weak_ptr_factory_(this) { | 289 weak_ptr_factory_(this) { |
| 280 // None of the algorithms can have an empty name. | 290 // None of the algorithms can have an empty name. |
| 281 DCHECK(algorithm_name_to_enum_.end() == | 291 DCHECK(algorithm_name_to_enum_.end() == |
| 282 algorithm_name_to_enum_.find(std::string())); | 292 algorithm_name_to_enum_.find(std::string())); |
| 283 | 293 |
| 284 DCHECK_EQ(algorithm_name_to_enum_.size(), | 294 DCHECK_EQ(algorithm_name_to_enum_.size(), |
| 285 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: | 295 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: |
| 286 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); | 296 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); |
| 287 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: | 297 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: |
| 288 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, | 298 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 void NetworkQualityEstimator::SetUseSmallResponsesForTesting( | 729 void NetworkQualityEstimator::SetUseSmallResponsesForTesting( |
| 720 bool use_small_responses) { | 730 bool use_small_responses) { |
| 721 DCHECK(thread_checker_.CalledOnValidThread()); | 731 DCHECK(thread_checker_.CalledOnValidThread()); |
| 722 use_small_responses_ = use_small_responses; | 732 use_small_responses_ = use_small_responses; |
| 723 throughput_analyzer_->SetUseSmallResponsesForTesting(use_small_responses_); | 733 throughput_analyzer_->SetUseSmallResponsesForTesting(use_small_responses_); |
| 724 } | 734 } |
| 725 | 735 |
| 726 void NetworkQualityEstimator::ReportEffectiveConnectionTypeForTesting( | 736 void NetworkQualityEstimator::ReportEffectiveConnectionTypeForTesting( |
| 727 EffectiveConnectionType effective_connection_type) { | 737 EffectiveConnectionType effective_connection_type) { |
| 728 DCHECK(thread_checker_.CalledOnValidThread()); | 738 DCHECK(thread_checker_.CalledOnValidThread()); |
| 739 |
| 740 nqe::internal::AddEffectiveConnectionTypeChangedEventToNetLog( |
| 741 net_log_, typical_network_quality_[effective_connection_type].http_rtt(), |
| 742 typical_network_quality_[effective_connection_type].transport_rtt(), |
| 743 typical_network_quality_[effective_connection_type] |
| 744 .downstream_throughput_kbps(), |
| 745 effective_connection_type); |
| 746 |
| 729 for (auto& observer : effective_connection_type_observer_list_) | 747 for (auto& observer : effective_connection_type_observer_list_) |
| 730 observer.OnEffectiveConnectionTypeChanged(effective_connection_type); | 748 observer.OnEffectiveConnectionTypeChanged(effective_connection_type); |
| 731 | 749 |
| 732 network_quality_store_->Add(current_network_id_, | 750 network_quality_store_->Add(current_network_id_, |
| 733 nqe::internal::CachedNetworkQuality( | 751 nqe::internal::CachedNetworkQuality( |
| 734 tick_clock_->NowTicks(), network_quality_, | 752 tick_clock_->NowTicks(), network_quality_, |
| 735 effective_connection_type)); | 753 effective_connection_type)); |
| 736 } | 754 } |
| 737 | 755 |
| 738 bool NetworkQualityEstimator::RequestProvidesRTTObservation( | 756 bool NetworkQualityEstimator::RequestProvidesRTTObservation( |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1548 return; | 1566 return; |
| 1549 } | 1567 } |
| 1550 ComputeEffectiveConnectionType(); | 1568 ComputeEffectiveConnectionType(); |
| 1551 } | 1569 } |
| 1552 | 1570 |
| 1553 void NetworkQualityEstimator:: | 1571 void NetworkQualityEstimator:: |
| 1554 NotifyObserversOfEffectiveConnectionTypeChanged() { | 1572 NotifyObserversOfEffectiveConnectionTypeChanged() { |
| 1555 DCHECK(thread_checker_.CalledOnValidThread()); | 1573 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1556 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_); | 1574 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_); |
| 1557 | 1575 |
| 1576 nqe::internal::AddEffectiveConnectionTypeChangedEventToNetLog( |
| 1577 net_log_, network_quality_.http_rtt(), network_quality_.transport_rtt(), |
| 1578 network_quality_.downstream_throughput_kbps(), |
| 1579 effective_connection_type_); |
| 1580 |
| 1558 // TODO(tbansal): Add hysteresis in the notification. | 1581 // TODO(tbansal): Add hysteresis in the notification. |
| 1559 for (auto& observer : effective_connection_type_observer_list_) | 1582 for (auto& observer : effective_connection_type_observer_list_) |
| 1560 observer.OnEffectiveConnectionTypeChanged(effective_connection_type_); | 1583 observer.OnEffectiveConnectionTypeChanged(effective_connection_type_); |
| 1561 | 1584 |
| 1562 // Add the estimates of the current network to the cache store. | 1585 // Add the estimates of the current network to the cache store. |
| 1563 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { | 1586 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { |
| 1564 network_quality_store_->Add(current_network_id_, | 1587 network_quality_store_->Add(current_network_id_, |
| 1565 nqe::internal::CachedNetworkQuality( | 1588 nqe::internal::CachedNetworkQuality( |
| 1566 tick_clock_->NowTicks(), network_quality_, | 1589 tick_clock_->NowTicks(), network_quality_, |
| 1567 effective_connection_type_)); | 1590 effective_connection_type_)); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1683 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); | 1706 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); |
| 1684 downstream_throughput_kbps_observations_.AddObservation( | 1707 downstream_throughput_kbps_observations_.AddObservation( |
| 1685 throughput_observation); | 1708 throughput_observation); |
| 1686 NotifyObserversOfThroughput(throughput_observation); | 1709 NotifyObserversOfThroughput(throughput_observation); |
| 1687 } | 1710 } |
| 1688 | 1711 |
| 1689 ComputeEffectiveConnectionType(); | 1712 ComputeEffectiveConnectionType(); |
| 1690 } | 1713 } |
| 1691 | 1714 |
| 1692 } // namespace net | 1715 } // namespace net |
| OLD | NEW |