OLD | NEW |
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 int32_t variations_value = 0; | 72 int32_t variations_value = 0; |
73 auto it = params.find("HalfLifeSeconds"); | 73 auto it = params.find("HalfLifeSeconds"); |
74 if (it != params.end() && base::StringToInt(it->second, &variations_value) && | 74 if (it != params.end() && base::StringToInt(it->second, &variations_value) && |
75 variations_value >= 1) { | 75 variations_value >= 1) { |
76 half_life_seconds = variations_value; | 76 half_life_seconds = variations_value; |
77 } | 77 } |
78 DCHECK_GT(half_life_seconds, 0); | 78 DCHECK_GT(half_life_seconds, 0); |
79 return pow(0.5, 1.0 / half_life_seconds); | 79 return pow(0.5, 1.0 / half_life_seconds); |
80 } | 80 } |
81 | 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( | 82 bool GetPersistentCacheReadingEnabled( |
104 const std::map<std::string, std::string>& params) { | 83 const std::map<std::string, std::string>& params) { |
105 if (GetStringValueForVariationParamWithDefaultValue( | 84 if (GetStringValueForVariationParamWithDefaultValue( |
106 params, "persistent_cache_reading_enabled", "false") != "true") { | 85 params, "persistent_cache_reading_enabled", "false") != "true") { |
107 return false; | 86 return false; |
108 } | 87 } |
109 return true; | 88 return true; |
110 } | 89 } |
111 | 90 |
112 base::TimeDelta GetMinSocketWatcherNotificationInterval( | 91 base::TimeDelta GetMinSocketWatcherNotificationInterval( |
113 const std::map<std::string, std::string>& params) { | 92 const std::map<std::string, std::string>& params) { |
114 // Use 1000 milliseconds as the default value. | 93 // Use 1000 milliseconds as the default value. |
115 return base::TimeDelta::FromMilliseconds(GetValueForVariationParam( | 94 return base::TimeDelta::FromMilliseconds(GetValueForVariationParam( |
116 params, "min_socket_watcher_notification_interval_msec", 1000)); | 95 params, "min_socket_watcher_notification_interval_msec", 1000)); |
117 } | 96 } |
118 | 97 |
119 } // namespace | 98 } // namespace |
120 | 99 |
121 namespace net { | 100 namespace net { |
122 | 101 |
| 102 const char kForceEffectiveConnectionType[] = "force_effective_connection_type"; |
| 103 |
| 104 namespace { |
| 105 |
| 106 base::Optional<EffectiveConnectionType> GetForcedEffectiveConnectionType( |
| 107 const std::map<std::string, std::string>& params) { |
| 108 std::string forced_value = GetStringValueForVariationParamWithDefaultValue( |
| 109 params, kForceEffectiveConnectionType, ""); |
| 110 if (forced_value.empty()) |
| 111 return base::Optional<EffectiveConnectionType>(); |
| 112 |
| 113 EffectiveConnectionType forced_effective_connection_type = |
| 114 EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
| 115 |
| 116 bool effective_connection_type_available = GetEffectiveConnectionTypeForName( |
| 117 forced_value, &forced_effective_connection_type); |
| 118 |
| 119 DCHECK(effective_connection_type_available); |
| 120 |
| 121 // Silence unused variable warning in release builds. |
| 122 (void)effective_connection_type_available; |
| 123 |
| 124 return forced_effective_connection_type; |
| 125 } |
| 126 |
| 127 } // namespace |
| 128 |
123 namespace nqe { | 129 namespace nqe { |
124 | 130 |
125 namespace internal { | 131 namespace internal { |
126 | 132 |
127 NetworkQualityEstimatorParams::NetworkQualityEstimatorParams( | 133 NetworkQualityEstimatorParams::NetworkQualityEstimatorParams( |
128 const std::map<std::string, std::string>& params) | 134 const std::map<std::string, std::string>& params) |
129 : params_(params), | 135 : params_(params), |
130 weight_multiplier_per_second_(GetWeightMultiplierPerSecond(params_)), | 136 weight_multiplier_per_second_(GetWeightMultiplierPerSecond(params_)), |
131 weight_multiplier_per_dbm_( | 137 weight_multiplier_per_dbm_( |
132 GetDoubleValueForVariationParamWithDefaultValue(params_, | 138 GetDoubleValueForVariationParamWithDefaultValue(params_, |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 DCHECK(i == 0 || | 398 DCHECK(i == 0 || |
393 connection_thresholds[i].IsFaster(connection_thresholds[i - 1])); | 399 connection_thresholds[i].IsFaster(connection_thresholds[i - 1])); |
394 } | 400 } |
395 } | 401 } |
396 | 402 |
397 } // namespace internal | 403 } // namespace internal |
398 | 404 |
399 } // namespace nqe | 405 } // namespace nqe |
400 | 406 |
401 } // namespace net | 407 } // namespace net |
OLD | NEW |