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

Side by Side Diff: components/cronet/android/cronet_url_request_context_adapter.cc

Issue 2416473004: Add functionality for embedders to configure NQE (Closed)
Patch Set: mgersh comments Created 3 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/cronet/android/cronet_url_request_context_adapter.h" 5 #include "components/cronet/android/cronet_url_request_context_adapter.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 void CronetURLRequestContextAdapter::ProvideThroughputObservations( 600 void CronetURLRequestContextAdapter::ProvideThroughputObservations(
601 JNIEnv* env, 601 JNIEnv* env,
602 const JavaParamRef<jobject>& jcaller, 602 const JavaParamRef<jobject>& jcaller,
603 bool should) { 603 bool should) {
604 PostTaskToNetworkThread( 604 PostTaskToNetworkThread(
605 FROM_HERE, base::Bind(&CronetURLRequestContextAdapter:: 605 FROM_HERE, base::Bind(&CronetURLRequestContextAdapter::
606 ProvideThroughputObservationsOnNetworkThread, 606 ProvideThroughputObservationsOnNetworkThread,
607 base::Unretained(this), should)); 607 base::Unretained(this), should));
608 } 608 }
609 609
610 void CronetURLRequestContextAdapter::InitializeNQEPrefsOnNetworkThread() const {
611 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
612
613 // Initializing |network_qualities_prefs_manager_| may post a callback to
614 // |this|. So, |network_qualities_prefs_manager_| should be initialized after
615 // |jcronet_url_request_context_| has been constructed.
616 DCHECK(jcronet_url_request_context_.obj() != nullptr);
617 network_qualities_prefs_manager_->InitializeOnNetworkThread(
618 network_quality_estimator_.get());
619 }
620
610 void CronetURLRequestContextAdapter::InitializeOnNetworkThread( 621 void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
611 std::unique_ptr<URLRequestContextConfig> config, 622 std::unique_ptr<URLRequestContextConfig> config,
612 const base::android::ScopedJavaGlobalRef<jobject>& 623 const base::android::ScopedJavaGlobalRef<jobject>&
613 jcronet_url_request_context) { 624 jcronet_url_request_context) {
614 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 625 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
615 DCHECK(!is_context_initialized_); 626 DCHECK(!is_context_initialized_);
616 DCHECK(proxy_config_service_); 627 DCHECK(proxy_config_service_);
617 628
618 // TODO(mmenke): Add method to have the builder enable SPDY. 629 // TODO(mmenke): Add method to have the builder enable SPDY.
619 net::URLRequestContextBuilder context_builder; 630 net::URLRequestContextBuilder context_builder;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 // Explicitly disable the persister for Cronet to avoid persistence of dynamic 692 // Explicitly disable the persister for Cronet to avoid persistence of dynamic
682 // HPKP. This is a safety measure ensuring that nobody enables the persistence 693 // HPKP. This is a safety measure ensuring that nobody enables the persistence
683 // of HPKP by specifying transport_security_persister_path in the future. 694 // of HPKP by specifying transport_security_persister_path in the future.
684 context_builder.set_transport_security_persister_path(base::FilePath()); 695 context_builder.set_transport_security_persister_path(base::FilePath());
685 696
686 // Disable net::CookieStore and net::ChannelIDService. 697 // Disable net::CookieStore and net::ChannelIDService.
687 context_builder.SetCookieAndChannelIdStores(nullptr, nullptr); 698 context_builder.SetCookieAndChannelIdStores(nullptr, nullptr);
688 699
689 if (config->enable_network_quality_estimator) { 700 if (config->enable_network_quality_estimator) {
690 DCHECK(!network_quality_estimator_); 701 DCHECK(!network_quality_estimator_);
691 std::map<std::string, std::string> variation_params; 702 std::unique_ptr<net::NetworkQualityEstimatorParams> nqe_params =
692 // Configure network quality estimator: Specify the algorithm that should 703 base::MakeUnique<net::NetworkQualityEstimatorParams>(
693 // be used for computing the effective connection type. The algorithm 704 std::map<std::string, std::string>());
694 // is specified using the key-value pairs defined in 705 nqe_params->set_persistent_cache_reading_enabled(
695 // //net/nqe/network_quality_estimator.cc. 706 config->nqe_persistent_caching_enabled);
696 // TODO(tbansal): Investigate a more robust way of configuring the network 707 if (config->nqe_forced_effective_connection_type) {
697 // quality estimator. 708 nqe_params->SetForcedEffectiveConnectionType(
698 variation_params["effective_connection_type_algorithm"] = 709 config->nqe_forced_effective_connection_type.value());
699 "TransportRTTOrDownstreamThroughput"; 710 }
711
700 network_quality_estimator_ = base::MakeUnique<net::NetworkQualityEstimator>( 712 network_quality_estimator_ = base::MakeUnique<net::NetworkQualityEstimator>(
701 std::unique_ptr<net::ExternalEstimateProvider>(), 713 std::unique_ptr<net::ExternalEstimateProvider>(), std::move(nqe_params),
702 base::MakeUnique<net::NetworkQualityEstimatorParams>(variation_params),
703 g_net_log.Get().net_log()); 714 g_net_log.Get().net_log());
704 network_quality_estimator_->AddEffectiveConnectionTypeObserver(this); 715 network_quality_estimator_->AddEffectiveConnectionTypeObserver(this);
705 network_quality_estimator_->AddRTTAndThroughputEstimatesObserver(this); 716 network_quality_estimator_->AddRTTAndThroughputEstimatesObserver(this);
706 717
707 // Set up network quality prefs if the storage path is specified. 718 // Set up network quality prefs if the storage path is specified.
708 if (!config->storage_path.empty()) { 719 if (!config->storage_path.empty()) {
709 DCHECK(!network_qualities_prefs_manager_); 720 DCHECK(!network_qualities_prefs_manager_);
710 network_qualities_prefs_manager_ = 721 network_qualities_prefs_manager_ =
711 base::MakeUnique<net::NetworkQualitiesPrefsManager>( 722 base::MakeUnique<net::NetworkQualitiesPrefsManager>(
712 base::MakeUnique<NetworkQualitiesPrefDelegateImpl>( 723 base::MakeUnique<NetworkQualitiesPrefDelegateImpl>(
713 pref_service_.get())); 724 pref_service_.get()));
714 network_qualities_prefs_manager_->InitializeOnNetworkThread( 725 PostTaskToNetworkThread(FROM_HERE,
715 network_quality_estimator_.get()); 726 base::Bind(&CronetURLRequestContextAdapter::
727 InitializeNQEPrefsOnNetworkThread,
728 base::Unretained(this)));
716 } 729 }
717 context_builder.set_network_quality_estimator( 730 context_builder.set_network_quality_estimator(
718 network_quality_estimator_.get()); 731 network_quality_estimator_.get());
719 } 732 }
720 733
721 context_ = context_builder.Build(); 734 context_ = context_builder.Build();
722 735
723 // Set up host cache persistence if it's enabled. Happens after building the 736 // Set up host cache persistence if it's enabled. Happens after building the
724 // URLRequestContext to get access to the HostCache. 737 // URLRequestContext to get access to the HostCache.
725 if (pref_service_ && config->enable_host_cache_persistence) { 738 if (pref_service_ && config->enable_host_cache_persistence) {
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 JNIEnv* env, 1207 JNIEnv* env,
1195 const JavaParamRef<jclass>& jcaller) { 1208 const JavaParamRef<jclass>& jcaller) {
1196 DCHECK(base::StatisticsRecorder::IsActive()); 1209 DCHECK(base::StatisticsRecorder::IsActive());
1197 std::vector<uint8_t> data; 1210 std::vector<uint8_t> data;
1198 if (!HistogramManager::GetInstance()->GetDeltas(&data)) 1211 if (!HistogramManager::GetInstance()->GetDeltas(&data))
1199 return ScopedJavaLocalRef<jbyteArray>(); 1212 return ScopedJavaLocalRef<jbyteArray>();
1200 return base::android::ToJavaByteArray(env, &data[0], data.size()); 1213 return base::android::ToJavaByteArray(env, &data[0], data.size());
1201 } 1214 }
1202 1215
1203 } // namespace cronet 1216 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698