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

Side by Side Diff: net/nqe/network_quality_estimator_params.cc

Issue 2858743002: NQE: Move params from the estimator class to the params class (Closed)
Patch Set: ryansturm comments Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/nqe/network_quality_estimator_params.h" 5 #include "net/nqe/network_quality_estimator_params.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 std::string GetStringValueForVariationParamWithDefaultValue( 55 std::string GetStringValueForVariationParamWithDefaultValue(
56 const std::map<std::string, std::string>& params, 56 const std::map<std::string, std::string>& params,
57 const std::string& parameter_name, 57 const std::string& parameter_name,
58 const std::string& default_value) { 58 const std::string& default_value) {
59 const auto it = params.find(parameter_name); 59 const auto it = params.find(parameter_name);
60 if (it == params.end()) 60 if (it == params.end())
61 return default_value; 61 return default_value;
62 return it->second; 62 return it->second;
63 } 63 }
64 64
65 double GetWeightMultiplierPerSecond(
66 const std::map<std::string, std::string>& params) {
67 // Default value of the half life (in seconds) for computing time weighted
68 // percentiles. Every half life, the weight of all observations reduces by
69 // half. Lowering the half life would reduce the weight of older values
70 // faster.
71 int half_life_seconds = 60;
72 int32_t variations_value = 0;
73 auto it = params.find("HalfLifeSeconds");
74 if (it != params.end() && base::StringToInt(it->second, &variations_value) &&
75 variations_value >= 1) {
76 half_life_seconds = variations_value;
77 }
78 DCHECK_GT(half_life_seconds, 0);
79 return pow(0.5, 1.0 / half_life_seconds);
80 }
81
82 base::Optional<net::EffectiveConnectionType> GetForcedEffectiveConnectionType(
83 const std::map<std::string, std::string>& params) {
84 std::string forced_value = GetStringValueForVariationParamWithDefaultValue(
85 params, "force_effective_connection_type", "");
86 if (forced_value.empty())
87 return base::Optional<net::EffectiveConnectionType>();
88
89 net::EffectiveConnectionType forced_effective_connection_type =
90 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
91
92 bool effective_connection_type_available = GetEffectiveConnectionTypeForName(
93 forced_value, &forced_effective_connection_type);
94
95 DCHECK(effective_connection_type_available);
96
97 // Silence unused variable warning in release builds.
98 (void)effective_connection_type_available;
99
100 return forced_effective_connection_type;
101 }
102
103 bool GetPersistentCacheReadingEnabled(
104 const std::map<std::string, std::string>& params) {
105 if (GetStringValueForVariationParamWithDefaultValue(
106 params, "persistent_cache_reading_enabled", "false") != "true") {
107 return false;
108 }
109 return true;
110 }
111
112 base::TimeDelta GetMinSocketWatcherNotificationInterval(
113 const std::map<std::string, std::string>& params) {
114 // Use 1000 milliseconds as the default value.
115 return base::TimeDelta::FromMilliseconds(GetValueForVariationParam(
116 params, "min_socket_watcher_notification_interval_msec", 1000));
117 }
118
65 } // namespace 119 } // namespace
66 120
67 namespace net { 121 namespace net {
68 122
69 namespace nqe { 123 namespace nqe {
70 124
71 namespace internal { 125 namespace internal {
72 126
73 NetworkQualityEstimatorParams::NetworkQualityEstimatorParams( 127 NetworkQualityEstimatorParams::NetworkQualityEstimatorParams(
74 const std::map<std::string, std::string>& params) 128 const std::map<std::string, std::string>& params)
75 : params_(params) {} 129 : params_(params),
130 weight_multiplier_per_second_(GetWeightMultiplierPerSecond(params_)),
131 weight_multiplier_per_dbm_(
132 GetDoubleValueForVariationParamWithDefaultValue(params_,
133 "rssi_weight_per_dbm",
134 1.0)),
135 correlation_uma_logging_probability_(
136 GetDoubleValueForVariationParamWithDefaultValue(
137 params_,
138 "correlation_logging_probability",
139 0.01)),
140 forced_effective_connection_type_(
141 GetForcedEffectiveConnectionType(params_)),
142 persistent_cache_reading_enabled_(
143 GetPersistentCacheReadingEnabled(params_)),
144 min_socket_watcher_notification_interval_(
145 GetMinSocketWatcherNotificationInterval(params_)) {
146 DCHECK_LE(0.0, correlation_uma_logging_probability_);
147 DCHECK_GE(1.0, correlation_uma_logging_probability_);
148 }
76 149
77 NetworkQualityEstimatorParams::~NetworkQualityEstimatorParams() { 150 NetworkQualityEstimatorParams::~NetworkQualityEstimatorParams() {
78 DCHECK(thread_checker_.CalledOnValidThread()); 151 DCHECK(thread_checker_.CalledOnValidThread());
79 } 152 }
80 153
81 std::string NetworkQualityEstimatorParams::GetEffectiveConnectionTypeAlgorithm() 154 std::string NetworkQualityEstimatorParams::GetEffectiveConnectionTypeAlgorithm()
82 const { 155 const {
83 DCHECK(thread_checker_.CalledOnValidThread()); 156 DCHECK(thread_checker_.CalledOnValidThread());
84 157
85 const auto it = params_.find("effective_connection_type_algorithm"); 158 const auto it = params_.find("effective_connection_type_algorithm");
86 if (it == params_.end()) 159 if (it == params_.end())
87 return std::string(); 160 return std::string();
88 return it->second; 161 return it->second;
89 } 162 }
90 163
91 double NetworkQualityEstimatorParams::GetWeightMultiplierPerSecond() const {
92 DCHECK(thread_checker_.CalledOnValidThread());
93
94 // Default value of the half life (in seconds) for computing time weighted
95 // percentiles. Every half life, the weight of all observations reduces by
96 // half. Lowering the half life would reduce the weight of older values
97 // faster.
98 int half_life_seconds = 60;
99 int32_t variations_value = 0;
100 auto it = params_.find("HalfLifeSeconds");
101 if (it != params_.end() && base::StringToInt(it->second, &variations_value) &&
102 variations_value >= 1) {
103 half_life_seconds = variations_value;
104 }
105 DCHECK_GT(half_life_seconds, 0);
106 return pow(0.5, 1.0 / half_life_seconds);
107 }
108
109 double NetworkQualityEstimatorParams::GetWeightMultiplierPerDbm() const {
110 DCHECK(thread_checker_.CalledOnValidThread());
111
112 // The default weight is set to 1.0, so by default, RSSI has no effect on the
113 // observation's weight.
114 return GetDoubleValueForVariationParamWithDefaultValue(
115 params_, "rssi_weight_per_dbm", 1.0);
116 }
117
118 // static 164 // static
119 const char* NetworkQualityEstimatorParams::GetNameForConnectionType( 165 const char* NetworkQualityEstimatorParams::GetNameForConnectionType(
120 net::NetworkChangeNotifier::ConnectionType connection_type) { 166 net::NetworkChangeNotifier::ConnectionType connection_type) {
121 switch (connection_type) { 167 switch (connection_type) {
122 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN: 168 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN:
123 return "Unknown"; 169 return "Unknown";
124 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: 170 case net::NetworkChangeNotifier::CONNECTION_ETHERNET:
125 return "Ethernet"; 171 return "Ethernet";
126 case net::NetworkChangeNotifier::CONNECTION_WIFI: 172 case net::NetworkChangeNotifier::CONNECTION_WIFI:
127 return "WiFi"; 173 return "WiFi";
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 connection_thresholds[i].set_downstream_throughput_kbps( 387 connection_thresholds[i].set_downstream_throughput_kbps(
342 GetValueForVariationParam( 388 GetValueForVariationParam(
343 params_, connection_type_name + ".ThresholdMedianKbps", 389 params_, connection_type_name + ".ThresholdMedianKbps",
344 default_effective_connection_type_thresholds[i] 390 default_effective_connection_type_thresholds[i]
345 .downstream_throughput_kbps())); 391 .downstream_throughput_kbps()));
346 DCHECK(i == 0 || 392 DCHECK(i == 0 ||
347 connection_thresholds[i].IsFaster(connection_thresholds[i - 1])); 393 connection_thresholds[i].IsFaster(connection_thresholds[i - 1]));
348 } 394 }
349 } 395 }
350 396
351 double NetworkQualityEstimatorParams::correlation_uma_logging_probability()
352 const {
353 DCHECK(thread_checker_.CalledOnValidThread());
354
355 double correlation_uma_logging_probability =
356 GetDoubleValueForVariationParamWithDefaultValue(
357 params_, "correlation_logging_probability", 0.01);
358 DCHECK_LE(0.0, correlation_uma_logging_probability);
359 DCHECK_GE(1.0, correlation_uma_logging_probability);
360 return correlation_uma_logging_probability;
361 }
362
363 bool NetworkQualityEstimatorParams::forced_effective_connection_type_set()
364 const {
365 return !GetStringValueForVariationParamWithDefaultValue(
366 params_, "force_effective_connection_type", "")
367 .empty();
368 }
369
370 EffectiveConnectionType
371 NetworkQualityEstimatorParams::forced_effective_connection_type() const {
372 EffectiveConnectionType forced_effective_connection_type =
373 EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
374 std::string forced_value = GetStringValueForVariationParamWithDefaultValue(
375 params_, "force_effective_connection_type",
376 GetNameForEffectiveConnectionType(EFFECTIVE_CONNECTION_TYPE_UNKNOWN));
377 DCHECK(!forced_value.empty());
378 bool effective_connection_type_available = GetEffectiveConnectionTypeForName(
379 forced_value, &forced_effective_connection_type);
380 DCHECK(effective_connection_type_available);
381
382 // Silence unused variable warning in release builds.
383 (void)effective_connection_type_available;
384
385 return forced_effective_connection_type;
386 }
387
388 bool NetworkQualityEstimatorParams::persistent_cache_reading_enabled() const {
389 DCHECK(thread_checker_.CalledOnValidThread());
390
391 if (GetStringValueForVariationParamWithDefaultValue(
392 params_, "persistent_cache_reading_enabled", "false") != "true") {
393 return false;
394 }
395 return true;
396 }
397
398 base::TimeDelta
399 NetworkQualityEstimatorParams::GetMinSocketWatcherNotificationInterval() const {
400 DCHECK(thread_checker_.CalledOnValidThread());
401
402 // Use 1000 milliseconds as the default value.
403 return base::TimeDelta::FromMilliseconds(GetValueForVariationParam(
404 params_, "min_socket_watcher_notification_interval_msec", 1000));
405 }
406
407 } // namespace internal 397 } // namespace internal
408 398
409 } // namespace nqe 399 } // namespace nqe
410 400
411 } // namespace net 401 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_estimator_params.h ('k') | net/nqe/network_quality_estimator_params_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698