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

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

Issue 2487883002: NQE: Use cached estimates (Closed)
Patch Set: ps 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
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);
RyanSturm 2016/12/13 21:08:35 Can you add a class comment to NotifyObserversOfRT
tbansal1 2016/12/14 01:37:37 Done.
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 (std::map<nqe::internal::NetworkID,
1599 // current estimates. 1611 nqe::internal::CachedNetworkQuality>::const_iterator it =
RyanSturm 2016/12/13 21:08:35 nit: maybe use auto instead since the map is const
tbansal1 2016/12/14 01:37:37 Done. This looks much better.
1612 read_prefs.begin();
1613 it != read_prefs.end(); ++it) {
1614 EffectiveConnectionType effective_connection_type =
1615 it->second.effective_connection_type();
1616 if (effective_connection_type == EFFECTIVE_CONNECTION_TYPE_UNKNOWN ||
1617 effective_connection_type == EFFECTIVE_CONNECTION_TYPE_OFFLINE) {
1618 continue;
1619 }
1620
1621 // RTT and throughput values are not set in the prefs.
1622 DCHECK_EQ(nqe::internal::InvalidRTT(),
1623 it->second.network_quality().http_rtt());
1624 DCHECK_EQ(nqe::internal::InvalidRTT(),
1625 it->second.network_quality().transport_rtt());
1626 DCHECK_EQ(nqe::internal::kInvalidThroughput,
1627 it->second.network_quality().downstream_throughput_kbps());
1628
1629 nqe::internal::NetworkQuality network_quality(
1630 typical_network_quality_[effective_connection_type].http_rtt(),
1631 typical_network_quality_[effective_connection_type].transport_rtt(),
1632 typical_network_quality_[effective_connection_type]
1633 .downstream_throughput_kbps());
1634
1635 nqe::internal::CachedNetworkQuality cached_network_quality(
1636 base::TimeTicks::Now(), network_quality, effective_connection_type);
1637
1638 network_quality_store_->Add(it->first, cached_network_quality);
RyanSturm 2016/12/13 21:08:35 talked offline, consider using ListValue instead D
tbansal1 2016/12/14 01:37:37 I have changed the behavior in prefs manager to us
1639 if (it->first == current_network_id_) {
1640 // Since the cached network quality is for the current network, add it to
1641 // the current observations.
1642 RttObservation http_rtt_observation(
1643 network_quality.http_rtt(), base::TimeTicks::Now(),
1644 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE);
1645 rtt_observations_.AddObservation(http_rtt_observation);
1646 NotifyObserversOfRTT(http_rtt_observation);
1647
1648 RttObservation transport_rtt_observation(
1649 network_quality.transport_rtt(), base::TimeTicks::Now(),
1650 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE);
1651 rtt_observations_.AddObservation(transport_rtt_observation);
1652 NotifyObserversOfRTT(transport_rtt_observation);
1653
1654 if (network_quality.downstream_throughput_kbps() !=
RyanSturm 2016/12/13 21:08:35 Can you add a comment referencing the bug to add t
tbansal1 2016/12/14 01:37:37 Done.
1655 nqe::internal::kInvalidThroughput) {
1656 ThroughputObservation throughput_observation(
1657 network_quality.downstream_throughput_kbps(),
1658 base::TimeTicks::Now(),
1659 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE);
1660 downstream_throughput_kbps_observations_.AddObservation(
1661 throughput_observation);
1662 NotifyObserversOfThroughput(throughput_observation);
1663 }
1664
1665 ComputeEffectiveConnectionType();
1666 }
1667 }
1600 } 1668 }
1601 1669
1602 } // namespace net 1670 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698