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 @@
#include "net/http/http_response_headers.h"
#include "net/http/http_response_info.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/throughput_analyzer.h"
#include "net/url_request/url_request.h"
......@@ -60,7 +59,9 @@ base::HistogramBase* GetHistogram(const std::string& statistic_name,
const size_t kBucketCount = 50;
return base::Histogram::FactoryGet(
"NQE." + statistic_name + nqe::internal::GetNameForConnectionType(type),
"NQE." + statistic_name +
nqe::internal::NetworkQualityEstimatorParams::
GetNameForConnectionType(type),
kLowerLimit, max_limit, kBucketCount,
base::HistogramBase::kUmaTargetedHistogramFlag);
}
......@@ -247,22 +248,20 @@ NetworkQualityEstimator::NetworkQualityEstimator(
{"TransportRTTOrDownstreamThroughput",
EffectiveConnectionTypeAlgorithm::
TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}),
params_(variation_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),
weight_multiplier_per_second_(
nqe::internal::GetWeightMultiplierPerSecond(variation_params)),
weight_multiplier_per_dbm_(
nqe::internal::GetWeightMultiplierPerDbm(variation_params)),
weight_multiplier_per_second_(params_.GetWeightMultiplierPerSecond()),
weight_multiplier_per_dbm_(params_.GetWeightMultiplierPerDbm()),
effective_connection_type_algorithm_(
algorithm_name_to_enum_.find(
nqe::internal::GetEffectiveConnectionTypeAlgorithm(
variation_params)) == algorithm_name_to_enum_.end()
params_.GetEffectiveConnectionTypeAlgorithm()) ==
algorithm_name_to_enum_.end()
? kDefaultEffectiveConnectionTypeAlgorithm
: algorithm_name_to_enum_
.find(nqe::internal::GetEffectiveConnectionTypeAlgorithm(
variation_params))
.find(params_.GetEffectiveConnectionTypeAlgorithm())
->second),
tick_clock_(new base::DefaultTickClock()),
last_connection_change_(tick_clock_->NowTicks()),
......@@ -285,14 +284,13 @@ NetworkQualityEstimator::NetworkQualityEstimator(
min_signal_strength_since_connection_change_(INT32_MAX),
max_signal_strength_since_connection_change_(INT32_MIN),
correlation_uma_logging_probability_(
nqe::internal::correlation_uma_logging_probability(variation_params)),
params_.correlation_uma_logging_probability()),
forced_effective_connection_type_set_(
nqe::internal::forced_effective_connection_type_set(
variation_params)),
params_.forced_effective_connection_type_set()),
forced_effective_connection_type_(
nqe::internal::forced_effective_connection_type(variation_params)),
params_.forced_effective_connection_type()),
persistent_cache_reading_enabled_(
nqe::internal::persistent_cache_reading_enabled(variation_params)),
params_.persistent_cache_reading_enabled()),
event_creator_(net_log),
disallowed_observation_sources_for_http_(
{NETWORK_QUALITY_OBSERVATION_SOURCE_TCP,
......@@ -317,7 +315,7 @@ NetworkQualityEstimator::NetworkQualityEstimator(
effective_connection_type_algorithm_);
network_quality_store_.reset(new nqe::internal::NetworkQualityStore());
ObtainOperatingParams(variation_params);
ObtainOperatingParams();
NetworkChangeNotifier::AddConnectionTypeObserver(this);
if (external_estimate_provider_) {
RecordExternalEstimateProviderMetrics(
......@@ -338,7 +336,7 @@ NetworkQualityEstimator::NetworkQualityEstimator(
watcher_factory_.reset(new nqe::internal::SocketWatcherFactory(
base::ThreadTaskRunnerHandle::Get(),
nqe::internal::GetMinSocketWatcherNotificationInterval(variation_params),
params_.GetMinSocketWatcherNotificationInterval(),
base::Bind(&NetworkQualityEstimator::OnUpdatedRTTAvailable,
base::Unretained(this)),
tick_clock_.get()));
......@@ -352,14 +350,11 @@ NetworkQualityEstimator::NetworkQualityEstimator(
http_rtt_at_last_main_frame_[i] = nqe::internal::InvalidRTT();
}
void NetworkQualityEstimator::ObtainOperatingParams(
const std::map<std::string, std::string>& variation_params) {
void NetworkQualityEstimator::ObtainOperatingParams() {
DCHECK(thread_checker_.CalledOnValidThread());
nqe::internal::ObtainDefaultObservations(variation_params,
default_observations_);
nqe::internal::ObtainEffectiveConnectionTypeModelParams(
variation_params, connection_thresholds_);
nqe::internal::ObtainTypicalNetworkQuality(typical_network_quality_);
params_.ObtainDefaultObservations(default_observations_);
params_.ObtainEffectiveConnectionTypeModelParams(connection_thresholds_);
params_.ObtainTypicalNetworkQuality(typical_network_quality_);
}
void NetworkQualityEstimator::AddDefaultEstimates() {
......@@ -1053,7 +1048,8 @@ void NetworkQualityEstimator::RecordMetricsOnMainFrameRequest() const {
base::HistogramBase* effective_connection_type_histogram =
base::Histogram::FactoryGet(
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,
EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */,
base::HistogramBase::kUmaTargetedHistogramFlag);
......
......@@ -28,6 +28,7 @@
#include "net/nqe/external_estimate_provider.h"
#include "net/nqe/network_id.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_source.h"
#include "net/nqe/network_quality_store.h"
......@@ -536,8 +537,7 @@ class NET_EXPORT NetworkQualityEstimator
// the field trial parameters. For each effective connection type, a model
// (currently composed of a RTT threshold and a downlink throughput threshold)
// is provided by the field trial.
void ObtainOperatingParams(
const std::map<std::string, std::string>& variation_params);
void ObtainOperatingParams();
// Adds the default median RTT and downstream throughput estimate for the
// current connection type to the observation buffer.
......@@ -650,6 +650,9 @@ class NET_EXPORT NetworkQualityEstimator
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
// network quality. Set to true only for tests.
bool use_localhost_requests_;
......
This diff is collapsed.
......@@ -8,6 +8,8 @@
#include <map>
#include <string>
#include "base/macros.h"
#include "base/threading/thread_checker.h"
#include "net/base/network_change_notifier.h"
#include "net/nqe/effective_connection_type.h"
#include "net/nqe/network_quality.h"
......@@ -18,70 +20,81 @@ namespace nqe {
namespace internal {
// Returns the algorithm that should be used for computing effective connection
// type based on field trial params. Returns an empty string if a valid
// algorithm paramter is not present in the field trial params.
std::string GetEffectiveConnectionTypeAlgorithm(
const std::map<std::string, std::string>& variation_params);
// Computes and returns the weight multiplier per second, which represents the
// factor by which the weight of an observation reduces every second.
// |variation_params| is the map containing all field trial parameters
// related to the NetworkQualityualityEstimator field trial.
double GetWeightMultiplierPerSecond(
const std::map<std::string, std::string>& variation_params);
// Returns the factor by which the weight of an observation reduces for every
// dBm difference between the current signal strength (in dBm), and the signal
// strength at the time when the observation was taken.
double GetWeightMultiplierPerDbm(
const std::map<std::string, std::string>& variation_params);
// Returns a descriptive name corresponding to |connection_type|.
const char* GetNameForConnectionType(
// NetworkQualityEstimatorParams computes the configuration parameters for
// the network quality estimator.
class NetworkQualityEstimatorParams {
public:
// |params| is the map containing all field trial parameters related to
// NetworkQualityEstimator field trial.
explicit NetworkQualityEstimatorParams(
const std::map<std::string, std::string>& params);
~NetworkQualityEstimatorParams();
// Returns the algorithm that should be used for computing effective
// connection type. Returns an empty string if a valid algorithm paramter is
// not specified.
std::string GetEffectiveConnectionTypeAlgorithm() const;
// Computes and returns the weight multiplier per second, which represents the
// factor by which the weight of an observation reduces every second.
double GetWeightMultiplierPerSecond() const;
// Returns the factor by which the weight of an observation reduces for every
// dBm difference between the current signal strength (in dBm), and the signal
// strength at the time when the observation was taken.
double GetWeightMultiplierPerDbm() const;
// Returns a descriptive name corresponding to |connection_type|.
static const char* GetNameForConnectionType(
net::NetworkChangeNotifier::ConnectionType connection_type);
// 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>& variation_params,
nqe::internal::NetworkQuality default_observations[]);
// Sets |typical_network_quality| to typical network quality for different
// effective connection types.
void ObtainTypicalNetworkQuality(NetworkQuality typical_network_quality[]);
// Parses the variation paramaters and sets the thresholds for different
// effective connection types in |connection_thresholds|.
void ObtainEffectiveConnectionTypeModelParams(
const std::map<std::string, std::string>& variation_params,
nqe::internal::NetworkQuality connection_thresholds[]);
// Returns the fraction of URL requests that should record the correlation UMA.
double correlation_uma_logging_probability(
const std::map<std::string, std::string>& variation_params);
// Returns true if the effective connection type has been determined via
// variation parameters.
bool forced_effective_connection_type_set(
const std::map<std::string, std::string>& variation_params);
// Returns the effective connection type that was configured by variation
// parameters.
EffectiveConnectionType forced_effective_connection_type(
const std::map<std::string, std::string>& variation_params);
// Returns true if reading from the persistent cache has been enabled via field
// trial.
bool persistent_cache_reading_enabled(
const std::map<std::string, std::string>& variation_params);
// Returns the the minimum interval betweeen consecutive notifications to a
// single socket watcher.
base::TimeDelta GetMinSocketWatcherNotificationInterval(
const std::map<std::string, std::string>& variation_params);
// 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(
nqe::internal::NetworkQuality default_observations[]) const;
// Sets |typical_network_quality| to typical network quality for different
// effective connection types.
void ObtainTypicalNetworkQuality(
NetworkQuality typical_network_quality[]) const;
// Sets the thresholds for different effective connection types in
// |connection_thresholds|.
void ObtainEffectiveConnectionTypeModelParams(
nqe::internal::NetworkQuality connection_thresholds[]) const;
// Returns the fraction of URL requests that should record the correlation
// UMA.
double correlation_uma_logging_probability() const;
// Returns true if the effective connection type has been forced via field
// trial parameters.
bool forced_effective_connection_type_set() const;
// Returns the effective connection type if it has been forced via field trial
// parameters.
EffectiveConnectionType forced_effective_connection_type() const;
// Returns true if reading from the persistent cache is enabled.
bool persistent_cache_reading_enabled() const;
// Returns the the minimum interval betweeen consecutive notifications to a
// 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
......
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