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

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

Issue 2593243003: Add network quality change events to net log (Closed)
Patch Set: rebased Created 3 years, 11 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
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_test_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
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 disable_offline_check_(false), 251 disable_offline_check_(false),
243 add_default_platform_observations_(add_default_platform_observations), 252 add_default_platform_observations_(add_default_platform_observations),
(...skipping 30 matching lines...) Expand all
274 signal_strength_dbm_(INT32_MIN), 283 signal_strength_dbm_(INT32_MIN),
275 min_signal_strength_since_connection_change_(INT32_MAX), 284 min_signal_strength_since_connection_change_(INT32_MAX),
276 max_signal_strength_since_connection_change_(INT32_MIN), 285 max_signal_strength_since_connection_change_(INT32_MIN),
277 correlation_uma_logging_probability_( 286 correlation_uma_logging_probability_(
278 nqe::internal::correlation_uma_logging_probability(variation_params)), 287 nqe::internal::correlation_uma_logging_probability(variation_params)),
279 forced_effective_connection_type_set_( 288 forced_effective_connection_type_set_(
280 nqe::internal::forced_effective_connection_type_set( 289 nqe::internal::forced_effective_connection_type_set(
281 variation_params)), 290 variation_params)),
282 forced_effective_connection_type_( 291 forced_effective_connection_type_(
283 nqe::internal::forced_effective_connection_type(variation_params)), 292 nqe::internal::forced_effective_connection_type(variation_params)),
293 net_log_(net_log),
284 weak_ptr_factory_(this) { 294 weak_ptr_factory_(this) {
285 // None of the algorithms can have an empty name. 295 // None of the algorithms can have an empty name.
286 DCHECK(algorithm_name_to_enum_.end() == 296 DCHECK(algorithm_name_to_enum_.end() ==
287 algorithm_name_to_enum_.find(std::string())); 297 algorithm_name_to_enum_.find(std::string()));
288 298
289 DCHECK_EQ(algorithm_name_to_enum_.size(), 299 DCHECK_EQ(algorithm_name_to_enum_.size(),
290 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: 300 static_cast<size_t>(EffectiveConnectionTypeAlgorithm::
291 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); 301 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST));
292 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: 302 DCHECK_NE(EffectiveConnectionTypeAlgorithm::
293 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, 303 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST,
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 void NetworkQualityEstimator::DisableOfflineCheckForTesting( 739 void NetworkQualityEstimator::DisableOfflineCheckForTesting(
730 bool disable_offline_check) { 740 bool disable_offline_check) {
731 DCHECK(thread_checker_.CalledOnValidThread()); 741 DCHECK(thread_checker_.CalledOnValidThread());
732 disable_offline_check_ = disable_offline_check; 742 disable_offline_check_ = disable_offline_check;
733 network_quality_store_->DisableOfflineCheckForTesting(disable_offline_check_); 743 network_quality_store_->DisableOfflineCheckForTesting(disable_offline_check_);
734 } 744 }
735 745
736 void NetworkQualityEstimator::ReportEffectiveConnectionTypeForTesting( 746 void NetworkQualityEstimator::ReportEffectiveConnectionTypeForTesting(
737 EffectiveConnectionType effective_connection_type) { 747 EffectiveConnectionType effective_connection_type) {
738 DCHECK(thread_checker_.CalledOnValidThread()); 748 DCHECK(thread_checker_.CalledOnValidThread());
749
750 nqe::internal::AddEffectiveConnectionTypeChangedEventToNetLog(
751 net_log_, typical_network_quality_[effective_connection_type].http_rtt(),
752 typical_network_quality_[effective_connection_type].transport_rtt(),
753 typical_network_quality_[effective_connection_type]
754 .downstream_throughput_kbps(),
755 effective_connection_type);
756
739 for (auto& observer : effective_connection_type_observer_list_) 757 for (auto& observer : effective_connection_type_observer_list_)
740 observer.OnEffectiveConnectionTypeChanged(effective_connection_type); 758 observer.OnEffectiveConnectionTypeChanged(effective_connection_type);
741 759
742 network_quality_store_->Add(current_network_id_, 760 network_quality_store_->Add(current_network_id_,
743 nqe::internal::CachedNetworkQuality( 761 nqe::internal::CachedNetworkQuality(
744 tick_clock_->NowTicks(), network_quality_, 762 tick_clock_->NowTicks(), network_quality_,
745 effective_connection_type)); 763 effective_connection_type));
746 } 764 }
747 765
748 bool NetworkQualityEstimator::RequestProvidesRTTObservation( 766 bool NetworkQualityEstimator::RequestProvidesRTTObservation(
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
1562 return; 1580 return;
1563 } 1581 }
1564 ComputeEffectiveConnectionType(); 1582 ComputeEffectiveConnectionType();
1565 } 1583 }
1566 1584
1567 void NetworkQualityEstimator:: 1585 void NetworkQualityEstimator::
1568 NotifyObserversOfEffectiveConnectionTypeChanged() { 1586 NotifyObserversOfEffectiveConnectionTypeChanged() {
1569 DCHECK(thread_checker_.CalledOnValidThread()); 1587 DCHECK(thread_checker_.CalledOnValidThread());
1570 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_); 1588 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_);
1571 1589
1590 nqe::internal::AddEffectiveConnectionTypeChangedEventToNetLog(
1591 net_log_, network_quality_.http_rtt(), network_quality_.transport_rtt(),
1592 network_quality_.downstream_throughput_kbps(),
1593 effective_connection_type_);
1594
1572 // TODO(tbansal): Add hysteresis in the notification. 1595 // TODO(tbansal): Add hysteresis in the notification.
1573 for (auto& observer : effective_connection_type_observer_list_) 1596 for (auto& observer : effective_connection_type_observer_list_)
1574 observer.OnEffectiveConnectionTypeChanged(effective_connection_type_); 1597 observer.OnEffectiveConnectionTypeChanged(effective_connection_type_);
1575 1598
1576 // Add the estimates of the current network to the cache store. 1599 // Add the estimates of the current network to the cache store.
1577 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { 1600 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
1578 network_quality_store_->Add(current_network_id_, 1601 network_quality_store_->Add(current_network_id_,
1579 nqe::internal::CachedNetworkQuality( 1602 nqe::internal::CachedNetworkQuality(
1580 tick_clock_->NowTicks(), network_quality_, 1603 tick_clock_->NowTicks(), network_quality_,
1581 effective_connection_type_)); 1604 effective_connection_type_));
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); 1720 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE);
1698 downstream_throughput_kbps_observations_.AddObservation( 1721 downstream_throughput_kbps_observations_.AddObservation(
1699 throughput_observation); 1722 throughput_observation);
1700 NotifyObserversOfThroughput(throughput_observation); 1723 NotifyObserversOfThroughput(throughput_observation);
1701 } 1724 }
1702 1725
1703 ComputeEffectiveConnectionType(); 1726 ComputeEffectiveConnectionType();
1704 } 1727 }
1705 1728
1706 } // namespace net 1729 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698