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 24 matching lines...) Expand all Loading... |
35 #include "net/http/http_response_info.h" | 35 #include "net/http/http_response_info.h" |
36 #include "net/http/http_status_code.h" | 36 #include "net/http/http_status_code.h" |
37 #include "net/nqe/network_quality_estimator_params.h" | 37 #include "net/nqe/network_quality_estimator_params.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_status.h" | 41 #include "net/url_request/url_request_status.h" |
42 #include "url/gurl.h" | 42 #include "url/gurl.h" |
43 | 43 |
44 #if defined(OS_ANDROID) | 44 #if defined(OS_ANDROID) |
45 #include "net/android/cellular_signal_strength.h" | |
46 #include "net/android/network_library.h" | 45 #include "net/android/network_library.h" |
47 #endif // OS_ANDROID | 46 #endif // OS_ANDROID |
48 | 47 |
49 namespace net { | 48 namespace net { |
50 | 49 |
51 namespace { | 50 namespace { |
52 | 51 |
53 // Returns the histogram that should be used to record the given statistic. | 52 // 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. | 53 // |max_limit| is the maximum value that can be stored in the histogram. |
55 base::HistogramBase* GetHistogram(const std::string& statistic_name, | 54 base::HistogramBase* GetHistogram(const std::string& statistic_name, |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, | 245 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, |
247 {"TransportRTTOrDownstreamThroughput", | 246 {"TransportRTTOrDownstreamThroughput", |
248 EffectiveConnectionTypeAlgorithm:: | 247 EffectiveConnectionTypeAlgorithm:: |
249 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}), | 248 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}), |
250 use_localhost_requests_(use_local_host_requests_for_tests), | 249 use_localhost_requests_(use_local_host_requests_for_tests), |
251 use_small_responses_(use_smaller_responses_for_tests), | 250 use_small_responses_(use_smaller_responses_for_tests), |
252 disable_offline_check_(false), | 251 disable_offline_check_(false), |
253 add_default_platform_observations_(add_default_platform_observations), | 252 add_default_platform_observations_(add_default_platform_observations), |
254 weight_multiplier_per_second_( | 253 weight_multiplier_per_second_( |
255 nqe::internal::GetWeightMultiplierPerSecond(variation_params)), | 254 nqe::internal::GetWeightMultiplierPerSecond(variation_params)), |
256 weight_multiplier_per_dbm_( | 255 weight_multiplier_per_signal_strength_level_( |
257 nqe::internal::GetWeightMultiplierPerDbm(variation_params)), | 256 nqe::internal::GetWeightMultiplierPerSignalStrengthLevel( |
| 257 variation_params)), |
258 effective_connection_type_algorithm_( | 258 effective_connection_type_algorithm_( |
259 algorithm_name_to_enum_.find( | 259 algorithm_name_to_enum_.find( |
260 nqe::internal::GetEffectiveConnectionTypeAlgorithm( | 260 nqe::internal::GetEffectiveConnectionTypeAlgorithm( |
261 variation_params)) == algorithm_name_to_enum_.end() | 261 variation_params)) == algorithm_name_to_enum_.end() |
262 ? kDefaultEffectiveConnectionTypeAlgorithm | 262 ? kDefaultEffectiveConnectionTypeAlgorithm |
263 : algorithm_name_to_enum_ | 263 : algorithm_name_to_enum_ |
264 .find(nqe::internal::GetEffectiveConnectionTypeAlgorithm( | 264 .find(nqe::internal::GetEffectiveConnectionTypeAlgorithm( |
265 variation_params)) | 265 variation_params)) |
266 ->second), | 266 ->second), |
267 tick_clock_(new base::DefaultTickClock()), | 267 tick_clock_(new base::DefaultTickClock()), |
268 last_connection_change_(tick_clock_->NowTicks()), | 268 last_connection_change_(tick_clock_->NowTicks()), |
269 current_network_id_(nqe::internal::NetworkID( | 269 current_network_id_(nqe::internal::NetworkID( |
270 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, | 270 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, |
271 std::string())), | 271 std::string())), |
272 downstream_throughput_kbps_observations_(weight_multiplier_per_second_, | 272 downstream_throughput_kbps_observations_( |
273 weight_multiplier_per_dbm_), | 273 weight_multiplier_per_second_, |
| 274 weight_multiplier_per_signal_strength_level_), |
274 rtt_observations_(weight_multiplier_per_second_, | 275 rtt_observations_(weight_multiplier_per_second_, |
275 weight_multiplier_per_dbm_), | 276 weight_multiplier_per_signal_strength_level_), |
276 effective_connection_type_at_last_main_frame_( | 277 effective_connection_type_at_last_main_frame_( |
277 EFFECTIVE_CONNECTION_TYPE_UNKNOWN), | 278 EFFECTIVE_CONNECTION_TYPE_UNKNOWN), |
278 external_estimate_provider_(std::move(external_estimates_provider)), | 279 external_estimate_provider_(std::move(external_estimates_provider)), |
279 effective_connection_type_recomputation_interval_( | 280 effective_connection_type_recomputation_interval_( |
280 base::TimeDelta::FromSeconds(10)), | 281 base::TimeDelta::FromSeconds(10)), |
281 rtt_observations_size_at_last_ect_computation_(0), | 282 rtt_observations_size_at_last_ect_computation_(0), |
282 throughput_observations_size_at_last_ect_computation_(0), | 283 throughput_observations_size_at_last_ect_computation_(0), |
283 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), | 284 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), |
284 signal_strength_dbm_(INT32_MIN), | |
285 min_signal_strength_since_connection_change_(INT32_MAX), | |
286 max_signal_strength_since_connection_change_(INT32_MIN), | |
287 correlation_uma_logging_probability_( | 285 correlation_uma_logging_probability_( |
288 nqe::internal::correlation_uma_logging_probability(variation_params)), | 286 nqe::internal::correlation_uma_logging_probability(variation_params)), |
289 forced_effective_connection_type_set_( | 287 forced_effective_connection_type_set_( |
290 nqe::internal::forced_effective_connection_type_set( | 288 nqe::internal::forced_effective_connection_type_set( |
291 variation_params)), | 289 variation_params)), |
292 forced_effective_connection_type_( | 290 forced_effective_connection_type_( |
293 nqe::internal::forced_effective_connection_type(variation_params)), | 291 nqe::internal::forced_effective_connection_type(variation_params)), |
294 persistent_cache_reading_enabled_( | 292 persistent_cache_reading_enabled_( |
295 nqe::internal::persistent_cache_reading_enabled(variation_params)), | 293 nqe::internal::persistent_cache_reading_enabled(variation_params)), |
296 event_creator_(net_log), | 294 event_creator_(net_log), |
(...skipping 14 matching lines...) Expand all Loading... |
311 | 309 |
312 DCHECK_EQ(algorithm_name_to_enum_.size(), | 310 DCHECK_EQ(algorithm_name_to_enum_.size(), |
313 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: | 311 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: |
314 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); | 312 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); |
315 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: | 313 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: |
316 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, | 314 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, |
317 effective_connection_type_algorithm_); | 315 effective_connection_type_algorithm_); |
318 | 316 |
319 network_quality_store_.reset(new nqe::internal::NetworkQualityStore()); | 317 network_quality_store_.reset(new nqe::internal::NetworkQualityStore()); |
320 ObtainOperatingParams(variation_params); | 318 ObtainOperatingParams(variation_params); |
| 319 |
| 320 #if defined(OS_ANDROID) |
| 321 if (weight_multiplier_per_signal_strength_level_ < 1.0) |
| 322 cellular_signal_strength_.reset(new android::CellularSignalStrength()); |
| 323 #endif // OS_ANDROID |
| 324 |
321 NetworkChangeNotifier::AddConnectionTypeObserver(this); | 325 NetworkChangeNotifier::AddConnectionTypeObserver(this); |
322 if (external_estimate_provider_) { | 326 if (external_estimate_provider_) { |
323 RecordExternalEstimateProviderMetrics( | 327 RecordExternalEstimateProviderMetrics( |
324 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE); | 328 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE); |
325 external_estimate_provider_->SetUpdatedEstimateDelegate(this); | 329 external_estimate_provider_->SetUpdatedEstimateDelegate(this); |
326 } else { | 330 } else { |
327 RecordExternalEstimateProviderMetrics( | 331 RecordExternalEstimateProviderMetrics( |
328 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE); | 332 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE); |
329 } | 333 } |
330 current_network_id_ = GetCurrentNetworkID(); | 334 current_network_id_ = GetCurrentNetworkID(); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 base::TimeDelta observed_http_rtt = | 490 base::TimeDelta observed_http_rtt = |
487 load_timing_info.receive_headers_end - load_timing_info.send_start; | 491 load_timing_info.receive_headers_end - load_timing_info.send_start; |
488 DCHECK_GE(observed_http_rtt, base::TimeDelta()); | 492 DCHECK_GE(observed_http_rtt, base::TimeDelta()); |
489 if (observed_http_rtt < peak_network_quality_.http_rtt() || | 493 if (observed_http_rtt < peak_network_quality_.http_rtt() || |
490 peak_network_quality_.http_rtt() == nqe::internal::InvalidRTT()) { | 494 peak_network_quality_.http_rtt() == nqe::internal::InvalidRTT()) { |
491 peak_network_quality_ = nqe::internal::NetworkQuality( | 495 peak_network_quality_ = nqe::internal::NetworkQuality( |
492 observed_http_rtt, peak_network_quality_.transport_rtt(), | 496 observed_http_rtt, peak_network_quality_.transport_rtt(), |
493 peak_network_quality_.downstream_throughput_kbps()); | 497 peak_network_quality_.downstream_throughput_kbps()); |
494 } | 498 } |
495 | 499 |
496 RttObservation http_rtt_observation( | 500 RttObservation http_rtt_observation(observed_http_rtt, |
497 observed_http_rtt, tick_clock_->NowTicks(), signal_strength_dbm_, | 501 tick_clock_->NowTicks(), signal_strength_, |
498 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP); | 502 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP); |
499 rtt_observations_.AddObservation(http_rtt_observation); | 503 rtt_observations_.AddObservation(http_rtt_observation); |
500 NotifyObserversOfRTT(http_rtt_observation); | 504 NotifyObserversOfRTT(http_rtt_observation); |
501 } | 505 } |
502 | 506 |
503 void NetworkQualityEstimator::RecordAccuracyAfterMainFrame( | 507 void NetworkQualityEstimator::RecordAccuracyAfterMainFrame( |
504 base::TimeDelta measuring_duration) const { | 508 base::TimeDelta measuring_duration) const { |
505 DCHECK(thread_checker_.CalledOnValidThread()); | 509 DCHECK(thread_checker_.CalledOnValidThread()); |
506 DCHECK_EQ(0, measuring_duration.InMilliseconds() % 1000); | 510 DCHECK_EQ(0, measuring_duration.InMilliseconds() % 1000); |
507 DCHECK(ContainsValue(GetAccuracyRecordingIntervals(), measuring_duration)); | 511 DCHECK(ContainsValue(GetAccuracyRecordingIntervals(), measuring_duration)); |
508 | 512 |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 last_effective_connection_type_computation_, | 853 last_effective_connection_type_computation_, |
850 network_quality_, effective_connection_type_)); | 854 network_quality_, effective_connection_type_)); |
851 | 855 |
852 // Clear the local state. | 856 // Clear the local state. |
853 last_connection_change_ = tick_clock_->NowTicks(); | 857 last_connection_change_ = tick_clock_->NowTicks(); |
854 peak_network_quality_ = nqe::internal::NetworkQuality(); | 858 peak_network_quality_ = nqe::internal::NetworkQuality(); |
855 downstream_throughput_kbps_observations_.Clear(); | 859 downstream_throughput_kbps_observations_.Clear(); |
856 rtt_observations_.Clear(); | 860 rtt_observations_.Clear(); |
857 | 861 |
858 #if defined(OS_ANDROID) | 862 #if defined(OS_ANDROID) |
859 if (weight_multiplier_per_dbm_ < 1.0 && | 863 if (cellular_signal_strength_ && |
860 NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) { | 864 NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) { |
861 UMA_HISTOGRAM_BOOLEAN( | 865 bool signal_strength_available = |
862 "NQE.CellularSignalStrengthAvailable", | 866 min_signal_strength_since_connection_change_ && |
863 min_signal_strength_since_connection_change_ != INT32_MAX && | 867 max_signal_strength_since_connection_change_; |
864 max_signal_strength_since_connection_change_ != INT32_MIN); | 868 UMA_HISTOGRAM_BOOLEAN("NQE.CellularSignalStrength.LevelAvailable", |
| 869 signal_strength_available); |
865 | 870 |
866 if (min_signal_strength_since_connection_change_ != INT32_MAX && | 871 if (signal_strength_available) { |
867 max_signal_strength_since_connection_change_ != INT32_MIN) { | |
868 UMA_HISTOGRAM_COUNTS_100( | 872 UMA_HISTOGRAM_COUNTS_100( |
869 "NQE.CellularSignalStrengthDifference", | 873 "NQE.CellularSignalStrength.LevelDifference", |
870 max_signal_strength_since_connection_change_ - | 874 max_signal_strength_since_connection_change_.value() - |
871 min_signal_strength_since_connection_change_); | 875 min_signal_strength_since_connection_change_.value()); |
872 } | 876 } |
873 } | 877 } |
874 #endif // OS_ANDROID | 878 #endif // OS_ANDROID |
875 signal_strength_dbm_ = INT32_MIN; | 879 signal_strength_.reset(); |
876 min_signal_strength_since_connection_change_ = INT32_MAX; | 880 min_signal_strength_since_connection_change_.reset(); |
877 max_signal_strength_since_connection_change_ = INT32_MIN; | 881 max_signal_strength_since_connection_change_.reset(); |
878 network_quality_ = nqe::internal::NetworkQuality(); | 882 network_quality_ = nqe::internal::NetworkQuality(); |
879 effective_connection_type_ = EFFECTIVE_CONNECTION_TYPE_UNKNOWN; | 883 effective_connection_type_ = EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
880 effective_connection_type_at_last_main_frame_ = | 884 effective_connection_type_at_last_main_frame_ = |
881 EFFECTIVE_CONNECTION_TYPE_UNKNOWN; | 885 EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
882 rtt_observations_size_at_last_ect_computation_ = 0; | 886 rtt_observations_size_at_last_ect_computation_ = 0; |
883 throughput_observations_size_at_last_ect_computation_ = 0; | 887 throughput_observations_size_at_last_ect_computation_ = 0; |
884 | 888 |
885 // Update the local state as part of preparation for the new connection. | 889 // Update the local state as part of preparation for the new connection. |
886 current_network_id_ = GetCurrentNetworkID(); | 890 current_network_id_ = GetCurrentNetworkID(); |
887 RecordNetworkIDAvailability(); | 891 RecordNetworkIDAvailability(); |
(...skipping 22 matching lines...) Expand all Loading... |
910 current_network_id_.type != NetworkChangeNotifier::CONNECTION_UNKNOWN && | 914 current_network_id_.type != NetworkChangeNotifier::CONNECTION_UNKNOWN && |
911 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET && | 915 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET && |
912 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) { | 916 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) { |
913 RecordExternalEstimateProviderMetrics( | 917 RecordExternalEstimateProviderMetrics( |
914 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED); | 918 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED); |
915 external_estimate_provider_->Update(); | 919 external_estimate_provider_->Update(); |
916 } | 920 } |
917 } | 921 } |
918 | 922 |
919 void NetworkQualityEstimator::UpdateSignalStrength() { | 923 void NetworkQualityEstimator::UpdateSignalStrength() { |
| 924 DCHECK(thread_checker_.CalledOnValidThread()); |
| 925 |
| 926 signal_strength_.reset(); |
920 #if defined(OS_ANDROID) | 927 #if defined(OS_ANDROID) |
921 if (weight_multiplier_per_dbm_ >= 1.0 || | 928 if (!cellular_signal_strength_) |
922 !NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type) || | 929 return; |
923 !android::cellular_signal_strength::GetSignalStrengthDbm( | 930 if (!NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) |
924 &signal_strength_dbm_)) { | 931 return; |
925 signal_strength_dbm_ = INT32_MIN; | 932 |
926 } | 933 signal_strength_ = cellular_signal_strength_->GetSignalStrengthLevel(); |
927 min_signal_strength_since_connection_change_ = std::min( | 934 |
928 min_signal_strength_since_connection_change_, signal_strength_dbm_); | 935 if (!signal_strength_) |
929 max_signal_strength_since_connection_change_ = std::max( | 936 return; |
930 max_signal_strength_since_connection_change_, signal_strength_dbm_); | 937 |
| 938 min_signal_strength_since_connection_change_ = |
| 939 std::min(min_signal_strength_since_connection_change_.value_or(INT32_MAX), |
| 940 signal_strength_.value()); |
| 941 max_signal_strength_since_connection_change_ = |
| 942 std::max(max_signal_strength_since_connection_change_.value_or(INT32_MIN), |
| 943 signal_strength_.value()); |
931 #endif // OS_ANDROID | 944 #endif // OS_ANDROID |
932 } | 945 } |
933 | 946 |
934 void NetworkQualityEstimator::RecordMetricsOnConnectionTypeChanged() const { | 947 void NetworkQualityEstimator::RecordMetricsOnConnectionTypeChanged() const { |
935 DCHECK(thread_checker_.CalledOnValidThread()); | 948 DCHECK(thread_checker_.CalledOnValidThread()); |
936 if (peak_network_quality_.http_rtt() != nqe::internal::InvalidRTT()) { | 949 if (peak_network_quality_.http_rtt() != nqe::internal::InvalidRTT()) { |
937 base::HistogramBase* rtt_histogram = | 950 base::HistogramBase* rtt_histogram = |
938 GetHistogram("FastestRTT.", current_network_id_.type, 10 * 1000); | 951 GetHistogram("FastestRTT.", current_network_id_.type, 10 * 1000); |
939 rtt_histogram->Add(peak_network_quality_.http_rtt().InMilliseconds()); | 952 rtt_histogram->Add(peak_network_quality_.http_rtt().InMilliseconds()); |
940 } | 953 } |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 const base::Optional<Statistic>& statistic, | 1386 const base::Optional<Statistic>& statistic, |
1374 int percentile) const { | 1387 int percentile) const { |
1375 DCHECK(thread_checker_.CalledOnValidThread()); | 1388 DCHECK(thread_checker_.CalledOnValidThread()); |
1376 | 1389 |
1377 // RTT observations are sorted by duration from shortest to longest, thus | 1390 // RTT observations are sorted by duration from shortest to longest, thus |
1378 // a higher percentile RTT will have a longer RTT than a lower percentile. | 1391 // a higher percentile RTT will have a longer RTT than a lower percentile. |
1379 base::TimeDelta rtt = nqe::internal::InvalidRTT(); | 1392 base::TimeDelta rtt = nqe::internal::InvalidRTT(); |
1380 | 1393 |
1381 if (!statistic) { | 1394 if (!statistic) { |
1382 // Use default statistic algorithm. | 1395 // Use default statistic algorithm. |
1383 if (!rtt_observations_.GetPercentile(start_time, signal_strength_dbm_, &rtt, | 1396 if (!rtt_observations_.GetPercentile(start_time, signal_strength_, &rtt, |
1384 percentile, | 1397 percentile, |
1385 disallowed_observation_sources)) { | 1398 disallowed_observation_sources)) { |
1386 return nqe::internal::InvalidRTT(); | 1399 return nqe::internal::InvalidRTT(); |
1387 } | 1400 } |
1388 return rtt; | 1401 return rtt; |
1389 } | 1402 } |
1390 | 1403 |
1391 switch (statistic.value()) { | 1404 switch (statistic.value()) { |
1392 case STATISTIC_LAST: | 1405 case STATISTIC_LAST: |
1393 NOTREACHED(); | 1406 NOTREACHED(); |
1394 return nqe::internal::InvalidRTT(); | 1407 return nqe::internal::InvalidRTT(); |
1395 case STATISTIC_WEIGHTED_AVERAGE: | 1408 case STATISTIC_WEIGHTED_AVERAGE: |
1396 if (!rtt_observations_.GetWeightedAverage( | 1409 if (!rtt_observations_.GetWeightedAverage(start_time, signal_strength_, |
1397 start_time, signal_strength_dbm_, disallowed_observation_sources, | 1410 disallowed_observation_sources, |
1398 &rtt)) { | 1411 &rtt)) { |
1399 return nqe::internal::InvalidRTT(); | 1412 return nqe::internal::InvalidRTT(); |
1400 } | 1413 } |
1401 return rtt; | 1414 return rtt; |
1402 case STATISTIC_UNWEIGHTED_AVERAGE: | 1415 case STATISTIC_UNWEIGHTED_AVERAGE: |
1403 if (!rtt_observations_.GetUnweightedAverage( | 1416 if (!rtt_observations_.GetUnweightedAverage( |
1404 start_time, signal_strength_dbm_, disallowed_observation_sources, | 1417 start_time, signal_strength_, disallowed_observation_sources, |
1405 &rtt)) { | 1418 &rtt)) { |
1406 return nqe::internal::InvalidRTT(); | 1419 return nqe::internal::InvalidRTT(); |
1407 } | 1420 } |
1408 return rtt; | 1421 return rtt; |
1409 } | 1422 } |
1410 NOTREACHED(); | 1423 NOTREACHED(); |
1411 return nqe::internal::InvalidRTT(); | 1424 return nqe::internal::InvalidRTT(); |
1412 } | 1425 } |
1413 | 1426 |
1414 int32_t NetworkQualityEstimator::GetDownlinkThroughputKbpsEstimateInternal( | 1427 int32_t NetworkQualityEstimator::GetDownlinkThroughputKbpsEstimateInternal( |
1415 const base::TimeTicks& start_time, | 1428 const base::TimeTicks& start_time, |
1416 int percentile) const { | 1429 int percentile) const { |
1417 DCHECK(thread_checker_.CalledOnValidThread()); | 1430 DCHECK(thread_checker_.CalledOnValidThread()); |
1418 | 1431 |
1419 // Throughput observations are sorted by kbps from slowest to fastest, | 1432 // Throughput observations are sorted by kbps from slowest to fastest, |
1420 // thus a higher percentile throughput will be faster than a lower one. | 1433 // thus a higher percentile throughput will be faster than a lower one. |
1421 int32_t kbps = nqe::internal::kInvalidThroughput; | 1434 int32_t kbps = nqe::internal::kInvalidThroughput; |
1422 if (!downstream_throughput_kbps_observations_.GetPercentile( | 1435 if (!downstream_throughput_kbps_observations_.GetPercentile( |
1423 start_time, signal_strength_dbm_, &kbps, 100 - percentile, | 1436 start_time, signal_strength_, &kbps, 100 - percentile, |
1424 std::vector<NetworkQualityObservationSource>())) { | 1437 std::vector<NetworkQualityObservationSource>())) { |
1425 return nqe::internal::kInvalidThroughput; | 1438 return nqe::internal::kInvalidThroughput; |
1426 } | 1439 } |
1427 return kbps; | 1440 return kbps; |
1428 } | 1441 } |
1429 | 1442 |
1430 nqe::internal::NetworkID NetworkQualityEstimator::GetCurrentNetworkID() const { | 1443 nqe::internal::NetworkID NetworkQualityEstimator::GetCurrentNetworkID() const { |
1431 DCHECK(thread_checker_.CalledOnValidThread()); | 1444 DCHECK(thread_checker_.CalledOnValidThread()); |
1432 | 1445 |
1433 // TODO(tbansal): crbug.com/498068 Add NetworkQualityEstimatorAndroid class | 1446 // TODO(tbansal): crbug.com/498068 Add NetworkQualityEstimatorAndroid class |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1536 RecordExternalEstimateProviderMetrics( | 1549 RecordExternalEstimateProviderMetrics( |
1537 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK); | 1550 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK); |
1538 | 1551 |
1539 external_estimate_provider_quality_ = nqe::internal::NetworkQuality(); | 1552 external_estimate_provider_quality_ = nqe::internal::NetworkQuality(); |
1540 | 1553 |
1541 if (rtt > base::TimeDelta()) { | 1554 if (rtt > base::TimeDelta()) { |
1542 RecordExternalEstimateProviderMetrics( | 1555 RecordExternalEstimateProviderMetrics( |
1543 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE); | 1556 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE); |
1544 UMA_HISTOGRAM_TIMES("NQE.ExternalEstimateProvider.RTT", rtt); | 1557 UMA_HISTOGRAM_TIMES("NQE.ExternalEstimateProvider.RTT", rtt); |
1545 RttObservation rtt_observation( | 1558 RttObservation rtt_observation( |
1546 rtt, tick_clock_->NowTicks(), signal_strength_dbm_, | 1559 rtt, tick_clock_->NowTicks(), signal_strength_, |
1547 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE); | 1560 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE); |
1548 rtt_observations_.AddObservation(rtt_observation); | 1561 rtt_observations_.AddObservation(rtt_observation); |
1549 external_estimate_provider_quality_.set_http_rtt(rtt); | 1562 external_estimate_provider_quality_.set_http_rtt(rtt); |
1550 NotifyObserversOfRTT(rtt_observation); | 1563 NotifyObserversOfRTT(rtt_observation); |
1551 } | 1564 } |
1552 | 1565 |
1553 if (downstream_throughput_kbps > 0) { | 1566 if (downstream_throughput_kbps > 0) { |
1554 RecordExternalEstimateProviderMetrics( | 1567 RecordExternalEstimateProviderMetrics( |
1555 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE); | 1568 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE); |
1556 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth", | 1569 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth", |
1557 downstream_throughput_kbps); | 1570 downstream_throughput_kbps); |
1558 ThroughputObservation throughput_observation( | 1571 ThroughputObservation throughput_observation( |
1559 downstream_throughput_kbps, tick_clock_->NowTicks(), | 1572 downstream_throughput_kbps, tick_clock_->NowTicks(), signal_strength_, |
1560 signal_strength_dbm_, | |
1561 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE); | 1573 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE); |
1562 downstream_throughput_kbps_observations_.AddObservation( | 1574 downstream_throughput_kbps_observations_.AddObservation( |
1563 throughput_observation); | 1575 throughput_observation); |
1564 external_estimate_provider_quality_.set_downstream_throughput_kbps( | 1576 external_estimate_provider_quality_.set_downstream_throughput_kbps( |
1565 downstream_throughput_kbps); | 1577 downstream_throughput_kbps); |
1566 NotifyObserversOfThroughput(throughput_observation); | 1578 NotifyObserversOfThroughput(throughput_observation); |
1567 } | 1579 } |
1568 } | 1580 } |
1569 | 1581 |
1570 void NetworkQualityEstimator::SetTickClockForTesting( | 1582 void NetworkQualityEstimator::SetTickClockForTesting( |
1571 std::unique_ptr<base::TickClock> tick_clock) { | 1583 std::unique_ptr<base::TickClock> tick_clock) { |
1572 DCHECK(thread_checker_.CalledOnValidThread()); | 1584 DCHECK(thread_checker_.CalledOnValidThread()); |
1573 tick_clock_ = std::move(tick_clock); | 1585 tick_clock_ = std::move(tick_clock); |
1574 } | 1586 } |
1575 | 1587 |
1576 double NetworkQualityEstimator::RandDouble() const { | 1588 double NetworkQualityEstimator::RandDouble() const { |
1577 return base::RandDouble(); | 1589 return base::RandDouble(); |
1578 } | 1590 } |
1579 | 1591 |
1580 void NetworkQualityEstimator::OnUpdatedRTTAvailable( | 1592 void NetworkQualityEstimator::OnUpdatedRTTAvailable( |
1581 SocketPerformanceWatcherFactory::Protocol protocol, | 1593 SocketPerformanceWatcherFactory::Protocol protocol, |
1582 const base::TimeDelta& rtt) { | 1594 const base::TimeDelta& rtt) { |
1583 DCHECK(thread_checker_.CalledOnValidThread()); | 1595 DCHECK(thread_checker_.CalledOnValidThread()); |
1584 DCHECK_NE(nqe::internal::InvalidRTT(), rtt); | 1596 DCHECK_NE(nqe::internal::InvalidRTT(), rtt); |
1585 | 1597 |
1586 RttObservation observation(rtt, tick_clock_->NowTicks(), signal_strength_dbm_, | 1598 RttObservation observation(rtt, tick_clock_->NowTicks(), signal_strength_, |
1587 ProtocolSourceToObservationSource(protocol)); | 1599 ProtocolSourceToObservationSource(protocol)); |
1588 NotifyObserversOfRTT(observation); | 1600 NotifyObserversOfRTT(observation); |
1589 rtt_observations_.AddObservation(observation); | 1601 rtt_observations_.AddObservation(observation); |
1590 } | 1602 } |
1591 | 1603 |
1592 void NetworkQualityEstimator::NotifyObserversOfRTT( | 1604 void NetworkQualityEstimator::NotifyObserversOfRTT( |
1593 const RttObservation& observation) { | 1605 const RttObservation& observation) { |
1594 DCHECK(thread_checker_.CalledOnValidThread()); | 1606 DCHECK(thread_checker_.CalledOnValidThread()); |
1595 DCHECK_NE(nqe::internal::InvalidRTT(), observation.value); | 1607 DCHECK_NE(nqe::internal::InvalidRTT(), observation.value); |
1596 DCHECK_GT(NETWORK_QUALITY_OBSERVATION_SOURCE_MAX, observation.source); | 1608 DCHECK_GT(NETWORK_QUALITY_OBSERVATION_SOURCE_MAX, observation.source); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1635 DCHECK_NE(nqe::internal::kInvalidThroughput, downstream_kbps); | 1647 DCHECK_NE(nqe::internal::kInvalidThroughput, downstream_kbps); |
1636 | 1648 |
1637 if (downstream_kbps > peak_network_quality_.downstream_throughput_kbps() || | 1649 if (downstream_kbps > peak_network_quality_.downstream_throughput_kbps() || |
1638 peak_network_quality_.downstream_throughput_kbps() == | 1650 peak_network_quality_.downstream_throughput_kbps() == |
1639 nqe::internal::kInvalidThroughput) { | 1651 nqe::internal::kInvalidThroughput) { |
1640 peak_network_quality_ = nqe::internal::NetworkQuality( | 1652 peak_network_quality_ = nqe::internal::NetworkQuality( |
1641 peak_network_quality_.http_rtt(), peak_network_quality_.transport_rtt(), | 1653 peak_network_quality_.http_rtt(), peak_network_quality_.transport_rtt(), |
1642 downstream_kbps); | 1654 downstream_kbps); |
1643 } | 1655 } |
1644 ThroughputObservation throughput_observation( | 1656 ThroughputObservation throughput_observation( |
1645 downstream_kbps, tick_clock_->NowTicks(), signal_strength_dbm_, | 1657 downstream_kbps, tick_clock_->NowTicks(), signal_strength_, |
1646 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP); | 1658 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP); |
1647 downstream_throughput_kbps_observations_.AddObservation( | 1659 downstream_throughput_kbps_observations_.AddObservation( |
1648 throughput_observation); | 1660 throughput_observation); |
1649 NotifyObserversOfThroughput(throughput_observation); | 1661 NotifyObserversOfThroughput(throughput_observation); |
1650 } | 1662 } |
1651 | 1663 |
1652 void NetworkQualityEstimator::MaybeComputeEffectiveConnectionType() { | 1664 void NetworkQualityEstimator::MaybeComputeEffectiveConnectionType() { |
1653 DCHECK(thread_checker_.CalledOnValidThread()); | 1665 DCHECK(thread_checker_.CalledOnValidThread()); |
1654 | 1666 |
1655 const base::TimeTicks now = tick_clock_->NowTicks(); | 1667 const base::TimeTicks now = tick_clock_->NowTicks(); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1844 return base::Optional<base::TimeDelta>(); | 1856 return base::Optional<base::TimeDelta>(); |
1845 } | 1857 } |
1846 | 1858 |
1847 base::Optional<int32_t> | 1859 base::Optional<int32_t> |
1848 NetworkQualityEstimator::NetworkQualityProvider::GetDownstreamThroughputKbps() | 1860 NetworkQualityEstimator::NetworkQualityProvider::GetDownstreamThroughputKbps() |
1849 const { | 1861 const { |
1850 return base::Optional<int32_t>(); | 1862 return base::Optional<int32_t>(); |
1851 } | 1863 } |
1852 | 1864 |
1853 } // namespace net | 1865 } // namespace net |
OLD | NEW |