Chromium Code Reviews| Index: net/base/network_quality_estimator.h |
| diff --git a/net/base/network_quality_estimator.h b/net/base/network_quality_estimator.h |
| index ecfa08af6b8341b3a9bb06897a89baa42651c7b7..36c9448989a61694aa5fd14fc6cc35a1abc4ba70 100644 |
| --- a/net/base/network_quality_estimator.h |
| +++ b/net/base/network_quality_estimator.h |
| @@ -15,6 +15,36 @@ |
| namespace net { |
| +// CachedNetworkQuality stores the quality of a previously seen network. |
| +// A network is uniquely identified by combination of |connection_type| and |
| +// |network_name|. |
| +struct NET_EXPORT_PRIVATE CachedNetworkQuality { |
|
mmenke
2015/05/28 15:25:02
Since a subclass for testing only needs to be able
mmenke
2015/05/28 15:25:02
This should be a protected or private class - priv
tbansal1
2015/05/29 02:27:23
Done.
tbansal1
2015/05/29 02:27:24
Done.
|
| + CachedNetworkQuality(NetworkChangeNotifier::ConnectionType connection_type, |
| + std::string network_name, |
| + int median_kbps, |
| + int median_rtt_milliseconds); |
| + |
| + ~CachedNetworkQuality(); |
| + |
| + void UpdateNetworkQuality(int updated_median_kbps, |
| + int updated_median_rtt_milliseconds); |
| + |
| + // Connection type of this cached network. |
| + NetworkChangeNotifier::ConnectionType connection_type; |
| + |
| + // Name of this cached network. |
| + std::string network_name; |
| + |
| + // Median Kbps of this cached network. |
| + int median_kbps; |
| + |
| + // Median RTT (in milliseconds) of this cached network. |
| + int median_rtt_milliseconds; |
| + |
| + // Time when this cache entry was last updated. |
| + base::TimeTicks last_updated; |
| +}; |
| + |
| struct NetworkQuality; |
| // NetworkQualityEstimator provides network quality estimates (quality of the |
| @@ -47,6 +77,7 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
| TestPeakKbpsFastestRTTUpdates); |
| FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator); |
| + friend class NetworkQualityEstimatorTest; |
|
mmenke
2015/05/28 15:25:02
Should not need to friend a subclass. Just make p
tbansal1
2015/05/29 02:27:24
Done.
|
| // Tiny transfer sizes may give inaccurate throughput results. |
| // Minimum size of the transfer over which the throughput is computed. |
| @@ -69,6 +100,23 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| void OnConnectionTypeChanged( |
| NetworkChangeNotifier::ConnectionType type) override; |
| + // Returns the current network name: |
| + // WiFi SSID (if the user is connected to a WiFi access point and the SSID |
| + // name is available), or |
| + // The MCCMNC code of the cellular carrier if the device is connected to a |
| + // cellular network, or |
| + // "ethernet" if the device is connected to an Ethernet network. |
| + // Returns empty string in all other cases or if the network name is not |
| + // exposed by platform APIs. |
| + // Virtualized for testing. |
| + virtual std::string GetCurrentNetworkName() const; |
|
mmenke
2015/05/28 15:25:02
include <string>
tbansal1
2015/05/29 02:27:24
Done.
|
| + |
| + // Returns true if cached network quality estimate was successfully read. |
| + bool ReadCachedNetworkQualityEstimate(); |
| + |
| + // Write the estimated quality of the current network to the cache. |
| + void CacheNetworkQualityEstimate(); |
| + |
| // Determines if the requests to local host can be used in estimating the |
| // network quality. Set to true only for tests. |
| const bool allow_localhost_requests_; |
| @@ -87,12 +135,18 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| // from URLRequest creation until first byte received. |
| base::TimeDelta fastest_RTT_since_last_connection_change_; |
| + // Cache to store quality of previously seen networks. |
| + std::vector<CachedNetworkQuality> cached_network_quality_; |
|
mmenke
2015/05/28 15:25:03
include <vector>
tbansal1
2015/05/29 02:27:24
Done.
|
| + |
| // Rough measurement of downlink peak Kbps witnessed since last connectivity |
| // change. The accuracy is decreased by ignoring these factors: |
| // 1) Multiple URLRequests can occur concurrently. |
| // 2) The transfer time includes at least one RTT while no bytes are read. |
| uint64_t peak_kbps_since_last_connection_change_; |
| + // Name of the current network as returned by GetCurrentNetworkName. |
| + std::string current_network_name_; |
| + |
| base::ThreadChecker thread_checker_; |
| DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |