| 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> |
| 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/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/metrics/histogram_base.h" | 17 #include "base/metrics/histogram_base.h" |
| 18 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
| 19 #include "base/metrics/sparse_histogram.h" | 19 #include "base/metrics/sparse_histogram.h" |
| 20 #include "base/rand_util.h" | 20 #include "base/rand_util.h" |
| 21 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
| 22 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
| 23 #include "base/strings/string_piece.h" |
| 23 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 24 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
| 25 #include "base/time/default_tick_clock.h" | 26 #include "base/time/default_tick_clock.h" |
| 26 #include "base/trace_event/trace_event.h" | 27 #include "base/trace_event/trace_event.h" |
| 27 #include "build/build_config.h" | 28 #include "build/build_config.h" |
| 28 #include "net/base/load_flags.h" | 29 #include "net/base/load_flags.h" |
| 29 #include "net/base/load_timing_info.h" | 30 #include "net/base/load_timing_info.h" |
| 30 #include "net/base/network_interfaces.h" | 31 #include "net/base/network_interfaces.h" |
| 31 #include "net/base/trace_constants.h" | 32 #include "net/base/trace_constants.h" |
| 32 #include "net/base/url_util.h" | 33 #include "net/base/url_util.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 // kBitsPerMetric. | 148 // kBitsPerMetric. |
| 148 static const int32_t kLargestValuePossible = (1 << kBitsPerMetric) - 1; | 149 static const int32_t kLargestValuePossible = (1 << kBitsPerMetric) - 1; |
| 149 if (metric > kLargestValuePossible) { | 150 if (metric > kLargestValuePossible) { |
| 150 // Fit |metric| in kBitsPerMetric by clamping it down. | 151 // Fit |metric| in kBitsPerMetric by clamping it down. |
| 151 metric = kLargestValuePossible; | 152 metric = kLargestValuePossible; |
| 152 } | 153 } |
| 153 DCHECK_EQ(0, metric >> kBitsPerMetric) << metric; | 154 DCHECK_EQ(0, metric >> kBitsPerMetric) << metric; |
| 154 return metric; | 155 return metric; |
| 155 } | 156 } |
| 156 | 157 |
| 157 void RecordRTTAccuracy(const char* prefix, | 158 void RecordRTTAccuracy(base::StringPiece prefix, |
| 158 int32_t metric, | 159 int32_t metric, |
| 159 base::TimeDelta measuring_duration, | 160 base::TimeDelta measuring_duration, |
| 160 base::TimeDelta observed_rtt) { | 161 base::TimeDelta observed_rtt) { |
| 161 const std::string histogram_name = | 162 const std::string histogram_name = |
| 162 base::StringPrintf("%s.EstimatedObservedDiff.%s.%d.%s", prefix, | 163 base::StringPrintf("%s.EstimatedObservedDiff.%s.%d.%s", prefix.data(), |
| 163 metric >= 0 ? "Positive" : "Negative", | 164 metric >= 0 ? "Positive" : "Negative", |
| 164 static_cast<int32_t>(measuring_duration.InSeconds()), | 165 static_cast<int32_t>(measuring_duration.InSeconds()), |
| 165 GetHistogramSuffixObservedRTT(observed_rtt)); | 166 GetHistogramSuffixObservedRTT(observed_rtt)); |
| 166 | 167 |
| 167 base::HistogramBase* histogram = base::Histogram::FactoryGet( | 168 base::HistogramBase* histogram = base::Histogram::FactoryGet( |
| 168 histogram_name, 1, 10 * 1000 /* 10 seconds */, 50 /* Number of buckets */, | 169 histogram_name, 1, 10 * 1000 /* 10 seconds */, 50 /* Number of buckets */, |
| 169 base::HistogramBase::kUmaTargetedHistogramFlag); | 170 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 170 histogram->Add(std::abs(metric)); | 171 histogram->Add(std::abs(metric)); |
| 171 } | 172 } |
| 172 | 173 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 base::ThreadTaskRunnerHandle::Get(), | 339 base::ThreadTaskRunnerHandle::Get(), |
| 339 nqe::internal::GetMinSocketWatcherNotificationInterval(variation_params), | 340 nqe::internal::GetMinSocketWatcherNotificationInterval(variation_params), |
| 340 base::Bind(&NetworkQualityEstimator::OnUpdatedRTTAvailable, | 341 base::Bind(&NetworkQualityEstimator::OnUpdatedRTTAvailable, |
| 341 base::Unretained(this)), | 342 base::Unretained(this)), |
| 342 tick_clock_.get())); | 343 tick_clock_.get())); |
| 343 | 344 |
| 344 // Record accuracy after a 15 second interval. The values used here must | 345 // Record accuracy after a 15 second interval. The values used here must |
| 345 // remain in sync with the suffixes specified in | 346 // remain in sync with the suffixes specified in |
| 346 // tools/metrics/histograms/histograms.xml. | 347 // tools/metrics/histograms/histograms.xml. |
| 347 accuracy_recording_intervals_.push_back(base::TimeDelta::FromSeconds(15)); | 348 accuracy_recording_intervals_.push_back(base::TimeDelta::FromSeconds(15)); |
| 349 |
| 350 for (int i = 0; i < STATISTIC_LAST; ++i) |
| 351 http_rtt_at_last_main_frame_[i] = nqe::internal::InvalidRTT(); |
| 348 } | 352 } |
| 349 | 353 |
| 350 void NetworkQualityEstimator::ObtainOperatingParams( | 354 void NetworkQualityEstimator::ObtainOperatingParams( |
| 351 const std::map<std::string, std::string>& variation_params) { | 355 const std::map<std::string, std::string>& variation_params) { |
| 352 DCHECK(thread_checker_.CalledOnValidThread()); | 356 DCHECK(thread_checker_.CalledOnValidThread()); |
| 353 nqe::internal::ObtainDefaultObservations(variation_params, | 357 nqe::internal::ObtainDefaultObservations(variation_params, |
| 354 default_observations_); | 358 default_observations_); |
| 355 nqe::internal::ObtainEffectiveConnectionTypeModelParams( | 359 nqe::internal::ObtainEffectiveConnectionTypeModelParams( |
| 356 variation_params, connection_thresholds_); | 360 variation_params, connection_thresholds_); |
| 357 nqe::internal::ObtainTypicalNetworkQuality(typical_network_quality_); | 361 nqe::internal::ObtainTypicalNetworkQuality(typical_network_quality_); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 // request. | 422 // request. |
| 419 // TODO(tbansal): Refactor this to a separate method. | 423 // TODO(tbansal): Refactor this to a separate method. |
| 420 if (request.load_flags() & LOAD_MAIN_FRAME_DEPRECATED) { | 424 if (request.load_flags() & LOAD_MAIN_FRAME_DEPRECATED) { |
| 421 base::TimeTicks now = tick_clock_->NowTicks(); | 425 base::TimeTicks now = tick_clock_->NowTicks(); |
| 422 last_main_frame_request_ = now; | 426 last_main_frame_request_ = now; |
| 423 | 427 |
| 424 MaybeComputeEffectiveConnectionType(); | 428 MaybeComputeEffectiveConnectionType(); |
| 425 effective_connection_type_at_last_main_frame_ = effective_connection_type_; | 429 effective_connection_type_at_last_main_frame_ = effective_connection_type_; |
| 426 estimated_quality_at_last_main_frame_ = network_quality_; | 430 estimated_quality_at_last_main_frame_ = network_quality_; |
| 427 | 431 |
| 432 // Record the HTTP at the last main frame for experimental statistics. |
| 433 for (int i = 0; i < STATISTIC_LAST; ++i) { |
| 434 http_rtt_at_last_main_frame_[i] = GetRTTEstimateInternal( |
| 435 disallowed_observation_sources_for_http_, base::TimeTicks(), |
| 436 static_cast<Statistic>(i), 50); |
| 437 } |
| 438 |
| 428 // Post the tasks which will run in the future and record the estimation | 439 // Post the tasks which will run in the future and record the estimation |
| 429 // accuracy based on the observations received between now and the time of | 440 // accuracy based on the observations received between now and the time of |
| 430 // task execution. Posting the task at different intervals makes it | 441 // task execution. Posting the task at different intervals makes it |
| 431 // possible to measure the accuracy by comparing the estimate with the | 442 // possible to measure the accuracy by comparing the estimate with the |
| 432 // observations received over intervals of varying durations. | 443 // observations received over intervals of varying durations. |
| 433 for (const base::TimeDelta& measuring_delay : | 444 for (const base::TimeDelta& measuring_delay : |
| 434 GetAccuracyRecordingIntervals()) { | 445 GetAccuracyRecordingIntervals()) { |
| 435 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 446 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 436 FROM_HERE, | 447 FROM_HERE, |
| 437 base::Bind(&NetworkQualityEstimator::RecordAccuracyAfterMainFrame, | 448 base::Bind(&NetworkQualityEstimator::RecordAccuracyAfterMainFrame, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 // time. Returning here ensures that we do not take inaccurate readings. | 519 // time. Returning here ensures that we do not take inaccurate readings. |
| 509 if (now - last_main_frame_request_ > 2 * measuring_duration) | 520 if (now - last_main_frame_request_ > 2 * measuring_duration) |
| 510 return; | 521 return; |
| 511 | 522 |
| 512 // Do not record accuracy if there was a connection change since the last main | 523 // Do not record accuracy if there was a connection change since the last main |
| 513 // frame request. | 524 // frame request. |
| 514 if (last_main_frame_request_ <= last_connection_change_) | 525 if (last_main_frame_request_ <= last_connection_change_) |
| 515 return; | 526 return; |
| 516 | 527 |
| 517 base::TimeDelta recent_http_rtt; | 528 base::TimeDelta recent_http_rtt; |
| 529 |
| 530 // Record the HTTP prediction accuracy for experimental statistics. |
| 531 for (int i = 0; i < STATISTIC_LAST; ++i) { |
| 532 recent_http_rtt = GetRTTEstimateInternal( |
| 533 disallowed_observation_sources_for_http_, last_main_frame_request_, |
| 534 static_cast<Statistic>(i), 50); |
| 535 if (recent_http_rtt != nqe::internal::InvalidRTT() && |
| 536 http_rtt_at_last_main_frame_[i] != nqe::internal::InvalidRTT()) { |
| 537 int estimated_observed_diff_milliseconds = |
| 538 http_rtt_at_last_main_frame_[i].InMilliseconds() - |
| 539 recent_http_rtt.InMilliseconds(); |
| 540 |
| 541 std::string histogram_name = |
| 542 base::StringPrintf("NQE.%s.Accuracy.HttpRTT", GetNameForStatistic(i)); |
| 543 RecordRTTAccuracy(histogram_name, estimated_observed_diff_milliseconds, |
| 544 measuring_duration, recent_http_rtt); |
| 545 } |
| 546 } |
| 547 |
| 518 if (!GetRecentHttpRTT(last_main_frame_request_, &recent_http_rtt)) | 548 if (!GetRecentHttpRTT(last_main_frame_request_, &recent_http_rtt)) |
| 519 recent_http_rtt = nqe::internal::InvalidRTT(); | 549 recent_http_rtt = nqe::internal::InvalidRTT(); |
| 520 | 550 |
| 521 if (estimated_quality_at_last_main_frame_.http_rtt() != | 551 if (estimated_quality_at_last_main_frame_.http_rtt() != |
| 522 nqe::internal::InvalidRTT() && | 552 nqe::internal::InvalidRTT() && |
| 523 recent_http_rtt != nqe::internal::InvalidRTT()) { | 553 recent_http_rtt != nqe::internal::InvalidRTT()) { |
| 524 const int estimated_observed_diff_milliseconds = | 554 const int estimated_observed_diff_milliseconds = |
| 525 estimated_quality_at_last_main_frame_.http_rtt().InMilliseconds() - | 555 estimated_quality_at_last_main_frame_.http_rtt().InMilliseconds() - |
| 526 recent_http_rtt.InMilliseconds(); | 556 recent_http_rtt.InMilliseconds(); |
| 527 | 557 |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 current_network_id_ = GetCurrentNetworkID(); | 873 current_network_id_ = GetCurrentNetworkID(); |
| 844 RecordNetworkIDAvailability(); | 874 RecordNetworkIDAvailability(); |
| 845 | 875 |
| 846 MaybeQueryExternalEstimateProvider(); | 876 MaybeQueryExternalEstimateProvider(); |
| 847 | 877 |
| 848 // Read any cached estimates for the new network. If cached estimates are | 878 // Read any cached estimates for the new network. If cached estimates are |
| 849 // unavailable, add the default estimates. | 879 // unavailable, add the default estimates. |
| 850 if (!ReadCachedNetworkQualityEstimate()) | 880 if (!ReadCachedNetworkQualityEstimate()) |
| 851 AddDefaultEstimates(); | 881 AddDefaultEstimates(); |
| 852 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality(); | 882 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality(); |
| 883 |
| 884 for (int i = 0; i < STATISTIC_LAST; ++i) |
| 885 http_rtt_at_last_main_frame_[i] = nqe::internal::InvalidRTT(); |
| 886 |
| 853 throughput_analyzer_->OnConnectionTypeChanged(); | 887 throughput_analyzer_->OnConnectionTypeChanged(); |
| 854 MaybeComputeEffectiveConnectionType(); | 888 MaybeComputeEffectiveConnectionType(); |
| 855 } | 889 } |
| 856 | 890 |
| 857 void NetworkQualityEstimator::MaybeQueryExternalEstimateProvider() const { | 891 void NetworkQualityEstimator::MaybeQueryExternalEstimateProvider() const { |
| 858 // Query the external estimate provider on certain connection types. Once the | 892 // Query the external estimate provider on certain connection types. Once the |
| 859 // updated estimates are available, OnUpdatedEstimateAvailable will be called | 893 // updated estimates are available, OnUpdatedEstimateAvailable will be called |
| 860 // by |external_estimate_provider_| with updated estimates. | 894 // by |external_estimate_provider_| with updated estimates. |
| 861 if (external_estimate_provider_ && | 895 if (external_estimate_provider_ && |
| 862 current_network_id_.type != NetworkChangeNotifier::CONNECTION_NONE && | 896 current_network_id_.type != NetworkChangeNotifier::CONNECTION_NONE && |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 base::TimeDelta rtt; | 935 base::TimeDelta rtt; |
| 902 if (GetRecentHttpRTT(base::TimeTicks(), &rtt)) { | 936 if (GetRecentHttpRTT(base::TimeTicks(), &rtt)) { |
| 903 // Add the 50th percentile value. | 937 // Add the 50th percentile value. |
| 904 base::HistogramBase* rtt_percentile = | 938 base::HistogramBase* rtt_percentile = |
| 905 GetHistogram("RTT.Percentile50.", current_network_id_.type, 10 * 1000); | 939 GetHistogram("RTT.Percentile50.", current_network_id_.type, 10 * 1000); |
| 906 rtt_percentile->Add(rtt.InMilliseconds()); | 940 rtt_percentile->Add(rtt.InMilliseconds()); |
| 907 | 941 |
| 908 // Add the remaining percentile values. | 942 // Add the remaining percentile values. |
| 909 static const int kPercentiles[] = {0, 10, 90, 100}; | 943 static const int kPercentiles[] = {0, 10, 90, 100}; |
| 910 for (size_t i = 0; i < arraysize(kPercentiles); ++i) { | 944 for (size_t i = 0; i < arraysize(kPercentiles); ++i) { |
| 911 rtt = GetRTTEstimateInternal(disallowed_observation_sources_for_http_, | 945 rtt = GetRTTEstimateInternal( |
| 912 base::TimeTicks(), kPercentiles[i]); | 946 disallowed_observation_sources_for_http_, base::TimeTicks(), |
| 947 base::Optional<Statistic>(), kPercentiles[i]); |
| 913 | 948 |
| 914 rtt_percentile = GetHistogram( | 949 rtt_percentile = GetHistogram( |
| 915 "RTT.Percentile" + base::IntToString(kPercentiles[i]) + ".", | 950 "RTT.Percentile" + base::IntToString(kPercentiles[i]) + ".", |
| 916 current_network_id_.type, 10 * 1000); // 10 seconds | 951 current_network_id_.type, 10 * 1000); // 10 seconds |
| 917 rtt_percentile->Add(rtt.InMilliseconds()); | 952 rtt_percentile->Add(rtt.InMilliseconds()); |
| 918 } | 953 } |
| 919 } | 954 } |
| 920 | 955 |
| 921 if (GetRecentTransportRTT(base::TimeTicks(), &rtt)) { | 956 if (GetRecentTransportRTT(base::TimeTicks(), &rtt)) { |
| 922 // Add the 50th percentile value. | 957 // Add the 50th percentile value. |
| 923 base::HistogramBase* transport_rtt_percentile = GetHistogram( | 958 base::HistogramBase* transport_rtt_percentile = GetHistogram( |
| 924 "TransportRTT.Percentile50.", current_network_id_.type, 10 * 1000); | 959 "TransportRTT.Percentile50.", current_network_id_.type, 10 * 1000); |
| 925 transport_rtt_percentile->Add(rtt.InMilliseconds()); | 960 transport_rtt_percentile->Add(rtt.InMilliseconds()); |
| 926 | 961 |
| 927 // Add the remaining percentile values. | 962 // Add the remaining percentile values. |
| 928 static const int kPercentiles[] = {0, 10, 90, 100}; | 963 static const int kPercentiles[] = {0, 10, 90, 100}; |
| 929 for (size_t i = 0; i < arraysize(kPercentiles); ++i) { | 964 for (size_t i = 0; i < arraysize(kPercentiles); ++i) { |
| 930 rtt = | 965 rtt = GetRTTEstimateInternal( |
| 931 GetRTTEstimateInternal(disallowed_observation_sources_for_transport_, | 966 disallowed_observation_sources_for_transport_, base::TimeTicks(), |
| 932 base::TimeTicks(), kPercentiles[i]); | 967 base::Optional<Statistic>(), kPercentiles[i]); |
| 933 | 968 |
| 934 transport_rtt_percentile = GetHistogram( | 969 transport_rtt_percentile = GetHistogram( |
| 935 "TransportRTT.Percentile" + base::IntToString(kPercentiles[i]) + ".", | 970 "TransportRTT.Percentile" + base::IntToString(kPercentiles[i]) + ".", |
| 936 current_network_id_.type, 10 * 1000); // 10 seconds | 971 current_network_id_.type, 10 * 1000); // 10 seconds |
| 937 transport_rtt_percentile->Add(rtt.InMilliseconds()); | 972 transport_rtt_percentile->Add(rtt.InMilliseconds()); |
| 938 } | 973 } |
| 939 } | 974 } |
| 940 } | 975 } |
| 941 | 976 |
| 942 void NetworkQualityEstimator::RecordNetworkIDAvailability() const { | 977 void NetworkQualityEstimator::RecordNetworkIDAvailability() const { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 base::HistogramBase* effective_connection_type_histogram = | 1038 base::HistogramBase* effective_connection_type_histogram = |
| 1004 base::Histogram::FactoryGet( | 1039 base::Histogram::FactoryGet( |
| 1005 std::string("NQE.MainFrame.EffectiveConnectionType.") + | 1040 std::string("NQE.MainFrame.EffectiveConnectionType.") + |
| 1006 nqe::internal::GetNameForConnectionType(current_network_id_.type), | 1041 nqe::internal::GetNameForConnectionType(current_network_id_.type), |
| 1007 0, EFFECTIVE_CONNECTION_TYPE_LAST, | 1042 0, EFFECTIVE_CONNECTION_TYPE_LAST, |
| 1008 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, | 1043 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, |
| 1009 base::HistogramBase::kUmaTargetedHistogramFlag); | 1044 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 1010 | 1045 |
| 1011 effective_connection_type_histogram->Add( | 1046 effective_connection_type_histogram->Add( |
| 1012 effective_connection_type_at_last_main_frame_); | 1047 effective_connection_type_at_last_main_frame_); |
| 1048 |
| 1049 // Record the HTTP RTT at the main frames for experimental statistics. |
| 1050 for (int i = 0; i < STATISTIC_LAST; ++i) { |
| 1051 if (http_rtt_at_last_main_frame_[i] != nqe::internal::InvalidRTT()) { |
| 1052 base::HistogramBase* rtt_histogram = base::Histogram::FactoryGet( |
| 1053 base::StringPrintf("NQE.%s.MainFrame.RTT", GetNameForStatistic(i)), 1, |
| 1054 10 * 1000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
| 1055 rtt_histogram->Add(http_rtt_at_last_main_frame_[i].InMilliseconds()); |
| 1056 } |
| 1057 } |
| 1013 } | 1058 } |
| 1014 | 1059 |
| 1015 void NetworkQualityEstimator::ComputeEffectiveConnectionType() { | 1060 void NetworkQualityEstimator::ComputeEffectiveConnectionType() { |
| 1016 DCHECK(thread_checker_.CalledOnValidThread()); | 1061 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1017 | 1062 |
| 1018 UpdateSignalStrength(); | 1063 UpdateSignalStrength(); |
| 1019 | 1064 |
| 1020 const base::TimeTicks now = tick_clock_->NowTicks(); | 1065 const base::TimeTicks now = tick_clock_->NowTicks(); |
| 1021 | 1066 |
| 1022 const EffectiveConnectionType past_type = effective_connection_type_; | 1067 const EffectiveConnectionType past_type = effective_connection_type_; |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 RTTAndThroughputEstimatesObserver* observer) { | 1323 RTTAndThroughputEstimatesObserver* observer) { |
| 1279 DCHECK(thread_checker_.CalledOnValidThread()); | 1324 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1280 rtt_and_throughput_estimates_observer_list_.RemoveObserver(observer); | 1325 rtt_and_throughput_estimates_observer_list_.RemoveObserver(observer); |
| 1281 } | 1326 } |
| 1282 | 1327 |
| 1283 bool NetworkQualityEstimator::GetRecentHttpRTT( | 1328 bool NetworkQualityEstimator::GetRecentHttpRTT( |
| 1284 const base::TimeTicks& start_time, | 1329 const base::TimeTicks& start_time, |
| 1285 base::TimeDelta* rtt) const { | 1330 base::TimeDelta* rtt) const { |
| 1286 DCHECK(thread_checker_.CalledOnValidThread()); | 1331 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1287 *rtt = GetRTTEstimateInternal(disallowed_observation_sources_for_http_, | 1332 *rtt = GetRTTEstimateInternal(disallowed_observation_sources_for_http_, |
| 1288 start_time, 50); | 1333 start_time, base::Optional<Statistic>(), 50); |
| 1289 return (*rtt != nqe::internal::InvalidRTT()); | 1334 return (*rtt != nqe::internal::InvalidRTT()); |
| 1290 } | 1335 } |
| 1291 | 1336 |
| 1292 bool NetworkQualityEstimator::GetRecentTransportRTT( | 1337 bool NetworkQualityEstimator::GetRecentTransportRTT( |
| 1293 const base::TimeTicks& start_time, | 1338 const base::TimeTicks& start_time, |
| 1294 base::TimeDelta* rtt) const { | 1339 base::TimeDelta* rtt) const { |
| 1295 DCHECK(thread_checker_.CalledOnValidThread()); | 1340 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1296 *rtt = GetRTTEstimateInternal(disallowed_observation_sources_for_transport_, | 1341 *rtt = GetRTTEstimateInternal(disallowed_observation_sources_for_transport_, |
| 1297 start_time, 50); | 1342 start_time, base::Optional<Statistic>(), 50); |
| 1298 return (*rtt != nqe::internal::InvalidRTT()); | 1343 return (*rtt != nqe::internal::InvalidRTT()); |
| 1299 } | 1344 } |
| 1300 | 1345 |
| 1301 bool NetworkQualityEstimator::GetRecentDownlinkThroughputKbps( | 1346 bool NetworkQualityEstimator::GetRecentDownlinkThroughputKbps( |
| 1302 const base::TimeTicks& start_time, | 1347 const base::TimeTicks& start_time, |
| 1303 int32_t* kbps) const { | 1348 int32_t* kbps) const { |
| 1304 DCHECK(thread_checker_.CalledOnValidThread()); | 1349 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1305 *kbps = GetDownlinkThroughputKbpsEstimateInternal(start_time, 50); | 1350 *kbps = GetDownlinkThroughputKbpsEstimateInternal(start_time, 50); |
| 1306 return (*kbps != nqe::internal::kInvalidThroughput); | 1351 return (*kbps != nqe::internal::kInvalidThroughput); |
| 1307 } | 1352 } |
| 1308 | 1353 |
| 1309 base::TimeDelta NetworkQualityEstimator::GetRTTEstimateInternal( | 1354 base::TimeDelta NetworkQualityEstimator::GetRTTEstimateInternal( |
| 1310 const std::vector<NetworkQualityObservationSource>& | 1355 const std::vector<NetworkQualityObservationSource>& |
| 1311 disallowed_observation_sources, | 1356 disallowed_observation_sources, |
| 1312 const base::TimeTicks& start_time, | 1357 base::TimeTicks start_time, |
| 1358 const base::Optional<Statistic>& statistic, |
| 1313 int percentile) const { | 1359 int percentile) const { |
| 1314 DCHECK(thread_checker_.CalledOnValidThread()); | 1360 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1315 | 1361 |
| 1316 // RTT observations are sorted by duration from shortest to longest, thus | 1362 // RTT observations are sorted by duration from shortest to longest, thus |
| 1317 // a higher percentile RTT will have a longer RTT than a lower percentile. | 1363 // a higher percentile RTT will have a longer RTT than a lower percentile. |
| 1318 base::TimeDelta rtt = nqe::internal::InvalidRTT(); | 1364 base::TimeDelta rtt = nqe::internal::InvalidRTT(); |
| 1319 if (!rtt_observations_.GetPercentile(start_time, signal_strength_dbm_, &rtt, | 1365 |
| 1320 percentile, | 1366 if (!statistic) { |
| 1321 disallowed_observation_sources)) { | 1367 // Use default statistic algorithm. |
| 1322 return nqe::internal::InvalidRTT(); | 1368 if (!rtt_observations_.GetPercentile(start_time, signal_strength_dbm_, &rtt, |
| 1369 percentile, |
| 1370 disallowed_observation_sources)) { |
| 1371 return nqe::internal::InvalidRTT(); |
| 1372 } |
| 1373 return rtt; |
| 1323 } | 1374 } |
| 1324 return rtt; | 1375 |
| 1376 switch (statistic.value()) { |
| 1377 case STATISTIC_LAST: |
| 1378 NOTREACHED(); |
| 1379 return nqe::internal::InvalidRTT(); |
| 1380 case STATISTIC_WEIGHTED_AVERAGE: |
| 1381 if (!rtt_observations_.GetWeightedAverage( |
| 1382 start_time, signal_strength_dbm_, disallowed_observation_sources, |
| 1383 &rtt)) { |
| 1384 return nqe::internal::InvalidRTT(); |
| 1385 } |
| 1386 return rtt; |
| 1387 case STATISTIC_UNWEIGHTED_AVERAGE: |
| 1388 if (!rtt_observations_.GetUnweightedAverage( |
| 1389 start_time, signal_strength_dbm_, disallowed_observation_sources, |
| 1390 &rtt)) { |
| 1391 return nqe::internal::InvalidRTT(); |
| 1392 } |
| 1393 return rtt; |
| 1394 } |
| 1395 NOTREACHED(); |
| 1396 return nqe::internal::InvalidRTT(); |
| 1325 } | 1397 } |
| 1326 | 1398 |
| 1327 int32_t NetworkQualityEstimator::GetDownlinkThroughputKbpsEstimateInternal( | 1399 int32_t NetworkQualityEstimator::GetDownlinkThroughputKbpsEstimateInternal( |
| 1328 const base::TimeTicks& start_time, | 1400 const base::TimeTicks& start_time, |
| 1329 int percentile) const { | 1401 int percentile) const { |
| 1330 DCHECK(thread_checker_.CalledOnValidThread()); | 1402 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1331 | 1403 |
| 1332 // Throughput observations are sorted by kbps from slowest to fastest, | 1404 // Throughput observations are sorted by kbps from slowest to fastest, |
| 1333 // thus a higher percentile throughput will be faster than a lower one. | 1405 // thus a higher percentile throughput will be faster than a lower one. |
| 1334 int32_t kbps = nqe::internal::kInvalidThroughput; | 1406 int32_t kbps = nqe::internal::kInvalidThroughput; |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1723 base::TimeTicks::Now(), INT32_MIN, | 1795 base::TimeTicks::Now(), INT32_MIN, |
| 1724 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); | 1796 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); |
| 1725 downstream_throughput_kbps_observations_.AddObservation( | 1797 downstream_throughput_kbps_observations_.AddObservation( |
| 1726 throughput_observation); | 1798 throughput_observation); |
| 1727 NotifyObserversOfThroughput(throughput_observation); | 1799 NotifyObserversOfThroughput(throughput_observation); |
| 1728 } | 1800 } |
| 1729 | 1801 |
| 1730 ComputeEffectiveConnectionType(); | 1802 ComputeEffectiveConnectionType(); |
| 1731 } | 1803 } |
| 1732 | 1804 |
| 1805 const char* NetworkQualityEstimator::GetNameForStatistic(int i) const { |
| 1806 Statistic statistic = static_cast<Statistic>(i); |
| 1807 switch (statistic) { |
| 1808 case STATISTIC_WEIGHTED_AVERAGE: |
| 1809 return "WeightedAverage"; |
| 1810 case STATISTIC_UNWEIGHTED_AVERAGE: |
| 1811 return "UnweightedAverage"; |
| 1812 case STATISTIC_LAST: |
| 1813 NOTREACHED(); |
| 1814 return ""; |
| 1815 } |
| 1816 NOTREACHED(); |
| 1817 return ""; |
| 1818 } |
| 1819 |
| 1733 } // namespace net | 1820 } // namespace net |
| OLD | NEW |