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

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: rebased, 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 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 // Explicitly disable the persister for Cronet to avoid persistence of dynamic 681 // Explicitly disable the persister for Cronet to avoid persistence of dynamic
682 // HPKP. This is a safety measure ensuring that nobody enables the persistence 682 // HPKP. This is a safety measure ensuring that nobody enables the persistence
683 // of HPKP by specifying transport_security_persister_path in the future. 683 // of HPKP by specifying transport_security_persister_path in the future.
684 context_builder.set_transport_security_persister_path(base::FilePath()); 684 context_builder.set_transport_security_persister_path(base::FilePath());
685 685
686 // Disable net::CookieStore and net::ChannelIDService. 686 // Disable net::CookieStore and net::ChannelIDService.
687 context_builder.SetCookieAndChannelIdStores(nullptr, nullptr); 687 context_builder.SetCookieAndChannelIdStores(nullptr, nullptr);
688 688
689 if (config->enable_network_quality_estimator) { 689 if (config->enable_network_quality_estimator) {
690 DCHECK(!network_quality_estimator_); 690 DCHECK(!network_quality_estimator_);
691 std::map<std::string, std::string> variation_params; 691 std::unique_ptr<net::NetworkQualityEstimatorParams> nqe_params =
692 // Configure network quality estimator: Specify the algorithm that should 692 base::MakeUnique<net::NetworkQualityEstimatorParams>(
693 // be used for computing the effective connection type. The algorithm 693 std::map<std::string, std::string>());
694 // is specified using the key-value pairs defined in 694 nqe_params->set_persistent_cache_reading_enabled(
695 // //net/nqe/network_quality_estimator.cc. 695 config->nqe_persistent_caching_enabled);
696 // TODO(tbansal): Investigate a more robust way of configuring the network 696 if (config->nqe_forced_effective_connection_type) {
697 // quality estimator. 697 nqe_params->SetForcedEffectiveConnectionType(
698 variation_params["effective_connection_type_algorithm"] = 698 config->nqe_forced_effective_connection_type.value());
699 "TransportRTTOrDownstreamThroughput"; 699 }
700
700 network_quality_estimator_ = base::MakeUnique<net::NetworkQualityEstimator>( 701 network_quality_estimator_ = base::MakeUnique<net::NetworkQualityEstimator>(
701 std::unique_ptr<net::ExternalEstimateProvider>(), 702 std::unique_ptr<net::ExternalEstimateProvider>(), std::move(nqe_params),
702 base::MakeUnique<net::NetworkQualityEstimatorParams>(variation_params),
703 g_net_log.Get().net_log()); 703 g_net_log.Get().net_log());
704 network_quality_estimator_->AddEffectiveConnectionTypeObserver(this); 704 network_quality_estimator_->AddEffectiveConnectionTypeObserver(this);
705 network_quality_estimator_->AddRTTAndThroughputEstimatesObserver(this); 705 network_quality_estimator_->AddRTTAndThroughputEstimatesObserver(this);
706 706
707 // Set up network quality prefs if the storage path is specified. 707 // Set up network quality prefs if the storage path is specified.
708 if (!config->storage_path.empty()) { 708 if (!config->storage_path.empty()) {
709 DCHECK(!network_qualities_prefs_manager_); 709 DCHECK(!network_qualities_prefs_manager_);
710 network_qualities_prefs_manager_ = 710 network_qualities_prefs_manager_ =
711 base::MakeUnique<net::NetworkQualitiesPrefsManager>( 711 base::MakeUnique<net::NetworkQualitiesPrefsManager>(
712 base::MakeUnique<NetworkQualitiesPrefDelegateImpl>( 712 base::MakeUnique<NetworkQualitiesPrefDelegateImpl>(
713 pref_service_.get())); 713 pref_service_.get()));
714 network_qualities_prefs_manager_->InitializeOnNetworkThread(
715 network_quality_estimator_.get());
716 } 714 }
717 context_builder.set_network_quality_estimator( 715 context_builder.set_network_quality_estimator(
718 network_quality_estimator_.get()); 716 network_quality_estimator_.get());
719 } 717 }
720 718
721 context_ = context_builder.Build(); 719 context_ = context_builder.Build();
722 720
723 // Set up host cache persistence if it's enabled. Happens after building the 721 // Set up host cache persistence if it's enabled. Happens after building the
724 // URLRequestContext to get access to the HostCache. 722 // URLRequestContext to get access to the HostCache.
725 if (pref_service_ && config->enable_host_cache_persistence) { 723 if (pref_service_ && config->enable_host_cache_persistence) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 context_->transport_security_state() 809 context_->transport_security_state()
812 ->SetEnablePublicKeyPinningBypassForLocalTrustAnchors( 810 ->SetEnablePublicKeyPinningBypassForLocalTrustAnchors(
813 config->bypass_public_key_pinning_for_local_trust_anchors); 811 config->bypass_public_key_pinning_for_local_trust_anchors);
814 812
815 JNIEnv* env = base::android::AttachCurrentThread(); 813 JNIEnv* env = base::android::AttachCurrentThread();
816 jcronet_url_request_context_.Reset(env, jcronet_url_request_context.obj()); 814 jcronet_url_request_context_.Reset(env, jcronet_url_request_context.obj());
817 Java_CronetUrlRequestContext_initNetworkThread(env, 815 Java_CronetUrlRequestContext_initNetworkThread(env,
818 jcronet_url_request_context); 816 jcronet_url_request_context);
819 817
820 is_context_initialized_ = true; 818 is_context_initialized_ = true;
819 if (config->enable_network_quality_estimator &&
820 !config->storage_path.empty()) {
821 // Initializing |network_qualities_prefs_manager_| may post a callback to
822 // |this|. So, initialize it after |jcronet_url_request_context_| has been
823 // constructed.
824 DCHECK(jcronet_url_request_context_.obj() != nullptr);
825 network_qualities_prefs_manager_->InitializeOnNetworkThread(
826 network_quality_estimator_.get());
827 }
828
821 while (!tasks_waiting_for_context_.empty()) { 829 while (!tasks_waiting_for_context_.empty()) {
822 tasks_waiting_for_context_.front().Run(); 830 tasks_waiting_for_context_.front().Run();
823 tasks_waiting_for_context_.pop(); 831 tasks_waiting_for_context_.pop();
824 } 832 }
825 } 833 }
826 834
827 void CronetURLRequestContextAdapter::Destroy( 835 void CronetURLRequestContextAdapter::Destroy(
828 JNIEnv* env, 836 JNIEnv* env,
829 const JavaParamRef<jobject>& jcaller) { 837 const JavaParamRef<jobject>& jcaller) {
830 DCHECK(!GetNetworkTaskRunner()->BelongsToCurrentThread()); 838 DCHECK(!GetNetworkTaskRunner()->BelongsToCurrentThread());
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 JNIEnv* env, 1202 JNIEnv* env,
1195 const JavaParamRef<jclass>& jcaller) { 1203 const JavaParamRef<jclass>& jcaller) {
1196 DCHECK(base::StatisticsRecorder::IsActive()); 1204 DCHECK(base::StatisticsRecorder::IsActive());
1197 std::vector<uint8_t> data; 1205 std::vector<uint8_t> data;
1198 if (!HistogramManager::GetInstance()->GetDeltas(&data)) 1206 if (!HistogramManager::GetInstance()->GetDeltas(&data))
1199 return ScopedJavaLocalRef<jbyteArray>(); 1207 return ScopedJavaLocalRef<jbyteArray>();
1200 return base::android::ToJavaByteArray(env, &data[0], data.size()); 1208 return base::android::ToJavaByteArray(env, &data[0], data.size());
1201 } 1209 }
1202 1210
1203 } // namespace cronet 1211 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698