| Index: net/nqe/network_quality_estimator_params.cc
|
| diff --git a/net/nqe/network_quality_estimator_params.cc b/net/nqe/network_quality_estimator_params.cc
|
| index 56ab6298f96ad81980119cc3bbd28e0dfa121501..7372ba5bbaf493df21b5e8fbc0df8bee38af143f 100644
|
| --- a/net/nqe/network_quality_estimator_params.cc
|
| +++ b/net/nqe/network_quality_estimator_params.cc
|
| @@ -9,6 +9,14 @@
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/time/time.h"
|
|
|
| +namespace net {
|
| +
|
| +const char kForceEffectiveConnectionType[] = "force_effective_connection_type";
|
| +
|
| +namespace nqe {
|
| +
|
| +namespace internal {
|
| +
|
| namespace {
|
|
|
| // Minimum valid value of the variation parameter that holds RTT (in
|
| @@ -95,97 +103,25 @@ base::TimeDelta GetMinSocketWatcherNotificationInterval(
|
| params, "min_socket_watcher_notification_interval_msec", 1000));
|
| }
|
|
|
| -} // namespace
|
| -
|
| -namespace net {
|
| -
|
| -const char kForceEffectiveConnectionType[] = "force_effective_connection_type";
|
| -
|
| -namespace {
|
| -
|
| -base::Optional<EffectiveConnectionType> GetForcedEffectiveConnectionType(
|
| - const std::map<std::string, std::string>& params) {
|
| - std::string forced_value = GetStringValueForVariationParamWithDefaultValue(
|
| - params, kForceEffectiveConnectionType, "");
|
| - if (forced_value.empty())
|
| - return base::Optional<EffectiveConnectionType>();
|
| -
|
| - EffectiveConnectionType forced_effective_connection_type =
|
| - EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
|
| -
|
| - bool effective_connection_type_available = GetEffectiveConnectionTypeForName(
|
| - forced_value, &forced_effective_connection_type);
|
| -
|
| - DCHECK(effective_connection_type_available);
|
| -
|
| - // Silence unused variable warning in release builds.
|
| - (void)effective_connection_type_available;
|
| -
|
| - return forced_effective_connection_type;
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| -namespace nqe {
|
| -
|
| -namespace internal {
|
| -
|
| -NetworkQualityEstimatorParams::NetworkQualityEstimatorParams(
|
| - const std::map<std::string, std::string>& params)
|
| - : params_(params),
|
| - weight_multiplier_per_second_(GetWeightMultiplierPerSecond(params_)),
|
| - weight_multiplier_per_dbm_(
|
| - GetDoubleValueForVariationParamWithDefaultValue(params_,
|
| - "rssi_weight_per_dbm",
|
| - 1.0)),
|
| - correlation_uma_logging_probability_(
|
| - GetDoubleValueForVariationParamWithDefaultValue(
|
| - params_,
|
| - "correlation_logging_probability",
|
| - 0.01)),
|
| - forced_effective_connection_type_(
|
| - GetForcedEffectiveConnectionType(params_)),
|
| - persistent_cache_reading_enabled_(
|
| - GetPersistentCacheReadingEnabled(params_)),
|
| - min_socket_watcher_notification_interval_(
|
| - GetMinSocketWatcherNotificationInterval(params_)) {
|
| - DCHECK_LE(0.0, correlation_uma_logging_probability_);
|
| - DCHECK_GE(1.0, correlation_uma_logging_probability_);
|
| -}
|
| -
|
| -NetworkQualityEstimatorParams::~NetworkQualityEstimatorParams() {
|
| - DCHECK(thread_checker_.CalledOnValidThread());
|
| -}
|
| -
|
| -std::string NetworkQualityEstimatorParams::GetEffectiveConnectionTypeAlgorithm()
|
| - const {
|
| - DCHECK(thread_checker_.CalledOnValidThread());
|
| -
|
| - const auto it = params_.find("effective_connection_type_algorithm");
|
| - if (it == params_.end())
|
| - return std::string();
|
| - return it->second;
|
| -}
|
| -
|
| // static
|
| -const char* NetworkQualityEstimatorParams::GetNameForConnectionType(
|
| - net::NetworkChangeNotifier::ConnectionType connection_type) {
|
| +const char* GetNameForConnectionTypeInternal(
|
| + NetworkChangeNotifier::ConnectionType connection_type) {
|
| switch (connection_type) {
|
| - case net::NetworkChangeNotifier::CONNECTION_UNKNOWN:
|
| + case NetworkChangeNotifier::CONNECTION_UNKNOWN:
|
| return "Unknown";
|
| - case net::NetworkChangeNotifier::CONNECTION_ETHERNET:
|
| + case NetworkChangeNotifier::CONNECTION_ETHERNET:
|
| return "Ethernet";
|
| - case net::NetworkChangeNotifier::CONNECTION_WIFI:
|
| + case NetworkChangeNotifier::CONNECTION_WIFI:
|
| return "WiFi";
|
| - case net::NetworkChangeNotifier::CONNECTION_2G:
|
| + case NetworkChangeNotifier::CONNECTION_2G:
|
| return "2G";
|
| - case net::NetworkChangeNotifier::CONNECTION_3G:
|
| + case NetworkChangeNotifier::CONNECTION_3G:
|
| return "3G";
|
| - case net::NetworkChangeNotifier::CONNECTION_4G:
|
| + case NetworkChangeNotifier::CONNECTION_4G:
|
| return "4G";
|
| - case net::NetworkChangeNotifier::CONNECTION_NONE:
|
| + case NetworkChangeNotifier::CONNECTION_NONE:
|
| return "None";
|
| - case net::NetworkChangeNotifier::CONNECTION_BLUETOOTH:
|
| + case NetworkChangeNotifier::CONNECTION_BLUETOOTH:
|
| return "Bluetooth";
|
| default:
|
| NOTREACHED();
|
| @@ -194,10 +130,13 @@ const char* NetworkQualityEstimatorParams::GetNameForConnectionType(
|
| return "";
|
| }
|
|
|
| -void NetworkQualityEstimatorParams::ObtainDefaultObservations(
|
| - NetworkQuality default_observations[]) const {
|
| - DCHECK(thread_checker_.CalledOnValidThread());
|
| -
|
| +// 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,
|
| + NetworkQuality default_observations[]) {
|
| for (size_t i = 0; i < NetworkChangeNotifier::CONNECTION_LAST; ++i) {
|
| DCHECK_EQ(InvalidRTT(), default_observations[i].http_rtt());
|
| DCHECK_EQ(InvalidRTT(), default_observations[i].transport_rtt());
|
| @@ -247,10 +186,11 @@ void NetworkQualityEstimatorParams::ObtainDefaultObservations(
|
| static_cast<NetworkChangeNotifier::ConnectionType>(i);
|
|
|
| int32_t variations_value = kMinimumRTTVariationParameterMsec - 1;
|
| - std::string parameter_name = std::string(GetNameForConnectionType(type))
|
| - .append(".DefaultMedianRTTMsec");
|
| - auto it = params_.find(parameter_name);
|
| - if (it != params_.end() &&
|
| + 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] =
|
| @@ -260,10 +200,10 @@ void NetworkQualityEstimatorParams::ObtainDefaultObservations(
|
| }
|
|
|
| variations_value = kMinimumRTTVariationParameterMsec - 1;
|
| - parameter_name = std::string(GetNameForConnectionType(type))
|
| + parameter_name = std::string(GetNameForConnectionTypeInternal(type))
|
| .append(".DefaultMedianTransportRTTMsec");
|
| - it = params_.find(parameter_name);
|
| - if (it != params_.end() &&
|
| + it = params.find(parameter_name);
|
| + if (it != params.end() &&
|
| base::StringToInt(it->second, &variations_value) &&
|
| variations_value >= kMinimumRTTVariationParameterMsec) {
|
| default_observations[i] =
|
| @@ -273,11 +213,11 @@ void NetworkQualityEstimatorParams::ObtainDefaultObservations(
|
| }
|
|
|
| variations_value = kMinimumThroughputVariationParameterKbps - 1;
|
| - parameter_name = std::string(GetNameForConnectionType(type))
|
| + parameter_name = std::string(GetNameForConnectionTypeInternal(type))
|
| .append(".DefaultMedianKbps");
|
| - it = params_.find(parameter_name);
|
| + it = params.find(parameter_name);
|
|
|
| - if (it != params_.end() &&
|
| + if (it != params.end() &&
|
| base::StringToInt(it->second, &variations_value) &&
|
| variations_value >= kMinimumThroughputVariationParameterKbps) {
|
| default_observations[i] = NetworkQuality(
|
| @@ -287,10 +227,11 @@ void NetworkQualityEstimatorParams::ObtainDefaultObservations(
|
| }
|
| }
|
|
|
| -void NetworkQualityEstimatorParams::ObtainTypicalNetworkQuality(
|
| - NetworkQuality typical_network_quality[]) const {
|
| - DCHECK(thread_checker_.CalledOnValidThread());
|
| -
|
| +// Sets |typical_network_quality| to typical network quality for different
|
| +// effective connection types.
|
| +void ObtainTypicalNetworkQualities(
|
| + const std::map<std::string, std::string>& params,
|
| + NetworkQuality typical_network_quality[]) {
|
| for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) {
|
| DCHECK_EQ(InvalidRTT(), typical_network_quality[i].http_rtt());
|
| DCHECK_EQ(InvalidRTT(), typical_network_quality[i].transport_rtt());
|
| @@ -299,9 +240,9 @@ void NetworkQualityEstimatorParams::ObtainTypicalNetworkQuality(
|
| }
|
|
|
| typical_network_quality[EFFECTIVE_CONNECTION_TYPE_SLOW_2G] = 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.
|
| + // 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.
|
| base::TimeDelta::FromMilliseconds(3600),
|
| base::TimeDelta::FromMilliseconds(3000), 40);
|
|
|
| @@ -329,10 +270,11 @@ void NetworkQualityEstimatorParams::ObtainTypicalNetworkQuality(
|
| "Missing effective connection type");
|
| }
|
|
|
| -void NetworkQualityEstimatorParams::ObtainEffectiveConnectionTypeModelParams(
|
| - NetworkQuality connection_thresholds[]) const {
|
| - DCHECK(thread_checker_.CalledOnValidThread());
|
| -
|
| +// Sets the thresholds for different effective connection types in
|
| +// |connection_thresholds|.
|
| +void ObtainConnectionThresholds(
|
| + const std::map<std::string, std::string>& params,
|
| + NetworkQuality connection_thresholds[]) {
|
| // First set the default thresholds.
|
| NetworkQuality default_effective_connection_type_thresholds
|
| [EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_LAST];
|
| @@ -378,21 +320,21 @@ void NetworkQualityEstimatorParams::ObtainEffectiveConnectionTypeModelParams(
|
|
|
| connection_thresholds[i].set_http_rtt(
|
| base::TimeDelta::FromMilliseconds(GetValueForVariationParam(
|
| - params_, connection_type_name + ".ThresholdMedianHttpRTTMsec",
|
| + params, connection_type_name + ".ThresholdMedianHttpRTTMsec",
|
| default_effective_connection_type_thresholds[i]
|
| .http_rtt()
|
| .InMilliseconds())));
|
|
|
| connection_thresholds[i].set_transport_rtt(
|
| base::TimeDelta::FromMilliseconds(GetValueForVariationParam(
|
| - params_, connection_type_name + ".ThresholdMedianTransportRTTMsec",
|
| + params, connection_type_name + ".ThresholdMedianTransportRTTMsec",
|
| default_effective_connection_type_thresholds[i]
|
| .transport_rtt()
|
| .InMilliseconds())));
|
|
|
| connection_thresholds[i].set_downstream_throughput_kbps(
|
| GetValueForVariationParam(
|
| - params_, connection_type_name + ".ThresholdMedianKbps",
|
| + params, connection_type_name + ".ThresholdMedianKbps",
|
| default_effective_connection_type_thresholds[i]
|
| .downstream_throughput_kbps()));
|
| DCHECK(i == 0 ||
|
| @@ -400,6 +342,94 @@ void NetworkQualityEstimatorParams::ObtainEffectiveConnectionTypeModelParams(
|
| }
|
| }
|
|
|
| +base::Optional<EffectiveConnectionType> GetForcedEffectiveConnectionType(
|
| + const std::map<std::string, std::string>& params) {
|
| + std::string forced_value = GetStringValueForVariationParamWithDefaultValue(
|
| + params, kForceEffectiveConnectionType, "");
|
| + if (forced_value.empty())
|
| + return base::Optional<EffectiveConnectionType>();
|
| +
|
| + EffectiveConnectionType forced_effective_connection_type =
|
| + EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
|
| +
|
| + bool effective_connection_type_available = GetEffectiveConnectionTypeForName(
|
| + forced_value, &forced_effective_connection_type);
|
| +
|
| + DCHECK(effective_connection_type_available);
|
| +
|
| + // Silence unused variable warning in release builds.
|
| + (void)effective_connection_type_available;
|
| +
|
| + return forced_effective_connection_type;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +NetworkQualityEstimatorParams::NetworkQualityEstimatorParams(
|
| + const std::map<std::string, std::string>& params)
|
| + : params_(params),
|
| + weight_multiplier_per_second_(GetWeightMultiplierPerSecond(params_)),
|
| + weight_multiplier_per_dbm_(
|
| + GetDoubleValueForVariationParamWithDefaultValue(params_,
|
| + "rssi_weight_per_dbm",
|
| + 1.0)),
|
| + correlation_uma_logging_probability_(
|
| + GetDoubleValueForVariationParamWithDefaultValue(
|
| + params_,
|
| + "correlation_logging_probability",
|
| + 0.01)),
|
| + forced_effective_connection_type_(
|
| + GetForcedEffectiveConnectionType(params_)),
|
| + persistent_cache_reading_enabled_(
|
| + GetPersistentCacheReadingEnabled(params_)),
|
| + min_socket_watcher_notification_interval_(
|
| + GetMinSocketWatcherNotificationInterval(params_)) {
|
| + DCHECK_LE(0.0, correlation_uma_logging_probability_);
|
| + DCHECK_GE(1.0, correlation_uma_logging_probability_);
|
| +
|
| + ObtainDefaultObservations(params_, default_observations_);
|
| + ObtainTypicalNetworkQualities(params_, typical_network_quality_);
|
| + ObtainConnectionThresholds(params_, connection_thresholds_);
|
| +}
|
| +
|
| +NetworkQualityEstimatorParams::~NetworkQualityEstimatorParams() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| +}
|
| +
|
| +std::string NetworkQualityEstimatorParams::GetEffectiveConnectionTypeAlgorithm()
|
| + const {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| +
|
| + const auto it = params_.find("effective_connection_type_algorithm");
|
| + if (it == params_.end())
|
| + return std::string();
|
| + return it->second;
|
| +}
|
| +
|
| +// static
|
| +const char* NetworkQualityEstimatorParams::GetNameForConnectionType(
|
| + NetworkChangeNotifier::ConnectionType connection_type) {
|
| + return GetNameForConnectionTypeInternal(connection_type);
|
| +}
|
| +
|
| +const NetworkQuality& NetworkQualityEstimatorParams::DefaultObservation(
|
| + NetworkChangeNotifier::ConnectionType type) const {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + return default_observations_[type];
|
| +}
|
| +
|
| +const NetworkQuality& NetworkQualityEstimatorParams::TypicalNetworkQuality(
|
| + EffectiveConnectionType type) const {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + return typical_network_quality_[type];
|
| +}
|
| +
|
| +const NetworkQuality& NetworkQualityEstimatorParams::ConnectionThreshold(
|
| + EffectiveConnectionType type) const {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + return connection_thresholds_[type];
|
| +}
|
| +
|
| } // namespace internal
|
|
|
| } // namespace nqe
|
|
|