| Index: net/nqe/network_quality_estimator.cc
|
| diff --git a/net/nqe/network_quality_estimator.cc b/net/nqe/network_quality_estimator.cc
|
| index 1728675dc93c4cc2f27f1593577248b6af2ec028..e282d7cbaf2b789c373720660e4eaa1ffa9f8e1b 100644
|
| --- a/net/nqe/network_quality_estimator.cc
|
| +++ b/net/nqe/network_quality_estimator.cc
|
| @@ -13,6 +13,7 @@
|
| #include "base/bind_helpers.h"
|
| #include "base/location.h"
|
| #include "base/logging.h"
|
| +#include "base/memory/ptr_util.h"
|
| #include "base/metrics/histogram.h"
|
| #include "base/metrics/histogram_base.h"
|
| #include "base/metrics/histogram_macros.h"
|
| @@ -211,25 +212,13 @@ void RecordEffectiveConnectionTypeAccuracy(
|
|
|
| NetworkQualityEstimator::NetworkQualityEstimator(
|
| std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
|
| - const std::map<std::string, std::string>& variation_params,
|
| - NetLog* net_log)
|
| - : NetworkQualityEstimator(std::move(external_estimates_provider),
|
| - variation_params,
|
| - false,
|
| - false,
|
| - net_log) {}
|
| -
|
| -NetworkQualityEstimator::NetworkQualityEstimator(
|
| - std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
|
| - const std::map<std::string, std::string>& variation_params,
|
| - bool use_local_host_requests_for_tests,
|
| - bool use_smaller_responses_for_tests,
|
| + std::unique_ptr<nqe::internal::NetworkQualityEstimatorParams> params,
|
| NetLog* net_log)
|
| : NetworkQualityEstimator(
|
| std::move(external_estimates_provider),
|
| - variation_params,
|
| - use_local_host_requests_for_tests,
|
| - use_smaller_responses_for_tests,
|
| + std::move(params),
|
| + false,
|
| + false,
|
| true,
|
| NetLogWithSource::Make(
|
| net_log,
|
| @@ -237,7 +226,7 @@ NetworkQualityEstimator::NetworkQualityEstimator(
|
|
|
| NetworkQualityEstimator::NetworkQualityEstimator(
|
| std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
|
| - const std::map<std::string, std::string>& variation_params,
|
| + std::unique_ptr<nqe::internal::NetworkQualityEstimatorParams> params,
|
| bool use_local_host_requests_for_tests,
|
| bool use_smaller_responses_for_tests,
|
| bool add_default_platform_observations,
|
| @@ -248,18 +237,18 @@ NetworkQualityEstimator::NetworkQualityEstimator(
|
| {"TransportRTTOrDownstreamThroughput",
|
| EffectiveConnectionTypeAlgorithm::
|
| TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}),
|
| - params_(variation_params),
|
| + params_(std::move(params)),
|
| use_localhost_requests_(use_local_host_requests_for_tests),
|
| use_small_responses_(use_smaller_responses_for_tests),
|
| disable_offline_check_(false),
|
| add_default_platform_observations_(add_default_platform_observations),
|
| effective_connection_type_algorithm_(
|
| algorithm_name_to_enum_.find(
|
| - params_.GetEffectiveConnectionTypeAlgorithm()) ==
|
| + params_->GetEffectiveConnectionTypeAlgorithm()) ==
|
| algorithm_name_to_enum_.end()
|
| ? kDefaultEffectiveConnectionTypeAlgorithm
|
| : algorithm_name_to_enum_
|
| - .find(params_.GetEffectiveConnectionTypeAlgorithm())
|
| + .find(params_->GetEffectiveConnectionTypeAlgorithm())
|
| ->second),
|
| tick_clock_(new base::DefaultTickClock()),
|
| last_connection_change_(tick_clock_->NowTicks()),
|
| @@ -267,10 +256,10 @@ NetworkQualityEstimator::NetworkQualityEstimator(
|
| NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN,
|
| std::string())),
|
| downstream_throughput_kbps_observations_(
|
| - params_.weight_multiplier_per_second(),
|
| - params_.weight_multiplier_per_dbm()),
|
| - rtt_observations_(params_.weight_multiplier_per_second(),
|
| - params_.weight_multiplier_per_dbm()),
|
| + params_->weight_multiplier_per_second(),
|
| + params_->weight_multiplier_per_dbm()),
|
| + rtt_observations_(params_->weight_multiplier_per_second(),
|
| + params_->weight_multiplier_per_dbm()),
|
| effective_connection_type_at_last_main_frame_(
|
| EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
|
| external_estimate_provider_(std::move(external_estimates_provider)),
|
| @@ -326,7 +315,7 @@ NetworkQualityEstimator::NetworkQualityEstimator(
|
|
|
| watcher_factory_.reset(new nqe::internal::SocketWatcherFactory(
|
| base::ThreadTaskRunnerHandle::Get(),
|
| - params_.min_socket_watcher_notification_interval(),
|
| + params_->min_socket_watcher_notification_interval(),
|
| base::Bind(&NetworkQualityEstimator::OnUpdatedRTTAvailable,
|
| base::Unretained(this)),
|
| tick_clock_.get()));
|
| @@ -346,30 +335,30 @@ void NetworkQualityEstimator::AddDefaultEstimates() {
|
| if (!add_default_platform_observations_)
|
| return;
|
|
|
| - if (params_.DefaultObservation(current_network_id_.type).http_rtt() !=
|
| + if (params_->DefaultObservation(current_network_id_.type).http_rtt() !=
|
| nqe::internal::InvalidRTT()) {
|
| RttObservation rtt_observation(
|
| - params_.DefaultObservation(current_network_id_.type).http_rtt(),
|
| + params_->DefaultObservation(current_network_id_.type).http_rtt(),
|
| tick_clock_->NowTicks(), INT32_MIN,
|
| NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM);
|
| rtt_observations_.AddObservation(rtt_observation);
|
| NotifyObserversOfRTT(rtt_observation);
|
| }
|
|
|
| - if (params_.DefaultObservation(current_network_id_.type).transport_rtt() !=
|
| + if (params_->DefaultObservation(current_network_id_.type).transport_rtt() !=
|
| nqe::internal::InvalidRTT()) {
|
| RttObservation rtt_observation(
|
| - params_.DefaultObservation(current_network_id_.type).transport_rtt(),
|
| + params_->DefaultObservation(current_network_id_.type).transport_rtt(),
|
| tick_clock_->NowTicks(), INT32_MIN,
|
| NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM);
|
| rtt_observations_.AddObservation(rtt_observation);
|
| NotifyObserversOfRTT(rtt_observation);
|
| }
|
|
|
| - if (params_.DefaultObservation(current_network_id_.type)
|
| + if (params_->DefaultObservation(current_network_id_.type)
|
| .downstream_throughput_kbps() != nqe::internal::kInvalidThroughput) {
|
| ThroughputObservation throughput_observation(
|
| - params_.DefaultObservation(current_network_id_.type)
|
| + params_->DefaultObservation(current_network_id_.type)
|
| .downstream_throughput_kbps(),
|
| tick_clock_->NowTicks(), INT32_MIN,
|
| NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM);
|
| @@ -614,7 +603,7 @@ void NetworkQualityEstimator::RecordCorrelationMetric(const URLRequest& request,
|
| // The histogram is recorded randomly to reduce overhead involved with sparse
|
| // histograms. Furthermore, recording the correlation on each request is
|
| // unnecessary.
|
| - if (RandDouble() >= params_.correlation_uma_logging_probability())
|
| + if (RandDouble() >= params_->correlation_uma_logging_probability())
|
| return;
|
|
|
| if (request.response_info().was_cached ||
|
| @@ -774,7 +763,7 @@ void NetworkQualityEstimator::ReportEffectiveConnectionTypeForTesting(
|
|
|
| event_creator_.MaybeAddNetworkQualityChangedEventToNetLog(
|
| effective_connection_type_,
|
| - params_.TypicalNetworkQuality(effective_connection_type));
|
| + params_->TypicalNetworkQuality(effective_connection_type));
|
|
|
| for (auto& observer : effective_connection_type_observer_list_)
|
| observer.OnEffectiveConnectionTypeChanged(effective_connection_type);
|
| @@ -833,7 +822,7 @@ void NetworkQualityEstimator::OnConnectionTypeChanged(
|
| rtt_observations_.Clear();
|
|
|
| #if defined(OS_ANDROID)
|
| - if (params_.weight_multiplier_per_dbm() < 1.0 &&
|
| + if (params_->weight_multiplier_per_dbm() < 1.0 &&
|
| NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) {
|
| UMA_HISTOGRAM_BOOLEAN(
|
| "NQE.CellularSignalStrengthAvailable",
|
| @@ -895,7 +884,7 @@ void NetworkQualityEstimator::MaybeQueryExternalEstimateProvider() const {
|
|
|
| void NetworkQualityEstimator::UpdateSignalStrength() {
|
| #if defined(OS_ANDROID)
|
| - if (params_.weight_multiplier_per_dbm() >= 1.0 ||
|
| + if (params_->weight_multiplier_per_dbm() >= 1.0 ||
|
| !NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type) ||
|
| !android::cellular_signal_strength::GetSignalStrengthDbm(
|
| &signal_strength_dbm_)) {
|
| @@ -1191,21 +1180,22 @@ NetworkQualityEstimator::GetRecentEffectiveConnectionTypeUsingMetrics(
|
| *transport_rtt = nqe::internal::InvalidRTT();
|
| *downstream_throughput_kbps = nqe::internal::kInvalidThroughput;
|
|
|
| - if (params_.forced_effective_connection_type()) {
|
| + if (params_->forced_effective_connection_type()) {
|
| *http_rtt = params_
|
| - .TypicalNetworkQuality(
|
| - params_.forced_effective_connection_type().value())
|
| + ->TypicalNetworkQuality(
|
| + params_->forced_effective_connection_type().value())
|
| .http_rtt();
|
| - *transport_rtt = params_
|
| - .TypicalNetworkQuality(
|
| - params_.forced_effective_connection_type().value())
|
| - .transport_rtt();
|
| + *transport_rtt =
|
| + params_
|
| + ->TypicalNetworkQuality(
|
| + params_->forced_effective_connection_type().value())
|
| + .transport_rtt();
|
| *downstream_throughput_kbps =
|
| params_
|
| - .TypicalNetworkQuality(
|
| - params_.forced_effective_connection_type().value())
|
| + ->TypicalNetworkQuality(
|
| + params_->forced_effective_connection_type().value())
|
| .downstream_throughput_kbps();
|
| - return params_.forced_effective_connection_type().value();
|
| + return params_->forced_effective_connection_type().value();
|
| }
|
|
|
| // If the device is currently offline, then return
|
| @@ -1260,26 +1250,26 @@ NetworkQualityEstimator::GetRecentEffectiveConnectionTypeUsingMetrics(
|
| const bool estimated_http_rtt_is_higher_than_threshold =
|
| http_rtt_metric != NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
|
| *http_rtt != nqe::internal::InvalidRTT() &&
|
| - params_.ConnectionThreshold(type).http_rtt() !=
|
| + params_->ConnectionThreshold(type).http_rtt() !=
|
| nqe::internal::InvalidRTT() &&
|
| - *http_rtt >= params_.ConnectionThreshold(type).http_rtt();
|
| + *http_rtt >= params_->ConnectionThreshold(type).http_rtt();
|
|
|
| const bool estimated_transport_rtt_is_higher_than_threshold =
|
| transport_rtt_metric !=
|
| NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
|
| *transport_rtt != nqe::internal::InvalidRTT() &&
|
| - params_.ConnectionThreshold(type).transport_rtt() !=
|
| + params_->ConnectionThreshold(type).transport_rtt() !=
|
| nqe::internal::InvalidRTT() &&
|
| - *transport_rtt >= params_.ConnectionThreshold(type).transport_rtt();
|
| + *transport_rtt >= params_->ConnectionThreshold(type).transport_rtt();
|
|
|
| const bool estimated_throughput_is_lower_than_threshold =
|
| downstream_throughput_kbps_metric !=
|
| NetworkQualityEstimator::MetricUsage::DO_NOT_USE &&
|
| *downstream_throughput_kbps != nqe::internal::kInvalidThroughput &&
|
| - params_.ConnectionThreshold(type).downstream_throughput_kbps() !=
|
| + params_->ConnectionThreshold(type).downstream_throughput_kbps() !=
|
| nqe::internal::kInvalidThroughput &&
|
| *downstream_throughput_kbps <=
|
| - params_.ConnectionThreshold(type).downstream_throughput_kbps();
|
| + params_->ConnectionThreshold(type).downstream_throughput_kbps();
|
|
|
| if (estimated_http_rtt_is_higher_than_threshold ||
|
| estimated_transport_rtt_is_higher_than_threshold ||
|
| @@ -1469,7 +1459,7 @@ nqe::internal::NetworkID NetworkQualityEstimator::GetCurrentNetworkID() const {
|
| bool NetworkQualityEstimator::ReadCachedNetworkQualityEstimate() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| - if (!params_.persistent_cache_reading_enabled())
|
| + if (!params_->persistent_cache_reading_enabled())
|
| return false;
|
|
|
| nqe::internal::CachedNetworkQuality cached_network_quality;
|
| @@ -1759,7 +1749,7 @@ void NetworkQualityEstimator::OnPrefsRead(
|
|
|
| nqe::internal::CachedNetworkQuality cached_network_quality(
|
| base::TimeTicks::Now(),
|
| - params_.TypicalNetworkQuality(effective_connection_type),
|
| + params_->TypicalNetworkQuality(effective_connection_type),
|
| effective_connection_type);
|
|
|
| network_quality_store_->Add(it.first, cached_network_quality);
|
| @@ -1772,7 +1762,7 @@ void NetworkQualityEstimator::MaybeUpdateNetworkQualityFromCache(
|
| const nqe::internal::CachedNetworkQuality& cached_network_quality) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| - if (!params_.persistent_cache_reading_enabled())
|
| + if (!params_->persistent_cache_reading_enabled())
|
| return;
|
| if (network_id != current_network_id_)
|
| return;
|
|
|