network_quality_estimator_params.cc 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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
  3. // found in the LICENSE file.
  4. #include "net/nqe/network_quality_estimator_params.h"
  5. #include <stdint.h>
  6. #include "base/strings/string_number_conversions.h"
  7. #include "base/time/time.h"
  8. namespace net {
  9. const char kForceEffectiveConnectionType[] = "force_effective_connection_type";
  10. const char kEffectiveConnectionTypeSlow2GOnCellular[] = "Slow-2G-On-Cellular";
  11. const base::TimeDelta
  12. kHttpRttEffectiveConnectionTypeThresholds[EFFECTIVE_CONNECTION_TYPE_LAST] =
  13. {base::Milliseconds(0), base::Milliseconds(0),
  14. base::Milliseconds(2010), base::Milliseconds(1420),
  15. base::Milliseconds(272), base::Milliseconds(0)};
  16. namespace {
  17. // Minimum valid value of the variation parameter that holds RTT (in
  18. // milliseconds) values.
  19. static const int kMinimumRTTVariationParameterMsec = 1;
  20. // Minimum valid value of the variation parameter that holds throughput (in
  21. // kilobits per second) values.
  22. static const int kMinimumThroughputVariationParameterKbps = 1;
  23. // Returns the value of |parameter_name| read from |params|. If the
  24. // value is unavailable from |params|, then |default_value| is returned.
  25. int64_t GetValueForVariationParam(
  26. const std::map<std::string, std::string>& params,
  27. const std::string& parameter_name,
  28. int64_t default_value) {
  29. const auto it = params.find(parameter_name);
  30. int64_t variations_value = default_value;
  31. if (it != params.end() &&
  32. base::StringToInt64(it->second, &variations_value)) {
  33. return variations_value;
  34. }
  35. return default_value;
  36. }
  37. // Returns the variation value for |parameter_name|. If the value is
  38. // unavailable, |default_value| is returned.
  39. double GetDoubleValueForVariationParamWithDefaultValue(
  40. const std::map<std::string, std::string>& params,
  41. const std::string& parameter_name,
  42. double default_value) {
  43. const auto it = params.find(parameter_name);
  44. if (it == params.end())
  45. return default_value;
  46. double variations_value = default_value;
  47. if (!base::StringToDouble(it->second, &variations_value))
  48. return default_value;
  49. return variations_value;
  50. }
  51. // Returns the variation value for |parameter_name|. If the value is
  52. // unavailable, |default_value| is returned.
  53. std::string GetStringValueForVariationParamWithDefaultValue(
  54. const std::map<std::string, std::string>& params,
  55. const std::string& parameter_name,
  56. const std::string& default_value) {
  57. const auto it = params.find(parameter_name);
  58. if (it == params.end())
  59. return default_value;
  60. return it->second;
  61. }
  62. double GetWeightMultiplierPerSecond(
  63. const std::map<std::string, std::string>& params) {
  64. // Default value of the half life (in seconds) for computing time weighted
  65. // percentiles. Every half life, the weight of all observations reduces by
  66. // half. Lowering the half life would reduce the weight of older values
  67. // faster.
  68. int half_life_seconds = 60;
  69. int32_t variations_value = 0;
  70. auto it = params.find("HalfLifeSeconds");
  71. if (it != params.end() && base::StringToInt(it->second, &variations_value) &&
  72. variations_value >= 1) {
  73. half_life_seconds = variations_value;
  74. }
  75. DCHECK_GT(half_life_seconds, 0);
  76. return pow(0.5, 1.0 / half_life_seconds);
  77. }
  78. bool GetPersistentCacheReadingEnabled(
  79. const std::map<std::string, std::string>& params) {
  80. if (GetStringValueForVariationParamWithDefaultValue(
  81. params, "persistent_cache_reading_enabled", "true") != "true") {
  82. return false;
  83. }
  84. return true;
  85. }
  86. base::TimeDelta GetMinSocketWatcherNotificationInterval(
  87. const std::map<std::string, std::string>& params) {
  88. // Use 1000 milliseconds as the default value.
  89. return base::Milliseconds(GetValueForVariationParam(
  90. params, "min_socket_watcher_notification_interval_msec", 1000));
  91. }
  92. // static
  93. const char* GetNameForConnectionTypeInternal(
  94. NetworkChangeNotifier::ConnectionType connection_type) {
  95. switch (connection_type) {
  96. case NetworkChangeNotifier::CONNECTION_UNKNOWN:
  97. return "Unknown";
  98. case NetworkChangeNotifier::CONNECTION_ETHERNET:
  99. return "Ethernet";
  100. case NetworkChangeNotifier::CONNECTION_WIFI:
  101. return "WiFi";
  102. case NetworkChangeNotifier::CONNECTION_2G:
  103. return "2G";
  104. case NetworkChangeNotifier::CONNECTION_3G:
  105. return "3G";
  106. case NetworkChangeNotifier::CONNECTION_4G:
  107. return "4G";
  108. case NetworkChangeNotifier::CONNECTION_5G:
  109. return "5G";
  110. case NetworkChangeNotifier::CONNECTION_NONE:
  111. return "None";
  112. case NetworkChangeNotifier::CONNECTION_BLUETOOTH:
  113. return "Bluetooth";
  114. }
  115. return "";
  116. }
  117. // Sets the default observation for different connection types in
  118. // |default_observations|. The default observations are different for
  119. // different connection types (e.g., 2G, 3G, 4G, WiFi). The default
  120. // observations may be used to determine the network quality in absence of any
  121. // other information.
  122. void ObtainDefaultObservations(
  123. const std::map<std::string, std::string>& params,
  124. nqe::internal::NetworkQuality default_observations[]) {
  125. for (size_t i = 0; i < NetworkChangeNotifier::CONNECTION_LAST; ++i) {
  126. DCHECK_EQ(nqe::internal::InvalidRTT(), default_observations[i].http_rtt());
  127. DCHECK_EQ(nqe::internal::InvalidRTT(),
  128. default_observations[i].transport_rtt());
  129. DCHECK_EQ(nqe::internal::INVALID_RTT_THROUGHPUT,
  130. default_observations[i].downstream_throughput_kbps());
  131. }
  132. // Default observations for HTTP RTT, transport RTT, and downstream throughput
  133. // Kbps for the various connection types. These may be overridden by
  134. // variations params. The default observation for a connection type
  135. // corresponds to typical network quality for that connection type.
  136. default_observations[NetworkChangeNotifier::CONNECTION_UNKNOWN] =
  137. nqe::internal::NetworkQuality(base::Milliseconds(115),
  138. base::Milliseconds(55), 1961);
  139. default_observations[NetworkChangeNotifier::CONNECTION_ETHERNET] =
  140. nqe::internal::NetworkQuality(base::Milliseconds(90),
  141. base::Milliseconds(33), 1456);
  142. default_observations[NetworkChangeNotifier::CONNECTION_WIFI] =
  143. nqe::internal::NetworkQuality(base::Milliseconds(116),
  144. base::Milliseconds(66), 2658);
  145. default_observations[NetworkChangeNotifier::CONNECTION_2G] =
  146. nqe::internal::NetworkQuality(base::Milliseconds(1726),
  147. base::Milliseconds(1531), 74);
  148. default_observations[NetworkChangeNotifier::CONNECTION_3G] =
  149. nqe::internal::NetworkQuality(base::Milliseconds(273),
  150. base::Milliseconds(209), 749);
  151. default_observations[NetworkChangeNotifier::CONNECTION_4G] =
  152. nqe::internal::NetworkQuality(base::Milliseconds(137),
  153. base::Milliseconds(80), 1708);
  154. default_observations[NetworkChangeNotifier::CONNECTION_NONE] =
  155. nqe::internal::NetworkQuality(base::Milliseconds(163),
  156. base::Milliseconds(83), 575);
  157. default_observations[NetworkChangeNotifier::CONNECTION_BLUETOOTH] =
  158. nqe::internal::NetworkQuality(base::Milliseconds(385),
  159. base::Milliseconds(318), 476);
  160. // Override using the values provided via variation params.
  161. for (size_t i = 0; i <= NetworkChangeNotifier::CONNECTION_LAST; ++i) {
  162. NetworkChangeNotifier::ConnectionType type =
  163. static_cast<NetworkChangeNotifier::ConnectionType>(i);
  164. int32_t variations_value = kMinimumRTTVariationParameterMsec - 1;
  165. std::string parameter_name =
  166. std::string(GetNameForConnectionTypeInternal(type))
  167. .append(".DefaultMedianRTTMsec");
  168. auto it = params.find(parameter_name);
  169. if (it != params.end() &&
  170. base::StringToInt(it->second, &variations_value) &&
  171. variations_value >= kMinimumRTTVariationParameterMsec) {
  172. default_observations[i] = nqe::internal::NetworkQuality(
  173. base::Milliseconds(variations_value),
  174. default_observations[i].transport_rtt(),
  175. default_observations[i].downstream_throughput_kbps());
  176. }
  177. variations_value = kMinimumRTTVariationParameterMsec - 1;
  178. parameter_name = std::string(GetNameForConnectionTypeInternal(type))
  179. .append(".DefaultMedianTransportRTTMsec");
  180. it = params.find(parameter_name);
  181. if (it != params.end() &&
  182. base::StringToInt(it->second, &variations_value) &&
  183. variations_value >= kMinimumRTTVariationParameterMsec) {
  184. default_observations[i] = nqe::internal::NetworkQuality(
  185. default_observations[i].http_rtt(),
  186. base::Milliseconds(variations_value),
  187. default_observations[i].downstream_throughput_kbps());
  188. }
  189. variations_value = kMinimumThroughputVariationParameterKbps - 1;
  190. parameter_name = std::string(GetNameForConnectionTypeInternal(type))
  191. .append(".DefaultMedianKbps");
  192. it = params.find(parameter_name);
  193. if (it != params.end() &&
  194. base::StringToInt(it->second, &variations_value) &&
  195. variations_value >= kMinimumThroughputVariationParameterKbps) {
  196. default_observations[i] = nqe::internal::NetworkQuality(
  197. default_observations[i].http_rtt(),
  198. default_observations[i].transport_rtt(), variations_value);
  199. }
  200. }
  201. }
  202. // Typical HTTP RTT value corresponding to a given WebEffectiveConnectionType
  203. // value. Taken from
  204. // https://cs.chromium.org/chromium/src/net/nqe/network_quality_estimator_params.cc.
  205. const base::TimeDelta kTypicalHttpRttEffectiveConnectionType
  206. [net::EFFECTIVE_CONNECTION_TYPE_LAST] = {
  207. base::Milliseconds(0), base::Milliseconds(0),
  208. base::Milliseconds(3600), base::Milliseconds(1800),
  209. base::Milliseconds(450), base::Milliseconds(175)};
  210. // Typical downlink throughput (in Mbps) value corresponding to a given
  211. // WebEffectiveConnectionType value. Taken from
  212. // https://cs.chromium.org/chromium/src/net/nqe/network_quality_estimator_params.cc.
  213. const int32_t kTypicalDownlinkKbpsEffectiveConnectionType
  214. [net::EFFECTIVE_CONNECTION_TYPE_LAST] = {0, 0, 40, 75, 400, 1600};
  215. // Sets |typical_network_quality| to typical network quality for different
  216. // effective connection types.
  217. void ObtainTypicalNetworkQualities(
  218. const std::map<std::string, std::string>& params,
  219. nqe::internal::NetworkQuality typical_network_quality[]) {
  220. for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) {
  221. DCHECK_EQ(nqe::internal::InvalidRTT(),
  222. typical_network_quality[i].http_rtt());
  223. DCHECK_EQ(nqe::internal::InvalidRTT(),
  224. typical_network_quality[i].transport_rtt());
  225. DCHECK_EQ(nqe::internal::INVALID_RTT_THROUGHPUT,
  226. typical_network_quality[i].downstream_throughput_kbps());
  227. }
  228. typical_network_quality[EFFECTIVE_CONNECTION_TYPE_SLOW_2G] =
  229. nqe::internal::NetworkQuality(
  230. // Set to the 77.5th percentile of 2G RTT observations on Android.
  231. // This corresponds to the median RTT observation when effective
  232. // connection type is Slow 2G.
  233. kTypicalHttpRttEffectiveConnectionType
  234. [EFFECTIVE_CONNECTION_TYPE_SLOW_2G],
  235. base::Milliseconds(3000),
  236. kTypicalDownlinkKbpsEffectiveConnectionType
  237. [EFFECTIVE_CONNECTION_TYPE_SLOW_2G]);
  238. typical_network_quality[EFFECTIVE_CONNECTION_TYPE_2G] =
  239. nqe::internal::NetworkQuality(
  240. // Set to the 58th percentile of 2G RTT observations on Android. This
  241. // corresponds to the median RTT observation when effective connection
  242. // type is 2G.
  243. kTypicalHttpRttEffectiveConnectionType[EFFECTIVE_CONNECTION_TYPE_2G],
  244. base::Milliseconds(1500),
  245. kTypicalDownlinkKbpsEffectiveConnectionType
  246. [EFFECTIVE_CONNECTION_TYPE_2G]);
  247. typical_network_quality[EFFECTIVE_CONNECTION_TYPE_3G] =
  248. nqe::internal::NetworkQuality(
  249. // Set to the 75th percentile of 3G RTT observations on Android. This
  250. // corresponds to the median RTT observation when effective connection
  251. // type is 3G.
  252. kTypicalHttpRttEffectiveConnectionType[EFFECTIVE_CONNECTION_TYPE_3G],
  253. base::Milliseconds(400),
  254. kTypicalDownlinkKbpsEffectiveConnectionType
  255. [EFFECTIVE_CONNECTION_TYPE_3G]);
  256. // Set to the 25th percentile of 3G RTT observations on Android.
  257. typical_network_quality[EFFECTIVE_CONNECTION_TYPE_4G] =
  258. nqe::internal::NetworkQuality(
  259. kTypicalHttpRttEffectiveConnectionType[EFFECTIVE_CONNECTION_TYPE_4G],
  260. base::Milliseconds(125),
  261. kTypicalDownlinkKbpsEffectiveConnectionType
  262. [EFFECTIVE_CONNECTION_TYPE_4G]);
  263. static_assert(
  264. EFFECTIVE_CONNECTION_TYPE_4G + 1 == EFFECTIVE_CONNECTION_TYPE_LAST,
  265. "Missing effective connection type");
  266. }
  267. // Sets the thresholds for different effective connection types in
  268. // |connection_thresholds|.
  269. void ObtainConnectionThresholds(
  270. const std::map<std::string, std::string>& params,
  271. nqe::internal::NetworkQuality connection_thresholds[]) {
  272. // First set the default thresholds.
  273. nqe::internal::NetworkQuality default_effective_connection_type_thresholds
  274. [EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_LAST];
  275. DCHECK_LT(base::TimeDelta(), kHttpRttEffectiveConnectionTypeThresholds
  276. [EFFECTIVE_CONNECTION_TYPE_SLOW_2G]);
  277. default_effective_connection_type_thresholds
  278. [EFFECTIVE_CONNECTION_TYPE_SLOW_2G] = nqe::internal::NetworkQuality(
  279. // Set to the 66th percentile of 2G RTT observations on Android.
  280. kHttpRttEffectiveConnectionTypeThresholds
  281. [EFFECTIVE_CONNECTION_TYPE_SLOW_2G],
  282. nqe::internal::InvalidRTT(), nqe::internal::INVALID_RTT_THROUGHPUT);
  283. DCHECK_LT(
  284. base::TimeDelta(),
  285. kHttpRttEffectiveConnectionTypeThresholds[EFFECTIVE_CONNECTION_TYPE_2G]);
  286. default_effective_connection_type_thresholds[EFFECTIVE_CONNECTION_TYPE_2G] =
  287. nqe::internal::NetworkQuality(
  288. // Set to the 50th percentile of RTT observations on Android.
  289. kHttpRttEffectiveConnectionTypeThresholds
  290. [EFFECTIVE_CONNECTION_TYPE_2G],
  291. nqe::internal::InvalidRTT(), nqe::internal::INVALID_RTT_THROUGHPUT);
  292. DCHECK_LT(
  293. base::TimeDelta(),
  294. kHttpRttEffectiveConnectionTypeThresholds[EFFECTIVE_CONNECTION_TYPE_3G]);
  295. default_effective_connection_type_thresholds[EFFECTIVE_CONNECTION_TYPE_3G] =
  296. nqe::internal::NetworkQuality(
  297. // Set to the 50th percentile of 3G RTT observations on Android.
  298. kHttpRttEffectiveConnectionTypeThresholds
  299. [EFFECTIVE_CONNECTION_TYPE_3G],
  300. nqe::internal::InvalidRTT(), nqe::internal::INVALID_RTT_THROUGHPUT);
  301. // Connection threshold should not be set for 4G effective connection type
  302. // since it is the fastest.
  303. static_assert(
  304. EFFECTIVE_CONNECTION_TYPE_3G + 1 == EFFECTIVE_CONNECTION_TYPE_4G,
  305. "Missing effective connection type");
  306. static_assert(
  307. EFFECTIVE_CONNECTION_TYPE_4G + 1 == EFFECTIVE_CONNECTION_TYPE_LAST,
  308. "Missing effective connection type");
  309. for (size_t i = 0; i <= EFFECTIVE_CONNECTION_TYPE_3G; ++i) {
  310. EffectiveConnectionType effective_connection_type =
  311. static_cast<EffectiveConnectionType>(i);
  312. DCHECK_EQ(nqe::internal::InvalidRTT(), connection_thresholds[i].http_rtt());
  313. DCHECK_EQ(nqe::internal::InvalidRTT(),
  314. connection_thresholds[i].transport_rtt());
  315. DCHECK_EQ(nqe::internal::INVALID_RTT_THROUGHPUT,
  316. connection_thresholds[i].downstream_throughput_kbps());
  317. if (effective_connection_type == EFFECTIVE_CONNECTION_TYPE_UNKNOWN)
  318. continue;
  319. std::string connection_type_name = std::string(
  320. DeprecatedGetNameForEffectiveConnectionType(effective_connection_type));
  321. connection_thresholds[i].set_http_rtt(
  322. base::Milliseconds(GetValueForVariationParam(
  323. params, connection_type_name + ".ThresholdMedianHttpRTTMsec",
  324. default_effective_connection_type_thresholds[i]
  325. .http_rtt()
  326. .InMilliseconds())));
  327. DCHECK_EQ(nqe::internal::InvalidRTT(),
  328. default_effective_connection_type_thresholds[i].transport_rtt());
  329. DCHECK_EQ(nqe::internal::INVALID_RTT_THROUGHPUT,
  330. default_effective_connection_type_thresholds[i]
  331. .downstream_throughput_kbps());
  332. DCHECK(i == 0 ||
  333. connection_thresholds[i].IsFaster(connection_thresholds[i - 1]));
  334. }
  335. }
  336. std::string GetForcedEffectiveConnectionTypeString(
  337. const std::map<std::string, std::string>& params) {
  338. return GetStringValueForVariationParamWithDefaultValue(
  339. params, kForceEffectiveConnectionType, "");
  340. }
  341. bool GetForcedEffectiveConnectionTypeOnCellularOnly(
  342. const std::map<std::string, std::string>& params) {
  343. return GetForcedEffectiveConnectionTypeString(params) ==
  344. kEffectiveConnectionTypeSlow2GOnCellular;
  345. }
  346. absl::optional<EffectiveConnectionType> GetInitForcedEffectiveConnectionType(
  347. const std::map<std::string, std::string>& params) {
  348. if (GetForcedEffectiveConnectionTypeOnCellularOnly(params)) {
  349. return absl::nullopt;
  350. }
  351. std::string forced_value = GetForcedEffectiveConnectionTypeString(params);
  352. absl::optional<EffectiveConnectionType> ect =
  353. GetEffectiveConnectionTypeForName(forced_value);
  354. DCHECK(forced_value.empty() || ect);
  355. return ect;
  356. }
  357. } // namespace
  358. NetworkQualityEstimatorParams::NetworkQualityEstimatorParams(
  359. const std::map<std::string, std::string>& params)
  360. : params_(params),
  361. throughput_min_requests_in_flight_(
  362. GetValueForVariationParam(params_,
  363. "throughput_min_requests_in_flight",
  364. 5)),
  365. throughput_min_transfer_size_kilobytes_(
  366. GetValueForVariationParam(params_,
  367. "throughput_min_transfer_size_kilobytes",
  368. 32)),
  369. throughput_hanging_requests_cwnd_size_multiplier_(
  370. GetDoubleValueForVariationParamWithDefaultValue(
  371. params_,
  372. "throughput_hanging_requests_cwnd_size_multiplier",
  373. 1)),
  374. weight_multiplier_per_second_(GetWeightMultiplierPerSecond(params_)),
  375. forced_effective_connection_type_(
  376. GetInitForcedEffectiveConnectionType(params_)),
  377. forced_effective_connection_type_on_cellular_only_(
  378. GetForcedEffectiveConnectionTypeOnCellularOnly(params_)),
  379. persistent_cache_reading_enabled_(
  380. GetPersistentCacheReadingEnabled(params_)),
  381. min_socket_watcher_notification_interval_(
  382. GetMinSocketWatcherNotificationInterval(params_)),
  383. upper_bound_http_rtt_endtoend_rtt_multiplier_(
  384. GetDoubleValueForVariationParamWithDefaultValue(
  385. params_,
  386. "upper_bound_http_rtt_endtoend_rtt_multiplier",
  387. 3.0)),
  388. hanging_request_http_rtt_upper_bound_transport_rtt_multiplier_(
  389. GetValueForVariationParam(
  390. params_,
  391. "hanging_request_http_rtt_upper_bound_transport_rtt_multiplier",
  392. 8)),
  393. hanging_request_http_rtt_upper_bound_http_rtt_multiplier_(
  394. GetValueForVariationParam(
  395. params_,
  396. "hanging_request_http_rtt_upper_bound_http_rtt_multiplier",
  397. 6)),
  398. http_rtt_transport_rtt_min_count_(
  399. GetValueForVariationParam(params_,
  400. "http_rtt_transport_rtt_min_count",
  401. 5)),
  402. increase_in_transport_rtt_logging_interval_(
  403. base::Milliseconds(GetDoubleValueForVariationParamWithDefaultValue(
  404. params_,
  405. "increase_in_transport_rtt_logging_interval",
  406. 10000))),
  407. recent_time_threshold_(
  408. base::Milliseconds(GetDoubleValueForVariationParamWithDefaultValue(
  409. params_,
  410. "recent_time_threshold",
  411. 5000))),
  412. historical_time_threshold_(
  413. base::Milliseconds(GetDoubleValueForVariationParamWithDefaultValue(
  414. params_,
  415. "historical_time_threshold",
  416. 60000))),
  417. hanging_request_duration_http_rtt_multiplier_(GetValueForVariationParam(
  418. params_,
  419. "hanging_request_duration_http_rtt_multiplier",
  420. 5)),
  421. add_default_platform_observations_(
  422. GetStringValueForVariationParamWithDefaultValue(
  423. params_,
  424. "add_default_platform_observations",
  425. "true") == "true"),
  426. socket_watchers_min_notification_interval_(
  427. base::Milliseconds(GetValueForVariationParam(
  428. params_,
  429. "socket_watchers_min_notification_interval_msec",
  430. 200))),
  431. upper_bound_typical_kbps_multiplier_(
  432. GetDoubleValueForVariationParamWithDefaultValue(
  433. params_,
  434. "upper_bound_typical_kbps_multiplier",
  435. 3.5)),
  436. adjust_rtt_based_on_rtt_counts_(
  437. GetStringValueForVariationParamWithDefaultValue(
  438. params_,
  439. "adjust_rtt_based_on_rtt_counts",
  440. "false") == "true") {
  441. DCHECK(hanging_request_http_rtt_upper_bound_transport_rtt_multiplier_ == -1 ||
  442. hanging_request_http_rtt_upper_bound_transport_rtt_multiplier_ > 0);
  443. DCHECK(hanging_request_http_rtt_upper_bound_http_rtt_multiplier_ == -1 ||
  444. hanging_request_http_rtt_upper_bound_http_rtt_multiplier_ > 0);
  445. DCHECK(hanging_request_http_rtt_upper_bound_transport_rtt_multiplier_ == -1 ||
  446. hanging_request_http_rtt_upper_bound_http_rtt_multiplier_ == -1 ||
  447. hanging_request_http_rtt_upper_bound_transport_rtt_multiplier_ >=
  448. hanging_request_http_rtt_upper_bound_http_rtt_multiplier_);
  449. DCHECK_LT(0, hanging_request_duration_http_rtt_multiplier());
  450. DCHECK_LT(0, hanging_request_http_rtt_upper_bound_http_rtt_multiplier());
  451. DCHECK_LT(0, hanging_request_http_rtt_upper_bound_transport_rtt_multiplier());
  452. ObtainDefaultObservations(params_, default_observations_);
  453. ObtainTypicalNetworkQualities(params_, typical_network_quality_);
  454. ObtainConnectionThresholds(params_, connection_thresholds_);
  455. }
  456. NetworkQualityEstimatorParams::~NetworkQualityEstimatorParams() = default;
  457. void NetworkQualityEstimatorParams::SetUseSmallResponsesForTesting(
  458. bool use_small_responses) {
  459. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  460. use_small_responses_ = use_small_responses;
  461. }
  462. bool NetworkQualityEstimatorParams::use_small_responses() const {
  463. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  464. return use_small_responses_;
  465. }
  466. // static
  467. base::TimeDelta NetworkQualityEstimatorParams::GetDefaultTypicalHttpRtt(
  468. EffectiveConnectionType effective_connection_type) {
  469. return kTypicalHttpRttEffectiveConnectionType[effective_connection_type];
  470. }
  471. // static
  472. int32_t NetworkQualityEstimatorParams::GetDefaultTypicalDownlinkKbps(
  473. EffectiveConnectionType effective_connection_type) {
  474. return kTypicalDownlinkKbpsEffectiveConnectionType[effective_connection_type];
  475. }
  476. void NetworkQualityEstimatorParams::SetForcedEffectiveConnectionTypeForTesting(
  477. EffectiveConnectionType type) {
  478. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  479. DCHECK(!forced_effective_connection_type_on_cellular_only_);
  480. forced_effective_connection_type_ = type;
  481. }
  482. absl::optional<EffectiveConnectionType>
  483. NetworkQualityEstimatorParams::GetForcedEffectiveConnectionType(
  484. NetworkChangeNotifier::ConnectionType connection_type) {
  485. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  486. if (forced_effective_connection_type_) {
  487. return forced_effective_connection_type_;
  488. }
  489. if (forced_effective_connection_type_on_cellular_only_ &&
  490. net::NetworkChangeNotifier::IsConnectionCellular(connection_type)) {
  491. return EFFECTIVE_CONNECTION_TYPE_SLOW_2G;
  492. }
  493. return absl::nullopt;
  494. }
  495. size_t NetworkQualityEstimatorParams::throughput_min_requests_in_flight()
  496. const {
  497. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  498. // If |use_small_responses_| is set to true for testing, then consider one
  499. // request as sufficient for taking throughput sample.
  500. return use_small_responses_ ? 1 : throughput_min_requests_in_flight_;
  501. }
  502. int64_t NetworkQualityEstimatorParams::GetThroughputMinTransferSizeBits()
  503. const {
  504. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  505. return static_cast<int64_t>(throughput_min_transfer_size_kilobytes_) * 8 *
  506. 1000;
  507. }
  508. const nqe::internal::NetworkQuality&
  509. NetworkQualityEstimatorParams::DefaultObservation(
  510. NetworkChangeNotifier::ConnectionType type) const {
  511. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  512. return default_observations_[type];
  513. }
  514. const nqe::internal::NetworkQuality&
  515. NetworkQualityEstimatorParams::TypicalNetworkQuality(
  516. EffectiveConnectionType type) const {
  517. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  518. return typical_network_quality_[type];
  519. }
  520. const nqe::internal::NetworkQuality&
  521. NetworkQualityEstimatorParams::ConnectionThreshold(
  522. EffectiveConnectionType type) const {
  523. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  524. return connection_thresholds_[type];
  525. }
  526. } // namespace net