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

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

Issue 2936823002: NQE: Exclude network observations from private networks (Closed)
Patch Set: bengr comments, rebased Created 3 years, 6 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_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>
11 #include <vector>
12 11
13 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
14 #include "base/location.h" 13 #include "base/location.h"
15 #include "base/logging.h" 14 #include "base/logging.h"
16 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
17 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
18 #include "base/metrics/histogram_base.h" 17 #include "base/metrics/histogram_base.h"
19 #include "base/metrics/histogram_macros.h" 18 #include "base/metrics/histogram_macros.h"
20 #include "base/metrics/sparse_histogram.h" 19 #include "base/metrics/sparse_histogram.h"
21 #include "base/rand_util.h" 20 #include "base/rand_util.h"
22 #include "base/single_thread_task_runner.h" 21 #include "base/single_thread_task_runner.h"
23 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/string_piece.h" 23 #include "base/strings/string_piece.h"
25 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
26 #include "base/threading/thread_task_runner_handle.h" 25 #include "base/threading/thread_task_runner_handle.h"
27 #include "base/time/default_tick_clock.h" 26 #include "base/time/default_tick_clock.h"
28 #include "base/trace_event/trace_event.h" 27 #include "base/trace_event/trace_event.h"
29 #include "build/build_config.h" 28 #include "build/build_config.h"
29 #include "net/base/host_port_pair.h"
30 #include "net/base/load_flags.h" 30 #include "net/base/load_flags.h"
31 #include "net/base/load_timing_info.h" 31 #include "net/base/load_timing_info.h"
32 #include "net/base/network_interfaces.h" 32 #include "net/base/network_interfaces.h"
33 #include "net/base/trace_constants.h" 33 #include "net/base/trace_constants.h"
34 #include "net/base/url_util.h"
35 #include "net/http/http_response_headers.h" 34 #include "net/http/http_response_headers.h"
36 #include "net/http/http_response_info.h" 35 #include "net/http/http_response_info.h"
37 #include "net/http/http_status_code.h" 36 #include "net/http/http_status_code.h"
37 #include "net/nqe/network_quality_estimator_util.h"
38 #include "net/nqe/socket_watcher_factory.h" 38 #include "net/nqe/socket_watcher_factory.h"
39 #include "net/nqe/throughput_analyzer.h" 39 #include "net/nqe/throughput_analyzer.h"
40 #include "net/url_request/url_request.h" 40 #include "net/url_request/url_request.h"
41 #include "net/url_request/url_request_context.h"
41 #include "net/url_request/url_request_status.h" 42 #include "net/url_request/url_request_status.h"
42 #include "url/gurl.h" 43 #include "url/gurl.h"
43 44
44 #if defined(OS_ANDROID) 45 #if defined(OS_ANDROID)
45 #include "net/android/cellular_signal_strength.h" 46 #include "net/android/cellular_signal_strength.h"
46 #include "net/android/network_library.h" 47 #include "net/android/network_library.h"
47 #endif // OS_ANDROID 48 #endif // OS_ANDROID
48 49
49 namespace net { 50 namespace net {
50 51
52 class HostResolver;
53
51 namespace { 54 namespace {
52 55
53 // Returns the histogram that should be used to record the given statistic. 56 // Returns the histogram that should be used to record the given statistic.
54 // |max_limit| is the maximum value that can be stored in the histogram. 57 // |max_limit| is the maximum value that can be stored in the histogram.
55 base::HistogramBase* GetHistogram(const std::string& statistic_name, 58 base::HistogramBase* GetHistogram(const std::string& statistic_name,
56 NetworkChangeNotifier::ConnectionType type, 59 NetworkChangeNotifier::ConnectionType type,
57 int32_t max_limit) { 60 int32_t max_limit) {
58 const base::LinearHistogram::Sample kLowerLimit = 1; 61 const base::LinearHistogram::Sample kLowerLimit = 1;
59 DCHECK_GT(max_limit, kLowerLimit); 62 DCHECK_GT(max_limit, kLowerLimit);
60 const size_t kBucketCount = 50; 63 const size_t kBucketCount = 50;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 disallowed_observation_sources_for_http_( 277 disallowed_observation_sources_for_http_(
275 {NETWORK_QUALITY_OBSERVATION_SOURCE_TCP, 278 {NETWORK_QUALITY_OBSERVATION_SOURCE_TCP,
276 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC, 279 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC,
277 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE, 280 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE,
278 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM}), 281 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM}),
279 disallowed_observation_sources_for_transport_( 282 disallowed_observation_sources_for_transport_(
280 {NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP, 283 {NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP,
281 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE, 284 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE,
282 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE, 285 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE,
283 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM}), 286 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM}),
287 net_log_(net_log),
284 weak_ptr_factory_(this) { 288 weak_ptr_factory_(this) {
285 // None of the algorithms can have an empty name. 289 // None of the algorithms can have an empty name.
286 DCHECK(algorithm_name_to_enum_.end() == 290 DCHECK(algorithm_name_to_enum_.end() ==
287 algorithm_name_to_enum_.find(std::string())); 291 algorithm_name_to_enum_.find(std::string()));
288 292
289 DCHECK_EQ(algorithm_name_to_enum_.size(), 293 DCHECK_EQ(algorithm_name_to_enum_.size(),
290 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: 294 static_cast<size_t>(EffectiveConnectionTypeAlgorithm::
291 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); 295 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST));
292 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: 296 DCHECK_NE(EffectiveConnectionTypeAlgorithm::
293 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, 297 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST,
294 effective_connection_type_algorithm_); 298 effective_connection_type_algorithm_);
295 299
296 network_quality_store_.reset(new nqe::internal::NetworkQualityStore()); 300 network_quality_store_.reset(new nqe::internal::NetworkQualityStore());
297 NetworkChangeNotifier::AddConnectionTypeObserver(this); 301 NetworkChangeNotifier::AddConnectionTypeObserver(this);
298 if (external_estimate_provider_) { 302 if (external_estimate_provider_) {
299 RecordExternalEstimateProviderMetrics( 303 RecordExternalEstimateProviderMetrics(
300 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE); 304 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE);
301 external_estimate_provider_->SetUpdatedEstimateDelegate(this); 305 external_estimate_provider_->SetUpdatedEstimateDelegate(this);
302 } else { 306 } else {
303 RecordExternalEstimateProviderMetrics( 307 RecordExternalEstimateProviderMetrics(
304 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE); 308 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE);
305 } 309 }
306 current_network_id_ = GetCurrentNetworkID(); 310 current_network_id_ = GetCurrentNetworkID();
307 AddDefaultEstimates(); 311 AddDefaultEstimates();
308 312
309 throughput_analyzer_.reset(new nqe::internal::ThroughputAnalyzer( 313 throughput_analyzer_.reset(new nqe::internal::ThroughputAnalyzer(
310 params_.get(), base::ThreadTaskRunnerHandle::Get(), 314 params_.get(), base::ThreadTaskRunnerHandle::Get(),
311 base::Bind(&NetworkQualityEstimator::OnNewThroughputObservationAvailable, 315 base::Bind(&NetworkQualityEstimator::OnNewThroughputObservationAvailable,
312 base::Unretained(this)), 316 base::Unretained(this)),
313 use_localhost_requests_, use_smaller_responses_for_tests)); 317 use_localhost_requests_, use_smaller_responses_for_tests, net_log_));
314 318
315 watcher_factory_.reset(new nqe::internal::SocketWatcherFactory( 319 watcher_factory_.reset(new nqe::internal::SocketWatcherFactory(
316 base::ThreadTaskRunnerHandle::Get(), 320 base::ThreadTaskRunnerHandle::Get(),
317 params_->min_socket_watcher_notification_interval(), 321 params_->min_socket_watcher_notification_interval(),
318 base::Bind(&NetworkQualityEstimator::OnUpdatedRTTAvailable, 322 base::Bind(&NetworkQualityEstimator::OnUpdatedRTTAvailable,
319 base::Unretained(this)), 323 base::Unretained(this)),
320 tick_clock_.get())); 324 tick_clock_.get()));
321 325
322 // Record accuracy after a 15 second interval. The values used here must 326 // Record accuracy after a 15 second interval. The values used here must
323 // remain in sync with the suffixes specified in 327 // remain in sync with the suffixes specified in
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 785
782 for (auto& observer : rtt_and_throughput_estimates_observer_list_) 786 for (auto& observer : rtt_and_throughput_estimates_observer_list_)
783 observer.OnRTTOrThroughputEstimatesComputed(http_rtt, transport_rtt, 787 observer.OnRTTOrThroughputEstimatesComputed(http_rtt, transport_rtt,
784 downstream_throughput_kbps); 788 downstream_throughput_kbps);
785 } 789 }
786 790
787 bool NetworkQualityEstimator::RequestProvidesRTTObservation( 791 bool NetworkQualityEstimator::RequestProvidesRTTObservation(
788 const URLRequest& request) const { 792 const URLRequest& request) const {
789 DCHECK(thread_checker_.CalledOnValidThread()); 793 DCHECK(thread_checker_.CalledOnValidThread());
790 794
791 return (use_localhost_requests_ || !IsLocalhost(request.url().host())) && 795 bool private_network_request = nqe::internal::IsPrivateHost(
796 request.context()->host_resolver(),
797 HostPortPair(request.url().host(), request.url().EffectiveIntPort()),
798 net_log_);
799
800 return (use_localhost_requests_ || !private_network_request) &&
792 // Verify that response headers are received, so it can be ensured that 801 // Verify that response headers are received, so it can be ensured that
793 // response is not cached. 802 // response is not cached.
794 !request.response_info().response_time.is_null() && 803 !request.response_info().response_time.is_null() &&
795 !request.was_cached() && 804 !request.was_cached() &&
796 request.creation_time() >= last_connection_change_; 805 request.creation_time() >= last_connection_change_;
797 } 806 }
798 807
799 void NetworkQualityEstimator::RecordExternalEstimateProviderMetrics( 808 void NetworkQualityEstimator::RecordExternalEstimateProviderMetrics(
800 NQEExternalEstimateProviderStatus status) const { 809 NQEExternalEstimateProviderStatus status) const {
801 UMA_HISTOGRAM_ENUMERATION("NQE.ExternalEstimateProviderStatus", status, 810 UMA_HISTOGRAM_ENUMERATION("NQE.ExternalEstimateProviderStatus", status,
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after
1834 return "UnweightedAverage"; 1843 return "UnweightedAverage";
1835 case STATISTIC_LAST: 1844 case STATISTIC_LAST:
1836 NOTREACHED(); 1845 NOTREACHED();
1837 return ""; 1846 return "";
1838 } 1847 }
1839 NOTREACHED(); 1848 NOTREACHED();
1840 return ""; 1849 return "";
1841 } 1850 }
1842 1851
1843 } // namespace net 1852 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698