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

Unified Diff: net/base/network_quality_estimator.h

Issue 1144163008: Add in-memory caching of network quality estimates across network changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments and reorganized tests Created 5 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/base/network_quality_estimator.cc » ('j') | net/base/network_quality_estimator.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..702a531666eead6930256db51e9e91d9a0805bce 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,85 @@ 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.
+ bool ReadCachedNetworkQualityEstimate();
+
+ // NetworkChangeNotifier::ConnectionTypeObserver implementation.
+ void OnConnectionTypeChanged(
+ NetworkChangeNotifier::ConnectionType type) override;
+
+ // Set the current network name for testing.
+ void SetCurrentNetworkNameForTests(std::string network_name);
bengr 2015/05/29 17:38:10 const std::string&
tbansal1 2015/05/29 19:13:36 Done.
+
+ // 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 MCCMNC code of the cellular carrier if the device is connected to a
bengr 2015/05/29 17:38:10 nit: MCC/MNC
tbansal1 2015/05/29 19:13:36 Done.
+ // 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,
+ std::string network_name,
bengr 2015/05/29 17:38:10 const std::string&
tbansal1 2015/05/29 19:13:36 Done.
+ int median_kbps,
+ int median_rtt_milliseconds)
+ : median_kbps_(median_kbps),
+ median_rtt_milliseconds_(median_rtt_milliseconds),
+ last_updated_(base::TimeTicks::Now()),
+ connection_type_(connection_type),
+ network_name_(network_name) {
+ DCHECK_NE(network_name_, std::string());
bengr 2015/05/29 17:38:10 After reading the comment for UpdateCurrentNetwork
tbansal1 2015/05/29 19:13:37 The current network name may be empty but in that
+ }
+
+ virtual ~CachedNetworkQuality() {}
+
+ void UpdateNetworkQuality(int updated_median_kbps,
+ int updated_median_rtt_milliseconds) {
+ median_kbps_ = updated_median_kbps;
+ median_rtt_milliseconds_ = updated_median_rtt_milliseconds;
bengr 2015/05/29 17:38:10 Why are these not TimeDeltas?
tbansal1 2015/05/29 19:13:36 Initially, I did not make it TimeDelta because if
+ last_updated_ = base::TimeTicks::Now();
+ }
+
+ bool MatchesNetwork(NetworkChangeNotifier::ConnectionType connection_type,
+ std::string network_name) const {
bengr 2015/05/29 17:38:10 const std::string&
tbansal1 2015/05/29 19:13:36 Done.
+ return connection_type == connection_type_ &&
+ network_name == network_name_;
+ }
+
+ // Median Kbps of this cached network.
+ int median_kbps_;
+
+ // Median RTT (in milliseconds) of this cached network.
+ int median_rtt_milliseconds_;
bengr 2015/05/29 17:38:10 TimeDelta?
tbansal1 2015/05/29 19:13:36 Done.
+
+ // 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 +142,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 +163,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);
« no previous file with comments | « no previous file | net/base/network_quality_estimator.cc » ('j') | net/base/network_quality_estimator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698