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

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

Issue 2045703003: Enable NQE when Cronet Engine is built (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed mef comments Created 4 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 29 matching lines...) Expand all
40 #include "net/base/logging_network_change_observer.h" 40 #include "net/base/logging_network_change_observer.h"
41 #include "net/base/net_errors.h" 41 #include "net/base/net_errors.h"
42 #include "net/base/network_delegate_impl.h" 42 #include "net/base/network_delegate_impl.h"
43 #include "net/base/url_util.h" 43 #include "net/base/url_util.h"
44 #include "net/cert/cert_verifier.h" 44 #include "net/cert/cert_verifier.h"
45 #include "net/cookies/cookie_monster.h" 45 #include "net/cookies/cookie_monster.h"
46 #include "net/http/http_auth_handler_factory.h" 46 #include "net/http/http_auth_handler_factory.h"
47 #include "net/http/http_server_properties_manager.h" 47 #include "net/http/http_server_properties_manager.h"
48 #include "net/log/write_to_file_net_log_observer.h" 48 #include "net/log/write_to_file_net_log_observer.h"
49 #include "net/nqe/external_estimate_provider.h" 49 #include "net/nqe/external_estimate_provider.h"
50 #include "net/nqe/network_quality_estimator.h"
50 #include "net/proxy/proxy_config_service_android.h" 51 #include "net/proxy/proxy_config_service_android.h"
51 #include "net/proxy/proxy_service.h" 52 #include "net/proxy/proxy_service.h"
52 #include "net/sdch/sdch_owner.h" 53 #include "net/sdch/sdch_owner.h"
53 #include "net/ssl/channel_id_service.h" 54 #include "net/ssl/channel_id_service.h"
54 #include "net/url_request/url_request_context.h" 55 #include "net/url_request/url_request_context.h"
55 #include "net/url_request/url_request_context_builder.h" 56 #include "net/url_request/url_request_context_builder.h"
56 #include "net/url_request/url_request_interceptor.h" 57 #include "net/url_request/url_request_interceptor.h"
57 58
58 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 59 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
59 #include "components/cronet/android/cronet_data_reduction_proxy.h" 60 #include "components/cronet/android/cronet_data_reduction_proxy.h"
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 // android ProxyConfigServices. 414 // android ProxyConfigServices.
414 android_proxy_config_service->set_exclude_pac_url(true); 415 android_proxy_config_service->set_exclude_pac_url(true);
415 GetNetworkTaskRunner()->PostTask( 416 GetNetworkTaskRunner()->PostTask(
416 FROM_HERE, 417 FROM_HERE,
417 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, 418 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread,
418 base::Unretained(this), base::Passed(&context_config_), 419 base::Unretained(this), base::Passed(&context_config_),
419 jcaller_ref)); 420 jcaller_ref));
420 } 421 }
421 422
422 void CronetURLRequestContextAdapter:: 423 void CronetURLRequestContextAdapter::
423 EnableNetworkQualityEstimatorOnNetworkThread(bool use_local_host_requests, 424 ConfigureNetworkQualityEstimatorOnNetworkThreadForTesting(
424 bool use_smaller_responses) { 425 bool use_local_host_requests,
426 bool use_smaller_responses) {
427 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
428 network_quality_estimator_->SetUseLocalHostRequestsForTesting(
429 use_local_host_requests);
430 network_quality_estimator_->SetUseSmallResponsesForTesting(
431 use_smaller_responses);
432 }
433
434 void CronetURLRequestContextAdapter::ConfigureNetworkQualityEstimatorForTesting(
435 JNIEnv* env,
436 const JavaParamRef<jobject>& jcaller,
437 jboolean use_local_host_requests,
438 jboolean use_smaller_responses) {
439 PostTaskToNetworkThread(
440 FROM_HERE,
441 base::Bind(&CronetURLRequestContextAdapter::
442 ConfigureNetworkQualityEstimatorOnNetworkThreadForTesting,
443 base::Unretained(this), use_local_host_requests,
444 use_smaller_responses));
445 }
446
447 void CronetURLRequestContextAdapter::
448 EnableNetworkQualityEstimatorOnNetworkThread() {
425 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 449 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
426 DCHECK(!network_quality_estimator_); 450 DCHECK(!network_quality_estimator_);
427 network_quality_estimator_.reset(new net::NetworkQualityEstimator( 451 network_quality_estimator_.reset(new net::NetworkQualityEstimator(
428 std::unique_ptr<net::ExternalEstimateProvider>(), 452 std::unique_ptr<net::ExternalEstimateProvider>(),
429 std::map<std::string, std::string>(), use_local_host_requests, 453 std::map<std::string, std::string>()));
430 use_smaller_responses));
431 context_->set_network_quality_estimator(network_quality_estimator_.get()); 454 context_->set_network_quality_estimator(network_quality_estimator_.get());
432 } 455 }
433 456
434 void CronetURLRequestContextAdapter::EnableNetworkQualityEstimator( 457 void CronetURLRequestContextAdapter::EnableNetworkQualityEstimator(
435 JNIEnv* env, 458 JNIEnv* env,
436 const JavaParamRef<jobject>& jcaller, 459 const JavaParamRef<jobject>& jcaller) {
437 jboolean use_local_host_requests,
438 jboolean use_smaller_responses) {
439 PostTaskToNetworkThread( 460 PostTaskToNetworkThread(
440 FROM_HERE, base::Bind(&CronetURLRequestContextAdapter:: 461 FROM_HERE, base::Bind(&CronetURLRequestContextAdapter::
441 EnableNetworkQualityEstimatorOnNetworkThread, 462 EnableNetworkQualityEstimatorOnNetworkThread,
442 base::Unretained(this), use_local_host_requests, 463 base::Unretained(this)));
443 use_smaller_responses));
444 } 464 }
445 465
446 void CronetURLRequestContextAdapter::ProvideRTTObservationsOnNetworkThread( 466 void CronetURLRequestContextAdapter::ProvideRTTObservationsOnNetworkThread(
447 bool should) { 467 bool should) {
448 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 468 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
449 if (!network_quality_estimator_) 469 if (!network_quality_estimator_)
450 return; 470 return;
451 if (should) { 471 if (should) {
452 network_quality_estimator_->AddRTTObserver(this); 472 network_quality_estimator_->AddRTTObserver(this);
453 } else { 473 } else {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 } 584 }
565 585
566 // Explicitly disable the persister for Cronet to avoid persistence of dynamic 586 // Explicitly disable the persister for Cronet to avoid persistence of dynamic
567 // HPKP. This is a safety measure ensuring that nobody enables the persistence 587 // HPKP. This is a safety measure ensuring that nobody enables the persistence
568 // of HPKP by specifying transport_security_persister_path in the future. 588 // of HPKP by specifying transport_security_persister_path in the future.
569 context_builder.set_transport_security_persister_path(base::FilePath()); 589 context_builder.set_transport_security_persister_path(base::FilePath());
570 590
571 // Disable net::CookieStore and net::ChannelIDService. 591 // Disable net::CookieStore and net::ChannelIDService.
572 context_builder.SetCookieAndChannelIdStores(nullptr, nullptr); 592 context_builder.SetCookieAndChannelIdStores(nullptr, nullptr);
573 593
594 if (config->enable_network_quality_estimator) {
595 DCHECK(!network_quality_estimator_);
596 network_quality_estimator_.reset(new net::NetworkQualityEstimator(
597 std::unique_ptr<net::ExternalEstimateProvider>(),
598 std::map<std::string, std::string>(), false, false));
599 // Set the socket performance watcher factory so that network quality
600 // estimator is notified of socket performance metrics from TCP and QUIC.
601 context_builder.set_socket_performance_watcher_factory(
602 network_quality_estimator_->GetSocketPerformanceWatcherFactory());
603 }
604
574 context_ = context_builder.Build(); 605 context_ = context_builder.Build();
606 if (network_quality_estimator_)
607 context_->set_network_quality_estimator(network_quality_estimator_.get());
575 608
576 if (config->load_disable_cache) 609 if (config->load_disable_cache)
577 default_load_flags_ |= net::LOAD_DISABLE_CACHE; 610 default_load_flags_ |= net::LOAD_DISABLE_CACHE;
578 611
579 if (config->enable_sdch) { 612 if (config->enable_sdch) {
580 DCHECK(context_->sdch_manager()); 613 DCHECK(context_->sdch_manager());
581 sdch_owner_.reset( 614 sdch_owner_.reset(
582 new net::SdchOwner(context_->sdch_manager(), context_.get())); 615 new net::SdchOwner(context_->sdch_manager(), context_.get()));
583 if (json_pref_store_) { 616 if (json_pref_store_) {
584 sdch_owner_->EnablePersistentStorage( 617 sdch_owner_->EnablePersistentStorage(
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 jboolean jhttp2_enabled, 809 jboolean jhttp2_enabled,
777 jboolean jsdch_enabled, 810 jboolean jsdch_enabled,
778 const JavaParamRef<jstring>& jdata_reduction_proxy_key, 811 const JavaParamRef<jstring>& jdata_reduction_proxy_key,
779 const JavaParamRef<jstring>& jdata_reduction_proxy_primary_proxy, 812 const JavaParamRef<jstring>& jdata_reduction_proxy_primary_proxy,
780 const JavaParamRef<jstring>& jdata_reduction_proxy_fallback_proxy, 813 const JavaParamRef<jstring>& jdata_reduction_proxy_fallback_proxy,
781 const JavaParamRef<jstring>& jdata_reduction_proxy_secure_proxy_check_url, 814 const JavaParamRef<jstring>& jdata_reduction_proxy_secure_proxy_check_url,
782 jboolean jdisable_cache, 815 jboolean jdisable_cache,
783 jint jhttp_cache_mode, 816 jint jhttp_cache_mode,
784 jlong jhttp_cache_max_size, 817 jlong jhttp_cache_max_size,
785 const JavaParamRef<jstring>& jexperimental_quic_connection_options, 818 const JavaParamRef<jstring>& jexperimental_quic_connection_options,
786 jlong jmock_cert_verifier) { 819 jlong jmock_cert_verifier,
820 jboolean jenable_network_quality_estimator) {
787 return reinterpret_cast<jlong>(new URLRequestContextConfig( 821 return reinterpret_cast<jlong>(new URLRequestContextConfig(
788 jquic_enabled, 822 jquic_enabled,
789 ConvertNullableJavaStringToUTF8(env, jquic_default_user_agent_id), 823 ConvertNullableJavaStringToUTF8(env, jquic_default_user_agent_id),
790 jhttp2_enabled, jsdch_enabled, 824 jhttp2_enabled, jsdch_enabled,
791 static_cast<URLRequestContextConfig::HttpCacheType>(jhttp_cache_mode), 825 static_cast<URLRequestContextConfig::HttpCacheType>(jhttp_cache_mode),
792 jhttp_cache_max_size, jdisable_cache, 826 jhttp_cache_max_size, jdisable_cache,
793 ConvertNullableJavaStringToUTF8(env, jstorage_path), 827 ConvertNullableJavaStringToUTF8(env, jstorage_path),
794 ConvertNullableJavaStringToUTF8(env, juser_agent), 828 ConvertNullableJavaStringToUTF8(env, juser_agent),
795 ConvertNullableJavaStringToUTF8(env, 829 ConvertNullableJavaStringToUTF8(env,
796 jexperimental_quic_connection_options), 830 jexperimental_quic_connection_options),
797 ConvertNullableJavaStringToUTF8(env, jdata_reduction_proxy_key), 831 ConvertNullableJavaStringToUTF8(env, jdata_reduction_proxy_key),
798 ConvertNullableJavaStringToUTF8(env, jdata_reduction_proxy_primary_proxy), 832 ConvertNullableJavaStringToUTF8(env, jdata_reduction_proxy_primary_proxy),
799 ConvertNullableJavaStringToUTF8(env, 833 ConvertNullableJavaStringToUTF8(env,
800 jdata_reduction_proxy_fallback_proxy), 834 jdata_reduction_proxy_fallback_proxy),
801 ConvertNullableJavaStringToUTF8( 835 ConvertNullableJavaStringToUTF8(
802 env, jdata_reduction_proxy_secure_proxy_check_url), 836 env, jdata_reduction_proxy_secure_proxy_check_url),
803 base::WrapUnique( 837 base::WrapUnique(
804 reinterpret_cast<net::CertVerifier*>(jmock_cert_verifier)))); 838 reinterpret_cast<net::CertVerifier*>(jmock_cert_verifier)),
839 jenable_network_quality_estimator));
805 } 840 }
806 841
807 // Add a QUIC hint to a URLRequestContextConfig. 842 // Add a QUIC hint to a URLRequestContextConfig.
808 static void AddQuicHint(JNIEnv* env, 843 static void AddQuicHint(JNIEnv* env,
809 const JavaParamRef<jclass>& jcaller, 844 const JavaParamRef<jclass>& jcaller,
810 jlong jurl_request_context_config, 845 jlong jurl_request_context_config,
811 const JavaParamRef<jstring>& jhost, 846 const JavaParamRef<jstring>& jhost,
812 jint jport, 847 jint jport,
813 jint jalternate_port) { 848 jint jalternate_port) {
814 URLRequestContextConfig* config = 849 URLRequestContextConfig* config =
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 JNIEnv* env, 922 JNIEnv* env,
888 const JavaParamRef<jclass>& jcaller) { 923 const JavaParamRef<jclass>& jcaller) {
889 base::StatisticsRecorder::Initialize(); 924 base::StatisticsRecorder::Initialize();
890 std::vector<uint8_t> data; 925 std::vector<uint8_t> data;
891 if (!HistogramManager::GetInstance()->GetDeltas(&data)) 926 if (!HistogramManager::GetInstance()->GetDeltas(&data))
892 return ScopedJavaLocalRef<jbyteArray>(); 927 return ScopedJavaLocalRef<jbyteArray>();
893 return base::android::ToJavaByteArray(env, &data[0], data.size()); 928 return base::android::ToJavaByteArray(env, &data[0], data.size());
894 } 929 }
895 930
896 } // namespace cronet 931 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698