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

Unified Diff: net/nqe/network_quality_estimator.h

Issue 2128793003: Factor out NetworkID and caching mechanism from n_q_e.{h,cc} (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 5 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
Index: net/nqe/network_quality_estimator.h
diff --git a/net/nqe/network_quality_estimator.h b/net/nqe/network_quality_estimator.h
index afeca4eb01e1220879cb01bf87a644ebe06a9775..86ef7d2afd16d3da42fb238b4cbbaffa5cc040e3 100644
--- a/net/nqe/network_quality_estimator.h
+++ b/net/nqe/network_quality_estimator.h
@@ -10,7 +10,6 @@
#include <map>
#include <memory>
#include <string>
-#include <tuple>
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
@@ -24,6 +23,8 @@
#include "net/base/network_change_notifier.h"
#include "net/nqe/cached_network_quality.h"
#include "net/nqe/external_estimate_provider.h"
+#include "net/nqe/network_id.h"
+#include "net/nqe/network_qualities_manager.h"
#include "net/nqe/network_quality.h"
#include "net/nqe/network_quality_observation.h"
#include "net/nqe/network_quality_observation_source.h"
@@ -238,46 +239,6 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
void SetUseSmallResponsesForTesting(bool use_small_responses);
protected:
- // 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 |type| and
- // |id|. This approach is unable to distinguish networks with
- // same name (e.g., different Wi-Fi networks with same SSID).
- // This is a protected member to expose it to tests.
- struct NET_EXPORT_PRIVATE NetworkID {
- NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id)
- : type(type), id(id) {}
- NetworkID(const NetworkID& other) : type(other.type), id(other.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 std::tie(type, id) < std::tie(other.type, other.id);
- }
-
- // Connection type of the network.
- NetworkChangeNotifier::ConnectionType type;
-
- // Name of this network. This is set to:
- // - Wi-Fi SSID if the device is connected to a Wi-Fi access point and the
- // SSID name is available, or
- // - MCC/MNC code of the cellular carrier if the device is connected to a
- // cellular network, or
- // - "Ethernet" in case the device is connected to ethernet.
- // - An empty string in all other cases or if the network name is not
- // exposed by platform APIs.
- std::string id;
- };
-
- // Returns true if the cached network quality estimate was successfully read.
- bool ReadCachedNetworkQualityEstimate();
-
// NetworkChangeNotifier::ConnectionTypeObserver implementation:
void OnConnectionTypeChanged(
NetworkChangeNotifier::ConnectionType type) override;
@@ -352,9 +313,6 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
ObtainAlgorithmToUseFromParams);
FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam);
FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles);
- FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching);
- FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
- TestLRUCacheMaximumSize);
FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestGetMetricsSince);
FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
TestExternalEstimateProviderMergeEstimates);
@@ -368,12 +326,6 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
typedef nqe::internal::Observation<int32_t> ThroughputObservation;
typedef nqe::internal::ObservationBuffer<int32_t> ThroughputObservationBuffer;
- // This does not use a unordered_map or hash_map for code simplicity (key just
- // implements operator<, rather than hash and equality) and because the map is
- // tiny.
- typedef std::map<NetworkID, nqe::internal::CachedNetworkQuality>
- CachedNetworkQualities;
-
// Algorithms supported by network quality estimator for computing effective
// connection type.
enum class EffectiveConnectionTypeAlgorithm {
@@ -416,11 +368,6 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
// kilobits per second) values.
static const int kMinimumThroughputVariationParameterKbps = 1;
- // Maximum size of the cache that holds network quality estimates.
- // Smaller size may reduce the cache hit rate due to frequent evictions.
- // Larger size may affect performance.
- static const size_t kMaximumNetworkQualityCacheSize = 10;
-
// Returns the RTT value to be used when the valid RTT is unavailable. Readers
// should discard RTT if it is set to the value returned by |InvalidRTT()|.
static const base::TimeDelta InvalidRTT();
@@ -475,10 +422,7 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
// Returns the current network ID checking by calling the platform APIs.
// Virtualized for testing.
- virtual NetworkID GetCurrentNetworkID() const;
-
- // Writes the estimated quality of the current network to the cache.
- void CacheNetworkQualityEstimate();
+ virtual nqe::internal::NetworkID GetCurrentNetworkID() const;
void NotifyObserversOfRTT(const RttObservation& observation);
@@ -534,6 +478,9 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
void RecordExternalEstimateProviderMetrics(
NQEExternalEstimateProviderStatus status) const;
+ // Returns true if the cached network quality estimate was successfully read.
+ bool ReadCachedNetworkQualityEstimate();
+
// Determines if the requests to local host can be used in estimating the
// network quality. Set to true only for tests.
bool use_localhost_requests_;
@@ -570,7 +517,7 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
base::TimeTicks last_connection_change_;
// ID of the current network.
- NetworkID current_network_id_;
+ nqe::internal::NetworkID current_network_id_;
// Peak network quality (fastest round-trip-time (RTT) and highest
// downstream throughput) measured since last connectivity change. RTT is
@@ -580,9 +527,6 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
// 2) Includes server processing time.
nqe::internal::NetworkQuality peak_network_quality_;
- // Cache that stores quality of previously seen networks.
- CachedNetworkQualities cached_network_qualities_;
-
// Buffer that holds throughput observations (in kilobits per second) sorted
// by timestamp.
ThroughputObservationBuffer downstream_throughput_kbps_observations_;
@@ -642,6 +586,9 @@ class NET_EXPORT_PRIVATE NetworkQualityEstimator
int32_t min_signal_strength_since_connection_change_;
int32_t max_signal_strength_since_connection_change_;
+ // Manages the cache that holds the qualities of different networks.
+ nqe::internal::NetworkQualitiesManager network_qualities_manager_;
+
base::ThreadChecker thread_checker_;
base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_;

Powered by Google App Engine
This is Rietveld 408576698