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

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

Issue 2875073004: Move more variables to NQE params class (Closed)
Patch Set: ryansturm comments 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
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_params.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 algorithm_name_to_enum_.find(std::string())); 299 algorithm_name_to_enum_.find(std::string()));
300 300
301 DCHECK_EQ(algorithm_name_to_enum_.size(), 301 DCHECK_EQ(algorithm_name_to_enum_.size(),
302 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: 302 static_cast<size_t>(EffectiveConnectionTypeAlgorithm::
303 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); 303 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST));
304 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: 304 DCHECK_NE(EffectiveConnectionTypeAlgorithm::
305 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, 305 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST,
306 effective_connection_type_algorithm_); 306 effective_connection_type_algorithm_);
307 307
308 network_quality_store_.reset(new nqe::internal::NetworkQualityStore()); 308 network_quality_store_.reset(new nqe::internal::NetworkQualityStore());
309 ObtainOperatingParams();
310 NetworkChangeNotifier::AddConnectionTypeObserver(this); 309 NetworkChangeNotifier::AddConnectionTypeObserver(this);
311 if (external_estimate_provider_) { 310 if (external_estimate_provider_) {
312 RecordExternalEstimateProviderMetrics( 311 RecordExternalEstimateProviderMetrics(
313 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE); 312 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE);
314 external_estimate_provider_->SetUpdatedEstimateDelegate(this); 313 external_estimate_provider_->SetUpdatedEstimateDelegate(this);
315 } else { 314 } else {
316 RecordExternalEstimateProviderMetrics( 315 RecordExternalEstimateProviderMetrics(
317 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE); 316 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE);
318 } 317 }
319 current_network_id_ = GetCurrentNetworkID(); 318 current_network_id_ = GetCurrentNetworkID();
(...skipping 14 matching lines...) Expand all
334 333
335 // Record accuracy after a 15 second interval. The values used here must 334 // Record accuracy after a 15 second interval. The values used here must
336 // remain in sync with the suffixes specified in 335 // remain in sync with the suffixes specified in
337 // tools/metrics/histograms/histograms.xml. 336 // tools/metrics/histograms/histograms.xml.
338 accuracy_recording_intervals_.push_back(base::TimeDelta::FromSeconds(15)); 337 accuracy_recording_intervals_.push_back(base::TimeDelta::FromSeconds(15));
339 338
340 for (int i = 0; i < STATISTIC_LAST; ++i) 339 for (int i = 0; i < STATISTIC_LAST; ++i)
341 http_rtt_at_last_main_frame_[i] = nqe::internal::InvalidRTT(); 340 http_rtt_at_last_main_frame_[i] = nqe::internal::InvalidRTT();
342 } 341 }
343 342
344 void NetworkQualityEstimator::ObtainOperatingParams() {
345 DCHECK(thread_checker_.CalledOnValidThread());
346 params_.ObtainDefaultObservations(default_observations_);
347 params_.ObtainEffectiveConnectionTypeModelParams(connection_thresholds_);
348 params_.ObtainTypicalNetworkQuality(typical_network_quality_);
349 }
350
351 void NetworkQualityEstimator::AddDefaultEstimates() { 343 void NetworkQualityEstimator::AddDefaultEstimates() {
352 DCHECK(thread_checker_.CalledOnValidThread()); 344 DCHECK(thread_checker_.CalledOnValidThread());
353 345
354 if (!add_default_platform_observations_) 346 if (!add_default_platform_observations_)
355 return; 347 return;
356 348
357 if (default_observations_[current_network_id_.type].http_rtt() != 349 if (params_.DefaultObservation(current_network_id_.type).http_rtt() !=
358 nqe::internal::InvalidRTT()) { 350 nqe::internal::InvalidRTT()) {
359 RttObservation rtt_observation( 351 RttObservation rtt_observation(
360 default_observations_[current_network_id_.type].http_rtt(), 352 params_.DefaultObservation(current_network_id_.type).http_rtt(),
361 tick_clock_->NowTicks(), INT32_MIN, 353 tick_clock_->NowTicks(), INT32_MIN,
362 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM); 354 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM);
363 rtt_observations_.AddObservation(rtt_observation); 355 rtt_observations_.AddObservation(rtt_observation);
364 NotifyObserversOfRTT(rtt_observation); 356 NotifyObserversOfRTT(rtt_observation);
365 } 357 }
366 358
367 if (default_observations_[current_network_id_.type].transport_rtt() != 359 if (params_.DefaultObservation(current_network_id_.type).transport_rtt() !=
368 nqe::internal::InvalidRTT()) { 360 nqe::internal::InvalidRTT()) {
369 RttObservation rtt_observation( 361 RttObservation rtt_observation(
370 default_observations_[current_network_id_.type].transport_rtt(), 362 params_.DefaultObservation(current_network_id_.type).transport_rtt(),
371 tick_clock_->NowTicks(), INT32_MIN, 363 tick_clock_->NowTicks(), INT32_MIN,
372 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM); 364 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM);
373 rtt_observations_.AddObservation(rtt_observation); 365 rtt_observations_.AddObservation(rtt_observation);
374 NotifyObserversOfRTT(rtt_observation); 366 NotifyObserversOfRTT(rtt_observation);
375 } 367 }
376 368
377 if (default_observations_[current_network_id_.type] 369 if (params_.DefaultObservation(current_network_id_.type)
378 .downstream_throughput_kbps() != nqe::internal::kInvalidThroughput) { 370 .downstream_throughput_kbps() != nqe::internal::kInvalidThroughput) {
379 ThroughputObservation throughput_observation( 371 ThroughputObservation throughput_observation(
380 default_observations_[current_network_id_.type] 372 params_.DefaultObservation(current_network_id_.type)
381 .downstream_throughput_kbps(), 373 .downstream_throughput_kbps(),
382 tick_clock_->NowTicks(), INT32_MIN, 374 tick_clock_->NowTicks(), INT32_MIN,
383 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM); 375 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM);
384 downstream_throughput_kbps_observations_.AddObservation( 376 downstream_throughput_kbps_observations_.AddObservation(
385 throughput_observation); 377 throughput_observation);
386 NotifyObserversOfThroughput(throughput_observation); 378 NotifyObserversOfThroughput(throughput_observation);
387 } 379 }
388 } 380 }
389 381
390 NetworkQualityEstimator::~NetworkQualityEstimator() { 382 NetworkQualityEstimator::~NetworkQualityEstimator() {
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 disable_offline_check_ = disable_offline_check; 767 disable_offline_check_ = disable_offline_check;
776 network_quality_store_->DisableOfflineCheckForTesting(disable_offline_check_); 768 network_quality_store_->DisableOfflineCheckForTesting(disable_offline_check_);
777 } 769 }
778 770
779 void NetworkQualityEstimator::ReportEffectiveConnectionTypeForTesting( 771 void NetworkQualityEstimator::ReportEffectiveConnectionTypeForTesting(
780 EffectiveConnectionType effective_connection_type) { 772 EffectiveConnectionType effective_connection_type) {
781 DCHECK(thread_checker_.CalledOnValidThread()); 773 DCHECK(thread_checker_.CalledOnValidThread());
782 774
783 event_creator_.MaybeAddNetworkQualityChangedEventToNetLog( 775 event_creator_.MaybeAddNetworkQualityChangedEventToNetLog(
784 effective_connection_type_, 776 effective_connection_type_,
785 typical_network_quality_[effective_connection_type]); 777 params_.TypicalNetworkQuality(effective_connection_type));
786 778
787 for (auto& observer : effective_connection_type_observer_list_) 779 for (auto& observer : effective_connection_type_observer_list_)
788 observer.OnEffectiveConnectionTypeChanged(effective_connection_type); 780 observer.OnEffectiveConnectionTypeChanged(effective_connection_type);
789 781
790 network_quality_store_->Add(current_network_id_, 782 network_quality_store_->Add(current_network_id_,
791 nqe::internal::CachedNetworkQuality( 783 nqe::internal::CachedNetworkQuality(
792 tick_clock_->NowTicks(), network_quality_, 784 tick_clock_->NowTicks(), network_quality_,
793 effective_connection_type)); 785 effective_connection_type));
794 } 786 }
795 787
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 // EffectiveConnectionType that best matches the current connection's 1239 // EffectiveConnectionType that best matches the current connection's
1248 // performance. The match is done by comparing RTT and throughput. 1240 // performance. The match is done by comparing RTT and throughput.
1249 for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) { 1241 for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) {
1250 EffectiveConnectionType type = static_cast<EffectiveConnectionType>(i); 1242 EffectiveConnectionType type = static_cast<EffectiveConnectionType>(i);
1251 if (i == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) 1243 if (i == EFFECTIVE_CONNECTION_TYPE_UNKNOWN)
1252 continue; 1244 continue;
1253 1245
1254 const bool estimated_http_rtt_is_higher_than_threshold = 1246 const bool estimated_http_rtt_is_higher_than_threshold =
1255 http_rtt_metric != NetworkQualityEstimator::MetricUsage::DO_NOT_USE && 1247 http_rtt_metric != NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1256 *http_rtt != nqe::internal::InvalidRTT() && 1248 *http_rtt != nqe::internal::InvalidRTT() &&
1257 connection_thresholds_[i].http_rtt() != nqe::internal::InvalidRTT() && 1249 params_.ConnectionThreshold(type).http_rtt() !=
1258 *http_rtt >= connection_thresholds_[i].http_rtt(); 1250 nqe::internal::InvalidRTT() &&
1251 *http_rtt >= params_.ConnectionThreshold(type).http_rtt();
1259 1252
1260 const bool estimated_transport_rtt_is_higher_than_threshold = 1253 const bool estimated_transport_rtt_is_higher_than_threshold =
1261 transport_rtt_metric != 1254 transport_rtt_metric !=
1262 NetworkQualityEstimator::MetricUsage::DO_NOT_USE && 1255 NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1263 *transport_rtt != nqe::internal::InvalidRTT() && 1256 *transport_rtt != nqe::internal::InvalidRTT() &&
1264 connection_thresholds_[i].transport_rtt() != 1257 params_.ConnectionThreshold(type).transport_rtt() !=
1265 nqe::internal::InvalidRTT() && 1258 nqe::internal::InvalidRTT() &&
1266 *transport_rtt >= connection_thresholds_[i].transport_rtt(); 1259 *transport_rtt >= params_.ConnectionThreshold(type).transport_rtt();
1267 1260
1268 const bool estimated_throughput_is_lower_than_threshold = 1261 const bool estimated_throughput_is_lower_than_threshold =
1269 downstream_throughput_kbps_metric != 1262 downstream_throughput_kbps_metric !=
1270 NetworkQualityEstimator::MetricUsage::DO_NOT_USE && 1263 NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
1271 *downstream_throughput_kbps != nqe::internal::kInvalidThroughput && 1264 *downstream_throughput_kbps != nqe::internal::kInvalidThroughput &&
1272 connection_thresholds_[i].downstream_throughput_kbps() != 1265 params_.ConnectionThreshold(type).downstream_throughput_kbps() !=
1273 nqe::internal::kInvalidThroughput && 1266 nqe::internal::kInvalidThroughput &&
1274 *downstream_throughput_kbps <= 1267 *downstream_throughput_kbps <=
1275 connection_thresholds_[i].downstream_throughput_kbps(); 1268 params_.ConnectionThreshold(type).downstream_throughput_kbps();
1276 1269
1277 if (estimated_http_rtt_is_higher_than_threshold || 1270 if (estimated_http_rtt_is_higher_than_threshold ||
1278 estimated_transport_rtt_is_higher_than_threshold || 1271 estimated_transport_rtt_is_higher_than_threshold ||
1279 estimated_throughput_is_lower_than_threshold) { 1272 estimated_throughput_is_lower_than_threshold) {
1280 return type; 1273 return type;
1281 } 1274 }
1282 } 1275 }
1283 // Return the fastest connection type. 1276 // Return the fastest connection type.
1284 return static_cast<EffectiveConnectionType>(EFFECTIVE_CONNECTION_TYPE_LAST - 1277 return static_cast<EffectiveConnectionType>(EFFECTIVE_CONNECTION_TYPE_LAST -
1285 1); 1278 1);
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 } 1736 }
1744 1737
1745 // RTT and throughput values are not set in the prefs. 1738 // RTT and throughput values are not set in the prefs.
1746 DCHECK_EQ(nqe::internal::InvalidRTT(), 1739 DCHECK_EQ(nqe::internal::InvalidRTT(),
1747 it.second.network_quality().http_rtt()); 1740 it.second.network_quality().http_rtt());
1748 DCHECK_EQ(nqe::internal::InvalidRTT(), 1741 DCHECK_EQ(nqe::internal::InvalidRTT(),
1749 it.second.network_quality().transport_rtt()); 1742 it.second.network_quality().transport_rtt());
1750 DCHECK_EQ(nqe::internal::kInvalidThroughput, 1743 DCHECK_EQ(nqe::internal::kInvalidThroughput,
1751 it.second.network_quality().downstream_throughput_kbps()); 1744 it.second.network_quality().downstream_throughput_kbps());
1752 1745
1753 nqe::internal::NetworkQuality network_quality(
1754 typical_network_quality_[effective_connection_type].http_rtt(),
1755 typical_network_quality_[effective_connection_type].transport_rtt(),
1756 typical_network_quality_[effective_connection_type]
1757 .downstream_throughput_kbps());
1758
1759 nqe::internal::CachedNetworkQuality cached_network_quality( 1746 nqe::internal::CachedNetworkQuality cached_network_quality(
1760 base::TimeTicks::Now(), network_quality, effective_connection_type); 1747 base::TimeTicks::Now(),
1748 params_.TypicalNetworkQuality(effective_connection_type),
1749 effective_connection_type);
1761 1750
1762 network_quality_store_->Add(it.first, cached_network_quality); 1751 network_quality_store_->Add(it.first, cached_network_quality);
1763 MaybeUpdateNetworkQualityFromCache(it.first, cached_network_quality); 1752 MaybeUpdateNetworkQualityFromCache(it.first, cached_network_quality);
1764 } 1753 }
1765 } 1754 }
1766 1755
1767 void NetworkQualityEstimator::MaybeUpdateNetworkQualityFromCache( 1756 void NetworkQualityEstimator::MaybeUpdateNetworkQualityFromCache(
1768 const nqe::internal::NetworkID& network_id, 1757 const nqe::internal::NetworkID& network_id,
1769 const nqe::internal::CachedNetworkQuality& cached_network_quality) { 1758 const nqe::internal::CachedNetworkQuality& cached_network_quality) {
1770 DCHECK(thread_checker_.CalledOnValidThread()); 1759 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 return base::Optional<base::TimeDelta>(); 1819 return base::Optional<base::TimeDelta>();
1831 } 1820 }
1832 1821
1833 base::Optional<int32_t> 1822 base::Optional<int32_t>
1834 NetworkQualityEstimator::NetworkQualityProvider::GetDownstreamThroughputKbps() 1823 NetworkQualityEstimator::NetworkQualityProvider::GetDownstreamThroughputKbps()
1835 const { 1824 const {
1836 return base::Optional<int32_t>(); 1825 return base::Optional<int32_t>();
1837 } 1826 }
1838 1827
1839 } // namespace net 1828 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_params.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698