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

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

Issue 2899453002: Pass parsed network quality estimator params when constructing NQE (Closed)
Patch Set: 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_params.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> 11 #include <vector>
12 12
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/ptr_util.h"
16 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
17 #include "base/metrics/histogram_base.h" 18 #include "base/metrics/histogram_base.h"
18 #include "base/metrics/histogram_macros.h" 19 #include "base/metrics/histogram_macros.h"
19 #include "base/metrics/sparse_histogram.h" 20 #include "base/metrics/sparse_histogram.h"
20 #include "base/rand_util.h" 21 #include "base/rand_util.h"
21 #include "base/single_thread_task_runner.h" 22 #include "base/single_thread_task_runner.h"
22 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_piece.h" 24 #include "base/strings/string_piece.h"
24 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
25 #include "base/threading/thread_task_runner_handle.h" 26 #include "base/threading/thread_task_runner_handle.h"
(...skipping 27 matching lines...) Expand all
53 // |max_limit| is the maximum value that can be stored in the histogram. 54 // |max_limit| is the maximum value that can be stored in the histogram.
54 base::HistogramBase* GetHistogram(const std::string& statistic_name, 55 base::HistogramBase* GetHistogram(const std::string& statistic_name,
55 NetworkChangeNotifier::ConnectionType type, 56 NetworkChangeNotifier::ConnectionType type,
56 int32_t max_limit) { 57 int32_t max_limit) {
57 const base::LinearHistogram::Sample kLowerLimit = 1; 58 const base::LinearHistogram::Sample kLowerLimit = 1;
58 DCHECK_GT(max_limit, kLowerLimit); 59 DCHECK_GT(max_limit, kLowerLimit);
59 const size_t kBucketCount = 50; 60 const size_t kBucketCount = 50;
60 61
61 return base::Histogram::FactoryGet( 62 return base::Histogram::FactoryGet(
62 "NQE." + statistic_name + 63 "NQE." + statistic_name +
63 nqe::internal::NetworkQualityEstimatorParams:: 64 NetworkQualityEstimatorParams::GetNameForConnectionType(type),
64 GetNameForConnectionType(type),
65 kLowerLimit, max_limit, kBucketCount, 65 kLowerLimit, max_limit, kBucketCount,
66 base::HistogramBase::kUmaTargetedHistogramFlag); 66 base::HistogramBase::kUmaTargetedHistogramFlag);
67 } 67 }
68 68
69 NetworkQualityObservationSource ProtocolSourceToObservationSource( 69 NetworkQualityObservationSource ProtocolSourceToObservationSource(
70 SocketPerformanceWatcherFactory::Protocol protocol) { 70 SocketPerformanceWatcherFactory::Protocol protocol) {
71 switch (protocol) { 71 switch (protocol) {
72 case SocketPerformanceWatcherFactory::PROTOCOL_TCP: 72 case SocketPerformanceWatcherFactory::PROTOCOL_TCP:
73 return NETWORK_QUALITY_OBSERVATION_SOURCE_TCP; 73 return NETWORK_QUALITY_OBSERVATION_SOURCE_TCP;
74 case SocketPerformanceWatcherFactory::PROTOCOL_QUIC: 74 case SocketPerformanceWatcherFactory::PROTOCOL_QUIC:
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 histogram_name, 0, EFFECTIVE_CONNECTION_TYPE_LAST, 204 histogram_name, 0, EFFECTIVE_CONNECTION_TYPE_LAST,
205 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, 205 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */,
206 base::HistogramBase::kUmaTargetedHistogramFlag); 206 base::HistogramBase::kUmaTargetedHistogramFlag);
207 histogram->Add(std::abs(metric)); 207 histogram->Add(std::abs(metric));
208 } 208 }
209 209
210 } // namespace 210 } // namespace
211 211
212 NetworkQualityEstimator::NetworkQualityEstimator( 212 NetworkQualityEstimator::NetworkQualityEstimator(
213 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, 213 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
214 const std::map<std::string, std::string>& variation_params, 214 std::unique_ptr<NetworkQualityEstimatorParams> params,
215 NetLog* net_log)
216 : NetworkQualityEstimator(std::move(external_estimates_provider),
217 variation_params,
218 false,
219 false,
220 net_log) {}
221
222 NetworkQualityEstimator::NetworkQualityEstimator(
223 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
224 const std::map<std::string, std::string>& variation_params,
225 bool use_local_host_requests_for_tests,
226 bool use_smaller_responses_for_tests,
227 NetLog* net_log) 215 NetLog* net_log)
228 : NetworkQualityEstimator( 216 : NetworkQualityEstimator(
229 std::move(external_estimates_provider), 217 std::move(external_estimates_provider),
230 variation_params, 218 std::move(params),
231 use_local_host_requests_for_tests, 219 false,
232 use_smaller_responses_for_tests, 220 false,
233 true, 221 true,
234 NetLogWithSource::Make( 222 NetLogWithSource::Make(
235 net_log, 223 net_log,
236 net::NetLogSourceType::NETWORK_QUALITY_ESTIMATOR)) {} 224 net::NetLogSourceType::NETWORK_QUALITY_ESTIMATOR)) {}
237 225
238 NetworkQualityEstimator::NetworkQualityEstimator( 226 NetworkQualityEstimator::NetworkQualityEstimator(
239 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, 227 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
240 const std::map<std::string, std::string>& variation_params, 228 std::unique_ptr<NetworkQualityEstimatorParams> params,
241 bool use_local_host_requests_for_tests, 229 bool use_local_host_requests_for_tests,
242 bool use_smaller_responses_for_tests, 230 bool use_smaller_responses_for_tests,
243 bool add_default_platform_observations, 231 bool add_default_platform_observations,
244 const NetLogWithSource& net_log) 232 const NetLogWithSource& net_log)
245 : algorithm_name_to_enum_({{"HttpRTTAndDownstreamThroughput", 233 : algorithm_name_to_enum_({{"HttpRTTAndDownstreamThroughput",
246 EffectiveConnectionTypeAlgorithm:: 234 EffectiveConnectionTypeAlgorithm::
247 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, 235 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT},
248 {"TransportRTTOrDownstreamThroughput", 236 {"TransportRTTOrDownstreamThroughput",
249 EffectiveConnectionTypeAlgorithm:: 237 EffectiveConnectionTypeAlgorithm::
250 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}), 238 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}),
251 params_(variation_params), 239 params_(std::move(params)),
252 use_localhost_requests_(use_local_host_requests_for_tests), 240 use_localhost_requests_(use_local_host_requests_for_tests),
253 use_small_responses_(use_smaller_responses_for_tests), 241 use_small_responses_(use_smaller_responses_for_tests),
254 disable_offline_check_(false), 242 disable_offline_check_(false),
255 add_default_platform_observations_(add_default_platform_observations), 243 add_default_platform_observations_(add_default_platform_observations),
256 effective_connection_type_algorithm_( 244 effective_connection_type_algorithm_(
257 algorithm_name_to_enum_.find( 245 algorithm_name_to_enum_.find(
258 params_.GetEffectiveConnectionTypeAlgorithm()) == 246 params_->GetEffectiveConnectionTypeAlgorithm()) ==
259 algorithm_name_to_enum_.end() 247 algorithm_name_to_enum_.end()
260 ? kDefaultEffectiveConnectionTypeAlgorithm 248 ? kDefaultEffectiveConnectionTypeAlgorithm
261 : algorithm_name_to_enum_ 249 : algorithm_name_to_enum_
262 .find(params_.GetEffectiveConnectionTypeAlgorithm()) 250 .find(params_->GetEffectiveConnectionTypeAlgorithm())
263 ->second), 251 ->second),
264 tick_clock_(new base::DefaultTickClock()), 252 tick_clock_(new base::DefaultTickClock()),
265 last_connection_change_(tick_clock_->NowTicks()), 253 last_connection_change_(tick_clock_->NowTicks()),
266 current_network_id_(nqe::internal::NetworkID( 254 current_network_id_(nqe::internal::NetworkID(
267 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, 255 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN,
268 std::string())), 256 std::string())),
269 downstream_throughput_kbps_observations_( 257 downstream_throughput_kbps_observations_(
270 params_.weight_multiplier_per_second(), 258 params_->weight_multiplier_per_second(),
271 params_.weight_multiplier_per_dbm()), 259 params_->weight_multiplier_per_dbm()),
272 rtt_observations_(params_.weight_multiplier_per_second(), 260 rtt_observations_(params_->weight_multiplier_per_second(),
273 params_.weight_multiplier_per_dbm()), 261 params_->weight_multiplier_per_dbm()),
274 effective_connection_type_at_last_main_frame_( 262 effective_connection_type_at_last_main_frame_(
275 EFFECTIVE_CONNECTION_TYPE_UNKNOWN), 263 EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
276 external_estimate_provider_(std::move(external_estimates_provider)), 264 external_estimate_provider_(std::move(external_estimates_provider)),
277 effective_connection_type_recomputation_interval_( 265 effective_connection_type_recomputation_interval_(
278 base::TimeDelta::FromSeconds(10)), 266 base::TimeDelta::FromSeconds(10)),
279 rtt_observations_size_at_last_ect_computation_(0), 267 rtt_observations_size_at_last_ect_computation_(0),
280 throughput_observations_size_at_last_ect_computation_(0), 268 throughput_observations_size_at_last_ect_computation_(0),
281 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), 269 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
282 signal_strength_dbm_(INT32_MIN), 270 signal_strength_dbm_(INT32_MIN),
283 min_signal_strength_since_connection_change_(INT32_MAX), 271 min_signal_strength_since_connection_change_(INT32_MAX),
(...skipping 28 matching lines...) Expand all
312 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE); 300 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE);
313 external_estimate_provider_->SetUpdatedEstimateDelegate(this); 301 external_estimate_provider_->SetUpdatedEstimateDelegate(this);
314 } else { 302 } else {
315 RecordExternalEstimateProviderMetrics( 303 RecordExternalEstimateProviderMetrics(
316 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE); 304 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE);
317 } 305 }
318 current_network_id_ = GetCurrentNetworkID(); 306 current_network_id_ = GetCurrentNetworkID();
319 AddDefaultEstimates(); 307 AddDefaultEstimates();
320 308
321 throughput_analyzer_.reset(new nqe::internal::ThroughputAnalyzer( 309 throughput_analyzer_.reset(new nqe::internal::ThroughputAnalyzer(
322 &params_, base::ThreadTaskRunnerHandle::Get(), 310 params_.get(), base::ThreadTaskRunnerHandle::Get(),
323 base::Bind(&NetworkQualityEstimator::OnNewThroughputObservationAvailable, 311 base::Bind(&NetworkQualityEstimator::OnNewThroughputObservationAvailable,
324 base::Unretained(this)), 312 base::Unretained(this)),
325 use_localhost_requests_, use_smaller_responses_for_tests)); 313 use_localhost_requests_, use_smaller_responses_for_tests));
326 314
327 watcher_factory_.reset(new nqe::internal::SocketWatcherFactory( 315 watcher_factory_.reset(new nqe::internal::SocketWatcherFactory(
328 base::ThreadTaskRunnerHandle::Get(), 316 base::ThreadTaskRunnerHandle::Get(),
329 params_.min_socket_watcher_notification_interval(), 317 params_->min_socket_watcher_notification_interval(),
330 base::Bind(&NetworkQualityEstimator::OnUpdatedRTTAvailable, 318 base::Bind(&NetworkQualityEstimator::OnUpdatedRTTAvailable,
331 base::Unretained(this)), 319 base::Unretained(this)),
332 tick_clock_.get())); 320 tick_clock_.get()));
333 321
334 // Record accuracy after a 15 second interval. The values used here must 322 // Record accuracy after a 15 second interval. The values used here must
335 // remain in sync with the suffixes specified in 323 // remain in sync with the suffixes specified in
336 // tools/metrics/histograms/histograms.xml. 324 // tools/metrics/histograms/histograms.xml.
337 accuracy_recording_intervals_.push_back(base::TimeDelta::FromSeconds(15)); 325 accuracy_recording_intervals_.push_back(base::TimeDelta::FromSeconds(15));
338 326
339 for (int i = 0; i < STATISTIC_LAST; ++i) 327 for (int i = 0; i < STATISTIC_LAST; ++i)
340 http_rtt_at_last_main_frame_[i] = nqe::internal::InvalidRTT(); 328 http_rtt_at_last_main_frame_[i] = nqe::internal::InvalidRTT();
341 } 329 }
342 330
343 void NetworkQualityEstimator::AddDefaultEstimates() { 331 void NetworkQualityEstimator::AddDefaultEstimates() {
344 DCHECK(thread_checker_.CalledOnValidThread()); 332 DCHECK(thread_checker_.CalledOnValidThread());
345 333
346 if (!add_default_platform_observations_) 334 if (!add_default_platform_observations_)
347 return; 335 return;
348 336
349 if (params_.DefaultObservation(current_network_id_.type).http_rtt() != 337 if (params_->DefaultObservation(current_network_id_.type).http_rtt() !=
350 nqe::internal::InvalidRTT()) { 338 nqe::internal::InvalidRTT()) {
351 RttObservation rtt_observation( 339 RttObservation rtt_observation(
352 params_.DefaultObservation(current_network_id_.type).http_rtt(), 340 params_->DefaultObservation(current_network_id_.type).http_rtt(),
353 tick_clock_->NowTicks(), INT32_MIN, 341 tick_clock_->NowTicks(), INT32_MIN,
354 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM); 342 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM);
355 rtt_observations_.AddObservation(rtt_observation); 343 rtt_observations_.AddObservation(rtt_observation);
356 NotifyObserversOfRTT(rtt_observation); 344 NotifyObserversOfRTT(rtt_observation);
357 } 345 }
358 346
359 if (params_.DefaultObservation(current_network_id_.type).transport_rtt() != 347 if (params_->DefaultObservation(current_network_id_.type).transport_rtt() !=
360 nqe::internal::InvalidRTT()) { 348 nqe::internal::InvalidRTT()) {
361 RttObservation rtt_observation( 349 RttObservation rtt_observation(
362 params_.DefaultObservation(current_network_id_.type).transport_rtt(), 350 params_->DefaultObservation(current_network_id_.type).transport_rtt(),
363 tick_clock_->NowTicks(), INT32_MIN, 351 tick_clock_->NowTicks(), INT32_MIN,
364 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM); 352 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM);
365 rtt_observations_.AddObservation(rtt_observation); 353 rtt_observations_.AddObservation(rtt_observation);
366 NotifyObserversOfRTT(rtt_observation); 354 NotifyObserversOfRTT(rtt_observation);
367 } 355 }
368 356
369 if (params_.DefaultObservation(current_network_id_.type) 357 if (params_->DefaultObservation(current_network_id_.type)
370 .downstream_throughput_kbps() != nqe::internal::kInvalidThroughput) { 358 .downstream_throughput_kbps() != nqe::internal::kInvalidThroughput) {
371 ThroughputObservation throughput_observation( 359 ThroughputObservation throughput_observation(
372 params_.DefaultObservation(current_network_id_.type) 360 params_->DefaultObservation(current_network_id_.type)
373 .downstream_throughput_kbps(), 361 .downstream_throughput_kbps(),
374 tick_clock_->NowTicks(), INT32_MIN, 362 tick_clock_->NowTicks(), INT32_MIN,
375 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM); 363 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM);
376 downstream_throughput_kbps_observations_.AddObservation( 364 downstream_throughput_kbps_observations_.AddObservation(
377 throughput_observation); 365 throughput_observation);
378 NotifyObserversOfThroughput(throughput_observation); 366 NotifyObserversOfThroughput(throughput_observation);
379 } 367 }
380 } 368 }
381 369
382 NetworkQualityEstimator::~NetworkQualityEstimator() { 370 NetworkQualityEstimator::~NetworkQualityEstimator() {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 RecordCorrelationMetric(request, net_error); 595 RecordCorrelationMetric(request, net_error);
608 } 596 }
609 597
610 void NetworkQualityEstimator::RecordCorrelationMetric(const URLRequest& request, 598 void NetworkQualityEstimator::RecordCorrelationMetric(const URLRequest& request,
611 int net_error) const { 599 int net_error) const {
612 DCHECK(thread_checker_.CalledOnValidThread()); 600 DCHECK(thread_checker_.CalledOnValidThread());
613 601
614 // The histogram is recorded randomly to reduce overhead involved with sparse 602 // The histogram is recorded randomly to reduce overhead involved with sparse
615 // histograms. Furthermore, recording the correlation on each request is 603 // histograms. Furthermore, recording the correlation on each request is
616 // unnecessary. 604 // unnecessary.
617 if (RandDouble() >= params_.correlation_uma_logging_probability()) 605 if (RandDouble() >= params_->correlation_uma_logging_probability())
618 return; 606 return;
619 607
620 if (request.response_info().was_cached || 608 if (request.response_info().was_cached ||
621 !request.response_info().network_accessed) { 609 !request.response_info().network_accessed) {
622 return; 610 return;
623 } 611 }
624 612
625 LoadTimingInfo load_timing_info; 613 LoadTimingInfo load_timing_info;
626 request.GetLoadTimingInfo(&load_timing_info); 614 request.GetLoadTimingInfo(&load_timing_info);
627 // If the load timing info is unavailable, it probably means that the request 615 // If the load timing info is unavailable, it probably means that the request
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 disable_offline_check_ = disable_offline_check; 755 disable_offline_check_ = disable_offline_check;
768 network_quality_store_->DisableOfflineCheckForTesting(disable_offline_check_); 756 network_quality_store_->DisableOfflineCheckForTesting(disable_offline_check_);
769 } 757 }
770 758
771 void NetworkQualityEstimator::ReportEffectiveConnectionTypeForTesting( 759 void NetworkQualityEstimator::ReportEffectiveConnectionTypeForTesting(
772 EffectiveConnectionType effective_connection_type) { 760 EffectiveConnectionType effective_connection_type) {
773 DCHECK(thread_checker_.CalledOnValidThread()); 761 DCHECK(thread_checker_.CalledOnValidThread());
774 762
775 event_creator_.MaybeAddNetworkQualityChangedEventToNetLog( 763 event_creator_.MaybeAddNetworkQualityChangedEventToNetLog(
776 effective_connection_type_, 764 effective_connection_type_,
777 params_.TypicalNetworkQuality(effective_connection_type)); 765 params_->TypicalNetworkQuality(effective_connection_type));
778 766
779 for (auto& observer : effective_connection_type_observer_list_) 767 for (auto& observer : effective_connection_type_observer_list_)
780 observer.OnEffectiveConnectionTypeChanged(effective_connection_type); 768 observer.OnEffectiveConnectionTypeChanged(effective_connection_type);
781 769
782 network_quality_store_->Add(current_network_id_, 770 network_quality_store_->Add(current_network_id_,
783 nqe::internal::CachedNetworkQuality( 771 nqe::internal::CachedNetworkQuality(
784 tick_clock_->NowTicks(), network_quality_, 772 tick_clock_->NowTicks(), network_quality_,
785 effective_connection_type)); 773 effective_connection_type));
786 } 774 }
787 775
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 last_effective_connection_type_computation_, 814 last_effective_connection_type_computation_,
827 network_quality_, effective_connection_type_)); 815 network_quality_, effective_connection_type_));
828 816
829 // Clear the local state. 817 // Clear the local state.
830 last_connection_change_ = tick_clock_->NowTicks(); 818 last_connection_change_ = tick_clock_->NowTicks();
831 peak_network_quality_ = nqe::internal::NetworkQuality(); 819 peak_network_quality_ = nqe::internal::NetworkQuality();
832 downstream_throughput_kbps_observations_.Clear(); 820 downstream_throughput_kbps_observations_.Clear();
833 rtt_observations_.Clear(); 821 rtt_observations_.Clear();
834 822
835 #if defined(OS_ANDROID) 823 #if defined(OS_ANDROID)
836 if (params_.weight_multiplier_per_dbm() < 1.0 && 824 if (params_->weight_multiplier_per_dbm() < 1.0 &&
837 NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) { 825 NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) {
838 UMA_HISTOGRAM_BOOLEAN( 826 UMA_HISTOGRAM_BOOLEAN(
839 "NQE.CellularSignalStrengthAvailable", 827 "NQE.CellularSignalStrengthAvailable",
840 min_signal_strength_since_connection_change_ != INT32_MAX && 828 min_signal_strength_since_connection_change_ != INT32_MAX &&
841 max_signal_strength_since_connection_change_ != INT32_MIN); 829 max_signal_strength_since_connection_change_ != INT32_MIN);
842 830
843 if (min_signal_strength_since_connection_change_ != INT32_MAX && 831 if (min_signal_strength_since_connection_change_ != INT32_MAX &&
844 max_signal_strength_since_connection_change_ != INT32_MIN) { 832 max_signal_strength_since_connection_change_ != INT32_MIN) {
845 UMA_HISTOGRAM_COUNTS_100( 833 UMA_HISTOGRAM_COUNTS_100(
846 "NQE.CellularSignalStrengthDifference", 834 "NQE.CellularSignalStrengthDifference",
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET && 876 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET &&
889 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) { 877 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) {
890 RecordExternalEstimateProviderMetrics( 878 RecordExternalEstimateProviderMetrics(
891 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED); 879 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED);
892 external_estimate_provider_->Update(); 880 external_estimate_provider_->Update();
893 } 881 }
894 } 882 }
895 883
896 void NetworkQualityEstimator::UpdateSignalStrength() { 884 void NetworkQualityEstimator::UpdateSignalStrength() {
897 #if defined(OS_ANDROID) 885 #if defined(OS_ANDROID)
898 if (params_.weight_multiplier_per_dbm() >= 1.0 || 886 if (params_->weight_multiplier_per_dbm() >= 1.0 ||
899 !NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type) || 887 !NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type) ||
900 !android::cellular_signal_strength::GetSignalStrengthDbm( 888 !android::cellular_signal_strength::GetSignalStrengthDbm(
901 &signal_strength_dbm_)) { 889 &signal_strength_dbm_)) {
902 signal_strength_dbm_ = INT32_MIN; 890 signal_strength_dbm_ = INT32_MIN;
903 } 891 }
904 min_signal_strength_since_connection_change_ = std::min( 892 min_signal_strength_since_connection_change_ = std::min(
905 min_signal_strength_since_connection_change_, signal_strength_dbm_); 893 min_signal_strength_since_connection_change_, signal_strength_dbm_);
906 max_signal_strength_since_connection_change_ = std::max( 894 max_signal_strength_since_connection_change_ = std::max(
907 max_signal_strength_since_connection_change_, signal_strength_dbm_); 895 max_signal_strength_since_connection_change_, signal_strength_dbm_);
908 #endif // OS_ANDROID 896 #endif // OS_ANDROID
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 "NQE.EstimateAvailable.MainFrame.Kbps", 1011 "NQE.EstimateAvailable.MainFrame.Kbps",
1024 estimated_quality_at_last_main_frame_.downstream_throughput_kbps() != 1012 estimated_quality_at_last_main_frame_.downstream_throughput_kbps() !=
1025 nqe::internal::kInvalidThroughput); 1013 nqe::internal::kInvalidThroughput);
1026 1014
1027 UMA_HISTOGRAM_ENUMERATION("NQE.MainFrame.EffectiveConnectionType", 1015 UMA_HISTOGRAM_ENUMERATION("NQE.MainFrame.EffectiveConnectionType",
1028 effective_connection_type_at_last_main_frame_, 1016 effective_connection_type_at_last_main_frame_,
1029 EFFECTIVE_CONNECTION_TYPE_LAST); 1017 EFFECTIVE_CONNECTION_TYPE_LAST);
1030 base::HistogramBase* effective_connection_type_histogram = 1018 base::HistogramBase* effective_connection_type_histogram =
1031 base::Histogram::FactoryGet( 1019 base::Histogram::FactoryGet(
1032 std::string("NQE.MainFrame.EffectiveConnectionType.") + 1020 std::string("NQE.MainFrame.EffectiveConnectionType.") +
1033 nqe::internal::NetworkQualityEstimatorParams:: 1021 NetworkQualityEstimatorParams::GetNameForConnectionType(
1034 GetNameForConnectionType(current_network_id_.type), 1022 current_network_id_.type),
1035 0, EFFECTIVE_CONNECTION_TYPE_LAST, 1023 0, EFFECTIVE_CONNECTION_TYPE_LAST,
1036 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, 1024 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */,
1037 base::HistogramBase::kUmaTargetedHistogramFlag); 1025 base::HistogramBase::kUmaTargetedHistogramFlag);
1038 1026
1039 effective_connection_type_histogram->Add( 1027 effective_connection_type_histogram->Add(
1040 effective_connection_type_at_last_main_frame_); 1028 effective_connection_type_at_last_main_frame_);
1041 1029
1042 // Record the HTTP RTT at the main frames for experimental statistics. 1030 // Record the HTTP RTT at the main frames for experimental statistics.
1043 for (int i = 0; i < STATISTIC_LAST; ++i) { 1031 for (int i = 0; i < STATISTIC_LAST; ++i) {
1044 if (http_rtt_at_last_main_frame_[i] != nqe::internal::InvalidRTT()) { 1032 if (http_rtt_at_last_main_frame_[i] != nqe::internal::InvalidRTT()) {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 NetworkQualityEstimator::MetricUsage downstream_throughput_kbps_metric, 1172 NetworkQualityEstimator::MetricUsage downstream_throughput_kbps_metric,
1185 base::TimeDelta* http_rtt, 1173 base::TimeDelta* http_rtt,
1186 base::TimeDelta* transport_rtt, 1174 base::TimeDelta* transport_rtt,
1187 int32_t* downstream_throughput_kbps) const { 1175 int32_t* downstream_throughput_kbps) const {
1188 DCHECK(thread_checker_.CalledOnValidThread()); 1176 DCHECK(thread_checker_.CalledOnValidThread());
1189 1177
1190 *http_rtt = nqe::internal::InvalidRTT(); 1178 *http_rtt = nqe::internal::InvalidRTT();
1191 *transport_rtt = nqe::internal::InvalidRTT(); 1179 *transport_rtt = nqe::internal::InvalidRTT();
1192 *downstream_throughput_kbps = nqe::internal::kInvalidThroughput; 1180 *downstream_throughput_kbps = nqe::internal::kInvalidThroughput;
1193 1181
1194 if (params_.forced_effective_connection_type()) { 1182 if (params_->forced_effective_connection_type()) {
1195 *http_rtt = params_ 1183 *http_rtt = params_
1196 .TypicalNetworkQuality( 1184 ->TypicalNetworkQuality(
1197 params_.forced_effective_connection_type().value()) 1185 params_->forced_effective_connection_type().value())
1198 .http_rtt(); 1186 .http_rtt();
1199 *transport_rtt = params_ 1187 *transport_rtt =
1200 .TypicalNetworkQuality( 1188 params_
1201 params_.forced_effective_connection_type().value()) 1189 ->TypicalNetworkQuality(
1202 .transport_rtt(); 1190 params_->forced_effective_connection_type().value())
1191 .transport_rtt();
1203 *downstream_throughput_kbps = 1192 *downstream_throughput_kbps =
1204 params_ 1193 params_
1205 .TypicalNetworkQuality( 1194 ->TypicalNetworkQuality(
1206 params_.forced_effective_connection_type().value()) 1195 params_->forced_effective_connection_type().value())
1207 .downstream_throughput_kbps(); 1196 .downstream_throughput_kbps();
1208 return params_.forced_effective_connection_type().value(); 1197 return params_->forced_effective_connection_type().value();
1209 } 1198 }
1210 1199
1211 // If the device is currently offline, then return 1200 // If the device is currently offline, then return
1212 // EFFECTIVE_CONNECTION_TYPE_OFFLINE. 1201 // EFFECTIVE_CONNECTION_TYPE_OFFLINE.
1213 1202
1214 if (current_network_id_.type == NetworkChangeNotifier::CONNECTION_NONE && 1203 if (current_network_id_.type == NetworkChangeNotifier::CONNECTION_NONE &&
1215 !disable_offline_check_) { 1204 !disable_offline_check_) {
1216 return EFFECTIVE_CONNECTION_TYPE_OFFLINE; 1205 return EFFECTIVE_CONNECTION_TYPE_OFFLINE;
1217 } 1206 }
1218 1207
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 // EffectiveConnectionType that best matches the current connection's 1242 // EffectiveConnectionType that best matches the current connection's
1254 // performance. The match is done by comparing RTT and throughput. 1243 // performance. The match is done by comparing RTT and throughput.
1255 for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) { 1244 for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) {
1256 EffectiveConnectionType type = static_cast<EffectiveConnectionType>(i); 1245 EffectiveConnectionType type = static_cast<EffectiveConnectionType>(i);
1257 if (i == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) 1246 if (i == EFFECTIVE_CONNECTION_TYPE_UNKNOWN)
1258 continue; 1247 continue;
1259 1248
1260 const bool estimated_http_rtt_is_higher_than_threshold = 1249 const bool estimated_http_rtt_is_higher_than_threshold =
1261 http_rtt_metric != NetworkQualityEstimator::MetricUsage::DO_NOT_USE && 1250 http_rtt_metric != NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1262 *http_rtt != nqe::internal::InvalidRTT() && 1251 *http_rtt != nqe::internal::InvalidRTT() &&
1263 params_.ConnectionThreshold(type).http_rtt() != 1252 params_->ConnectionThreshold(type).http_rtt() !=
1264 nqe::internal::InvalidRTT() && 1253 nqe::internal::InvalidRTT() &&
1265 *http_rtt >= params_.ConnectionThreshold(type).http_rtt(); 1254 *http_rtt >= params_->ConnectionThreshold(type).http_rtt();
1266 1255
1267 const bool estimated_transport_rtt_is_higher_than_threshold = 1256 const bool estimated_transport_rtt_is_higher_than_threshold =
1268 transport_rtt_metric != 1257 transport_rtt_metric !=
1269 NetworkQualityEstimator::MetricUsage::DO_NOT_USE && 1258 NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1270 *transport_rtt != nqe::internal::InvalidRTT() && 1259 *transport_rtt != nqe::internal::InvalidRTT() &&
1271 params_.ConnectionThreshold(type).transport_rtt() != 1260 params_->ConnectionThreshold(type).transport_rtt() !=
1272 nqe::internal::InvalidRTT() && 1261 nqe::internal::InvalidRTT() &&
1273 *transport_rtt >= params_.ConnectionThreshold(type).transport_rtt(); 1262 *transport_rtt >= params_->ConnectionThreshold(type).transport_rtt();
1274 1263
1275 const bool estimated_throughput_is_lower_than_threshold = 1264 const bool estimated_throughput_is_lower_than_threshold =
1276 downstream_throughput_kbps_metric != 1265 downstream_throughput_kbps_metric !=
1277 NetworkQualityEstimator::MetricUsage::DO_NOT_USE && 1266 NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1278 *downstream_throughput_kbps != nqe::internal::kInvalidThroughput && 1267 *downstream_throughput_kbps != nqe::internal::kInvalidThroughput &&
1279 params_.ConnectionThreshold(type).downstream_throughput_kbps() != 1268 params_->ConnectionThreshold(type).downstream_throughput_kbps() !=
1280 nqe::internal::kInvalidThroughput && 1269 nqe::internal::kInvalidThroughput &&
1281 *downstream_throughput_kbps <= 1270 *downstream_throughput_kbps <=
1282 params_.ConnectionThreshold(type).downstream_throughput_kbps(); 1271 params_->ConnectionThreshold(type).downstream_throughput_kbps();
1283 1272
1284 if (estimated_http_rtt_is_higher_than_threshold || 1273 if (estimated_http_rtt_is_higher_than_threshold ||
1285 estimated_transport_rtt_is_higher_than_threshold || 1274 estimated_transport_rtt_is_higher_than_threshold ||
1286 estimated_throughput_is_lower_than_threshold) { 1275 estimated_throughput_is_lower_than_threshold) {
1287 return type; 1276 return type;
1288 } 1277 }
1289 } 1278 }
1290 // Return the fastest connection type. 1279 // Return the fastest connection type.
1291 return static_cast<EffectiveConnectionType>(EFFECTIVE_CONNECTION_TYPE_LAST - 1280 return static_cast<EffectiveConnectionType>(EFFECTIVE_CONNECTION_TYPE_LAST -
1292 1); 1281 1);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 1451
1463 if (network_id.type == NetworkChangeNotifier::GetConnectionType()) 1452 if (network_id.type == NetworkChangeNotifier::GetConnectionType())
1464 return network_id; 1453 return network_id;
1465 } 1454 }
1466 NOTREACHED(); 1455 NOTREACHED();
1467 } 1456 }
1468 1457
1469 bool NetworkQualityEstimator::ReadCachedNetworkQualityEstimate() { 1458 bool NetworkQualityEstimator::ReadCachedNetworkQualityEstimate() {
1470 DCHECK(thread_checker_.CalledOnValidThread()); 1459 DCHECK(thread_checker_.CalledOnValidThread());
1471 1460
1472 if (!params_.persistent_cache_reading_enabled()) 1461 if (!params_->persistent_cache_reading_enabled())
1473 return false; 1462 return false;
1474 1463
1475 nqe::internal::CachedNetworkQuality cached_network_quality; 1464 nqe::internal::CachedNetworkQuality cached_network_quality;
1476 1465
1477 const bool cached_estimate_available = network_quality_store_->GetById( 1466 const bool cached_estimate_available = network_quality_store_->GetById(
1478 current_network_id_, &cached_network_quality); 1467 current_network_id_, &cached_network_quality);
1479 if (network_quality_store_->EligibleForCaching(current_network_id_)) { 1468 if (network_quality_store_->EligibleForCaching(current_network_id_)) {
1480 UMA_HISTOGRAM_BOOLEAN("NQE.CachedNetworkQualityAvailable", 1469 UMA_HISTOGRAM_BOOLEAN("NQE.CachedNetworkQualityAvailable",
1481 cached_estimate_available); 1470 cached_estimate_available);
1482 } 1471 }
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 // RTT and throughput values are not set in the prefs. 1741 // RTT and throughput values are not set in the prefs.
1753 DCHECK_EQ(nqe::internal::InvalidRTT(), 1742 DCHECK_EQ(nqe::internal::InvalidRTT(),
1754 it.second.network_quality().http_rtt()); 1743 it.second.network_quality().http_rtt());
1755 DCHECK_EQ(nqe::internal::InvalidRTT(), 1744 DCHECK_EQ(nqe::internal::InvalidRTT(),
1756 it.second.network_quality().transport_rtt()); 1745 it.second.network_quality().transport_rtt());
1757 DCHECK_EQ(nqe::internal::kInvalidThroughput, 1746 DCHECK_EQ(nqe::internal::kInvalidThroughput,
1758 it.second.network_quality().downstream_throughput_kbps()); 1747 it.second.network_quality().downstream_throughput_kbps());
1759 1748
1760 nqe::internal::CachedNetworkQuality cached_network_quality( 1749 nqe::internal::CachedNetworkQuality cached_network_quality(
1761 base::TimeTicks::Now(), 1750 base::TimeTicks::Now(),
1762 params_.TypicalNetworkQuality(effective_connection_type), 1751 params_->TypicalNetworkQuality(effective_connection_type),
1763 effective_connection_type); 1752 effective_connection_type);
1764 1753
1765 network_quality_store_->Add(it.first, cached_network_quality); 1754 network_quality_store_->Add(it.first, cached_network_quality);
1766 MaybeUpdateNetworkQualityFromCache(it.first, cached_network_quality); 1755 MaybeUpdateNetworkQualityFromCache(it.first, cached_network_quality);
1767 } 1756 }
1768 } 1757 }
1769 1758
1770 base::Optional<base::TimeDelta> NetworkQualityEstimator::GetHttpRTT() const { 1759 base::Optional<base::TimeDelta> NetworkQualityEstimator::GetHttpRTT() const {
1771 DCHECK(thread_checker_.CalledOnValidThread()); 1760 DCHECK(thread_checker_.CalledOnValidThread());
1772 1761
(...skipping 20 matching lines...) Expand all
1793 return base::Optional<int32_t>(); 1782 return base::Optional<int32_t>();
1794 } 1783 }
1795 return network_quality_.downstream_throughput_kbps(); 1784 return network_quality_.downstream_throughput_kbps();
1796 } 1785 }
1797 1786
1798 void NetworkQualityEstimator::MaybeUpdateNetworkQualityFromCache( 1787 void NetworkQualityEstimator::MaybeUpdateNetworkQualityFromCache(
1799 const nqe::internal::NetworkID& network_id, 1788 const nqe::internal::NetworkID& network_id,
1800 const nqe::internal::CachedNetworkQuality& cached_network_quality) { 1789 const nqe::internal::CachedNetworkQuality& cached_network_quality) {
1801 DCHECK(thread_checker_.CalledOnValidThread()); 1790 DCHECK(thread_checker_.CalledOnValidThread());
1802 1791
1803 if (!params_.persistent_cache_reading_enabled()) 1792 if (!params_->persistent_cache_reading_enabled())
1804 return; 1793 return;
1805 if (network_id != current_network_id_) 1794 if (network_id != current_network_id_)
1806 return; 1795 return;
1807 1796
1808 // Since the cached network quality is for the current network, add it to 1797 // Since the cached network quality is for the current network, add it to
1809 // the current observations. 1798 // the current observations.
1810 RttObservation http_rtt_observation( 1799 RttObservation http_rtt_observation(
1811 cached_network_quality.network_quality().http_rtt(), 1800 cached_network_quality.network_quality().http_rtt(),
1812 base::TimeTicks::Now(), INT32_MIN, 1801 base::TimeTicks::Now(), INT32_MIN,
1813 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); 1802 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 return "UnweightedAverage"; 1834 return "UnweightedAverage";
1846 case STATISTIC_LAST: 1835 case STATISTIC_LAST:
1847 NOTREACHED(); 1836 NOTREACHED();
1848 return ""; 1837 return "";
1849 } 1838 }
1850 NOTREACHED(); 1839 NOTREACHED();
1851 return ""; 1840 return "";
1852 } 1841 }
1853 1842
1854 } // namespace net 1843 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_params.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698