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

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

Issue 2899453002: Pass parsed network quality estimator params when constructing NQE (Closed)
Patch Set: Fix Android compile error Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/nqe/network_quality_estimator.h" 5 #include "net/nqe/network_quality_estimator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/ptr_util.h"
16 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
17 #include "base/metrics/histogram_base.h" 18 #include "base/metrics/histogram_base.h"
18 #include "base/metrics/histogram_macros.h" 19 #include "base/metrics/histogram_macros.h"
19 #include "base/metrics/sparse_histogram.h" 20 #include "base/metrics/sparse_histogram.h"
20 #include "base/rand_util.h" 21 #include "base/rand_util.h"
21 #include "base/single_thread_task_runner.h" 22 #include "base/single_thread_task_runner.h"
22 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_piece.h" 24 #include "base/strings/string_piece.h"
24 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
25 #include "base/threading/thread_task_runner_handle.h" 26 #include "base/threading/thread_task_runner_handle.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 histogram_name, 0, EFFECTIVE_CONNECTION_TYPE_LAST, 205 histogram_name, 0, EFFECTIVE_CONNECTION_TYPE_LAST,
205 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, 206 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */,
206 base::HistogramBase::kUmaTargetedHistogramFlag); 207 base::HistogramBase::kUmaTargetedHistogramFlag);
207 histogram->Add(std::abs(metric)); 208 histogram->Add(std::abs(metric));
208 } 209 }
209 210
210 } // namespace 211 } // namespace
211 212
212 NetworkQualityEstimator::NetworkQualityEstimator( 213 NetworkQualityEstimator::NetworkQualityEstimator(
213 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, 214 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
214 const std::map<std::string, std::string>& variation_params, 215 std::unique_ptr<nqe::internal::NetworkQualityEstimatorParams> params,
215 NetLog* net_log)
216 : NetworkQualityEstimator(std::move(external_estimates_provider),
217 variation_params,
218 false,
219 false,
220 net_log) {}
221
222 NetworkQualityEstimator::NetworkQualityEstimator(
223 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
224 const std::map<std::string, std::string>& variation_params,
225 bool use_local_host_requests_for_tests,
226 bool use_smaller_responses_for_tests,
227 NetLog* net_log) 216 NetLog* net_log)
228 : NetworkQualityEstimator( 217 : NetworkQualityEstimator(
229 std::move(external_estimates_provider), 218 std::move(external_estimates_provider),
230 variation_params, 219 std::move(params),
231 use_local_host_requests_for_tests, 220 false,
232 use_smaller_responses_for_tests, 221 false,
233 true, 222 true,
234 NetLogWithSource::Make( 223 NetLogWithSource::Make(
235 net_log, 224 net_log,
236 net::NetLogSourceType::NETWORK_QUALITY_ESTIMATOR)) {} 225 net::NetLogSourceType::NETWORK_QUALITY_ESTIMATOR)) {}
237 226
238 NetworkQualityEstimator::NetworkQualityEstimator( 227 NetworkQualityEstimator::NetworkQualityEstimator(
239 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, 228 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
240 const std::map<std::string, std::string>& variation_params, 229 std::unique_ptr<nqe::internal::NetworkQualityEstimatorParams> params,
241 bool use_local_host_requests_for_tests, 230 bool use_local_host_requests_for_tests,
242 bool use_smaller_responses_for_tests, 231 bool use_smaller_responses_for_tests,
243 bool add_default_platform_observations, 232 bool add_default_platform_observations,
244 const NetLogWithSource& net_log) 233 const NetLogWithSource& net_log)
245 : algorithm_name_to_enum_({{"HttpRTTAndDownstreamThroughput", 234 : algorithm_name_to_enum_({{"HttpRTTAndDownstreamThroughput",
246 EffectiveConnectionTypeAlgorithm:: 235 EffectiveConnectionTypeAlgorithm::
247 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, 236 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT},
248 {"TransportRTTOrDownstreamThroughput", 237 {"TransportRTTOrDownstreamThroughput",
249 EffectiveConnectionTypeAlgorithm:: 238 EffectiveConnectionTypeAlgorithm::
250 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}), 239 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}),
251 params_(variation_params), 240 params_(std::move(params)),
252 use_localhost_requests_(use_local_host_requests_for_tests), 241 use_localhost_requests_(use_local_host_requests_for_tests),
253 use_small_responses_(use_smaller_responses_for_tests), 242 use_small_responses_(use_smaller_responses_for_tests),
254 disable_offline_check_(false), 243 disable_offline_check_(false),
255 add_default_platform_observations_(add_default_platform_observations), 244 add_default_platform_observations_(add_default_platform_observations),
256 effective_connection_type_algorithm_( 245 effective_connection_type_algorithm_(
257 algorithm_name_to_enum_.find( 246 algorithm_name_to_enum_.find(
258 params_.GetEffectiveConnectionTypeAlgorithm()) == 247 params_->GetEffectiveConnectionTypeAlgorithm()) ==
259 algorithm_name_to_enum_.end() 248 algorithm_name_to_enum_.end()
260 ? kDefaultEffectiveConnectionTypeAlgorithm 249 ? kDefaultEffectiveConnectionTypeAlgorithm
261 : algorithm_name_to_enum_ 250 : algorithm_name_to_enum_
262 .find(params_.GetEffectiveConnectionTypeAlgorithm()) 251 .find(params_->GetEffectiveConnectionTypeAlgorithm())
263 ->second), 252 ->second),
264 tick_clock_(new base::DefaultTickClock()), 253 tick_clock_(new base::DefaultTickClock()),
265 last_connection_change_(tick_clock_->NowTicks()), 254 last_connection_change_(tick_clock_->NowTicks()),
266 current_network_id_(nqe::internal::NetworkID( 255 current_network_id_(nqe::internal::NetworkID(
267 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, 256 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN,
268 std::string())), 257 std::string())),
269 downstream_throughput_kbps_observations_( 258 downstream_throughput_kbps_observations_(
270 params_.weight_multiplier_per_second(), 259 params_->weight_multiplier_per_second(),
271 params_.weight_multiplier_per_dbm()), 260 params_->weight_multiplier_per_dbm()),
272 rtt_observations_(params_.weight_multiplier_per_second(), 261 rtt_observations_(params_->weight_multiplier_per_second(),
273 params_.weight_multiplier_per_dbm()), 262 params_->weight_multiplier_per_dbm()),
274 effective_connection_type_at_last_main_frame_( 263 effective_connection_type_at_last_main_frame_(
275 EFFECTIVE_CONNECTION_TYPE_UNKNOWN), 264 EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
276 external_estimate_provider_(std::move(external_estimates_provider)), 265 external_estimate_provider_(std::move(external_estimates_provider)),
277 effective_connection_type_recomputation_interval_( 266 effective_connection_type_recomputation_interval_(
278 base::TimeDelta::FromSeconds(10)), 267 base::TimeDelta::FromSeconds(10)),
279 rtt_observations_size_at_last_ect_computation_(0), 268 rtt_observations_size_at_last_ect_computation_(0),
280 throughput_observations_size_at_last_ect_computation_(0), 269 throughput_observations_size_at_last_ect_computation_(0),
281 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), 270 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
282 signal_strength_dbm_(INT32_MIN), 271 signal_strength_dbm_(INT32_MIN),
283 min_signal_strength_since_connection_change_(INT32_MAX), 272 min_signal_strength_since_connection_change_(INT32_MAX),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 AddDefaultEstimates(); 308 AddDefaultEstimates();
320 309
321 throughput_analyzer_.reset(new nqe::internal::ThroughputAnalyzer( 310 throughput_analyzer_.reset(new nqe::internal::ThroughputAnalyzer(
322 base::ThreadTaskRunnerHandle::Get(), 311 base::ThreadTaskRunnerHandle::Get(),
323 base::Bind(&NetworkQualityEstimator::OnNewThroughputObservationAvailable, 312 base::Bind(&NetworkQualityEstimator::OnNewThroughputObservationAvailable,
324 base::Unretained(this)), 313 base::Unretained(this)),
325 use_localhost_requests_, use_smaller_responses_for_tests)); 314 use_localhost_requests_, use_smaller_responses_for_tests));
326 315
327 watcher_factory_.reset(new nqe::internal::SocketWatcherFactory( 316 watcher_factory_.reset(new nqe::internal::SocketWatcherFactory(
328 base::ThreadTaskRunnerHandle::Get(), 317 base::ThreadTaskRunnerHandle::Get(),
329 params_.min_socket_watcher_notification_interval(), 318 params_->min_socket_watcher_notification_interval(),
330 base::Bind(&NetworkQualityEstimator::OnUpdatedRTTAvailable, 319 base::Bind(&NetworkQualityEstimator::OnUpdatedRTTAvailable,
331 base::Unretained(this)), 320 base::Unretained(this)),
332 tick_clock_.get())); 321 tick_clock_.get()));
333 322
334 // Record accuracy after a 15 second interval. The values used here must 323 // Record accuracy after a 15 second interval. The values used here must
335 // remain in sync with the suffixes specified in 324 // remain in sync with the suffixes specified in
336 // tools/metrics/histograms/histograms.xml. 325 // tools/metrics/histograms/histograms.xml.
337 accuracy_recording_intervals_.push_back(base::TimeDelta::FromSeconds(15)); 326 accuracy_recording_intervals_.push_back(base::TimeDelta::FromSeconds(15));
338 327
339 for (int i = 0; i < STATISTIC_LAST; ++i) 328 for (int i = 0; i < STATISTIC_LAST; ++i)
340 http_rtt_at_last_main_frame_[i] = nqe::internal::InvalidRTT(); 329 http_rtt_at_last_main_frame_[i] = nqe::internal::InvalidRTT();
341 } 330 }
342 331
343 void NetworkQualityEstimator::AddDefaultEstimates() { 332 void NetworkQualityEstimator::AddDefaultEstimates() {
344 DCHECK(thread_checker_.CalledOnValidThread()); 333 DCHECK(thread_checker_.CalledOnValidThread());
345 334
346 if (!add_default_platform_observations_) 335 if (!add_default_platform_observations_)
347 return; 336 return;
348 337
349 if (params_.DefaultObservation(current_network_id_.type).http_rtt() != 338 if (params_->DefaultObservation(current_network_id_.type).http_rtt() !=
350 nqe::internal::InvalidRTT()) { 339 nqe::internal::InvalidRTT()) {
351 RttObservation rtt_observation( 340 RttObservation rtt_observation(
352 params_.DefaultObservation(current_network_id_.type).http_rtt(), 341 params_->DefaultObservation(current_network_id_.type).http_rtt(),
353 tick_clock_->NowTicks(), INT32_MIN, 342 tick_clock_->NowTicks(), INT32_MIN,
354 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM); 343 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM);
355 rtt_observations_.AddObservation(rtt_observation); 344 rtt_observations_.AddObservation(rtt_observation);
356 NotifyObserversOfRTT(rtt_observation); 345 NotifyObserversOfRTT(rtt_observation);
357 } 346 }
358 347
359 if (params_.DefaultObservation(current_network_id_.type).transport_rtt() != 348 if (params_->DefaultObservation(current_network_id_.type).transport_rtt() !=
360 nqe::internal::InvalidRTT()) { 349 nqe::internal::InvalidRTT()) {
361 RttObservation rtt_observation( 350 RttObservation rtt_observation(
362 params_.DefaultObservation(current_network_id_.type).transport_rtt(), 351 params_->DefaultObservation(current_network_id_.type).transport_rtt(),
363 tick_clock_->NowTicks(), INT32_MIN, 352 tick_clock_->NowTicks(), INT32_MIN,
364 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM); 353 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM);
365 rtt_observations_.AddObservation(rtt_observation); 354 rtt_observations_.AddObservation(rtt_observation);
366 NotifyObserversOfRTT(rtt_observation); 355 NotifyObserversOfRTT(rtt_observation);
367 } 356 }
368 357
369 if (params_.DefaultObservation(current_network_id_.type) 358 if (params_->DefaultObservation(current_network_id_.type)
370 .downstream_throughput_kbps() != nqe::internal::kInvalidThroughput) { 359 .downstream_throughput_kbps() != nqe::internal::kInvalidThroughput) {
371 ThroughputObservation throughput_observation( 360 ThroughputObservation throughput_observation(
372 params_.DefaultObservation(current_network_id_.type) 361 params_->DefaultObservation(current_network_id_.type)
373 .downstream_throughput_kbps(), 362 .downstream_throughput_kbps(),
374 tick_clock_->NowTicks(), INT32_MIN, 363 tick_clock_->NowTicks(), INT32_MIN,
375 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM); 364 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM);
376 downstream_throughput_kbps_observations_.AddObservation( 365 downstream_throughput_kbps_observations_.AddObservation(
377 throughput_observation); 366 throughput_observation);
378 NotifyObserversOfThroughput(throughput_observation); 367 NotifyObserversOfThroughput(throughput_observation);
379 } 368 }
380 } 369 }
381 370
382 NetworkQualityEstimator::~NetworkQualityEstimator() { 371 NetworkQualityEstimator::~NetworkQualityEstimator() {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 RecordCorrelationMetric(request, net_error); 596 RecordCorrelationMetric(request, net_error);
608 } 597 }
609 598
610 void NetworkQualityEstimator::RecordCorrelationMetric(const URLRequest& request, 599 void NetworkQualityEstimator::RecordCorrelationMetric(const URLRequest& request,
611 int net_error) const { 600 int net_error) const {
612 DCHECK(thread_checker_.CalledOnValidThread()); 601 DCHECK(thread_checker_.CalledOnValidThread());
613 602
614 // The histogram is recorded randomly to reduce overhead involved with sparse 603 // The histogram is recorded randomly to reduce overhead involved with sparse
615 // histograms. Furthermore, recording the correlation on each request is 604 // histograms. Furthermore, recording the correlation on each request is
616 // unnecessary. 605 // unnecessary.
617 if (RandDouble() >= params_.correlation_uma_logging_probability()) 606 if (RandDouble() >= params_->correlation_uma_logging_probability())
618 return; 607 return;
619 608
620 if (request.response_info().was_cached || 609 if (request.response_info().was_cached ||
621 !request.response_info().network_accessed) { 610 !request.response_info().network_accessed) {
622 return; 611 return;
623 } 612 }
624 613
625 LoadTimingInfo load_timing_info; 614 LoadTimingInfo load_timing_info;
626 request.GetLoadTimingInfo(&load_timing_info); 615 request.GetLoadTimingInfo(&load_timing_info);
627 // If the load timing info is unavailable, it probably means that the request 616 // If the load timing info is unavailable, it probably means that the request
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 disable_offline_check_ = disable_offline_check; 756 disable_offline_check_ = disable_offline_check;
768 network_quality_store_->DisableOfflineCheckForTesting(disable_offline_check_); 757 network_quality_store_->DisableOfflineCheckForTesting(disable_offline_check_);
769 } 758 }
770 759
771 void NetworkQualityEstimator::ReportEffectiveConnectionTypeForTesting( 760 void NetworkQualityEstimator::ReportEffectiveConnectionTypeForTesting(
772 EffectiveConnectionType effective_connection_type) { 761 EffectiveConnectionType effective_connection_type) {
773 DCHECK(thread_checker_.CalledOnValidThread()); 762 DCHECK(thread_checker_.CalledOnValidThread());
774 763
775 event_creator_.MaybeAddNetworkQualityChangedEventToNetLog( 764 event_creator_.MaybeAddNetworkQualityChangedEventToNetLog(
776 effective_connection_type_, 765 effective_connection_type_,
777 params_.TypicalNetworkQuality(effective_connection_type)); 766 params_->TypicalNetworkQuality(effective_connection_type));
778 767
779 for (auto& observer : effective_connection_type_observer_list_) 768 for (auto& observer : effective_connection_type_observer_list_)
780 observer.OnEffectiveConnectionTypeChanged(effective_connection_type); 769 observer.OnEffectiveConnectionTypeChanged(effective_connection_type);
781 770
782 network_quality_store_->Add(current_network_id_, 771 network_quality_store_->Add(current_network_id_,
783 nqe::internal::CachedNetworkQuality( 772 nqe::internal::CachedNetworkQuality(
784 tick_clock_->NowTicks(), network_quality_, 773 tick_clock_->NowTicks(), network_quality_,
785 effective_connection_type)); 774 effective_connection_type));
786 } 775 }
787 776
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 last_effective_connection_type_computation_, 815 last_effective_connection_type_computation_,
827 network_quality_, effective_connection_type_)); 816 network_quality_, effective_connection_type_));
828 817
829 // Clear the local state. 818 // Clear the local state.
830 last_connection_change_ = tick_clock_->NowTicks(); 819 last_connection_change_ = tick_clock_->NowTicks();
831 peak_network_quality_ = nqe::internal::NetworkQuality(); 820 peak_network_quality_ = nqe::internal::NetworkQuality();
832 downstream_throughput_kbps_observations_.Clear(); 821 downstream_throughput_kbps_observations_.Clear();
833 rtt_observations_.Clear(); 822 rtt_observations_.Clear();
834 823
835 #if defined(OS_ANDROID) 824 #if defined(OS_ANDROID)
836 if (params_.weight_multiplier_per_dbm() < 1.0 && 825 if (params_->weight_multiplier_per_dbm() < 1.0 &&
837 NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) { 826 NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) {
838 UMA_HISTOGRAM_BOOLEAN( 827 UMA_HISTOGRAM_BOOLEAN(
839 "NQE.CellularSignalStrengthAvailable", 828 "NQE.CellularSignalStrengthAvailable",
840 min_signal_strength_since_connection_change_ != INT32_MAX && 829 min_signal_strength_since_connection_change_ != INT32_MAX &&
841 max_signal_strength_since_connection_change_ != INT32_MIN); 830 max_signal_strength_since_connection_change_ != INT32_MIN);
842 831
843 if (min_signal_strength_since_connection_change_ != INT32_MAX && 832 if (min_signal_strength_since_connection_change_ != INT32_MAX &&
844 max_signal_strength_since_connection_change_ != INT32_MIN) { 833 max_signal_strength_since_connection_change_ != INT32_MIN) {
845 UMA_HISTOGRAM_COUNTS_100( 834 UMA_HISTOGRAM_COUNTS_100(
846 "NQE.CellularSignalStrengthDifference", 835 "NQE.CellularSignalStrengthDifference",
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET && 877 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET &&
889 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) { 878 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) {
890 RecordExternalEstimateProviderMetrics( 879 RecordExternalEstimateProviderMetrics(
891 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED); 880 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED);
892 external_estimate_provider_->Update(); 881 external_estimate_provider_->Update();
893 } 882 }
894 } 883 }
895 884
896 void NetworkQualityEstimator::UpdateSignalStrength() { 885 void NetworkQualityEstimator::UpdateSignalStrength() {
897 #if defined(OS_ANDROID) 886 #if defined(OS_ANDROID)
898 if (params_.weight_multiplier_per_dbm() >= 1.0 || 887 if (params_->weight_multiplier_per_dbm() >= 1.0 ||
899 !NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type) || 888 !NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type) ||
900 !android::cellular_signal_strength::GetSignalStrengthDbm( 889 !android::cellular_signal_strength::GetSignalStrengthDbm(
901 &signal_strength_dbm_)) { 890 &signal_strength_dbm_)) {
902 signal_strength_dbm_ = INT32_MIN; 891 signal_strength_dbm_ = INT32_MIN;
903 } 892 }
904 min_signal_strength_since_connection_change_ = std::min( 893 min_signal_strength_since_connection_change_ = std::min(
905 min_signal_strength_since_connection_change_, signal_strength_dbm_); 894 min_signal_strength_since_connection_change_, signal_strength_dbm_);
906 max_signal_strength_since_connection_change_ = std::max( 895 max_signal_strength_since_connection_change_ = std::max(
907 max_signal_strength_since_connection_change_, signal_strength_dbm_); 896 max_signal_strength_since_connection_change_, signal_strength_dbm_);
908 #endif // OS_ANDROID 897 #endif // OS_ANDROID
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 NetworkQualityEstimator::MetricUsage downstream_throughput_kbps_metric, 1173 NetworkQualityEstimator::MetricUsage downstream_throughput_kbps_metric,
1185 base::TimeDelta* http_rtt, 1174 base::TimeDelta* http_rtt,
1186 base::TimeDelta* transport_rtt, 1175 base::TimeDelta* transport_rtt,
1187 int32_t* downstream_throughput_kbps) const { 1176 int32_t* downstream_throughput_kbps) const {
1188 DCHECK(thread_checker_.CalledOnValidThread()); 1177 DCHECK(thread_checker_.CalledOnValidThread());
1189 1178
1190 *http_rtt = nqe::internal::InvalidRTT(); 1179 *http_rtt = nqe::internal::InvalidRTT();
1191 *transport_rtt = nqe::internal::InvalidRTT(); 1180 *transport_rtt = nqe::internal::InvalidRTT();
1192 *downstream_throughput_kbps = nqe::internal::kInvalidThroughput; 1181 *downstream_throughput_kbps = nqe::internal::kInvalidThroughput;
1193 1182
1194 if (params_.forced_effective_connection_type()) { 1183 if (params_->forced_effective_connection_type()) {
1195 *http_rtt = params_ 1184 *http_rtt = params_
1196 .TypicalNetworkQuality( 1185 ->TypicalNetworkQuality(
1197 params_.forced_effective_connection_type().value()) 1186 params_->forced_effective_connection_type().value())
1198 .http_rtt(); 1187 .http_rtt();
1199 *transport_rtt = params_ 1188 *transport_rtt =
1200 .TypicalNetworkQuality( 1189 params_
1201 params_.forced_effective_connection_type().value()) 1190 ->TypicalNetworkQuality(
1202 .transport_rtt(); 1191 params_->forced_effective_connection_type().value())
1192 .transport_rtt();
1203 *downstream_throughput_kbps = 1193 *downstream_throughput_kbps =
1204 params_ 1194 params_
1205 .TypicalNetworkQuality( 1195 ->TypicalNetworkQuality(
1206 params_.forced_effective_connection_type().value()) 1196 params_->forced_effective_connection_type().value())
1207 .downstream_throughput_kbps(); 1197 .downstream_throughput_kbps();
1208 return params_.forced_effective_connection_type().value(); 1198 return params_->forced_effective_connection_type().value();
1209 } 1199 }
1210 1200
1211 // If the device is currently offline, then return 1201 // If the device is currently offline, then return
1212 // EFFECTIVE_CONNECTION_TYPE_OFFLINE. 1202 // EFFECTIVE_CONNECTION_TYPE_OFFLINE.
1213 1203
1214 if (current_network_id_.type == NetworkChangeNotifier::CONNECTION_NONE && 1204 if (current_network_id_.type == NetworkChangeNotifier::CONNECTION_NONE &&
1215 !disable_offline_check_) { 1205 !disable_offline_check_) {
1216 return EFFECTIVE_CONNECTION_TYPE_OFFLINE; 1206 return EFFECTIVE_CONNECTION_TYPE_OFFLINE;
1217 } 1207 }
1218 1208
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 // EffectiveConnectionType that best matches the current connection's 1243 // EffectiveConnectionType that best matches the current connection's
1254 // performance. The match is done by comparing RTT and throughput. 1244 // performance. The match is done by comparing RTT and throughput.
1255 for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) { 1245 for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) {
1256 EffectiveConnectionType type = static_cast<EffectiveConnectionType>(i); 1246 EffectiveConnectionType type = static_cast<EffectiveConnectionType>(i);
1257 if (i == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) 1247 if (i == EFFECTIVE_CONNECTION_TYPE_UNKNOWN)
1258 continue; 1248 continue;
1259 1249
1260 const bool estimated_http_rtt_is_higher_than_threshold = 1250 const bool estimated_http_rtt_is_higher_than_threshold =
1261 http_rtt_metric != NetworkQualityEstimator::MetricUsage::DO_NOT_USE && 1251 http_rtt_metric != NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1262 *http_rtt != nqe::internal::InvalidRTT() && 1252 *http_rtt != nqe::internal::InvalidRTT() &&
1263 params_.ConnectionThreshold(type).http_rtt() != 1253 params_->ConnectionThreshold(type).http_rtt() !=
1264 nqe::internal::InvalidRTT() && 1254 nqe::internal::InvalidRTT() &&
1265 *http_rtt >= params_.ConnectionThreshold(type).http_rtt(); 1255 *http_rtt >= params_->ConnectionThreshold(type).http_rtt();
1266 1256
1267 const bool estimated_transport_rtt_is_higher_than_threshold = 1257 const bool estimated_transport_rtt_is_higher_than_threshold =
1268 transport_rtt_metric != 1258 transport_rtt_metric !=
1269 NetworkQualityEstimator::MetricUsage::DO_NOT_USE && 1259 NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1270 *transport_rtt != nqe::internal::InvalidRTT() && 1260 *transport_rtt != nqe::internal::InvalidRTT() &&
1271 params_.ConnectionThreshold(type).transport_rtt() != 1261 params_->ConnectionThreshold(type).transport_rtt() !=
1272 nqe::internal::InvalidRTT() && 1262 nqe::internal::InvalidRTT() &&
1273 *transport_rtt >= params_.ConnectionThreshold(type).transport_rtt(); 1263 *transport_rtt >= params_->ConnectionThreshold(type).transport_rtt();
1274 1264
1275 const bool estimated_throughput_is_lower_than_threshold = 1265 const bool estimated_throughput_is_lower_than_threshold =
1276 downstream_throughput_kbps_metric != 1266 downstream_throughput_kbps_metric !=
1277 NetworkQualityEstimator::MetricUsage::DO_NOT_USE && 1267 NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1278 *downstream_throughput_kbps != nqe::internal::kInvalidThroughput && 1268 *downstream_throughput_kbps != nqe::internal::kInvalidThroughput &&
1279 params_.ConnectionThreshold(type).downstream_throughput_kbps() != 1269 params_->ConnectionThreshold(type).downstream_throughput_kbps() !=
1280 nqe::internal::kInvalidThroughput && 1270 nqe::internal::kInvalidThroughput &&
1281 *downstream_throughput_kbps <= 1271 *downstream_throughput_kbps <=
1282 params_.ConnectionThreshold(type).downstream_throughput_kbps(); 1272 params_->ConnectionThreshold(type).downstream_throughput_kbps();
1283 1273
1284 if (estimated_http_rtt_is_higher_than_threshold || 1274 if (estimated_http_rtt_is_higher_than_threshold ||
1285 estimated_transport_rtt_is_higher_than_threshold || 1275 estimated_transport_rtt_is_higher_than_threshold ||
1286 estimated_throughput_is_lower_than_threshold) { 1276 estimated_throughput_is_lower_than_threshold) {
1287 return type; 1277 return type;
1288 } 1278 }
1289 } 1279 }
1290 // Return the fastest connection type. 1280 // Return the fastest connection type.
1291 return static_cast<EffectiveConnectionType>(EFFECTIVE_CONNECTION_TYPE_LAST - 1281 return static_cast<EffectiveConnectionType>(EFFECTIVE_CONNECTION_TYPE_LAST -
1292 1); 1282 1);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 1452
1463 if (network_id.type == NetworkChangeNotifier::GetConnectionType()) 1453 if (network_id.type == NetworkChangeNotifier::GetConnectionType())
1464 return network_id; 1454 return network_id;
1465 } 1455 }
1466 NOTREACHED(); 1456 NOTREACHED();
1467 } 1457 }
1468 1458
1469 bool NetworkQualityEstimator::ReadCachedNetworkQualityEstimate() { 1459 bool NetworkQualityEstimator::ReadCachedNetworkQualityEstimate() {
1470 DCHECK(thread_checker_.CalledOnValidThread()); 1460 DCHECK(thread_checker_.CalledOnValidThread());
1471 1461
1472 if (!params_.persistent_cache_reading_enabled()) 1462 if (!params_->persistent_cache_reading_enabled())
1473 return false; 1463 return false;
1474 1464
1475 nqe::internal::CachedNetworkQuality cached_network_quality; 1465 nqe::internal::CachedNetworkQuality cached_network_quality;
1476 1466
1477 const bool cached_estimate_available = network_quality_store_->GetById( 1467 const bool cached_estimate_available = network_quality_store_->GetById(
1478 current_network_id_, &cached_network_quality); 1468 current_network_id_, &cached_network_quality);
1479 if (network_quality_store_->EligibleForCaching(current_network_id_)) { 1469 if (network_quality_store_->EligibleForCaching(current_network_id_)) {
1480 UMA_HISTOGRAM_BOOLEAN("NQE.CachedNetworkQualityAvailable", 1470 UMA_HISTOGRAM_BOOLEAN("NQE.CachedNetworkQualityAvailable",
1481 cached_estimate_available); 1471 cached_estimate_available);
1482 } 1472 }
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 // RTT and throughput values are not set in the prefs. 1742 // RTT and throughput values are not set in the prefs.
1753 DCHECK_EQ(nqe::internal::InvalidRTT(), 1743 DCHECK_EQ(nqe::internal::InvalidRTT(),
1754 it.second.network_quality().http_rtt()); 1744 it.second.network_quality().http_rtt());
1755 DCHECK_EQ(nqe::internal::InvalidRTT(), 1745 DCHECK_EQ(nqe::internal::InvalidRTT(),
1756 it.second.network_quality().transport_rtt()); 1746 it.second.network_quality().transport_rtt());
1757 DCHECK_EQ(nqe::internal::kInvalidThroughput, 1747 DCHECK_EQ(nqe::internal::kInvalidThroughput,
1758 it.second.network_quality().downstream_throughput_kbps()); 1748 it.second.network_quality().downstream_throughput_kbps());
1759 1749
1760 nqe::internal::CachedNetworkQuality cached_network_quality( 1750 nqe::internal::CachedNetworkQuality cached_network_quality(
1761 base::TimeTicks::Now(), 1751 base::TimeTicks::Now(),
1762 params_.TypicalNetworkQuality(effective_connection_type), 1752 params_->TypicalNetworkQuality(effective_connection_type),
1763 effective_connection_type); 1753 effective_connection_type);
1764 1754
1765 network_quality_store_->Add(it.first, cached_network_quality); 1755 network_quality_store_->Add(it.first, cached_network_quality);
1766 MaybeUpdateNetworkQualityFromCache(it.first, cached_network_quality); 1756 MaybeUpdateNetworkQualityFromCache(it.first, cached_network_quality);
1767 } 1757 }
1768 } 1758 }
1769 1759
1770 void NetworkQualityEstimator::MaybeUpdateNetworkQualityFromCache( 1760 void NetworkQualityEstimator::MaybeUpdateNetworkQualityFromCache(
1771 const nqe::internal::NetworkID& network_id, 1761 const nqe::internal::NetworkID& network_id,
1772 const nqe::internal::CachedNetworkQuality& cached_network_quality) { 1762 const nqe::internal::CachedNetworkQuality& cached_network_quality) {
1773 DCHECK(thread_checker_.CalledOnValidThread()); 1763 DCHECK(thread_checker_.CalledOnValidThread());
1774 1764
1775 if (!params_.persistent_cache_reading_enabled()) 1765 if (!params_->persistent_cache_reading_enabled())
1776 return; 1766 return;
1777 if (network_id != current_network_id_) 1767 if (network_id != current_network_id_)
1778 return; 1768 return;
1779 1769
1780 // Since the cached network quality is for the current network, add it to 1770 // Since the cached network quality is for the current network, add it to
1781 // the current observations. 1771 // the current observations.
1782 RttObservation http_rtt_observation( 1772 RttObservation http_rtt_observation(
1783 cached_network_quality.network_quality().http_rtt(), 1773 cached_network_quality.network_quality().http_rtt(),
1784 base::TimeTicks::Now(), INT32_MIN, 1774 base::TimeTicks::Now(), INT32_MIN,
1785 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); 1775 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1833 return base::Optional<base::TimeDelta>(); 1823 return base::Optional<base::TimeDelta>();
1834 } 1824 }
1835 1825
1836 base::Optional<int32_t> 1826 base::Optional<int32_t>
1837 NetworkQualityEstimator::NetworkQualityProvider::GetDownstreamThroughputKbps() 1827 NetworkQualityEstimator::NetworkQualityProvider::GetDownstreamThroughputKbps()
1838 const { 1828 const {
1839 return base::Optional<int32_t>(); 1829 return base::Optional<int32_t>();
1840 } 1830 }
1841 1831
1842 } // namespace net 1832 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698