Commit 6b61964c authored by tbansal's avatar tbansal Committed by Commit bot

NQE: Make params a class

Make network quality estimator (NQE) params a class.

Next CL will move the storing of the params to the Params class
from the NQE class to make it simpler to query the params again and
again. This CL does not make any functional change.

BUG=705691
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.android:android_cronet_tester

Review-Url: https://codereview.chromium.org/2775223004
Cr-Commit-Position: refs/heads/master@{#460582}
parent a2c84a76
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
#include "net/http/http_response_info.h" #include "net/http/http_response_info.h"
#include "net/http/http_status_code.h" #include "net/http/http_status_code.h"
#include "net/nqe/network_quality_estimator_params.h"
#include "net/nqe/socket_watcher_factory.h" #include "net/nqe/socket_watcher_factory.h"
#include "net/nqe/throughput_analyzer.h" #include "net/nqe/throughput_analyzer.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
...@@ -60,7 +59,9 @@ base::HistogramBase* GetHistogram(const std::string& statistic_name, ...@@ -60,7 +59,9 @@ base::HistogramBase* GetHistogram(const std::string& statistic_name,
const size_t kBucketCount = 50; const size_t kBucketCount = 50;
return base::Histogram::FactoryGet( return base::Histogram::FactoryGet(
"NQE." + statistic_name + nqe::internal::GetNameForConnectionType(type), "NQE." + statistic_name +
nqe::internal::NetworkQualityEstimatorParams::
GetNameForConnectionType(type),
kLowerLimit, max_limit, kBucketCount, kLowerLimit, max_limit, kBucketCount,
base::HistogramBase::kUmaTargetedHistogramFlag); base::HistogramBase::kUmaTargetedHistogramFlag);
} }
...@@ -247,22 +248,20 @@ NetworkQualityEstimator::NetworkQualityEstimator( ...@@ -247,22 +248,20 @@ NetworkQualityEstimator::NetworkQualityEstimator(
{"TransportRTTOrDownstreamThroughput", {"TransportRTTOrDownstreamThroughput",
EffectiveConnectionTypeAlgorithm:: EffectiveConnectionTypeAlgorithm::
TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}), TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}),
params_(variation_params),
use_localhost_requests_(use_local_host_requests_for_tests), use_localhost_requests_(use_local_host_requests_for_tests),
use_small_responses_(use_smaller_responses_for_tests), use_small_responses_(use_smaller_responses_for_tests),
disable_offline_check_(false), disable_offline_check_(false),
add_default_platform_observations_(add_default_platform_observations), add_default_platform_observations_(add_default_platform_observations),
weight_multiplier_per_second_( weight_multiplier_per_second_(params_.GetWeightMultiplierPerSecond()),
nqe::internal::GetWeightMultiplierPerSecond(variation_params)), weight_multiplier_per_dbm_(params_.GetWeightMultiplierPerDbm()),
weight_multiplier_per_dbm_(
nqe::internal::GetWeightMultiplierPerDbm(variation_params)),
effective_connection_type_algorithm_( effective_connection_type_algorithm_(
algorithm_name_to_enum_.find( algorithm_name_to_enum_.find(
nqe::internal::GetEffectiveConnectionTypeAlgorithm( params_.GetEffectiveConnectionTypeAlgorithm()) ==
variation_params)) == algorithm_name_to_enum_.end() algorithm_name_to_enum_.end()
? kDefaultEffectiveConnectionTypeAlgorithm ? kDefaultEffectiveConnectionTypeAlgorithm
: algorithm_name_to_enum_ : algorithm_name_to_enum_
.find(nqe::internal::GetEffectiveConnectionTypeAlgorithm( .find(params_.GetEffectiveConnectionTypeAlgorithm())
variation_params))
->second), ->second),
tick_clock_(new base::DefaultTickClock()), tick_clock_(new base::DefaultTickClock()),
last_connection_change_(tick_clock_->NowTicks()), last_connection_change_(tick_clock_->NowTicks()),
...@@ -285,14 +284,13 @@ NetworkQualityEstimator::NetworkQualityEstimator( ...@@ -285,14 +284,13 @@ NetworkQualityEstimator::NetworkQualityEstimator(
min_signal_strength_since_connection_change_(INT32_MAX), min_signal_strength_since_connection_change_(INT32_MAX),
max_signal_strength_since_connection_change_(INT32_MIN), max_signal_strength_since_connection_change_(INT32_MIN),
correlation_uma_logging_probability_( correlation_uma_logging_probability_(
nqe::internal::correlation_uma_logging_probability(variation_params)), params_.correlation_uma_logging_probability()),
forced_effective_connection_type_set_( forced_effective_connection_type_set_(
nqe::internal::forced_effective_connection_type_set( params_.forced_effective_connection_type_set()),
variation_params)),
forced_effective_connection_type_( forced_effective_connection_type_(
nqe::internal::forced_effective_connection_type(variation_params)), params_.forced_effective_connection_type()),
persistent_cache_reading_enabled_( persistent_cache_reading_enabled_(
nqe::internal::persistent_cache_reading_enabled(variation_params)), params_.persistent_cache_reading_enabled()),
event_creator_(net_log), event_creator_(net_log),
disallowed_observation_sources_for_http_( disallowed_observation_sources_for_http_(
{NETWORK_QUALITY_OBSERVATION_SOURCE_TCP, {NETWORK_QUALITY_OBSERVATION_SOURCE_TCP,
...@@ -317,7 +315,7 @@ NetworkQualityEstimator::NetworkQualityEstimator( ...@@ -317,7 +315,7 @@ NetworkQualityEstimator::NetworkQualityEstimator(
effective_connection_type_algorithm_); effective_connection_type_algorithm_);
network_quality_store_.reset(new nqe::internal::NetworkQualityStore()); network_quality_store_.reset(new nqe::internal::NetworkQualityStore());
ObtainOperatingParams(variation_params); ObtainOperatingParams();
NetworkChangeNotifier::AddConnectionTypeObserver(this); NetworkChangeNotifier::AddConnectionTypeObserver(this);
if (external_estimate_provider_) { if (external_estimate_provider_) {
RecordExternalEstimateProviderMetrics( RecordExternalEstimateProviderMetrics(
...@@ -338,7 +336,7 @@ NetworkQualityEstimator::NetworkQualityEstimator( ...@@ -338,7 +336,7 @@ NetworkQualityEstimator::NetworkQualityEstimator(
watcher_factory_.reset(new nqe::internal::SocketWatcherFactory( watcher_factory_.reset(new nqe::internal::SocketWatcherFactory(
base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(),
nqe::internal::GetMinSocketWatcherNotificationInterval(variation_params), params_.GetMinSocketWatcherNotificationInterval(),
base::Bind(&NetworkQualityEstimator::OnUpdatedRTTAvailable, base::Bind(&NetworkQualityEstimator::OnUpdatedRTTAvailable,
base::Unretained(this)), base::Unretained(this)),
tick_clock_.get())); tick_clock_.get()));
...@@ -352,14 +350,11 @@ NetworkQualityEstimator::NetworkQualityEstimator( ...@@ -352,14 +350,11 @@ NetworkQualityEstimator::NetworkQualityEstimator(
http_rtt_at_last_main_frame_[i] = nqe::internal::InvalidRTT(); http_rtt_at_last_main_frame_[i] = nqe::internal::InvalidRTT();
} }
void NetworkQualityEstimator::ObtainOperatingParams( void NetworkQualityEstimator::ObtainOperatingParams() {
const std::map<std::string, std::string>& variation_params) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
nqe::internal::ObtainDefaultObservations(variation_params, params_.ObtainDefaultObservations(default_observations_);
default_observations_); params_.ObtainEffectiveConnectionTypeModelParams(connection_thresholds_);
nqe::internal::ObtainEffectiveConnectionTypeModelParams( params_.ObtainTypicalNetworkQuality(typical_network_quality_);
variation_params, connection_thresholds_);
nqe::internal::ObtainTypicalNetworkQuality(typical_network_quality_);
} }
void NetworkQualityEstimator::AddDefaultEstimates() { void NetworkQualityEstimator::AddDefaultEstimates() {
...@@ -1053,7 +1048,8 @@ void NetworkQualityEstimator::RecordMetricsOnMainFrameRequest() const { ...@@ -1053,7 +1048,8 @@ void NetworkQualityEstimator::RecordMetricsOnMainFrameRequest() const {
base::HistogramBase* effective_connection_type_histogram = base::HistogramBase* effective_connection_type_histogram =
base::Histogram::FactoryGet( base::Histogram::FactoryGet(
std::string("NQE.MainFrame.EffectiveConnectionType.") + std::string("NQE.MainFrame.EffectiveConnectionType.") +
nqe::internal::GetNameForConnectionType(current_network_id_.type), nqe::internal::NetworkQualityEstimatorParams::
GetNameForConnectionType(current_network_id_.type),
0, EFFECTIVE_CONNECTION_TYPE_LAST, 0, EFFECTIVE_CONNECTION_TYPE_LAST,
EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */,
base::HistogramBase::kUmaTargetedHistogramFlag); base::HistogramBase::kUmaTargetedHistogramFlag);
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "net/nqe/external_estimate_provider.h" #include "net/nqe/external_estimate_provider.h"
#include "net/nqe/network_id.h" #include "net/nqe/network_id.h"
#include "net/nqe/network_quality.h" #include "net/nqe/network_quality.h"
#include "net/nqe/network_quality_estimator_params.h"
#include "net/nqe/network_quality_observation.h" #include "net/nqe/network_quality_observation.h"
#include "net/nqe/network_quality_observation_source.h" #include "net/nqe/network_quality_observation_source.h"
#include "net/nqe/network_quality_store.h" #include "net/nqe/network_quality_store.h"
...@@ -536,8 +537,7 @@ class NET_EXPORT NetworkQualityEstimator ...@@ -536,8 +537,7 @@ class NET_EXPORT NetworkQualityEstimator
// the field trial parameters. For each effective connection type, a model // the field trial parameters. For each effective connection type, a model
// (currently composed of a RTT threshold and a downlink throughput threshold) // (currently composed of a RTT threshold and a downlink throughput threshold)
// is provided by the field trial. // is provided by the field trial.
void ObtainOperatingParams( void ObtainOperatingParams();
const std::map<std::string, std::string>& variation_params);
// Adds the default median RTT and downstream throughput estimate for the // Adds the default median RTT and downstream throughput estimate for the
// current connection type to the observation buffer. // current connection type to the observation buffer.
...@@ -650,6 +650,9 @@ class NET_EXPORT NetworkQualityEstimator ...@@ -650,6 +650,9 @@ class NET_EXPORT NetworkQualityEstimator
const char* GetNameForStatistic(int i) const; const char* GetNameForStatistic(int i) const;
// Params to configure the network quality estimator.
const nqe::internal::NetworkQualityEstimatorParams params_;
// Determines if the requests to local host can be used in estimating the // Determines if the requests to local host can be used in estimating the
// network quality. Set to true only for tests. // network quality. Set to true only for tests.
bool use_localhost_requests_; bool use_localhost_requests_;
......
This diff is collapsed.
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <map> #include <map>
#include <string> #include <string>
#include "base/macros.h"
#include "base/threading/thread_checker.h"
#include "net/base/network_change_notifier.h" #include "net/base/network_change_notifier.h"
#include "net/nqe/effective_connection_type.h" #include "net/nqe/effective_connection_type.h"
#include "net/nqe/network_quality.h" #include "net/nqe/network_quality.h"
...@@ -18,70 +20,81 @@ namespace nqe { ...@@ -18,70 +20,81 @@ namespace nqe {
namespace internal { namespace internal {
// Returns the algorithm that should be used for computing effective connection // NetworkQualityEstimatorParams computes the configuration parameters for
// type based on field trial params. Returns an empty string if a valid // the network quality estimator.
// algorithm paramter is not present in the field trial params. class NetworkQualityEstimatorParams {
std::string GetEffectiveConnectionTypeAlgorithm( public:
const std::map<std::string, std::string>& variation_params); // |params| is the map containing all field trial parameters related to
// NetworkQualityEstimator field trial.
// Computes and returns the weight multiplier per second, which represents the explicit NetworkQualityEstimatorParams(
// factor by which the weight of an observation reduces every second. const std::map<std::string, std::string>& params);
// |variation_params| is the map containing all field trial parameters
// related to the NetworkQualityualityEstimator field trial. ~NetworkQualityEstimatorParams();
double GetWeightMultiplierPerSecond(
const std::map<std::string, std::string>& variation_params); // Returns the algorithm that should be used for computing effective
// connection type. Returns an empty string if a valid algorithm paramter is
// Returns the factor by which the weight of an observation reduces for every // not specified.
// dBm difference between the current signal strength (in dBm), and the signal std::string GetEffectiveConnectionTypeAlgorithm() const;
// strength at the time when the observation was taken.
double GetWeightMultiplierPerDbm( // Computes and returns the weight multiplier per second, which represents the
const std::map<std::string, std::string>& variation_params); // factor by which the weight of an observation reduces every second.
double GetWeightMultiplierPerSecond() const;
// Returns a descriptive name corresponding to |connection_type|.
const char* GetNameForConnectionType( // Returns the factor by which the weight of an observation reduces for every
net::NetworkChangeNotifier::ConnectionType connection_type); // dBm difference between the current signal strength (in dBm), and the signal
// strength at the time when the observation was taken.
// Sets the default observation for different connection types in double GetWeightMultiplierPerDbm() const;
// |default_observations|. The default observations are different for different
// connection types (e.g., 2G, 3G, 4G, WiFi). The default observations may be // Returns a descriptive name corresponding to |connection_type|.
// used to determine the network quality in absence of any other information. static const char* GetNameForConnectionType(
void ObtainDefaultObservations( net::NetworkChangeNotifier::ConnectionType connection_type);
const std::map<std::string, std::string>& variation_params,
nqe::internal::NetworkQuality default_observations[]); // Sets the default observation for different connection types in
// |default_observations|. The default observations are different for
// Sets |typical_network_quality| to typical network quality for different // different connection types (e.g., 2G, 3G, 4G, WiFi). The default
// effective connection types. // observations may be used to determine the network quality in absence of any
void ObtainTypicalNetworkQuality(NetworkQuality typical_network_quality[]); // other information.
void ObtainDefaultObservations(
// Parses the variation paramaters and sets the thresholds for different nqe::internal::NetworkQuality default_observations[]) const;
// effective connection types in |connection_thresholds|.
void ObtainEffectiveConnectionTypeModelParams( // Sets |typical_network_quality| to typical network quality for different
const std::map<std::string, std::string>& variation_params, // effective connection types.
nqe::internal::NetworkQuality connection_thresholds[]); void ObtainTypicalNetworkQuality(
NetworkQuality typical_network_quality[]) const;
// Returns the fraction of URL requests that should record the correlation UMA.
double correlation_uma_logging_probability( // Sets the thresholds for different effective connection types in
const std::map<std::string, std::string>& variation_params); // |connection_thresholds|.
void ObtainEffectiveConnectionTypeModelParams(
// Returns true if the effective connection type has been determined via nqe::internal::NetworkQuality connection_thresholds[]) const;
// variation parameters.
bool forced_effective_connection_type_set( // Returns the fraction of URL requests that should record the correlation
const std::map<std::string, std::string>& variation_params); // UMA.
double correlation_uma_logging_probability() const;
// Returns the effective connection type that was configured by variation
// parameters. // Returns true if the effective connection type has been forced via field
EffectiveConnectionType forced_effective_connection_type( // trial parameters.
const std::map<std::string, std::string>& variation_params); bool forced_effective_connection_type_set() const;
// Returns true if reading from the persistent cache has been enabled via field // Returns the effective connection type if it has been forced via field trial
// trial. // parameters.
bool persistent_cache_reading_enabled( EffectiveConnectionType forced_effective_connection_type() const;
const std::map<std::string, std::string>& variation_params);
// Returns true if reading from the persistent cache is enabled.
// Returns the the minimum interval betweeen consecutive notifications to a bool persistent_cache_reading_enabled() const;
// single socket watcher.
base::TimeDelta GetMinSocketWatcherNotificationInterval( // Returns the the minimum interval betweeen consecutive notifications to a
const std::map<std::string, std::string>& variation_params); // single socket watcher.
base::TimeDelta GetMinSocketWatcherNotificationInterval() const;
private:
// Map containing all field trial parameters related to
// NetworkQualityEstimator field trial.
const std::map<std::string, std::string> params_;
base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimatorParams);
};
} // namespace internal } // namespace internal
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment