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 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
775 min_signal_strength_since_connection_change_ != INT32_MAX && | 775 min_signal_strength_since_connection_change_ != INT32_MAX && |
776 max_signal_strength_since_connection_change_ != INT32_MIN); | 776 max_signal_strength_since_connection_change_ != INT32_MIN); |
777 } | 777 } |
778 #endif // OS_ANDROID | 778 #endif // OS_ANDROID |
779 min_signal_strength_since_connection_change_ = INT32_MAX; | 779 min_signal_strength_since_connection_change_ = INT32_MAX; |
780 max_signal_strength_since_connection_change_ = INT32_MIN; | 780 max_signal_strength_since_connection_change_ = INT32_MIN; |
781 network_quality_ = nqe::internal::NetworkQuality(); | 781 network_quality_ = nqe::internal::NetworkQuality(); |
782 effective_connection_type_ = EFFECTIVE_CONNECTION_TYPE_UNKNOWN; | 782 effective_connection_type_ = EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
783 effective_connection_type_at_last_main_frame_ = | 783 effective_connection_type_at_last_main_frame_ = |
784 EFFECTIVE_CONNECTION_TYPE_UNKNOWN; | 784 EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
785 rtt_observations_size_at_last_ect_computation_ = 0; | |
786 throughput_observations_size_at_last_ect_computation_ = 0; | |
785 | 787 |
786 // Update the local state as part of preparation for the new connection. | 788 // Update the local state as part of preparation for the new connection. |
787 current_network_id_ = GetCurrentNetworkID(); | 789 current_network_id_ = GetCurrentNetworkID(); |
788 RecordNetworkIDAvailability(); | 790 RecordNetworkIDAvailability(); |
789 | 791 |
790 MaybeQueryExternalEstimateProvider(); | 792 MaybeQueryExternalEstimateProvider(); |
791 | 793 |
792 // Read any cached estimates for the new network. If cached estimates are | 794 // Read any cached estimates for the new network. If cached estimates are |
793 // unavailable, add the default estimates. | 795 // unavailable, add the default estimates. |
794 if (!ReadCachedNetworkQualityEstimate()) | 796 if (!ReadCachedNetworkQualityEstimate()) |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1377 } | 1379 } |
1378 | 1380 |
1379 if (cached_network_quality.network_quality().http_rtt() != | 1381 if (cached_network_quality.network_quality().http_rtt() != |
1380 nqe::internal::InvalidRTT()) { | 1382 nqe::internal::InvalidRTT()) { |
1381 RttObservation rtt_observation( | 1383 RttObservation rtt_observation( |
1382 cached_network_quality.network_quality().http_rtt(), now, | 1384 cached_network_quality.network_quality().http_rtt(), now, |
1383 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); | 1385 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); |
1384 rtt_observations_.AddObservation(rtt_observation); | 1386 rtt_observations_.AddObservation(rtt_observation); |
1385 NotifyObserversOfRTT(rtt_observation); | 1387 NotifyObserversOfRTT(rtt_observation); |
1386 } | 1388 } |
1389 | |
1390 if (cached_network_quality.network_quality().transport_rtt() != | |
1391 nqe::internal::InvalidRTT()) { | |
1392 RttObservation rtt_observation( | |
1393 cached_network_quality.network_quality().transport_rtt(), now, | |
1394 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE); | |
1395 rtt_observations_.AddObservation(rtt_observation); | |
1396 NotifyObserversOfRTT(rtt_observation); | |
1397 } | |
1387 return true; | 1398 return true; |
1388 } | 1399 } |
1389 | 1400 |
1390 void NetworkQualityEstimator::OnUpdatedEstimateAvailable( | 1401 void NetworkQualityEstimator::OnUpdatedEstimateAvailable( |
1391 const base::TimeDelta& rtt, | 1402 const base::TimeDelta& rtt, |
1392 int32_t downstream_throughput_kbps, | 1403 int32_t downstream_throughput_kbps, |
1393 int32_t upstream_throughput_kbps) { | 1404 int32_t upstream_throughput_kbps) { |
1394 DCHECK(thread_checker_.CalledOnValidThread()); | 1405 DCHECK(thread_checker_.CalledOnValidThread()); |
1395 DCHECK(external_estimate_provider_); | 1406 DCHECK(external_estimate_provider_); |
1396 | 1407 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1587 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver* | 1598 nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver* |
1588 observer) { | 1599 observer) { |
1589 DCHECK(thread_checker_.CalledOnValidThread()); | 1600 DCHECK(thread_checker_.CalledOnValidThread()); |
1590 network_quality_store_->RemoveNetworkQualitiesCacheObserver(observer); | 1601 network_quality_store_->RemoveNetworkQualitiesCacheObserver(observer); |
1591 } | 1602 } |
1592 | 1603 |
1593 void NetworkQualityEstimator::OnPrefsRead( | 1604 void NetworkQualityEstimator::OnPrefsRead( |
1594 const std::map<nqe::internal::NetworkID, | 1605 const std::map<nqe::internal::NetworkID, |
1595 nqe::internal::CachedNetworkQuality> read_prefs) { | 1606 nqe::internal::CachedNetworkQuality> read_prefs) { |
1596 DCHECK(thread_checker_.CalledOnValidThread()); | 1607 DCHECK(thread_checker_.CalledOnValidThread()); |
1608 | |
1597 UMA_HISTOGRAM_COUNTS("NQE.Prefs.ReadSize", read_prefs.size()); | 1609 UMA_HISTOGRAM_COUNTS("NQE.Prefs.ReadSize", read_prefs.size()); |
1598 // TODO(tbansal): crbug.com/490870. Incorporate the network quality into the | 1610 for (auto& it : read_prefs) { |
1599 // current estimates. | 1611 EffectiveConnectionType effective_connection_type = |
1612 it.second.effective_connection_type(); | |
1613 if (effective_connection_type == EFFECTIVE_CONNECTION_TYPE_UNKNOWN || | |
1614 effective_connection_type == EFFECTIVE_CONNECTION_TYPE_OFFLINE) { | |
1615 continue; | |
1616 } | |
1617 | |
1618 // RTT and throughput values are not set in the prefs. | |
1619 DCHECK_EQ(nqe::internal::InvalidRTT(), | |
1620 it.second.network_quality().http_rtt()); | |
1621 DCHECK_EQ(nqe::internal::InvalidRTT(), | |
1622 it.second.network_quality().transport_rtt()); | |
1623 DCHECK_EQ(nqe::internal::kInvalidThroughput, | |
1624 it.second.network_quality().downstream_throughput_kbps()); | |
1625 | |
1626 nqe::internal::NetworkQuality network_quality( | |
1627 typical_network_quality_[effective_connection_type].http_rtt(), | |
1628 typical_network_quality_[effective_connection_type].transport_rtt(), | |
1629 typical_network_quality_[effective_connection_type] | |
1630 .downstream_throughput_kbps()); | |
1631 | |
1632 nqe::internal::CachedNetworkQuality cached_network_quality( | |
1633 base::TimeTicks::Now(), network_quality, effective_connection_type); | |
1634 | |
1635 network_quality_store_->Add(it.first, cached_network_quality); | |
1636 if (it.first == current_network_id_) { | |
bengr
2016/12/15 23:51:26
Can you add a helper called something like UpdateN
tbansal1
2016/12/16 18:07:15
Done.
| |
1637 // Since the cached network quality is for the current network, add it to | |
1638 // the current observations. | |
1639 RttObservation http_rtt_observation( | |
1640 network_quality.http_rtt(), base::TimeTicks::Now(), | |
1641 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); | |
1642 rtt_observations_.AddObservation(http_rtt_observation); | |
1643 NotifyObserversOfRTT(http_rtt_observation); | |
1644 | |
1645 RttObservation transport_rtt_observation( | |
1646 network_quality.transport_rtt(), base::TimeTicks::Now(), | |
1647 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE); | |
1648 rtt_observations_.AddObservation(transport_rtt_observation); | |
1649 NotifyObserversOfRTT(transport_rtt_observation); | |
1650 | |
1651 // TODO(tbansal): crbug.com/673977: Remove this check. | |
1652 if (network_quality.downstream_throughput_kbps() != | |
1653 nqe::internal::kInvalidThroughput) { | |
1654 ThroughputObservation throughput_observation( | |
1655 network_quality.downstream_throughput_kbps(), | |
1656 base::TimeTicks::Now(), | |
1657 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); | |
1658 downstream_throughput_kbps_observations_.AddObservation( | |
1659 throughput_observation); | |
1660 NotifyObserversOfThroughput(throughput_observation); | |
1661 } | |
1662 | |
1663 ComputeEffectiveConnectionType(); | |
1664 } | |
1665 } | |
1600 } | 1666 } |
1601 | 1667 |
1602 } // namespace net | 1668 } // namespace net |
OLD | NEW |