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

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

Issue 2487883002: NQE: Use cached estimates (Closed)
Patch Set: bengr comments Created 4 years 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 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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 MaybeUpdateNetworkQualityFromCache(it.first, cached_network_quality);
1637 }
1638 }
1639
1640 void NetworkQualityEstimator::MaybeUpdateNetworkQualityFromCache(
1641 const nqe::internal::NetworkID& network_id,
1642 const nqe::internal::CachedNetworkQuality cached_network_quality) {
bengr 2016/12/16 20:33:43 Why isn't this a const ref?
tbansal1 2016/12/17 02:10:49 Done.
1643 DCHECK(thread_checker_.CalledOnValidThread());
1644 if (network_id != current_network_id_)
1645 return;
1646
1647 // Since the cached network quality is for the current network, add it to
1648 // the current observations.
1649 RttObservation http_rtt_observation(
1650 cached_network_quality.network_quality().http_rtt(),
1651 base::TimeTicks::Now(),
1652 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE);
1653 rtt_observations_.AddObservation(http_rtt_observation);
1654 NotifyObserversOfRTT(http_rtt_observation);
1655
1656 RttObservation transport_rtt_observation(
1657 cached_network_quality.network_quality().transport_rtt(),
1658 base::TimeTicks::Now(),
1659 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE);
1660 rtt_observations_.AddObservation(transport_rtt_observation);
1661 NotifyObserversOfRTT(transport_rtt_observation);
1662
1663 // TODO(tbansal): crbug.com/673977: Remove this check.
1664 if (cached_network_quality.network_quality().downstream_throughput_kbps() !=
1665 nqe::internal::kInvalidThroughput) {
1666 ThroughputObservation throughput_observation(
1667 cached_network_quality.network_quality().downstream_throughput_kbps(),
1668 base::TimeTicks::Now(),
1669 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE);
1670 downstream_throughput_kbps_observations_.AddObservation(
1671 throughput_observation);
1672 NotifyObserversOfThroughput(throughput_observation);
1673 }
1674
1675 ComputeEffectiveConnectionType();
1600 } 1676 }
1601 1677
1602 } // namespace net 1678 } // 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