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

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

Issue 2261813002: Add a network quality cache observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 3 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_unittest.cc » ('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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 393
394 DCHECK_EQ(algorithm_name_to_enum_.size(), 394 DCHECK_EQ(algorithm_name_to_enum_.size(),
395 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: 395 static_cast<size_t>(EffectiveConnectionTypeAlgorithm::
396 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); 396 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST));
397 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: 397 DCHECK_NE(EffectiveConnectionTypeAlgorithm::
398 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, 398 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST,
399 effective_connection_type_algorithm_); 399 effective_connection_type_algorithm_);
400 DCHECK_LE(0.0, correlation_uma_logging_probability_); 400 DCHECK_LE(0.0, correlation_uma_logging_probability_);
401 DCHECK_GE(1.0, correlation_uma_logging_probability_); 401 DCHECK_GE(1.0, correlation_uma_logging_probability_);
402 402
403 network_quality_store_.reset(new nqe::internal::NetworkQualityStore());
403 ObtainOperatingParams(variation_params); 404 ObtainOperatingParams(variation_params);
404 ObtainEffectiveConnectionTypeModelParams(variation_params); 405 ObtainEffectiveConnectionTypeModelParams(variation_params);
405 NetworkChangeNotifier::AddConnectionTypeObserver(this); 406 NetworkChangeNotifier::AddConnectionTypeObserver(this);
406 if (external_estimate_provider_) { 407 if (external_estimate_provider_) {
407 RecordExternalEstimateProviderMetrics( 408 RecordExternalEstimateProviderMetrics(
408 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE); 409 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE);
409 external_estimate_provider_->SetUpdatedEstimateDelegate(this); 410 external_estimate_provider_->SetUpdatedEstimateDelegate(this);
410 } else { 411 } else {
411 RecordExternalEstimateProviderMetrics( 412 RecordExternalEstimateProviderMetrics(
412 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE); 413 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE);
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY); 958 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY);
958 } 959 }
959 960
960 void NetworkQualityEstimator::OnConnectionTypeChanged( 961 void NetworkQualityEstimator::OnConnectionTypeChanged(
961 NetworkChangeNotifier::ConnectionType type) { 962 NetworkChangeNotifier::ConnectionType type) {
962 DCHECK(thread_checker_.CalledOnValidThread()); 963 DCHECK(thread_checker_.CalledOnValidThread());
963 964
964 RecordMetricsOnConnectionTypeChanged(); 965 RecordMetricsOnConnectionTypeChanged();
965 966
966 // Write the estimates of the previous network to the cache. 967 // Write the estimates of the previous network to the cache.
967 network_quality_store_.Add( 968 network_quality_store_->Add(
968 current_network_id_, 969 current_network_id_,
969 nqe::internal::CachedNetworkQuality( 970 nqe::internal::CachedNetworkQuality(
970 last_effective_connection_type_computation_, 971 last_effective_connection_type_computation_,
971 estimated_quality_at_last_main_frame_, effective_connection_type_)); 972 estimated_quality_at_last_main_frame_, effective_connection_type_));
972 973
973 // Clear the local state. 974 // Clear the local state.
974 last_connection_change_ = tick_clock_->NowTicks(); 975 last_connection_change_ = tick_clock_->NowTicks();
975 peak_network_quality_ = nqe::internal::NetworkQuality(); 976 peak_network_quality_ = nqe::internal::NetworkQuality();
976 downstream_throughput_kbps_observations_.Clear(); 977 downstream_throughput_kbps_observations_.Clear();
977 rtt_observations_.Clear(); 978 rtt_observations_.Clear();
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 estimated_transport_rtt_is_higher_than_threshold || 1300 estimated_transport_rtt_is_higher_than_threshold ||
1300 estimated_throughput_is_lower_than_threshold) { 1301 estimated_throughput_is_lower_than_threshold) {
1301 return type; 1302 return type;
1302 } 1303 }
1303 } 1304 }
1304 // Return the fastest connection type. 1305 // Return the fastest connection type.
1305 return static_cast<EffectiveConnectionType>(EFFECTIVE_CONNECTION_TYPE_LAST - 1306 return static_cast<EffectiveConnectionType>(EFFECTIVE_CONNECTION_TYPE_LAST -
1306 1); 1307 1);
1307 } 1308 }
1308 1309
1310 nqe::internal::NetworkQualityStore*
1311 NetworkQualityEstimator::NetworkQualityStoreForTesting() const {
1312 DCHECK(thread_checker_.CalledOnValidThread());
1313 return network_quality_store_.get();
1314 }
1315
1309 void NetworkQualityEstimator::AddEffectiveConnectionTypeObserver( 1316 void NetworkQualityEstimator::AddEffectiveConnectionTypeObserver(
1310 EffectiveConnectionTypeObserver* observer) { 1317 EffectiveConnectionTypeObserver* observer) {
1311 DCHECK(thread_checker_.CalledOnValidThread()); 1318 DCHECK(thread_checker_.CalledOnValidThread());
1312 effective_connection_type_observer_list_.AddObserver(observer); 1319 effective_connection_type_observer_list_.AddObserver(observer);
1313 } 1320 }
1314 1321
1315 void NetworkQualityEstimator::RemoveEffectiveConnectionTypeObserver( 1322 void NetworkQualityEstimator::RemoveEffectiveConnectionTypeObserver(
1316 EffectiveConnectionTypeObserver* observer) { 1323 EffectiveConnectionTypeObserver* observer) {
1317 DCHECK(thread_checker_.CalledOnValidThread()); 1324 DCHECK(thread_checker_.CalledOnValidThread());
1318 effective_connection_type_observer_list_.RemoveObserver(observer); 1325 effective_connection_type_observer_list_.RemoveObserver(observer);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 return network_id; 1459 return network_id;
1453 } 1460 }
1454 NOTREACHED(); 1461 NOTREACHED();
1455 } 1462 }
1456 1463
1457 bool NetworkQualityEstimator::ReadCachedNetworkQualityEstimate() { 1464 bool NetworkQualityEstimator::ReadCachedNetworkQualityEstimate() {
1458 DCHECK(thread_checker_.CalledOnValidThread()); 1465 DCHECK(thread_checker_.CalledOnValidThread());
1459 1466
1460 nqe::internal::CachedNetworkQuality cached_network_quality; 1467 nqe::internal::CachedNetworkQuality cached_network_quality;
1461 1468
1462 const bool cached_estimate_available = network_quality_store_.GetById( 1469 const bool cached_estimate_available = network_quality_store_->GetById(
1463 current_network_id_, &cached_network_quality); 1470 current_network_id_, &cached_network_quality);
1464 UMA_HISTOGRAM_BOOLEAN("NQE.CachedNetworkQualityAvailable", 1471 UMA_HISTOGRAM_BOOLEAN("NQE.CachedNetworkQualityAvailable",
1465 cached_estimate_available); 1472 cached_estimate_available);
1466 1473
1467 if (!cached_estimate_available) 1474 if (!cached_estimate_available)
1468 return false; 1475 return false;
1469 1476
1470 const base::TimeTicks now = tick_clock_->NowTicks(); 1477 const base::TimeTicks now = tick_clock_->NowTicks();
1471 1478
1472 if (effective_connection_type_ == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { 1479 if (effective_connection_type_ == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 DCHECK(thread_checker_.CalledOnValidThread()); 1659 DCHECK(thread_checker_.CalledOnValidThread());
1653 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_); 1660 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_);
1654 1661
1655 // TODO(tbansal): Add hysteresis in the notification. 1662 // TODO(tbansal): Add hysteresis in the notification.
1656 FOR_EACH_OBSERVER( 1663 FOR_EACH_OBSERVER(
1657 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, 1664 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_,
1658 OnEffectiveConnectionTypeChanged(effective_connection_type_)); 1665 OnEffectiveConnectionTypeChanged(effective_connection_type_));
1659 1666
1660 // Add the estimates of the current network to the cache store. 1667 // Add the estimates of the current network to the cache store.
1661 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { 1668 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
1662 network_quality_store_.Add( 1669 network_quality_store_->Add(
1663 current_network_id_, 1670 current_network_id_,
1664 nqe::internal::CachedNetworkQuality( 1671 nqe::internal::CachedNetworkQuality(
1665 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_, 1672 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_,
1666 effective_connection_type_)); 1673 effective_connection_type_));
1667 } 1674 }
1668 } 1675 }
1669 1676
1670 } // namespace net 1677 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698