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..c01f920c5b69b0359e4eb648655324fe75981d5d 100644 |
| --- a/net/base/network_quality_estimator.h |
| +++ b/net/base/network_quality_estimator.h |
| @@ -7,6 +7,9 @@ |
| #include <stdint.h> |
| +#include <string> |
| +#include <vector> |
| + |
| #include "base/gtest_prod_util.h" |
| #include "base/macros.h" |
| #include "base/threading/thread_checker.h" |
| @@ -43,11 +46,71 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| void NotifyDataReceived(const URLRequest& request, |
| int64_t prefilter_bytes_read); |
| + protected: |
| + // Returns true if cached network quality estimate was successfully read. |
|
bengr
2015/06/01 20:39:35
"if" -> "if the"
tbansal1
2015/06/01 21:56:51
Done.
|
| + bool ReadCachedNetworkQualityEstimate(); |
|
bengr
2015/06/01 20:39:34
You might want to bite the bullet now and make thi
tbansal1
2015/06/01 21:56:51
This CL is complete in the current form.
I would p
bengr
2015/06/01 23:21:10
Acknowledged.
tbansal1
2015/06/02 18:18:05
Done.
|
| + |
| + // NetworkChangeNotifier::ConnectionTypeObserver implementation. |
| + void OnConnectionTypeChanged( |
| + NetworkChangeNotifier::ConnectionType type) override; |
| + |
| + // Set the current network name for testing. |
| + void SetCurrentNetworkNameForTests(const std::string& network_name); |
| + |
| + // Returns the number of entries in the cache. Used only for testing. |
| + uint32_t GetCacheSizeForTests() const; |
| + |
| + // Updates the current network name to: |
| + // WiFi SSID (if the user is connected to a WiFi access point and the SSID |
| + // name is available), or |
| + // The MCC/MNC 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. |
| + // Updates the current network name to an empty string in all other cases or |
| + // if the network name is not exposed by platform APIs. |
| + // Virtualized for testing. |
| + virtual void UpdateCurrentNetworkName(); |
| + |
| private: |
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, |
| TestPeakKbpsFastestRTTUpdates); |
| FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator); |
| + // CachedNetworkQuality stores the quality of a previously seen network. |
| + // A network is uniquely identified by combination of |connection_type_| and |
| + // |network_name_|. |
| + class CachedNetworkQuality { |
| + public: |
| + CachedNetworkQuality(NetworkChangeNotifier::ConnectionType connection_type, |
| + const std::string& network_name, |
| + int median_kbps, |
| + const base::TimeDelta& median_rtt); |
| + |
| + virtual ~CachedNetworkQuality(); |
| + |
| + void UpdateNetworkQuality(int median_kbps, |
| + const base::TimeDelta& median_rtt); |
| + |
| + bool MatchesNetwork(NetworkChangeNotifier::ConnectionType connection_type, |
| + const std::string& network_name) const; |
| + |
| + // Median Kbps of this cached network. |
| + int median_kbps_; |
| + |
| + // Median RTT of this cached network. |
| + base::TimeDelta median_rtt_; |
| + |
| + // Time when this cache entry was last updated. |
| + base::TimeTicks last_updated_; |
| + |
| + private: |
| + // Connection type of this cached network. |
| + NetworkChangeNotifier::ConnectionType connection_type_; |
| + |
| + // Name of this cached network. |
| + std::string network_name_; |
| + }; |
| + |
| // Tiny transfer sizes may give inaccurate throughput results. |
| // Minimum size of the transfer over which the throughput is computed. |
| static const int kMinTransferSizeInBytes = 10000; |
| @@ -65,9 +128,8 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator |
| // used for network quality estimation. |
| explicit NetworkQualityEstimator(bool allow_local_host_requests_for_tests); |
| - // NetworkChangeNotifier::ConnectionTypeObserver implementation. |
| - void OnConnectionTypeChanged( |
| - NetworkChangeNotifier::ConnectionType type) override; |
| + // 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. |
| @@ -87,12 +149,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_; |
| + |
| // 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. |
| + std::string current_network_name_; |
| + |
| base::ThreadChecker thread_checker_; |
| DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |