| 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> |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 signal_strength_dbm_(INT32_MIN), | 274 signal_strength_dbm_(INT32_MIN), |
| 275 min_signal_strength_since_connection_change_(INT32_MAX), | 275 min_signal_strength_since_connection_change_(INT32_MAX), |
| 276 max_signal_strength_since_connection_change_(INT32_MIN), | 276 max_signal_strength_since_connection_change_(INT32_MIN), |
| 277 correlation_uma_logging_probability_( | 277 correlation_uma_logging_probability_( |
| 278 nqe::internal::correlation_uma_logging_probability(variation_params)), | 278 nqe::internal::correlation_uma_logging_probability(variation_params)), |
| 279 forced_effective_connection_type_set_( | 279 forced_effective_connection_type_set_( |
| 280 nqe::internal::forced_effective_connection_type_set( | 280 nqe::internal::forced_effective_connection_type_set( |
| 281 variation_params)), | 281 variation_params)), |
| 282 forced_effective_connection_type_( | 282 forced_effective_connection_type_( |
| 283 nqe::internal::forced_effective_connection_type(variation_params)), | 283 nqe::internal::forced_effective_connection_type(variation_params)), |
| 284 persistent_cache_reading_enabled_( |
| 285 nqe::internal::persistent_cache_reading_enabled(variation_params)), |
| 284 weak_ptr_factory_(this) { | 286 weak_ptr_factory_(this) { |
| 285 // None of the algorithms can have an empty name. | 287 // None of the algorithms can have an empty name. |
| 286 DCHECK(algorithm_name_to_enum_.end() == | 288 DCHECK(algorithm_name_to_enum_.end() == |
| 287 algorithm_name_to_enum_.find(std::string())); | 289 algorithm_name_to_enum_.find(std::string())); |
| 288 | 290 |
| 289 DCHECK_EQ(algorithm_name_to_enum_.size(), | 291 DCHECK_EQ(algorithm_name_to_enum_.size(), |
| 290 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: | 292 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: |
| 291 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); | 293 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); |
| 292 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: | 294 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: |
| 293 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, | 295 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, |
| (...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1367 | 1369 |
| 1368 if (network_id.type == NetworkChangeNotifier::GetConnectionType()) | 1370 if (network_id.type == NetworkChangeNotifier::GetConnectionType()) |
| 1369 return network_id; | 1371 return network_id; |
| 1370 } | 1372 } |
| 1371 NOTREACHED(); | 1373 NOTREACHED(); |
| 1372 } | 1374 } |
| 1373 | 1375 |
| 1374 bool NetworkQualityEstimator::ReadCachedNetworkQualityEstimate() { | 1376 bool NetworkQualityEstimator::ReadCachedNetworkQualityEstimate() { |
| 1375 DCHECK(thread_checker_.CalledOnValidThread()); | 1377 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1376 | 1378 |
| 1379 if (!persistent_cache_reading_enabled_) |
| 1380 return false; |
| 1381 |
| 1377 nqe::internal::CachedNetworkQuality cached_network_quality; | 1382 nqe::internal::CachedNetworkQuality cached_network_quality; |
| 1378 | 1383 |
| 1379 const bool cached_estimate_available = network_quality_store_->GetById( | 1384 const bool cached_estimate_available = network_quality_store_->GetById( |
| 1380 current_network_id_, &cached_network_quality); | 1385 current_network_id_, &cached_network_quality); |
| 1381 UMA_HISTOGRAM_BOOLEAN("NQE.CachedNetworkQualityAvailable", | 1386 UMA_HISTOGRAM_BOOLEAN("NQE.CachedNetworkQualityAvailable", |
| 1382 cached_estimate_available); | 1387 cached_estimate_available); |
| 1383 | 1388 |
| 1384 if (!cached_estimate_available) | 1389 if (!cached_estimate_available) |
| 1385 return false; | 1390 return false; |
| 1386 | 1391 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1656 | 1661 |
| 1657 network_quality_store_->Add(it.first, cached_network_quality); | 1662 network_quality_store_->Add(it.first, cached_network_quality); |
| 1658 MaybeUpdateNetworkQualityFromCache(it.first, cached_network_quality); | 1663 MaybeUpdateNetworkQualityFromCache(it.first, cached_network_quality); |
| 1659 } | 1664 } |
| 1660 } | 1665 } |
| 1661 | 1666 |
| 1662 void NetworkQualityEstimator::MaybeUpdateNetworkQualityFromCache( | 1667 void NetworkQualityEstimator::MaybeUpdateNetworkQualityFromCache( |
| 1663 const nqe::internal::NetworkID& network_id, | 1668 const nqe::internal::NetworkID& network_id, |
| 1664 const nqe::internal::CachedNetworkQuality& cached_network_quality) { | 1669 const nqe::internal::CachedNetworkQuality& cached_network_quality) { |
| 1665 DCHECK(thread_checker_.CalledOnValidThread()); | 1670 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1671 |
| 1672 if (!persistent_cache_reading_enabled_) |
| 1673 return; |
| 1666 if (network_id != current_network_id_) | 1674 if (network_id != current_network_id_) |
| 1667 return; | 1675 return; |
| 1668 | 1676 |
| 1669 // Since the cached network quality is for the current network, add it to | 1677 // Since the cached network quality is for the current network, add it to |
| 1670 // the current observations. | 1678 // the current observations. |
| 1671 RttObservation http_rtt_observation( | 1679 RttObservation http_rtt_observation( |
| 1672 cached_network_quality.network_quality().http_rtt(), | 1680 cached_network_quality.network_quality().http_rtt(), |
| 1673 base::TimeTicks::Now(), INT32_MIN, | 1681 base::TimeTicks::Now(), INT32_MIN, |
| 1674 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); | 1682 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); |
| 1675 rtt_observations_.AddObservation(http_rtt_observation); | 1683 rtt_observations_.AddObservation(http_rtt_observation); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1691 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); | 1699 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); |
| 1692 downstream_throughput_kbps_observations_.AddObservation( | 1700 downstream_throughput_kbps_observations_.AddObservation( |
| 1693 throughput_observation); | 1701 throughput_observation); |
| 1694 NotifyObserversOfThroughput(throughput_observation); | 1702 NotifyObserversOfThroughput(throughput_observation); |
| 1695 } | 1703 } |
| 1696 | 1704 |
| 1697 ComputeEffectiveConnectionType(); | 1705 ComputeEffectiveConnectionType(); |
| 1698 } | 1706 } |
| 1699 | 1707 |
| 1700 } // namespace net | 1708 } // namespace net |
| OLD | NEW |