| 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..f9697e0f8f4c2ba7671104ae2b54e18aa895e5d0 100644
|
| --- a/net/base/network_quality_estimator.h
|
| +++ b/net/base/network_quality_estimator.h
|
| @@ -7,16 +7,18 @@
|
|
|
| #include <stdint.h>
|
|
|
| +#include <map>
|
| +#include <string>
|
| +
|
| #include "base/gtest_prod_util.h"
|
| #include "base/macros.h"
|
| #include "base/threading/thread_checker.h"
|
| #include "base/time/time.h"
|
| #include "net/base/network_change_notifier.h"
|
| +#include "net/base/network_quality.h"
|
|
|
| namespace net {
|
|
|
| -struct NetworkQuality;
|
| -
|
| // NetworkQualityEstimator provides network quality estimates (quality of the
|
| // full paths to all origins that have been connected to).
|
| // The estimates are based on the observed organic traffic.
|
| @@ -43,11 +45,75 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| void NotifyDataReceived(const URLRequest& request,
|
| int64_t prefilter_bytes_read);
|
|
|
| + protected:
|
| + // Returns true if the cached network quality estimate was successfully read.
|
| + bool ReadCachedNetworkQualityEstimate();
|
| +
|
| + // NetworkChangeNotifier::ConnectionTypeObserver implementation.
|
| + void OnConnectionTypeChanged(
|
| + NetworkChangeNotifier::ConnectionType type) override;
|
| +
|
| + // Returns the number of entries in the cache. Used only for testing.
|
| + size_t GetCacheSizeForTests() const;
|
| +
|
| private:
|
| FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
|
| TestPeakKbpsFastestRTTUpdates);
|
| FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator);
|
|
|
| + // NetworkID is used to uniquely identify a network.
|
| + // For the purpose of network quality estimation and caching, a network is
|
| + // uniquely identified by a combination of |connection_type_| and
|
| + // |network_name_|. This approach is unable to distinguish networks with
|
| + // same name (e.g., different Wi-Fi networks with same SSID).
|
| + struct NetworkID {
|
| + NetworkChangeNotifier::ConnectionType type;
|
| + std::string id;
|
| +
|
| + NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id)
|
| + : type(type), id(id) {}
|
| +
|
| + ~NetworkID() {}
|
| +
|
| + NetworkID& operator=(const NetworkID& other) {
|
| + type = other.type;
|
| + id = other.id;
|
| + return *this;
|
| + }
|
| +
|
| + // Overloaded because NetworkID is used as key in a map.
|
| + bool operator<(const NetworkID& other) const {
|
| + return type < other.type || (type == other.type && id < other.id);
|
| + }
|
| + };
|
| +
|
| + // CachedNetworkQuality stores the quality of a previously seen network.
|
| + class CachedNetworkQuality {
|
| + public:
|
| + explicit CachedNetworkQuality(const NetworkQuality& network_quality);
|
| +
|
| + ~CachedNetworkQuality();
|
| +
|
| + // Updates the network quality to the specified |median_kbps| and
|
| + // |median_rtt|.
|
| + void UpdateNetworkQuality(uint64_t median_kbps,
|
| + const base::TimeDelta& median_rtt);
|
| +
|
| + // Returns the time when this cached entry was last updated.
|
| + base::TimeTicks last_update_time() const { return last_update_time_; }
|
| +
|
| + private:
|
| + // Time when this cache entry was last updated.
|
| + base::TimeTicks last_update_time_;
|
| +
|
| + // Quality of this cached network.
|
| + NetworkQuality network_quality_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(CachedNetworkQuality);
|
| + };
|
| +
|
| + typedef std::map<NetworkID, scoped_ptr<CachedNetworkQuality>> CachedQualities;
|
| +
|
| // 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 +131,18 @@ 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;
|
| + // 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.
|
| + // 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 std::string GetCurrentNetworkName() const;
|
| +
|
| + // 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.
|
| @@ -76,10 +151,6 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
|
| // Time when last connection change was observed.
|
| base::TimeTicks last_connection_change_;
|
|
|
| - // Last value passed to |OnConnectionTypeChanged|. This indicates the
|
| - // current connection type.
|
| - NetworkChangeNotifier::ConnectionType current_connection_type_;
|
| -
|
| // Set if any network data has been received since last connectivity change.
|
| bool bytes_read_since_last_connection_change_;
|
|
|
| @@ -87,12 +158,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.
|
| + CachedQualities 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_;
|
|
|
| + // NetworkID of the current network.
|
| + NetworkID current_network_id_;
|
| +
|
| base::ThreadChecker thread_checker_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator);
|
|
|