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 signal_strength_(INT32_MIN), |
285 min_signal_strength_since_connection_change_(INT32_MAX), | 286 min_signal_strength_since_connection_change_(INT32_MAX), |
286 max_signal_strength_since_connection_change_(INT32_MIN), | 287 max_signal_strength_since_connection_change_(INT32_MIN), |
287 correlation_uma_logging_probability_( | 288 correlation_uma_logging_probability_( |
288 nqe::internal::correlation_uma_logging_probability(variation_params)), | 289 nqe::internal::correlation_uma_logging_probability(variation_params)), |
289 forced_effective_connection_type_set_( | 290 forced_effective_connection_type_set_( |
290 nqe::internal::forced_effective_connection_type_set( | 291 nqe::internal::forced_effective_connection_type_set( |
291 variation_params)), | 292 variation_params)), |
292 forced_effective_connection_type_( | 293 forced_effective_connection_type_( |
293 nqe::internal::forced_effective_connection_type(variation_params)), | 294 nqe::internal::forced_effective_connection_type(variation_params)), |
294 persistent_cache_reading_enabled_( | 295 persistent_cache_reading_enabled_( |
(...skipping 16 matching lines...) Expand all Loading... | |
311 | 312 |
312 DCHECK_EQ(algorithm_name_to_enum_.size(), | 313 DCHECK_EQ(algorithm_name_to_enum_.size(), |
313 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: | 314 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: |
314 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); | 315 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); |
315 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: | 316 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: |
316 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, | 317 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, |
317 effective_connection_type_algorithm_); | 318 effective_connection_type_algorithm_); |
318 | 319 |
319 network_quality_store_.reset(new nqe::internal::NetworkQualityStore()); | 320 network_quality_store_.reset(new nqe::internal::NetworkQualityStore()); |
320 ObtainOperatingParams(variation_params); | 321 ObtainOperatingParams(variation_params); |
322 | |
323 #if defined(OS_ANDROID) | |
324 if (weight_multiplier_per_signal_strength_level_ < 1.0) | |
325 cellular_signal_strength_.reset(new android::CellularSignalStrength()); | |
326 #endif // OS_ANDROID | |
327 | |
321 NetworkChangeNotifier::AddConnectionTypeObserver(this); | 328 NetworkChangeNotifier::AddConnectionTypeObserver(this); |
322 if (external_estimate_provider_) { | 329 if (external_estimate_provider_) { |
323 RecordExternalEstimateProviderMetrics( | 330 RecordExternalEstimateProviderMetrics( |
324 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE); | 331 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE); |
325 external_estimate_provider_->SetUpdatedEstimateDelegate(this); | 332 external_estimate_provider_->SetUpdatedEstimateDelegate(this); |
326 } else { | 333 } else { |
327 RecordExternalEstimateProviderMetrics( | 334 RecordExternalEstimateProviderMetrics( |
328 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE); | 335 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE); |
329 } | 336 } |
330 current_network_id_ = GetCurrentNetworkID(); | 337 current_network_id_ = GetCurrentNetworkID(); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 base::TimeDelta observed_http_rtt = | 493 base::TimeDelta observed_http_rtt = |
487 load_timing_info.receive_headers_end - load_timing_info.send_start; | 494 load_timing_info.receive_headers_end - load_timing_info.send_start; |
488 DCHECK_GE(observed_http_rtt, base::TimeDelta()); | 495 DCHECK_GE(observed_http_rtt, base::TimeDelta()); |
489 if (observed_http_rtt < peak_network_quality_.http_rtt() || | 496 if (observed_http_rtt < peak_network_quality_.http_rtt() || |
490 peak_network_quality_.http_rtt() == nqe::internal::InvalidRTT()) { | 497 peak_network_quality_.http_rtt() == nqe::internal::InvalidRTT()) { |
491 peak_network_quality_ = nqe::internal::NetworkQuality( | 498 peak_network_quality_ = nqe::internal::NetworkQuality( |
492 observed_http_rtt, peak_network_quality_.transport_rtt(), | 499 observed_http_rtt, peak_network_quality_.transport_rtt(), |
493 peak_network_quality_.downstream_throughput_kbps()); | 500 peak_network_quality_.downstream_throughput_kbps()); |
494 } | 501 } |
495 | 502 |
496 RttObservation http_rtt_observation( | 503 RttObservation http_rtt_observation(observed_http_rtt, |
497 observed_http_rtt, tick_clock_->NowTicks(), signal_strength_dbm_, | 504 tick_clock_->NowTicks(), signal_strength_, |
498 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP); | 505 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP); |
499 rtt_observations_.AddObservation(http_rtt_observation); | 506 rtt_observations_.AddObservation(http_rtt_observation); |
500 NotifyObserversOfRTT(http_rtt_observation); | 507 NotifyObserversOfRTT(http_rtt_observation); |
501 } | 508 } |
502 | 509 |
503 void NetworkQualityEstimator::RecordAccuracyAfterMainFrame( | 510 void NetworkQualityEstimator::RecordAccuracyAfterMainFrame( |
504 base::TimeDelta measuring_duration) const { | 511 base::TimeDelta measuring_duration) const { |
505 DCHECK(thread_checker_.CalledOnValidThread()); | 512 DCHECK(thread_checker_.CalledOnValidThread()); |
506 DCHECK_EQ(0, measuring_duration.InMilliseconds() % 1000); | 513 DCHECK_EQ(0, measuring_duration.InMilliseconds() % 1000); |
507 DCHECK(ContainsValue(GetAccuracyRecordingIntervals(), measuring_duration)); | 514 DCHECK(ContainsValue(GetAccuracyRecordingIntervals(), measuring_duration)); |
508 | 515 |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
849 last_effective_connection_type_computation_, | 856 last_effective_connection_type_computation_, |
850 network_quality_, effective_connection_type_)); | 857 network_quality_, effective_connection_type_)); |
851 | 858 |
852 // Clear the local state. | 859 // Clear the local state. |
853 last_connection_change_ = tick_clock_->NowTicks(); | 860 last_connection_change_ = tick_clock_->NowTicks(); |
854 peak_network_quality_ = nqe::internal::NetworkQuality(); | 861 peak_network_quality_ = nqe::internal::NetworkQuality(); |
855 downstream_throughput_kbps_observations_.Clear(); | 862 downstream_throughput_kbps_observations_.Clear(); |
856 rtt_observations_.Clear(); | 863 rtt_observations_.Clear(); |
857 | 864 |
858 #if defined(OS_ANDROID) | 865 #if defined(OS_ANDROID) |
859 if (weight_multiplier_per_dbm_ < 1.0 && | 866 if (cellular_signal_strength_ && |
860 NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) { | 867 NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) { |
861 UMA_HISTOGRAM_BOOLEAN( | 868 UMA_HISTOGRAM_BOOLEAN( |
862 "NQE.CellularSignalStrengthAvailable", | 869 "NQE.CellularSignalStrength.LevelAvailable", |
863 min_signal_strength_since_connection_change_ != INT32_MAX && | 870 min_signal_strength_since_connection_change_ != INT32_MAX && |
864 max_signal_strength_since_connection_change_ != INT32_MIN); | 871 max_signal_strength_since_connection_change_ != INT32_MIN); |
865 | 872 |
866 if (min_signal_strength_since_connection_change_ != INT32_MAX && | 873 if (min_signal_strength_since_connection_change_ != INT32_MAX && |
867 max_signal_strength_since_connection_change_ != INT32_MIN) { | 874 max_signal_strength_since_connection_change_ != INT32_MIN) { |
868 UMA_HISTOGRAM_COUNTS_100( | 875 UMA_HISTOGRAM_COUNTS_100( |
869 "NQE.CellularSignalStrengthDifference", | 876 "NQE.CellularSignalStrength.LevelDifference", |
870 max_signal_strength_since_connection_change_ - | 877 max_signal_strength_since_connection_change_ - |
871 min_signal_strength_since_connection_change_); | 878 min_signal_strength_since_connection_change_); |
872 } | 879 } |
873 } | 880 } |
874 #endif // OS_ANDROID | 881 #endif // OS_ANDROID |
875 signal_strength_dbm_ = INT32_MIN; | 882 signal_strength_ = INT32_MIN; |
RyanSturm
2017/03/22 21:51:08
Is this the right bound (would 0 and 6 work for mi
tbansal1
2017/03/23 18:28:53
I have changed these to base::Optional.
| |
876 min_signal_strength_since_connection_change_ = INT32_MAX; | 883 min_signal_strength_since_connection_change_ = INT32_MAX; |
877 max_signal_strength_since_connection_change_ = INT32_MIN; | 884 max_signal_strength_since_connection_change_ = INT32_MIN; |
878 network_quality_ = nqe::internal::NetworkQuality(); | 885 network_quality_ = nqe::internal::NetworkQuality(); |
879 effective_connection_type_ = EFFECTIVE_CONNECTION_TYPE_UNKNOWN; | 886 effective_connection_type_ = EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
880 effective_connection_type_at_last_main_frame_ = | 887 effective_connection_type_at_last_main_frame_ = |
881 EFFECTIVE_CONNECTION_TYPE_UNKNOWN; | 888 EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
882 rtt_observations_size_at_last_ect_computation_ = 0; | 889 rtt_observations_size_at_last_ect_computation_ = 0; |
883 throughput_observations_size_at_last_ect_computation_ = 0; | 890 throughput_observations_size_at_last_ect_computation_ = 0; |
884 | 891 |
885 // Update the local state as part of preparation for the new connection. | 892 // Update the local state as part of preparation for the new connection. |
(...skipping 24 matching lines...) Expand all Loading... | |
910 current_network_id_.type != NetworkChangeNotifier::CONNECTION_UNKNOWN && | 917 current_network_id_.type != NetworkChangeNotifier::CONNECTION_UNKNOWN && |
911 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET && | 918 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET && |
912 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) { | 919 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) { |
913 RecordExternalEstimateProviderMetrics( | 920 RecordExternalEstimateProviderMetrics( |
914 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED); | 921 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED); |
915 external_estimate_provider_->Update(); | 922 external_estimate_provider_->Update(); |
916 } | 923 } |
917 } | 924 } |
918 | 925 |
919 void NetworkQualityEstimator::UpdateSignalStrength() { | 926 void NetworkQualityEstimator::UpdateSignalStrength() { |
927 DCHECK(thread_checker_.CalledOnValidThread()); | |
928 | |
920 #if defined(OS_ANDROID) | 929 #if defined(OS_ANDROID) |
921 if (weight_multiplier_per_dbm_ >= 1.0 || | 930 if (!cellular_signal_strength_ || |
922 !NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type) || | 931 !NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type) || |
923 !android::cellular_signal_strength::GetSignalStrengthDbm( | 932 !cellular_signal_strength_->GetSignalStrengthLevel(&signal_strength_)) { |
924 &signal_strength_dbm_)) { | 933 signal_strength_ = INT32_MIN; |
925 signal_strength_dbm_ = INT32_MIN; | |
926 } | 934 } |
927 min_signal_strength_since_connection_change_ = std::min( | 935 min_signal_strength_since_connection_change_ = |
928 min_signal_strength_since_connection_change_, signal_strength_dbm_); | 936 std::min(min_signal_strength_since_connection_change_, signal_strength_); |
929 max_signal_strength_since_connection_change_ = std::max( | 937 max_signal_strength_since_connection_change_ = |
930 max_signal_strength_since_connection_change_, signal_strength_dbm_); | 938 std::max(max_signal_strength_since_connection_change_, signal_strength_); |
931 #endif // OS_ANDROID | 939 #endif // OS_ANDROID |
932 } | 940 } |
933 | 941 |
934 void NetworkQualityEstimator::RecordMetricsOnConnectionTypeChanged() const { | 942 void NetworkQualityEstimator::RecordMetricsOnConnectionTypeChanged() const { |
935 DCHECK(thread_checker_.CalledOnValidThread()); | 943 DCHECK(thread_checker_.CalledOnValidThread()); |
936 if (peak_network_quality_.http_rtt() != nqe::internal::InvalidRTT()) { | 944 if (peak_network_quality_.http_rtt() != nqe::internal::InvalidRTT()) { |
937 base::HistogramBase* rtt_histogram = | 945 base::HistogramBase* rtt_histogram = |
938 GetHistogram("FastestRTT.", current_network_id_.type, 10 * 1000); | 946 GetHistogram("FastestRTT.", current_network_id_.type, 10 * 1000); |
939 rtt_histogram->Add(peak_network_quality_.http_rtt().InMilliseconds()); | 947 rtt_histogram->Add(peak_network_quality_.http_rtt().InMilliseconds()); |
940 } | 948 } |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1373 const base::Optional<Statistic>& statistic, | 1381 const base::Optional<Statistic>& statistic, |
1374 int percentile) const { | 1382 int percentile) const { |
1375 DCHECK(thread_checker_.CalledOnValidThread()); | 1383 DCHECK(thread_checker_.CalledOnValidThread()); |
1376 | 1384 |
1377 // RTT observations are sorted by duration from shortest to longest, thus | 1385 // 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. | 1386 // a higher percentile RTT will have a longer RTT than a lower percentile. |
1379 base::TimeDelta rtt = nqe::internal::InvalidRTT(); | 1387 base::TimeDelta rtt = nqe::internal::InvalidRTT(); |
1380 | 1388 |
1381 if (!statistic) { | 1389 if (!statistic) { |
1382 // Use default statistic algorithm. | 1390 // Use default statistic algorithm. |
1383 if (!rtt_observations_.GetPercentile(start_time, signal_strength_dbm_, &rtt, | 1391 if (!rtt_observations_.GetPercentile(start_time, signal_strength_, &rtt, |
1384 percentile, | 1392 percentile, |
1385 disallowed_observation_sources)) { | 1393 disallowed_observation_sources)) { |
1386 return nqe::internal::InvalidRTT(); | 1394 return nqe::internal::InvalidRTT(); |
1387 } | 1395 } |
1388 return rtt; | 1396 return rtt; |
1389 } | 1397 } |
1390 | 1398 |
1391 switch (statistic.value()) { | 1399 switch (statistic.value()) { |
1392 case STATISTIC_LAST: | 1400 case STATISTIC_LAST: |
1393 NOTREACHED(); | 1401 NOTREACHED(); |
1394 return nqe::internal::InvalidRTT(); | 1402 return nqe::internal::InvalidRTT(); |
1395 case STATISTIC_WEIGHTED_AVERAGE: | 1403 case STATISTIC_WEIGHTED_AVERAGE: |
1396 if (!rtt_observations_.GetWeightedAverage( | 1404 if (!rtt_observations_.GetWeightedAverage(start_time, signal_strength_, |
1397 start_time, signal_strength_dbm_, disallowed_observation_sources, | 1405 disallowed_observation_sources, |
1398 &rtt)) { | 1406 &rtt)) { |
1399 return nqe::internal::InvalidRTT(); | 1407 return nqe::internal::InvalidRTT(); |
1400 } | 1408 } |
1401 return rtt; | 1409 return rtt; |
1402 case STATISTIC_UNWEIGHTED_AVERAGE: | 1410 case STATISTIC_UNWEIGHTED_AVERAGE: |
1403 if (!rtt_observations_.GetUnweightedAverage( | 1411 if (!rtt_observations_.GetUnweightedAverage( |
1404 start_time, signal_strength_dbm_, disallowed_observation_sources, | 1412 start_time, signal_strength_, disallowed_observation_sources, |
1405 &rtt)) { | 1413 &rtt)) { |
1406 return nqe::internal::InvalidRTT(); | 1414 return nqe::internal::InvalidRTT(); |
1407 } | 1415 } |
1408 return rtt; | 1416 return rtt; |
1409 } | 1417 } |
1410 NOTREACHED(); | 1418 NOTREACHED(); |
1411 return nqe::internal::InvalidRTT(); | 1419 return nqe::internal::InvalidRTT(); |
1412 } | 1420 } |
1413 | 1421 |
1414 int32_t NetworkQualityEstimator::GetDownlinkThroughputKbpsEstimateInternal( | 1422 int32_t NetworkQualityEstimator::GetDownlinkThroughputKbpsEstimateInternal( |
1415 const base::TimeTicks& start_time, | 1423 const base::TimeTicks& start_time, |
1416 int percentile) const { | 1424 int percentile) const { |
1417 DCHECK(thread_checker_.CalledOnValidThread()); | 1425 DCHECK(thread_checker_.CalledOnValidThread()); |
1418 | 1426 |
1419 // Throughput observations are sorted by kbps from slowest to fastest, | 1427 // Throughput observations are sorted by kbps from slowest to fastest, |
1420 // thus a higher percentile throughput will be faster than a lower one. | 1428 // thus a higher percentile throughput will be faster than a lower one. |
1421 int32_t kbps = nqe::internal::kInvalidThroughput; | 1429 int32_t kbps = nqe::internal::kInvalidThroughput; |
1422 if (!downstream_throughput_kbps_observations_.GetPercentile( | 1430 if (!downstream_throughput_kbps_observations_.GetPercentile( |
1423 start_time, signal_strength_dbm_, &kbps, 100 - percentile, | 1431 start_time, signal_strength_, &kbps, 100 - percentile, |
1424 std::vector<NetworkQualityObservationSource>())) { | 1432 std::vector<NetworkQualityObservationSource>())) { |
1425 return nqe::internal::kInvalidThroughput; | 1433 return nqe::internal::kInvalidThroughput; |
1426 } | 1434 } |
1427 return kbps; | 1435 return kbps; |
1428 } | 1436 } |
1429 | 1437 |
1430 nqe::internal::NetworkID NetworkQualityEstimator::GetCurrentNetworkID() const { | 1438 nqe::internal::NetworkID NetworkQualityEstimator::GetCurrentNetworkID() const { |
1431 DCHECK(thread_checker_.CalledOnValidThread()); | 1439 DCHECK(thread_checker_.CalledOnValidThread()); |
1432 | 1440 |
1433 // TODO(tbansal): crbug.com/498068 Add NetworkQualityEstimatorAndroid class | 1441 // TODO(tbansal): crbug.com/498068 Add NetworkQualityEstimatorAndroid class |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1536 RecordExternalEstimateProviderMetrics( | 1544 RecordExternalEstimateProviderMetrics( |
1537 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK); | 1545 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK); |
1538 | 1546 |
1539 external_estimate_provider_quality_ = nqe::internal::NetworkQuality(); | 1547 external_estimate_provider_quality_ = nqe::internal::NetworkQuality(); |
1540 | 1548 |
1541 if (rtt > base::TimeDelta()) { | 1549 if (rtt > base::TimeDelta()) { |
1542 RecordExternalEstimateProviderMetrics( | 1550 RecordExternalEstimateProviderMetrics( |
1543 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE); | 1551 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE); |
1544 UMA_HISTOGRAM_TIMES("NQE.ExternalEstimateProvider.RTT", rtt); | 1552 UMA_HISTOGRAM_TIMES("NQE.ExternalEstimateProvider.RTT", rtt); |
1545 RttObservation rtt_observation( | 1553 RttObservation rtt_observation( |
1546 rtt, tick_clock_->NowTicks(), signal_strength_dbm_, | 1554 rtt, tick_clock_->NowTicks(), signal_strength_, |
1547 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE); | 1555 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE); |
1548 rtt_observations_.AddObservation(rtt_observation); | 1556 rtt_observations_.AddObservation(rtt_observation); |
1549 external_estimate_provider_quality_.set_http_rtt(rtt); | 1557 external_estimate_provider_quality_.set_http_rtt(rtt); |
1550 NotifyObserversOfRTT(rtt_observation); | 1558 NotifyObserversOfRTT(rtt_observation); |
1551 } | 1559 } |
1552 | 1560 |
1553 if (downstream_throughput_kbps > 0) { | 1561 if (downstream_throughput_kbps > 0) { |
1554 RecordExternalEstimateProviderMetrics( | 1562 RecordExternalEstimateProviderMetrics( |
1555 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE); | 1563 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE); |
1556 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth", | 1564 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth", |
1557 downstream_throughput_kbps); | 1565 downstream_throughput_kbps); |
1558 ThroughputObservation throughput_observation( | 1566 ThroughputObservation throughput_observation( |
1559 downstream_throughput_kbps, tick_clock_->NowTicks(), | 1567 downstream_throughput_kbps, tick_clock_->NowTicks(), signal_strength_, |
1560 signal_strength_dbm_, | |
1561 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE); | 1568 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE); |
1562 downstream_throughput_kbps_observations_.AddObservation( | 1569 downstream_throughput_kbps_observations_.AddObservation( |
1563 throughput_observation); | 1570 throughput_observation); |
1564 external_estimate_provider_quality_.set_downstream_throughput_kbps( | 1571 external_estimate_provider_quality_.set_downstream_throughput_kbps( |
1565 downstream_throughput_kbps); | 1572 downstream_throughput_kbps); |
1566 NotifyObserversOfThroughput(throughput_observation); | 1573 NotifyObserversOfThroughput(throughput_observation); |
1567 } | 1574 } |
1568 } | 1575 } |
1569 | 1576 |
1570 void NetworkQualityEstimator::SetTickClockForTesting( | 1577 void NetworkQualityEstimator::SetTickClockForTesting( |
1571 std::unique_ptr<base::TickClock> tick_clock) { | 1578 std::unique_ptr<base::TickClock> tick_clock) { |
1572 DCHECK(thread_checker_.CalledOnValidThread()); | 1579 DCHECK(thread_checker_.CalledOnValidThread()); |
1573 tick_clock_ = std::move(tick_clock); | 1580 tick_clock_ = std::move(tick_clock); |
1574 } | 1581 } |
1575 | 1582 |
1576 double NetworkQualityEstimator::RandDouble() const { | 1583 double NetworkQualityEstimator::RandDouble() const { |
1577 return base::RandDouble(); | 1584 return base::RandDouble(); |
1578 } | 1585 } |
1579 | 1586 |
1580 void NetworkQualityEstimator::OnUpdatedRTTAvailable( | 1587 void NetworkQualityEstimator::OnUpdatedRTTAvailable( |
1581 SocketPerformanceWatcherFactory::Protocol protocol, | 1588 SocketPerformanceWatcherFactory::Protocol protocol, |
1582 const base::TimeDelta& rtt) { | 1589 const base::TimeDelta& rtt) { |
1583 DCHECK(thread_checker_.CalledOnValidThread()); | 1590 DCHECK(thread_checker_.CalledOnValidThread()); |
1584 DCHECK_NE(nqe::internal::InvalidRTT(), rtt); | 1591 DCHECK_NE(nqe::internal::InvalidRTT(), rtt); |
1585 | 1592 |
1586 RttObservation observation(rtt, tick_clock_->NowTicks(), signal_strength_dbm_, | 1593 RttObservation observation(rtt, tick_clock_->NowTicks(), signal_strength_, |
1587 ProtocolSourceToObservationSource(protocol)); | 1594 ProtocolSourceToObservationSource(protocol)); |
1588 NotifyObserversOfRTT(observation); | 1595 NotifyObserversOfRTT(observation); |
1589 rtt_observations_.AddObservation(observation); | 1596 rtt_observations_.AddObservation(observation); |
1590 } | 1597 } |
1591 | 1598 |
1592 void NetworkQualityEstimator::NotifyObserversOfRTT( | 1599 void NetworkQualityEstimator::NotifyObserversOfRTT( |
1593 const RttObservation& observation) { | 1600 const RttObservation& observation) { |
1594 DCHECK(thread_checker_.CalledOnValidThread()); | 1601 DCHECK(thread_checker_.CalledOnValidThread()); |
1595 DCHECK_NE(nqe::internal::InvalidRTT(), observation.value); | 1602 DCHECK_NE(nqe::internal::InvalidRTT(), observation.value); |
1596 DCHECK_GT(NETWORK_QUALITY_OBSERVATION_SOURCE_MAX, observation.source); | 1603 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); | 1642 DCHECK_NE(nqe::internal::kInvalidThroughput, downstream_kbps); |
1636 | 1643 |
1637 if (downstream_kbps > peak_network_quality_.downstream_throughput_kbps() || | 1644 if (downstream_kbps > peak_network_quality_.downstream_throughput_kbps() || |
1638 peak_network_quality_.downstream_throughput_kbps() == | 1645 peak_network_quality_.downstream_throughput_kbps() == |
1639 nqe::internal::kInvalidThroughput) { | 1646 nqe::internal::kInvalidThroughput) { |
1640 peak_network_quality_ = nqe::internal::NetworkQuality( | 1647 peak_network_quality_ = nqe::internal::NetworkQuality( |
1641 peak_network_quality_.http_rtt(), peak_network_quality_.transport_rtt(), | 1648 peak_network_quality_.http_rtt(), peak_network_quality_.transport_rtt(), |
1642 downstream_kbps); | 1649 downstream_kbps); |
1643 } | 1650 } |
1644 ThroughputObservation throughput_observation( | 1651 ThroughputObservation throughput_observation( |
1645 downstream_kbps, tick_clock_->NowTicks(), signal_strength_dbm_, | 1652 downstream_kbps, tick_clock_->NowTicks(), signal_strength_, |
1646 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP); | 1653 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP); |
1647 downstream_throughput_kbps_observations_.AddObservation( | 1654 downstream_throughput_kbps_observations_.AddObservation( |
1648 throughput_observation); | 1655 throughput_observation); |
1649 NotifyObserversOfThroughput(throughput_observation); | 1656 NotifyObserversOfThroughput(throughput_observation); |
1650 } | 1657 } |
1651 | 1658 |
1652 void NetworkQualityEstimator::MaybeComputeEffectiveConnectionType() { | 1659 void NetworkQualityEstimator::MaybeComputeEffectiveConnectionType() { |
1653 DCHECK(thread_checker_.CalledOnValidThread()); | 1660 DCHECK(thread_checker_.CalledOnValidThread()); |
1654 | 1661 |
1655 const base::TimeTicks now = tick_clock_->NowTicks(); | 1662 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>(); | 1851 return base::Optional<base::TimeDelta>(); |
1845 } | 1852 } |
1846 | 1853 |
1847 base::Optional<int32_t> | 1854 base::Optional<int32_t> |
1848 NetworkQualityEstimator::NetworkQualityProvider::GetDownstreamThroughputKbps() | 1855 NetworkQualityEstimator::NetworkQualityProvider::GetDownstreamThroughputKbps() |
1849 const { | 1856 const { |
1850 return base::Optional<int32_t>(); | 1857 return base::Optional<int32_t>(); |
1851 } | 1858 } |
1852 | 1859 |
1853 } // namespace net | 1860 } // namespace net |
OLD | NEW |