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