| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "net/base/net_errors.h" | 44 #include "net/base/net_errors.h" |
| 45 #include "net/base/network_delegate_impl.h" | 45 #include "net/base/network_delegate_impl.h" |
| 46 #include "net/base/url_util.h" | 46 #include "net/base/url_util.h" |
| 47 #include "net/cert/caching_cert_verifier.h" | 47 #include "net/cert/caching_cert_verifier.h" |
| 48 #include "net/cert/cert_verifier.h" | 48 #include "net/cert/cert_verifier.h" |
| 49 #include "net/cookies/cookie_monster.h" | 49 #include "net/cookies/cookie_monster.h" |
| 50 #include "net/http/http_auth_handler_factory.h" | 50 #include "net/http/http_auth_handler_factory.h" |
| 51 #include "net/http/http_server_properties_manager.h" | 51 #include "net/http/http_server_properties_manager.h" |
| 52 #include "net/log/write_to_file_net_log_observer.h" | 52 #include "net/log/write_to_file_net_log_observer.h" |
| 53 #include "net/nqe/external_estimate_provider.h" | 53 #include "net/nqe/external_estimate_provider.h" |
| 54 #include "net/nqe/network_quality_estimator.h" |
| 54 #include "net/proxy/proxy_config_service_android.h" | 55 #include "net/proxy/proxy_config_service_android.h" |
| 55 #include "net/proxy/proxy_service.h" | 56 #include "net/proxy/proxy_service.h" |
| 56 #include "net/sdch/sdch_owner.h" | 57 #include "net/sdch/sdch_owner.h" |
| 57 #include "net/ssl/channel_id_service.h" | 58 #include "net/ssl/channel_id_service.h" |
| 58 #include "net/url_request/url_request_context.h" | 59 #include "net/url_request/url_request_context.h" |
| 59 #include "net/url_request/url_request_context_builder.h" | 60 #include "net/url_request/url_request_context_builder.h" |
| 60 #include "net/url_request/url_request_interceptor.h" | 61 #include "net/url_request/url_request_interceptor.h" |
| 61 | 62 |
| 62 #if defined(DATA_REDUCTION_PROXY_SUPPORT) | 63 #if defined(DATA_REDUCTION_PROXY_SUPPORT) |
| 63 #include "components/cronet/android/cronet_data_reduction_proxy.h" | 64 #include "components/cronet/android/cronet_data_reduction_proxy.h" |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 CronetURLRequestContextAdapter::~CronetURLRequestContextAdapter() { | 409 CronetURLRequestContextAdapter::~CronetURLRequestContextAdapter() { |
| 409 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 410 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
| 410 | 411 |
| 411 if (http_server_properties_manager_) | 412 if (http_server_properties_manager_) |
| 412 http_server_properties_manager_->ShutdownOnPrefThread(); | 413 http_server_properties_manager_->ShutdownOnPrefThread(); |
| 413 if (pref_service_) | 414 if (pref_service_) |
| 414 pref_service_->CommitPendingWrite(); | 415 pref_service_->CommitPendingWrite(); |
| 415 if (network_quality_estimator_) { | 416 if (network_quality_estimator_) { |
| 416 network_quality_estimator_->RemoveRTTObserver(this); | 417 network_quality_estimator_->RemoveRTTObserver(this); |
| 417 network_quality_estimator_->RemoveThroughputObserver(this); | 418 network_quality_estimator_->RemoveThroughputObserver(this); |
| 418 network_quality_estimator_->RemoveEffectiveConnectionTypeObserver(this); | |
| 419 } | 419 } |
| 420 // Stop |write_to_file_observer_| if there is one. | 420 // Stop |write_to_file_observer_| if there is one. |
| 421 StopNetLogHelper(); | 421 StopNetLogHelper(); |
| 422 } | 422 } |
| 423 | 423 |
| 424 void CronetURLRequestContextAdapter::InitRequestContextOnMainThread( | 424 void CronetURLRequestContextAdapter::InitRequestContextOnMainThread( |
| 425 JNIEnv* env, | 425 JNIEnv* env, |
| 426 const JavaParamRef<jobject>& jcaller) { | 426 const JavaParamRef<jobject>& jcaller) { |
| 427 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref; | 427 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref; |
| 428 jcaller_ref.Reset(env, jcaller); | 428 jcaller_ref.Reset(env, jcaller); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 // Explicitly disable the persister for Cronet to avoid persistence of dynamic | 590 // Explicitly disable the persister for Cronet to avoid persistence of dynamic |
| 591 // HPKP. This is a safety measure ensuring that nobody enables the persistence | 591 // HPKP. This is a safety measure ensuring that nobody enables the persistence |
| 592 // of HPKP by specifying transport_security_persister_path in the future. | 592 // of HPKP by specifying transport_security_persister_path in the future. |
| 593 context_builder.set_transport_security_persister_path(base::FilePath()); | 593 context_builder.set_transport_security_persister_path(base::FilePath()); |
| 594 | 594 |
| 595 // Disable net::CookieStore and net::ChannelIDService. | 595 // Disable net::CookieStore and net::ChannelIDService. |
| 596 context_builder.SetCookieAndChannelIdStores(nullptr, nullptr); | 596 context_builder.SetCookieAndChannelIdStores(nullptr, nullptr); |
| 597 | 597 |
| 598 if (config->enable_network_quality_estimator) { | 598 if (config->enable_network_quality_estimator) { |
| 599 DCHECK(!network_quality_estimator_); | 599 DCHECK(!network_quality_estimator_); |
| 600 std::map<std::string, std::string> variation_params; | |
| 601 // Configure network quality estimator: Specify the algorithm that should | |
| 602 // be used for computing the effective connection type. The algorithm | |
| 603 // is specified using the key-value pairs defined in | |
| 604 // //net/nqe/network_quality_estimator.cc. | |
| 605 // TODO(tbansal): Investigate a more robust way of configuring the network | |
| 606 // quality estimator. | |
| 607 variation_params["effective_connection_type_algorithm"] = | |
| 608 "TransportRTTOrDownstreamThroughput"; | |
| 609 network_quality_estimator_.reset(new net::NetworkQualityEstimator( | 600 network_quality_estimator_.reset(new net::NetworkQualityEstimator( |
| 610 std::unique_ptr<net::ExternalEstimateProvider>(), variation_params, | 601 std::unique_ptr<net::ExternalEstimateProvider>(), |
| 611 false, false)); | 602 std::map<std::string, std::string>(), false, false)); |
| 612 // Set the socket performance watcher factory so that network quality | 603 // Set the socket performance watcher factory so that network quality |
| 613 // estimator is notified of socket performance metrics from TCP and QUIC. | 604 // estimator is notified of socket performance metrics from TCP and QUIC. |
| 614 context_builder.set_socket_performance_watcher_factory( | 605 context_builder.set_socket_performance_watcher_factory( |
| 615 network_quality_estimator_->GetSocketPerformanceWatcherFactory()); | 606 network_quality_estimator_->GetSocketPerformanceWatcherFactory()); |
| 616 network_quality_estimator_->AddEffectiveConnectionTypeObserver(this); | |
| 617 } | 607 } |
| 618 | 608 |
| 619 context_ = context_builder.Build(); | 609 context_ = context_builder.Build(); |
| 620 if (network_quality_estimator_) | 610 if (network_quality_estimator_) |
| 621 context_->set_network_quality_estimator(network_quality_estimator_.get()); | 611 context_->set_network_quality_estimator(network_quality_estimator_.get()); |
| 622 | 612 |
| 623 if (config->load_disable_cache) | 613 if (config->load_disable_cache) |
| 624 default_load_flags_ |= net::LOAD_DISABLE_CACHE; | 614 default_load_flags_ |= net::LOAD_DISABLE_CACHE; |
| 625 | 615 |
| 626 if (config->enable_sdch) { | 616 if (config->enable_sdch) { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 | 815 |
| 826 base::Thread* CronetURLRequestContextAdapter::GetFileThread() { | 816 base::Thread* CronetURLRequestContextAdapter::GetFileThread() { |
| 827 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 817 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
| 828 if (!file_thread_) { | 818 if (!file_thread_) { |
| 829 file_thread_.reset(new base::Thread("Network File Thread")); | 819 file_thread_.reset(new base::Thread("Network File Thread")); |
| 830 file_thread_->Start(); | 820 file_thread_->Start(); |
| 831 } | 821 } |
| 832 return file_thread_.get(); | 822 return file_thread_.get(); |
| 833 } | 823 } |
| 834 | 824 |
| 835 void CronetURLRequestContextAdapter::OnEffectiveConnectionTypeChanged( | |
| 836 net::EffectiveConnectionType effective_connection_type) { | |
| 837 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | |
| 838 Java_CronetUrlRequestContext_onEffectiveConnectionTypeChanged( | |
| 839 base::android::AttachCurrentThread(), jcronet_url_request_context_.obj(), | |
| 840 effective_connection_type); | |
| 841 } | |
| 842 | |
| 843 void CronetURLRequestContextAdapter::OnRTTObservation( | 825 void CronetURLRequestContextAdapter::OnRTTObservation( |
| 844 int32_t rtt_ms, | 826 int32_t rtt_ms, |
| 845 const base::TimeTicks& timestamp, | 827 const base::TimeTicks& timestamp, |
| 846 net::NetworkQualityObservationSource source) { | 828 net::NetworkQualityObservationSource source) { |
| 847 Java_CronetUrlRequestContext_onRttObservation( | 829 Java_CronetUrlRequestContext_onRttObservation( |
| 848 base::android::AttachCurrentThread(), jcronet_url_request_context_.obj(), | 830 base::android::AttachCurrentThread(), jcronet_url_request_context_.obj(), |
| 849 rtt_ms, (timestamp - base::TimeTicks::UnixEpoch()).InMilliseconds(), | 831 rtt_ms, (timestamp - base::TimeTicks::UnixEpoch()).InMilliseconds(), |
| 850 source); | 832 source); |
| 851 } | 833 } |
| 852 | 834 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 JNIEnv* env, | 978 JNIEnv* env, |
| 997 const JavaParamRef<jclass>& jcaller) { | 979 const JavaParamRef<jclass>& jcaller) { |
| 998 base::StatisticsRecorder::Initialize(); | 980 base::StatisticsRecorder::Initialize(); |
| 999 std::vector<uint8_t> data; | 981 std::vector<uint8_t> data; |
| 1000 if (!HistogramManager::GetInstance()->GetDeltas(&data)) | 982 if (!HistogramManager::GetInstance()->GetDeltas(&data)) |
| 1001 return ScopedJavaLocalRef<jbyteArray>(); | 983 return ScopedJavaLocalRef<jbyteArray>(); |
| 1002 return base::android::ToJavaByteArray(env, &data[0], data.size()); | 984 return base::android::ToJavaByteArray(env, &data[0], data.size()); |
| 1003 } | 985 } |
| 1004 | 986 |
| 1005 } // namespace cronet | 987 } // namespace cronet |
| OLD | NEW |