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/sparse_histogram.h" | |
19 #include "base/rand_util.h" | |
18 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
19 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
20 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
21 #include "base/time/default_tick_clock.h" | 23 #include "base/time/default_tick_clock.h" |
22 #include "base/trace_event/trace_event.h" | 24 #include "base/trace_event/trace_event.h" |
23 #include "build/build_config.h" | 25 #include "build/build_config.h" |
24 #include "net/base/load_flags.h" | 26 #include "net/base/load_flags.h" |
25 #include "net/base/load_timing_info.h" | 27 #include "net/base/load_timing_info.h" |
26 #include "net/base/network_interfaces.h" | 28 #include "net/base/network_interfaces.h" |
27 #include "net/base/url_util.h" | 29 #include "net/base/url_util.h" |
30 #include "net/http/http_status_code.h" | |
28 #include "net/nqe/socket_watcher_factory.h" | 31 #include "net/nqe/socket_watcher_factory.h" |
29 #include "net/nqe/throughput_analyzer.h" | 32 #include "net/nqe/throughput_analyzer.h" |
30 #include "net/url_request/url_request.h" | 33 #include "net/url_request/url_request.h" |
34 #include "net/url_request/url_request_status.h" | |
31 #include "url/gurl.h" | 35 #include "url/gurl.h" |
32 | 36 |
33 #if defined(OS_ANDROID) | 37 #if defined(OS_ANDROID) |
34 #include "net/android/cellular_signal_strength.h" | 38 #include "net/android/cellular_signal_strength.h" |
35 #include "net/android/network_library.h" | 39 #include "net/android/network_library.h" |
36 #endif // OS_ANDROID | 40 #endif // OS_ANDROID |
37 | 41 |
38 namespace { | 42 namespace { |
39 | 43 |
40 // Default value of the half life (in seconds) for computing time weighted | 44 // Default value of the half life (in seconds) for computing time weighted |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 | 146 |
143 bool GetValueForVariationParam( | 147 bool GetValueForVariationParam( |
144 const std::map<std::string, std::string>& variation_params, | 148 const std::map<std::string, std::string>& variation_params, |
145 const std::string& parameter_name, | 149 const std::string& parameter_name, |
146 int32_t* variations_value) { | 150 int32_t* variations_value) { |
147 const auto it = variation_params.find(parameter_name); | 151 const auto it = variation_params.find(parameter_name); |
148 return it != variation_params.end() && | 152 return it != variation_params.end() && |
149 base::StringToInt(it->second, variations_value); | 153 base::StringToInt(it->second, variations_value); |
150 } | 154 } |
151 | 155 |
156 // Returns the variation value for |parameter_name|. If the value is | |
157 // unavailable, |default_value| is returned. | |
158 double GetDoubleValueForVariationParamWithDefaultValue( | |
159 const std::map<std::string, std::string>& variation_params, | |
160 const std::string& parameter_name, | |
161 double default_value) { | |
162 const auto it = variation_params.find(parameter_name); | |
163 if (it == variation_params.end()) | |
164 return default_value; | |
165 | |
166 double variations_value = default_value; | |
167 if (!base::StringToDouble(it->second, &variations_value)) | |
168 return default_value; | |
169 return variations_value; | |
170 } | |
171 | |
152 // Returns the algorithm that should be used for computing effective connection | 172 // Returns the algorithm that should be used for computing effective connection |
153 // type based on field trial params. Returns an empty string if a valid | 173 // type based on field trial params. Returns an empty string if a valid |
154 // algorithm paramter is not present in the field trial params. | 174 // algorithm paramter is not present in the field trial params. |
155 std::string GetEffectiveConnectionTypeAlgorithm( | 175 std::string GetEffectiveConnectionTypeAlgorithm( |
156 const std::map<std::string, std::string>& variation_params) { | 176 const std::map<std::string, std::string>& variation_params) { |
157 const auto it = variation_params.find("effective_connection_type_algorithm"); | 177 const auto it = variation_params.find("effective_connection_type_algorithm"); |
158 if (it == variation_params.end()) | 178 if (it == variation_params.end()) |
159 return std::string(); | 179 return std::string(); |
160 return it->second; | 180 return it->second; |
161 } | 181 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 static const char* const kSuffixes[] = { | 229 static const char* const kSuffixes[] = { |
210 "0_20", "20_60", "60_140", "140_300", "300_620", | 230 "0_20", "20_60", "60_140", "140_300", "300_620", |
211 "620_1260", "1260_2540", "2540_5100", "5100_Infinity"}; | 231 "620_1260", "1260_2540", "2540_5100", "5100_Infinity"}; |
212 for (size_t i = 0; i < arraysize(kSuffixes) - 1; ++i) { | 232 for (size_t i = 0; i < arraysize(kSuffixes) - 1; ++i) { |
213 if (observed_throughput_kbps <= static_cast<float>((20 * (2 << i) - 20))) | 233 if (observed_throughput_kbps <= static_cast<float>((20 * (2 << i) - 20))) |
214 return kSuffixes[i]; | 234 return kSuffixes[i]; |
215 } | 235 } |
216 return kSuffixes[arraysize(kSuffixes) - 1]; | 236 return kSuffixes[arraysize(kSuffixes) - 1]; |
217 } | 237 } |
218 | 238 |
239 // The least significant kTrimBits of the metric will be discarded. If the | |
240 // trimmed metric value is greater than what can be fit in kBitsPerMetric bits, | |
241 // then the largest value that can be represented in kBitsPerMetric bits is | |
242 // returned. | |
243 const int32_t kTrimBits = 5; | |
244 | |
245 // Maximum number of bits in which one metric should fit. Restricting the amount | |
246 // of space allocated to a single metric makes it possile to fit multiple | |
247 // metrices in a single histogram sample, and ensures that all those metrices | |
Ilya Sherman
2016/07/21 21:38:08
nit: s/metrices/metrics
tbansal1
2016/07/21 22:42:53
Done.
| |
248 // are recorded together as a single tuple. | |
249 const int32_t kBitsPerMetric = 7; | |
250 | |
251 static_assert(31 >= kBitsPerMetric * 4, | |
252 "Four metrics would not fit in a 32-bit int with first bit " | |
253 "reserved for sign"); | |
Ilya Sherman
2016/07/21 21:38:08
FWIW, the sign bit is safe to use, as long as you
tbansal1
2016/07/21 22:42:53
Done.
| |
254 | |
255 // Trims the |metric| by removing the last kTrimBits, and then rounding down | |
256 // the |metric| such that the |metric| fits in kBitsPerMetric. | |
257 int32_t FitInKBitsPerMetricBits(int32_t metric) { | |
258 // Remove the last kTrimBits. This will allow the metric to fit within | |
259 // kBitsPerMetric while losing only the least significant bits. | |
260 metric = metric >> kTrimBits; | |
261 | |
262 // kLargestValuePossible is the largest value that can be recorded using | |
263 // kBitsPerMetric. | |
264 static const int32_t kLargestValuePossible = (1 << kBitsPerMetric) - 1; | |
265 if (metric > kLargestValuePossible) { | |
266 // Fit |metric| in kBitsPerMetric by clamping it down. | |
267 metric = kLargestValuePossible; | |
268 } | |
269 DCHECK_EQ(0, metric >> kBitsPerMetric); | |
270 return metric; | |
271 } | |
272 | |
219 } // namespace | 273 } // namespace |
220 | 274 |
221 namespace net { | 275 namespace net { |
222 | 276 |
223 NetworkQualityEstimator::NetworkQualityEstimator( | 277 NetworkQualityEstimator::NetworkQualityEstimator( |
224 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, | 278 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, |
225 const std::map<std::string, std::string>& variation_params) | 279 const std::map<std::string, std::string>& variation_params) |
226 : NetworkQualityEstimator(std::move(external_estimates_provider), | 280 : NetworkQualityEstimator(std::move(external_estimates_provider), |
227 variation_params, | 281 variation_params, |
228 false, | 282 false, |
(...skipping 29 matching lines...) Expand all Loading... | |
258 NetworkID(NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, | 312 NetworkID(NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, |
259 std::string())), | 313 std::string())), |
260 downstream_throughput_kbps_observations_(weight_multiplier_per_second_), | 314 downstream_throughput_kbps_observations_(weight_multiplier_per_second_), |
261 rtt_observations_(weight_multiplier_per_second_), | 315 rtt_observations_(weight_multiplier_per_second_), |
262 effective_connection_type_at_last_main_frame_( | 316 effective_connection_type_at_last_main_frame_( |
263 EFFECTIVE_CONNECTION_TYPE_UNKNOWN), | 317 EFFECTIVE_CONNECTION_TYPE_UNKNOWN), |
264 external_estimate_provider_(std::move(external_estimates_provider)), | 318 external_estimate_provider_(std::move(external_estimates_provider)), |
265 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), | 319 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), |
266 min_signal_strength_since_connection_change_(INT32_MAX), | 320 min_signal_strength_since_connection_change_(INT32_MAX), |
267 max_signal_strength_since_connection_change_(INT32_MIN), | 321 max_signal_strength_since_connection_change_(INT32_MIN), |
322 correlation_uma_logging_probability_( | |
323 GetDoubleValueForVariationParamWithDefaultValue( | |
324 variation_params, | |
325 "correlation_logging_probability", | |
326 0.0)), | |
268 weak_ptr_factory_(this) { | 327 weak_ptr_factory_(this) { |
269 static_assert(kDefaultHalfLifeSeconds > 0, | 328 static_assert(kDefaultHalfLifeSeconds > 0, |
270 "Default half life duration must be > 0"); | 329 "Default half life duration must be > 0"); |
271 static_assert(kMaximumNetworkQualityCacheSize > 0, | 330 static_assert(kMaximumNetworkQualityCacheSize > 0, |
272 "Size of the network quality cache must be > 0"); | 331 "Size of the network quality cache must be > 0"); |
273 // This limit should not be increased unless the logic for removing the | 332 // This limit should not be increased unless the logic for removing the |
274 // oldest cache entry is rewritten to use a doubly-linked-list LRU queue. | 333 // oldest cache entry is rewritten to use a doubly-linked-list LRU queue. |
275 static_assert(kMaximumNetworkQualityCacheSize <= 10, | 334 static_assert(kMaximumNetworkQualityCacheSize <= 10, |
276 "Size of the network quality cache must <= 10"); | 335 "Size of the network quality cache must <= 10"); |
277 // None of the algorithms can have an empty name. | 336 // None of the algorithms can have an empty name. |
278 DCHECK(algorithm_name_to_enum_.end() == | 337 DCHECK(algorithm_name_to_enum_.end() == |
279 algorithm_name_to_enum_.find(std::string())); | 338 algorithm_name_to_enum_.find(std::string())); |
280 | 339 |
281 DCHECK_EQ(algorithm_name_to_enum_.size(), | 340 DCHECK_EQ(algorithm_name_to_enum_.size(), |
282 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: | 341 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: |
283 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); | 342 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); |
284 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: | 343 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: |
285 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, | 344 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, |
286 effective_connection_type_algorithm_); | 345 effective_connection_type_algorithm_); |
346 DCHECK_LE(0.0, correlation_uma_logging_probability_); | |
347 DCHECK_GE(1.0, correlation_uma_logging_probability_); | |
287 | 348 |
288 ObtainOperatingParams(variation_params); | 349 ObtainOperatingParams(variation_params); |
289 ObtainEffectiveConnectionTypeModelParams(variation_params); | 350 ObtainEffectiveConnectionTypeModelParams(variation_params); |
290 NetworkChangeNotifier::AddConnectionTypeObserver(this); | 351 NetworkChangeNotifier::AddConnectionTypeObserver(this); |
291 if (external_estimate_provider_) { | 352 if (external_estimate_provider_) { |
292 RecordExternalEstimateProviderMetrics( | 353 RecordExternalEstimateProviderMetrics( |
293 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE); | 354 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE); |
294 external_estimate_provider_->SetUpdatedEstimateDelegate(this); | 355 external_estimate_provider_->SetUpdatedEstimateDelegate(this); |
295 } else { | 356 } else { |
296 RecordExternalEstimateProviderMetrics( | 357 RecordExternalEstimateProviderMetrics( |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 | 597 |
537 LoadTimingInfo load_timing_info; | 598 LoadTimingInfo load_timing_info; |
538 request.GetLoadTimingInfo(&load_timing_info); | 599 request.GetLoadTimingInfo(&load_timing_info); |
539 | 600 |
540 // If the load timing info is unavailable, it probably means that the request | 601 // If the load timing info is unavailable, it probably means that the request |
541 // did not go over the network. | 602 // did not go over the network. |
542 if (load_timing_info.send_start.is_null() || | 603 if (load_timing_info.send_start.is_null() || |
543 load_timing_info.receive_headers_end.is_null()) { | 604 load_timing_info.receive_headers_end.is_null()) { |
544 return; | 605 return; |
545 } | 606 } |
607 DCHECK(!request.response_info().was_cached); | |
546 | 608 |
547 // Duration between when the resource was requested and when the response | 609 // Duration between when the resource was requested and when the response |
548 // headers were received. | 610 // headers were received. |
549 base::TimeDelta observed_http_rtt = | 611 base::TimeDelta observed_http_rtt = |
550 load_timing_info.receive_headers_end - load_timing_info.send_start; | 612 load_timing_info.receive_headers_end - load_timing_info.send_start; |
551 DCHECK_GE(observed_http_rtt, base::TimeDelta()); | 613 DCHECK_GE(observed_http_rtt, base::TimeDelta()); |
552 if (observed_http_rtt < peak_network_quality_.http_rtt()) { | 614 if (observed_http_rtt < peak_network_quality_.http_rtt()) { |
553 peak_network_quality_ = nqe::internal::NetworkQuality( | 615 peak_network_quality_ = nqe::internal::NetworkQuality( |
554 observed_http_rtt, peak_network_quality_.transport_rtt(), | 616 observed_http_rtt, peak_network_quality_.transport_rtt(), |
555 peak_network_quality_.downstream_throughput_kbps()); | 617 peak_network_quality_.downstream_throughput_kbps()); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 void NetworkQualityEstimator::NotifyRequestCompleted( | 739 void NetworkQualityEstimator::NotifyRequestCompleted( |
678 const URLRequest& request) { | 740 const URLRequest& request) { |
679 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), | 741 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), |
680 "NetworkQualityEstimator::NotifyRequestCompleted"); | 742 "NetworkQualityEstimator::NotifyRequestCompleted"); |
681 DCHECK(thread_checker_.CalledOnValidThread()); | 743 DCHECK(thread_checker_.CalledOnValidThread()); |
682 | 744 |
683 if (!RequestSchemeIsHTTPOrHTTPS(request)) | 745 if (!RequestSchemeIsHTTPOrHTTPS(request)) |
684 return; | 746 return; |
685 | 747 |
686 throughput_analyzer_->NotifyRequestCompleted(request); | 748 throughput_analyzer_->NotifyRequestCompleted(request); |
749 RecordCorrelationMetric(request); | |
750 } | |
751 | |
752 void NetworkQualityEstimator::RecordCorrelationMetric( | |
753 const URLRequest& request) const { | |
754 DCHECK(thread_checker_.CalledOnValidThread()); | |
755 | |
756 // The histogram is recorded with probability | |
757 // |correlation_uma_logging_probability_| to reduce overhead involved with | |
758 // sparse histograms. Also, recording the correlation on each request is | |
759 // unnecessary. | |
760 if (RandDouble() >= correlation_uma_logging_probability_) | |
761 return; | |
762 | |
763 if (request.response_info().was_cached || | |
764 !request.response_info().network_accessed) { | |
765 return; | |
766 } | |
767 | |
768 LoadTimingInfo load_timing_info; | |
769 request.GetLoadTimingInfo(&load_timing_info); | |
770 DCHECK(!load_timing_info.send_start.is_null() && | |
771 !load_timing_info.receive_headers_end.is_null()); | |
772 | |
773 // Record UMA only for successful requests that have completed. | |
774 if (!request.status().is_success() || request.status().is_io_pending()) | |
775 return; | |
776 if (request.GetResponseCode() != HTTP_OK) | |
777 return; | |
778 if (load_timing_info.receive_headers_end < last_main_frame_request_) | |
779 return; | |
780 | |
781 const base::TimeTicks now = tick_clock_->NowTicks(); | |
782 // Record UMA only for requests that started recently. | |
783 if (now - last_main_frame_request_ > base::TimeDelta::FromSeconds(15)) | |
784 return; | |
785 | |
786 DCHECK_GE(now, load_timing_info.send_start); | |
787 | |
788 int32_t rtt = 0; | |
789 | |
790 if (UseTransportRTT()) { | |
791 rtt = estimated_quality_at_last_main_frame_.transport_rtt() != | |
792 nqe::internal::InvalidRTT() | |
793 ? FitInKBitsPerMetricBits( | |
794 estimated_quality_at_last_main_frame_.transport_rtt() | |
795 .InMilliseconds()) | |
796 : 0; | |
797 } else { | |
798 rtt = estimated_quality_at_last_main_frame_.http_rtt() != | |
799 nqe::internal::InvalidRTT() | |
800 ? FitInKBitsPerMetricBits( | |
801 estimated_quality_at_last_main_frame_.http_rtt() | |
802 .InMilliseconds()) | |
803 : 0; | |
804 } | |
805 | |
806 const int32_t downstream_throughput = | |
807 estimated_quality_at_last_main_frame_.downstream_throughput_kbps() != | |
808 nqe::internal::kInvalidThroughput | |
809 ? FitInKBitsPerMetricBits(estimated_quality_at_last_main_frame_ | |
810 .downstream_throughput_kbps()) | |
811 : 0; | |
812 | |
813 const int32_t resource_load_time = FitInKBitsPerMetricBits( | |
814 (now - load_timing_info.send_start).InMilliseconds()); | |
815 | |
816 int64_t resource_size = (request.GetTotalReceivedBytes() * 8) / 1024; | |
817 std::string histogram_name = "NQE.Correlation.ResourceLoadTime.0Kb_128Kb"; | |
Ilya Sherman
2016/07/21 21:38:08
nit: I'd just inline this constant below, where it
tbansal1
2016/07/21 22:42:53
Done.
| |
818 if (resource_size >= (1 << kBitsPerMetric)) { | |
819 // Too large resource size (at least 128 Kb). | |
820 return; | |
821 } | |
822 | |
823 DCHECK_EQ( | |
824 0, (rtt | downstream_throughput | resource_load_time | resource_size) >> | |
825 kBitsPerMetric); | |
826 | |
827 // First 32 - (4* kBitsPerMetric) of the sample are unset. Next | |
828 // kBitsPerMetric of the sample contain |rtt|. Next | |
829 // kBitsPerMetric contain |downstream_throughput|. Next kBitsPerMetric | |
830 // contain |resource_load_time|. And, the last kBitsPerMetric | |
831 // contain |resource_size|. | |
832 int32_t sample = rtt; | |
833 sample = (sample << kBitsPerMetric) | downstream_throughput; | |
834 sample = (sample << kBitsPerMetric) | resource_load_time; | |
835 sample = (sample << kBitsPerMetric) | resource_size; | |
Ilya Sherman
2016/07/21 21:38:08
How many distinct values for this metric is each c
tbansal1
2016/07/21 22:42:54
This could potentially be recorded once per HTTP r
| |
836 | |
837 UMA_HISTOGRAM_SPARSE_SLOWLY(histogram_name, sample); | |
687 } | 838 } |
688 | 839 |
689 void NetworkQualityEstimator::NotifyURLRequestDestroyed( | 840 void NetworkQualityEstimator::NotifyURLRequestDestroyed( |
690 const URLRequest& request) { | 841 const URLRequest& request) { |
691 DCHECK(thread_checker_.CalledOnValidThread()); | 842 DCHECK(thread_checker_.CalledOnValidThread()); |
692 | 843 |
693 NotifyRequestCompleted(request); | 844 if (!RequestSchemeIsHTTPOrHTTPS(request)) |
845 return; | |
846 | |
847 throughput_analyzer_->NotifyRequestCompleted(request); | |
694 } | 848 } |
695 | 849 |
696 void NetworkQualityEstimator::AddRTTObserver(RTTObserver* rtt_observer) { | 850 void NetworkQualityEstimator::AddRTTObserver(RTTObserver* rtt_observer) { |
697 DCHECK(thread_checker_.CalledOnValidThread()); | 851 DCHECK(thread_checker_.CalledOnValidThread()); |
698 rtt_observer_list_.AddObserver(rtt_observer); | 852 rtt_observer_list_.AddObserver(rtt_observer); |
699 } | 853 } |
700 | 854 |
701 void NetworkQualityEstimator::RemoveRTTObserver(RTTObserver* rtt_observer) { | 855 void NetworkQualityEstimator::RemoveRTTObserver(RTTObserver* rtt_observer) { |
702 DCHECK(thread_checker_.CalledOnValidThread()); | 856 DCHECK(thread_checker_.CalledOnValidThread()); |
703 rtt_observer_list_.RemoveObserver(rtt_observer); | 857 rtt_observer_list_.RemoveObserver(rtt_observer); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
962 NetworkQualityEstimator::MetricUsage:: | 1116 NetworkQualityEstimator::MetricUsage:: |
963 USE_IF_AVAILABLE /* transport_rtt_metric */, | 1117 USE_IF_AVAILABLE /* transport_rtt_metric */, |
964 NetworkQualityEstimator::MetricUsage:: | 1118 NetworkQualityEstimator::MetricUsage:: |
965 USE_IF_AVAILABLE /* downstream_throughput_kbps_metric */); | 1119 USE_IF_AVAILABLE /* downstream_throughput_kbps_metric */); |
966 } | 1120 } |
967 // Add additional algorithms here. | 1121 // Add additional algorithms here. |
968 NOTREACHED(); | 1122 NOTREACHED(); |
969 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; | 1123 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
970 } | 1124 } |
971 | 1125 |
1126 bool NetworkQualityEstimator::UseTransportRTT() const { | |
1127 DCHECK(thread_checker_.CalledOnValidThread()); | |
1128 | |
1129 if (effective_connection_type_algorithm_ == | |
1130 EffectiveConnectionTypeAlgorithm::HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT) { | |
1131 return false; | |
1132 } | |
1133 if (effective_connection_type_algorithm_ == | |
1134 EffectiveConnectionTypeAlgorithm:: | |
1135 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT) { | |
1136 return true; | |
1137 } | |
1138 // Add additional algorithms here. | |
1139 NOTREACHED(); | |
1140 return false; | |
1141 } | |
1142 | |
972 NetworkQualityEstimator::EffectiveConnectionType | 1143 NetworkQualityEstimator::EffectiveConnectionType |
973 NetworkQualityEstimator::GetRecentEffectiveConnectionTypeUsingMetrics( | 1144 NetworkQualityEstimator::GetRecentEffectiveConnectionTypeUsingMetrics( |
974 const base::TimeTicks& start_time, | 1145 const base::TimeTicks& start_time, |
975 NetworkQualityEstimator::MetricUsage http_rtt_metric, | 1146 NetworkQualityEstimator::MetricUsage http_rtt_metric, |
976 NetworkQualityEstimator::MetricUsage transport_rtt_metric, | 1147 NetworkQualityEstimator::MetricUsage transport_rtt_metric, |
977 NetworkQualityEstimator::MetricUsage downstream_throughput_kbps_metric) | 1148 NetworkQualityEstimator::MetricUsage downstream_throughput_kbps_metric) |
978 const { | 1149 const { |
979 DCHECK(thread_checker_.CalledOnValidThread()); | 1150 DCHECK(thread_checker_.CalledOnValidThread()); |
980 | 1151 |
981 // If the device is currently offline, then return | 1152 // If the device is currently offline, then return |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1330 NOTREACHED(); | 1501 NOTREACHED(); |
1331 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; | 1502 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
1332 } | 1503 } |
1333 | 1504 |
1334 void NetworkQualityEstimator::SetTickClockForTesting( | 1505 void NetworkQualityEstimator::SetTickClockForTesting( |
1335 std::unique_ptr<base::TickClock> tick_clock) { | 1506 std::unique_ptr<base::TickClock> tick_clock) { |
1336 DCHECK(thread_checker_.CalledOnValidThread()); | 1507 DCHECK(thread_checker_.CalledOnValidThread()); |
1337 tick_clock_ = std::move(tick_clock); | 1508 tick_clock_ = std::move(tick_clock); |
1338 } | 1509 } |
1339 | 1510 |
1511 double NetworkQualityEstimator::RandDouble() const { | |
1512 return base::RandDouble(); | |
1513 } | |
1514 | |
1340 void NetworkQualityEstimator::CacheNetworkQualityEstimate() { | 1515 void NetworkQualityEstimator::CacheNetworkQualityEstimate() { |
1341 DCHECK(thread_checker_.CalledOnValidThread()); | 1516 DCHECK(thread_checker_.CalledOnValidThread()); |
1342 DCHECK_LE(cached_network_qualities_.size(), | 1517 DCHECK_LE(cached_network_qualities_.size(), |
1343 static_cast<size_t>(kMaximumNetworkQualityCacheSize)); | 1518 static_cast<size_t>(kMaximumNetworkQualityCacheSize)); |
1344 | 1519 |
1345 // If the network name is unavailable, caching should not be performed. | 1520 // If the network name is unavailable, caching should not be performed. |
1346 if (current_network_id_.id.empty()) | 1521 if (current_network_id_.id.empty()) |
1347 return; | 1522 return; |
1348 | 1523 |
1349 base::TimeDelta http_rtt = nqe::internal::InvalidRTT(); | 1524 base::TimeDelta http_rtt = nqe::internal::InvalidRTT(); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1472 NotifyObserversOfEffectiveConnectionTypeChanged() { | 1647 NotifyObserversOfEffectiveConnectionTypeChanged() { |
1473 DCHECK(thread_checker_.CalledOnValidThread()); | 1648 DCHECK(thread_checker_.CalledOnValidThread()); |
1474 | 1649 |
1475 // TODO(tbansal): Add hysteresis in the notification. | 1650 // TODO(tbansal): Add hysteresis in the notification. |
1476 FOR_EACH_OBSERVER( | 1651 FOR_EACH_OBSERVER( |
1477 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, | 1652 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, |
1478 OnEffectiveConnectionTypeChanged(effective_connection_type_)); | 1653 OnEffectiveConnectionTypeChanged(effective_connection_type_)); |
1479 } | 1654 } |
1480 | 1655 |
1481 } // namespace net | 1656 } // namespace net |
OLD | NEW |