OLD | NEW |
---|---|
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 Loading... | |
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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 // android ProxyConfigServices. | 415 // android ProxyConfigServices. |
415 android_proxy_config_service->set_exclude_pac_url(true); | 416 android_proxy_config_service->set_exclude_pac_url(true); |
416 GetNetworkTaskRunner()->PostTask( | 417 GetNetworkTaskRunner()->PostTask( |
417 FROM_HERE, | 418 FROM_HERE, |
418 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, | 419 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, |
419 base::Unretained(this), base::Passed(&context_config_), | 420 base::Unretained(this), base::Passed(&context_config_), |
420 jcaller_ref)); | 421 jcaller_ref)); |
421 } | 422 } |
422 | 423 |
423 void CronetURLRequestContextAdapter:: | 424 void CronetURLRequestContextAdapter:: |
424 EnableNetworkQualityEstimatorOnNetworkThread(bool use_local_host_requests, | 425 ConfigureNetworkQualityEstimatorOnNetworkThreadForTesting( |
425 bool use_smaller_responses) { | 426 bool use_local_host_requests, |
427 bool use_smaller_responses) { | |
428 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | |
bengr
2016/06/07 20:53:16
DCHECK also that the nqe is enabled.
tbansal1
2016/06/07 21:37:16
The next line calls a function of network_quality_
| |
429 network_quality_estimator_->SetUseLocalHostRequestsForTesting( | |
430 use_local_host_requests); | |
431 network_quality_estimator_->SetUseSmallResponsesForTesting( | |
432 use_smaller_responses); | |
433 } | |
434 | |
435 void CronetURLRequestContextAdapter::ConfigureNetworkQualityEstimatorForTesting( | |
436 JNIEnv* env, | |
437 const JavaParamRef<jobject>& jcaller, | |
438 jboolean use_local_host_requests, | |
439 jboolean use_smaller_responses) { | |
440 PostTaskToNetworkThread( | |
441 FROM_HERE, | |
442 base::Bind(&CronetURLRequestContextAdapter:: | |
443 ConfigureNetworkQualityEstimatorOnNetworkThreadForTesting, | |
444 base::Unretained(this), use_local_host_requests, | |
445 use_smaller_responses)); | |
446 } | |
447 | |
448 void CronetURLRequestContextAdapter:: | |
449 EnableNetworkQualityEstimatorOnNetworkThread() { | |
426 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 450 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
427 DCHECK(!network_quality_estimator_); | 451 DCHECK(!network_quality_estimator_); |
428 network_quality_estimator_.reset(new net::NetworkQualityEstimator( | 452 network_quality_estimator_.reset(new net::NetworkQualityEstimator( |
429 std::unique_ptr<net::ExternalEstimateProvider>(), | 453 std::unique_ptr<net::ExternalEstimateProvider>(), |
430 std::map<std::string, std::string>(), use_local_host_requests, | 454 std::map<std::string, std::string>())); |
431 use_smaller_responses)); | |
432 context_->set_network_quality_estimator(network_quality_estimator_.get()); | 455 context_->set_network_quality_estimator(network_quality_estimator_.get()); |
433 } | 456 } |
434 | 457 |
435 void CronetURLRequestContextAdapter::EnableNetworkQualityEstimator( | 458 void CronetURLRequestContextAdapter::EnableNetworkQualityEstimator( |
436 JNIEnv* env, | 459 JNIEnv* env, |
437 const JavaParamRef<jobject>& jcaller, | 460 const JavaParamRef<jobject>& jcaller) { |
438 jboolean use_local_host_requests, | |
439 jboolean use_smaller_responses) { | |
440 PostTaskToNetworkThread( | 461 PostTaskToNetworkThread( |
441 FROM_HERE, base::Bind(&CronetURLRequestContextAdapter:: | 462 FROM_HERE, base::Bind(&CronetURLRequestContextAdapter:: |
442 EnableNetworkQualityEstimatorOnNetworkThread, | 463 EnableNetworkQualityEstimatorOnNetworkThread, |
443 base::Unretained(this), use_local_host_requests, | 464 base::Unretained(this))); |
444 use_smaller_responses)); | |
445 } | 465 } |
446 | 466 |
447 void CronetURLRequestContextAdapter::ProvideRTTObservationsOnNetworkThread( | 467 void CronetURLRequestContextAdapter::ProvideRTTObservationsOnNetworkThread( |
448 bool should) { | 468 bool should) { |
449 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 469 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
450 if (!network_quality_estimator_) | 470 if (!network_quality_estimator_) |
451 return; | 471 return; |
452 if (should) { | 472 if (should) { |
453 network_quality_estimator_->AddRTTObserver(this); | 473 network_quality_estimator_->AddRTTObserver(this); |
454 } else { | 474 } else { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
565 } | 585 } |
566 | 586 |
567 // Explicitly disable the persister for Cronet to avoid persistence of dynamic | 587 // Explicitly disable the persister for Cronet to avoid persistence of dynamic |
568 // HPKP. This is a safety measure ensuring that nobody enables the persistence | 588 // HPKP. This is a safety measure ensuring that nobody enables the persistence |
569 // of HPKP by specifying transport_security_persister_path in the future. | 589 // of HPKP by specifying transport_security_persister_path in the future. |
570 context_builder.set_transport_security_persister_path(base::FilePath()); | 590 context_builder.set_transport_security_persister_path(base::FilePath()); |
571 | 591 |
572 // Disable net::CookieStore and net::ChannelIDService. | 592 // Disable net::CookieStore and net::ChannelIDService. |
573 context_builder.SetCookieAndChannelIdStores(nullptr, nullptr); | 593 context_builder.SetCookieAndChannelIdStores(nullptr, nullptr); |
574 | 594 |
595 if (config->enable_network_quality_estimator) { | |
596 DCHECK(!network_quality_estimator_); | |
597 network_quality_estimator_.reset(new net::NetworkQualityEstimator( | |
598 std::unique_ptr<net::ExternalEstimateProvider>(), | |
599 std::map<std::string, std::string>(), false, false)); | |
600 // Set the socket performance watcher factory so that network quality | |
601 // estimator is notified of socket performance metrics from TCP and QUIC. | |
602 context_builder.set_socket_performance_watcher_factory( | |
603 network_quality_estimator_->GetSocketPerformanceWatcherFactory()); | |
604 } | |
605 | |
575 context_ = context_builder.Build(); | 606 context_ = context_builder.Build(); |
607 if (network_quality_estimator_) | |
608 context_->set_network_quality_estimator(network_quality_estimator_.get()); | |
576 | 609 |
577 if (config->load_disable_cache) | 610 if (config->load_disable_cache) |
578 default_load_flags_ |= net::LOAD_DISABLE_CACHE; | 611 default_load_flags_ |= net::LOAD_DISABLE_CACHE; |
579 | 612 |
580 if (config->enable_sdch) { | 613 if (config->enable_sdch) { |
581 DCHECK(context_->sdch_manager()); | 614 DCHECK(context_->sdch_manager()); |
582 sdch_owner_.reset( | 615 sdch_owner_.reset( |
583 new net::SdchOwner(context_->sdch_manager(), context_.get())); | 616 new net::SdchOwner(context_->sdch_manager(), context_.get())); |
584 if (json_pref_store_) { | 617 if (json_pref_store_) { |
585 sdch_owner_->EnablePersistentStorage( | 618 sdch_owner_->EnablePersistentStorage( |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
793 jboolean jhttp2_enabled, | 826 jboolean jhttp2_enabled, |
794 jboolean jsdch_enabled, | 827 jboolean jsdch_enabled, |
795 const JavaParamRef<jstring>& jdata_reduction_proxy_key, | 828 const JavaParamRef<jstring>& jdata_reduction_proxy_key, |
796 const JavaParamRef<jstring>& jdata_reduction_proxy_primary_proxy, | 829 const JavaParamRef<jstring>& jdata_reduction_proxy_primary_proxy, |
797 const JavaParamRef<jstring>& jdata_reduction_proxy_fallback_proxy, | 830 const JavaParamRef<jstring>& jdata_reduction_proxy_fallback_proxy, |
798 const JavaParamRef<jstring>& jdata_reduction_proxy_secure_proxy_check_url, | 831 const JavaParamRef<jstring>& jdata_reduction_proxy_secure_proxy_check_url, |
799 jboolean jdisable_cache, | 832 jboolean jdisable_cache, |
800 jint jhttp_cache_mode, | 833 jint jhttp_cache_mode, |
801 jlong jhttp_cache_max_size, | 834 jlong jhttp_cache_max_size, |
802 const JavaParamRef<jstring>& jexperimental_quic_connection_options, | 835 const JavaParamRef<jstring>& jexperimental_quic_connection_options, |
803 jlong jmock_cert_verifier) { | 836 jlong jmock_cert_verifier, |
837 jboolean jenable_network_quality_estimator) { | |
804 return reinterpret_cast<jlong>(new URLRequestContextConfig( | 838 return reinterpret_cast<jlong>(new URLRequestContextConfig( |
805 jquic_enabled, | 839 jquic_enabled, |
806 ConvertNullableJavaStringToUTF8(env, jquic_default_user_agent_id), | 840 ConvertNullableJavaStringToUTF8(env, jquic_default_user_agent_id), |
807 jhttp2_enabled, jsdch_enabled, | 841 jhttp2_enabled, jsdch_enabled, |
808 static_cast<URLRequestContextConfig::HttpCacheType>(jhttp_cache_mode), | 842 static_cast<URLRequestContextConfig::HttpCacheType>(jhttp_cache_mode), |
809 jhttp_cache_max_size, jdisable_cache, | 843 jhttp_cache_max_size, jdisable_cache, |
810 ConvertNullableJavaStringToUTF8(env, jstorage_path), | 844 ConvertNullableJavaStringToUTF8(env, jstorage_path), |
811 ConvertNullableJavaStringToUTF8(env, juser_agent), | 845 ConvertNullableJavaStringToUTF8(env, juser_agent), |
812 ConvertNullableJavaStringToUTF8(env, | 846 ConvertNullableJavaStringToUTF8(env, |
813 jexperimental_quic_connection_options), | 847 jexperimental_quic_connection_options), |
814 ConvertNullableJavaStringToUTF8(env, jdata_reduction_proxy_key), | 848 ConvertNullableJavaStringToUTF8(env, jdata_reduction_proxy_key), |
815 ConvertNullableJavaStringToUTF8(env, jdata_reduction_proxy_primary_proxy), | 849 ConvertNullableJavaStringToUTF8(env, jdata_reduction_proxy_primary_proxy), |
816 ConvertNullableJavaStringToUTF8(env, | 850 ConvertNullableJavaStringToUTF8(env, |
817 jdata_reduction_proxy_fallback_proxy), | 851 jdata_reduction_proxy_fallback_proxy), |
818 ConvertNullableJavaStringToUTF8( | 852 ConvertNullableJavaStringToUTF8( |
819 env, jdata_reduction_proxy_secure_proxy_check_url), | 853 env, jdata_reduction_proxy_secure_proxy_check_url), |
820 base::WrapUnique( | 854 base::WrapUnique( |
821 reinterpret_cast<net::CertVerifier*>(jmock_cert_verifier)))); | 855 reinterpret_cast<net::CertVerifier*>(jmock_cert_verifier)), |
856 jenable_network_quality_estimator)); | |
822 } | 857 } |
823 | 858 |
824 // Add a QUIC hint to a URLRequestContextConfig. | 859 // Add a QUIC hint to a URLRequestContextConfig. |
825 static void AddQuicHint(JNIEnv* env, | 860 static void AddQuicHint(JNIEnv* env, |
826 const JavaParamRef<jclass>& jcaller, | 861 const JavaParamRef<jclass>& jcaller, |
827 jlong jurl_request_context_config, | 862 jlong jurl_request_context_config, |
828 const JavaParamRef<jstring>& jhost, | 863 const JavaParamRef<jstring>& jhost, |
829 jint jport, | 864 jint jport, |
830 jint jalternate_port) { | 865 jint jalternate_port) { |
831 URLRequestContextConfig* config = | 866 URLRequestContextConfig* config = |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
904 JNIEnv* env, | 939 JNIEnv* env, |
905 const JavaParamRef<jclass>& jcaller) { | 940 const JavaParamRef<jclass>& jcaller) { |
906 base::StatisticsRecorder::Initialize(); | 941 base::StatisticsRecorder::Initialize(); |
907 std::vector<uint8_t> data; | 942 std::vector<uint8_t> data; |
908 if (!HistogramManager::GetInstance()->GetDeltas(&data)) | 943 if (!HistogramManager::GetInstance()->GetDeltas(&data)) |
909 return ScopedJavaLocalRef<jbyteArray>(); | 944 return ScopedJavaLocalRef<jbyteArray>(); |
910 return base::android::ToJavaByteArray(env, &data[0], data.size()); | 945 return base::android::ToJavaByteArray(env, &data[0], data.size()); |
911 } | 946 } |
912 | 947 |
913 } // namespace cronet | 948 } // namespace cronet |
OLD | NEW |