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

Unified Diff: net/nqe/network_quality_estimator.cc

Issue 2032443003: NQE: Allow algorithm to be set using variation params (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 6 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.cc
diff --git a/net/nqe/network_quality_estimator.cc b/net/nqe/network_quality_estimator.cc
index 6b6c7f3eab08c366b7309759683e2341d2a8ed42..39a7f2fdbc84095bb817b2657b21adae02d6e892 100644
--- a/net/nqe/network_quality_estimator.cc
+++ b/net/nqe/network_quality_estimator.cc
@@ -134,11 +134,22 @@ bool GetValueForVariationParam(
const std::map<std::string, std::string>& variation_params,
const std::string& parameter_name,
int32_t* variations_value) {
- auto it = variation_params.find(parameter_name);
+ const auto it = variation_params.find(parameter_name);
return it != variation_params.end() &&
base::StringToInt(it->second, variations_value);
}
+// Returns the algorithm that should be used for computing effective connection
+// type based on field trial params. Returns an empty string if a valid
+// algorithm paramter is not present in the field trial params.
+std::string GetEffectiveConnectionTypeAlgorithm(
+ const std::map<std::string, std::string>& variation_params) {
+ const auto it = variation_params.find("algorithm");
+ if (it == variation_params.end())
+ return std::string();
+ return it->second;
+}
+
net::NetworkQualityObservationSource ProtocolSourceToObservationSource(
net::SocketPerformanceWatcherFactory::Protocol protocol) {
switch (protocol) {
@@ -196,6 +207,13 @@ NetworkQualityEstimator::NetworkQualityEstimator(
use_small_responses_(use_smaller_responses_for_tests),
weight_multiplier_per_second_(
GetWeightMultiplierPerSecond(variation_params)),
+ algorithm_(
+ stringToAlgorithm_.find(GetEffectiveConnectionTypeAlgorithm(
+ variation_params)) == stringToAlgorithm_.end()
+ ? kDefaultEffectiveConnectionTypeAlgorithm
+ : stringToAlgorithm_
+ .find(GetEffectiveConnectionTypeAlgorithm(variation_params))
+ ->second),
tick_clock_(new base::DefaultTickClock()),
effective_connection_type_recomputation_interval_(
base::TimeDelta::FromSeconds(15)),
@@ -216,6 +234,15 @@ NetworkQualityEstimator::NetworkQualityEstimator(
// oldest cache entry is rewritten to use a doubly-linked-list LRU queue.
static_assert(kMaximumNetworkQualityCacheSize <= 10,
"Size of the network quality cache must <= 10");
+ // None of the algorithms can have an empty name.
+ DCHECK(stringToAlgorithm_.end() == stringToAlgorithm_.find(std::string()));
bengr 2016/06/08 23:33:11 Construction of the map should go write before thi
tbansal1 2016/06/08 23:48:29 Not doing this as discussed offline.
+
+ DCHECK_EQ(stringToAlgorithm_.size(),
+ static_cast<size_t>(EffectiveConnectionTypeAlgorithm::
+ EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST));
+ DCHECK_NE(EffectiveConnectionTypeAlgorithm::
+ EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST,
+ algorithm_);
ObtainOperatingParams(variation_params);
ObtainEffectiveConnectionTypeModelParams(variation_params);
@@ -756,6 +783,21 @@ NetworkQualityEstimator::GetRecentEffectiveConnectionType(
const base::TimeTicks& start_time) const {
DCHECK(thread_checker_.CalledOnValidThread());
+ if (algorithm_ ==
+ EffectiveConnectionTypeAlgorithm::HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT) {
+ return GetRecentEffectiveConnectionTypeHttpRTTAndDownstreamThroughput(
+ start_time);
+ }
+ // Add additional algorithms here.
+ NOTREACHED();
+ return EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
+}
+
+NetworkQualityEstimator::EffectiveConnectionType NetworkQualityEstimator::
+ GetRecentEffectiveConnectionTypeHttpRTTAndDownstreamThroughput(
+ const base::TimeTicks& start_time) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
// If the device is currently offline, then return
// EFFECTIVE_CONNECTION_TYPE_OFFLINE.
if (GetCurrentNetworkID().type == NetworkChangeNotifier::CONNECTION_NONE)
@@ -769,7 +811,7 @@ NetworkQualityEstimator::GetRecentEffectiveConnectionType(
if (!GetRecentMedianDownlinkThroughputKbps(start_time, &kbps))
kbps = nqe::internal::kInvalidThroughput;
- if (http_rtt == nqe::internal::InvalidRTT() &&
+ if (http_rtt == nqe::internal::InvalidRTT() ||
kbps == nqe::internal::kInvalidThroughput) {
// Quality of the current network is unknown.
return EFFECTIVE_CONNECTION_TYPE_UNKNOWN;

Powered by Google App Engine
This is Rietveld 408576698