Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Unified Diff: components/cronet/android/cronet_url_request_context_adapter.cc

Issue 2416473004: Add functionality for embedders to configure NQE (Closed)
Patch Set: rebased, mgersh comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/cronet/android/cronet_url_request_context_adapter.cc
diff --git a/components/cronet/android/cronet_url_request_context_adapter.cc b/components/cronet/android/cronet_url_request_context_adapter.cc
index e2b6068188437ac44bdefe9877af66a2a25418c5..9b0e2d60ebfcfc16f15040c7fa3b698405b63c08 100644
--- a/components/cronet/android/cronet_url_request_context_adapter.cc
+++ b/components/cronet/android/cronet_url_request_context_adapter.cc
@@ -688,18 +688,18 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
if (config->enable_network_quality_estimator) {
DCHECK(!network_quality_estimator_);
- std::map<std::string, std::string> variation_params;
- // Configure network quality estimator: Specify the algorithm that should
- // be used for computing the effective connection type. The algorithm
- // is specified using the key-value pairs defined in
- // //net/nqe/network_quality_estimator.cc.
- // TODO(tbansal): Investigate a more robust way of configuring the network
- // quality estimator.
- variation_params["effective_connection_type_algorithm"] =
- "TransportRTTOrDownstreamThroughput";
+ std::unique_ptr<net::NetworkQualityEstimatorParams> nqe_params =
+ base::MakeUnique<net::NetworkQualityEstimatorParams>(
+ std::map<std::string, std::string>());
+ nqe_params->set_persistent_cache_reading_enabled(
+ config->nqe_persistent_caching_enabled);
+ if (config->nqe_forced_effective_connection_type) {
+ nqe_params->SetForcedEffectiveConnectionType(
+ config->nqe_forced_effective_connection_type.value());
+ }
+
network_quality_estimator_ = base::MakeUnique<net::NetworkQualityEstimator>(
- std::unique_ptr<net::ExternalEstimateProvider>(),
- base::MakeUnique<net::NetworkQualityEstimatorParams>(variation_params),
+ std::unique_ptr<net::ExternalEstimateProvider>(), std::move(nqe_params),
g_net_log.Get().net_log());
network_quality_estimator_->AddEffectiveConnectionTypeObserver(this);
network_quality_estimator_->AddRTTAndThroughputEstimatesObserver(this);
@@ -711,8 +711,6 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
base::MakeUnique<net::NetworkQualitiesPrefsManager>(
base::MakeUnique<NetworkQualitiesPrefDelegateImpl>(
pref_service_.get()));
- network_qualities_prefs_manager_->InitializeOnNetworkThread(
- network_quality_estimator_.get());
}
context_builder.set_network_quality_estimator(
network_quality_estimator_.get());
@@ -818,6 +816,16 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
jcronet_url_request_context);
is_context_initialized_ = true;
+ if (config->enable_network_quality_estimator &&
+ !config->storage_path.empty()) {
+ // Initializing |network_qualities_prefs_manager_| may post a callback to
+ // |this|. So, initialize it after |jcronet_url_request_context_| has been
+ // constructed.
+ DCHECK(jcronet_url_request_context_.obj() != nullptr);
+ network_qualities_prefs_manager_->InitializeOnNetworkThread(
+ network_quality_estimator_.get());
+ }
+
while (!tasks_waiting_for_context_.empty()) {
tasks_waiting_for_context_.front().Run();
tasks_waiting_for_context_.pop();

Powered by Google App Engine
This is Rietveld 408576698