| 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 | |
| 10 #include <map> | 9 #include <map> |
| 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/android/jni_android.h" | 12 #include "base/android/jni_android.h" |
| 13 #include "base/android/jni_array.h" | 13 #include "base/android/jni_array.h" |
| 14 #include "base/android/jni_string.h" | 14 #include "base/android/jni_string.h" |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
| 18 #include "base/files/scoped_file.h" | 18 #include "base/files/scoped_file.h" |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/macros.h" | 20 #include "base/macros.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 131 |
| 132 // Explicitly register static JNI functions. | 132 // Explicitly register static JNI functions. |
| 133 bool CronetUrlRequestContextAdapterRegisterJni(JNIEnv* env) { | 133 bool CronetUrlRequestContextAdapterRegisterJni(JNIEnv* env) { |
| 134 return RegisterNativesImpl(env); | 134 return RegisterNativesImpl(env); |
| 135 } | 135 } |
| 136 | 136 |
| 137 CronetURLRequestContextAdapter::CronetURLRequestContextAdapter( | 137 CronetURLRequestContextAdapter::CronetURLRequestContextAdapter( |
| 138 scoped_ptr<URLRequestContextConfig> context_config) | 138 scoped_ptr<URLRequestContextConfig> context_config) |
| 139 : network_thread_(new base::Thread("network")), | 139 : network_thread_(new base::Thread("network")), |
| 140 http_server_properties_manager_(nullptr), | 140 http_server_properties_manager_(nullptr), |
| 141 context_config_(context_config.Pass()), | 141 context_config_(std::move(context_config)), |
| 142 is_context_initialized_(false), | 142 is_context_initialized_(false), |
| 143 default_load_flags_(net::LOAD_NORMAL) { | 143 default_load_flags_(net::LOAD_NORMAL) { |
| 144 base::Thread::Options options; | 144 base::Thread::Options options; |
| 145 options.message_loop_type = base::MessageLoop::TYPE_IO; | 145 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 146 network_thread_->StartWithOptions(options); | 146 network_thread_->StartWithOptions(options); |
| 147 } | 147 } |
| 148 | 148 |
| 149 CronetURLRequestContextAdapter::~CronetURLRequestContextAdapter() { | 149 CronetURLRequestContextAdapter::~CronetURLRequestContextAdapter() { |
| 150 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 150 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
| 151 | 151 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 config->data_reduction_fallback_proxy, | 278 config->data_reduction_fallback_proxy, |
| 279 config->data_reduction_secure_proxy_check_url, config->user_agent, | 279 config->data_reduction_secure_proxy_check_url, config->user_agent, |
| 280 GetNetworkTaskRunner(), net_log_.get())); | 280 GetNetworkTaskRunner(), net_log_.get())); |
| 281 network_delegate = | 281 network_delegate = |
| 282 data_reduction_proxy_->CreateNetworkDelegate(network_delegate.Pass()); | 282 data_reduction_proxy_->CreateNetworkDelegate(network_delegate.Pass()); |
| 283 std::vector<scoped_ptr<net::URLRequestInterceptor>> interceptors; | 283 std::vector<scoped_ptr<net::URLRequestInterceptor>> interceptors; |
| 284 interceptors.push_back(data_reduction_proxy_->CreateInterceptor()); | 284 interceptors.push_back(data_reduction_proxy_->CreateInterceptor()); |
| 285 context_builder.SetInterceptors(std::move(interceptors)); | 285 context_builder.SetInterceptors(std::move(interceptors)); |
| 286 } | 286 } |
| 287 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT) | 287 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT) |
| 288 context_builder.set_network_delegate(network_delegate.Pass()); | 288 context_builder.set_network_delegate(std::move(network_delegate)); |
| 289 context_builder.set_net_log(net_log_.get()); | 289 context_builder.set_net_log(net_log_.get()); |
| 290 | 290 |
| 291 // Android provides a local HTTP proxy server that handles proxying when a PAC | 291 // Android provides a local HTTP proxy server that handles proxying when a PAC |
| 292 // URL is present. Create a proxy service without a resolver and rely on this | 292 // URL is present. Create a proxy service without a resolver and rely on this |
| 293 // local HTTP proxy. See: crbug.com/432539. | 293 // local HTTP proxy. See: crbug.com/432539. |
| 294 context_builder.set_proxy_service( | 294 context_builder.set_proxy_service( |
| 295 net::ProxyService::CreateWithoutProxyResolver( | 295 net::ProxyService::CreateWithoutProxyResolver( |
| 296 proxy_config_service_.Pass(), net_log_.get())); | 296 std::move(proxy_config_service_), net_log_.get())); |
| 297 config->ConfigureURLRequestContextBuilder(&context_builder, net_log_.get()); | 297 config->ConfigureURLRequestContextBuilder(&context_builder, net_log_.get()); |
| 298 | 298 |
| 299 // Set up pref file if storage path is specified. | 299 // Set up pref file if storage path is specified. |
| 300 if (!config->storage_path.empty()) { | 300 if (!config->storage_path.empty()) { |
| 301 base::FilePath filepath(config->storage_path); | 301 base::FilePath filepath(config->storage_path); |
| 302 filepath = filepath.Append(FILE_PATH_LITERAL("local_prefs.json")); | 302 filepath = filepath.Append(FILE_PATH_LITERAL("local_prefs.json")); |
| 303 json_pref_store_ = new JsonPrefStore( | 303 json_pref_store_ = new JsonPrefStore( |
| 304 filepath, GetFileThread()->task_runner(), scoped_ptr<PrefFilter>()); | 304 filepath, GetFileThread()->task_runner(), scoped_ptr<PrefFilter>()); |
| 305 context_builder.SetFileTaskRunner(GetFileThread()->task_runner()); | 305 context_builder.SetFileTaskRunner(GetFileThread()->task_runner()); |
| 306 | 306 |
| 307 // Set up HttpServerPropertiesManager. | 307 // Set up HttpServerPropertiesManager. |
| 308 base::PrefServiceFactory factory; | 308 base::PrefServiceFactory factory; |
| 309 factory.set_user_prefs(json_pref_store_); | 309 factory.set_user_prefs(json_pref_store_); |
| 310 scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple()); | 310 scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple()); |
| 311 registry->RegisterDictionaryPref(kHttpServerProperties, | 311 registry->RegisterDictionaryPref(kHttpServerProperties, |
| 312 new base::DictionaryValue()); | 312 new base::DictionaryValue()); |
| 313 pref_service_ = factory.Create(registry.get()).Pass(); | 313 pref_service_ = factory.Create(registry.get()); |
| 314 | 314 |
| 315 scoped_ptr<net::HttpServerPropertiesManager> http_server_properties_manager( | 315 scoped_ptr<net::HttpServerPropertiesManager> http_server_properties_manager( |
| 316 new net::HttpServerPropertiesManager(pref_service_.get(), | 316 new net::HttpServerPropertiesManager(pref_service_.get(), |
| 317 kHttpServerProperties, | 317 kHttpServerProperties, |
| 318 GetNetworkTaskRunner())); | 318 GetNetworkTaskRunner())); |
| 319 http_server_properties_manager->InitializeOnNetworkThread(); | 319 http_server_properties_manager->InitializeOnNetworkThread(); |
| 320 http_server_properties_manager_ = http_server_properties_manager.get(); | 320 http_server_properties_manager_ = http_server_properties_manager.get(); |
| 321 context_builder.SetHttpServerProperties( | 321 context_builder.SetHttpServerProperties( |
| 322 http_server_properties_manager.Pass()); | 322 std::move(http_server_properties_manager)); |
| 323 } | 323 } |
| 324 | 324 |
| 325 // Explicitly disable the persister for Cronet to avoid persistence of dynamic | 325 // Explicitly disable the persister for Cronet to avoid persistence of dynamic |
| 326 // HPKP. This is a safety measure ensuring that nobody enables the persistence | 326 // HPKP. This is a safety measure ensuring that nobody enables the persistence |
| 327 // of HPKP by specifying transport_security_persister_path in the future. | 327 // of HPKP by specifying transport_security_persister_path in the future. |
| 328 context_builder.set_transport_security_persister_path(base::FilePath()); | 328 context_builder.set_transport_security_persister_path(base::FilePath()); |
| 329 | 329 |
| 330 context_ = context_builder.Build().Pass(); | 330 context_ = context_builder.Build(); |
| 331 | 331 |
| 332 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | | 332 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | |
| 333 net::LOAD_DO_NOT_SEND_COOKIES; | 333 net::LOAD_DO_NOT_SEND_COOKIES; |
| 334 if (config->load_disable_cache) | 334 if (config->load_disable_cache) |
| 335 default_load_flags_ |= net::LOAD_DISABLE_CACHE; | 335 default_load_flags_ |= net::LOAD_DISABLE_CACHE; |
| 336 | 336 |
| 337 if (config->enable_sdch) { | 337 if (config->enable_sdch) { |
| 338 DCHECK(context_->sdch_manager()); | 338 DCHECK(context_->sdch_manager()); |
| 339 sdch_owner_.reset( | 339 sdch_owner_.reset( |
| 340 new net::SdchOwner(context_->sdch_manager(), context_.get())); | 340 new net::SdchOwner(context_->sdch_manager(), context_.get())); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 base::FilePath file_path(file_name); | 492 base::FilePath file_path(file_name); |
| 493 base::ScopedFILE file(base::OpenFile(file_path, "w")); | 493 base::ScopedFILE file(base::OpenFile(file_path, "w")); |
| 494 if (!file) | 494 if (!file) |
| 495 return; | 495 return; |
| 496 | 496 |
| 497 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver()); | 497 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver()); |
| 498 if (log_all) { | 498 if (log_all) { |
| 499 write_to_file_observer_->set_capture_mode( | 499 write_to_file_observer_->set_capture_mode( |
| 500 net::NetLogCaptureMode::IncludeSocketBytes()); | 500 net::NetLogCaptureMode::IncludeSocketBytes()); |
| 501 } | 501 } |
| 502 write_to_file_observer_->StartObserving(context_->net_log(), file.Pass(), | 502 write_to_file_observer_->StartObserving(context_->net_log(), std::move(file), |
| 503 nullptr, context_.get()); | 503 nullptr, context_.get()); |
| 504 } | 504 } |
| 505 | 505 |
| 506 void CronetURLRequestContextAdapter::StopNetLogOnNetworkThread() { | 506 void CronetURLRequestContextAdapter::StopNetLogOnNetworkThread() { |
| 507 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 507 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
| 508 if (write_to_file_observer_) { | 508 if (write_to_file_observer_) { |
| 509 write_to_file_observer_->StopObserving(context_.get()); | 509 write_to_file_observer_->StopObserving(context_.get()); |
| 510 write_to_file_observer_.reset(); | 510 write_to_file_observer_.reset(); |
| 511 } | 511 } |
| 512 } | 512 } |
| 513 | 513 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 | 634 |
| 635 // Creates RequestContextAdater if config is valid URLRequestContextConfig, | 635 // Creates RequestContextAdater if config is valid URLRequestContextConfig, |
| 636 // returns 0 otherwise. | 636 // returns 0 otherwise. |
| 637 static jlong CreateRequestContextAdapter(JNIEnv* env, | 637 static jlong CreateRequestContextAdapter(JNIEnv* env, |
| 638 const JavaParamRef<jclass>& jcaller, | 638 const JavaParamRef<jclass>& jcaller, |
| 639 jlong jconfig) { | 639 jlong jconfig) { |
| 640 scoped_ptr<URLRequestContextConfig> context_config( | 640 scoped_ptr<URLRequestContextConfig> context_config( |
| 641 reinterpret_cast<URLRequestContextConfig*>(jconfig)); | 641 reinterpret_cast<URLRequestContextConfig*>(jconfig)); |
| 642 | 642 |
| 643 CronetURLRequestContextAdapter* context_adapter = | 643 CronetURLRequestContextAdapter* context_adapter = |
| 644 new CronetURLRequestContextAdapter(context_config.Pass()); | 644 new CronetURLRequestContextAdapter(std::move(context_config)); |
| 645 return reinterpret_cast<jlong>(context_adapter); | 645 return reinterpret_cast<jlong>(context_adapter); |
| 646 } | 646 } |
| 647 | 647 |
| 648 static jint SetMinLogLevel(JNIEnv* env, | 648 static jint SetMinLogLevel(JNIEnv* env, |
| 649 const JavaParamRef<jclass>& jcaller, | 649 const JavaParamRef<jclass>& jcaller, |
| 650 jint jlog_level) { | 650 jint jlog_level) { |
| 651 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); | 651 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); |
| 652 // MinLogLevel is global, shared by all URLRequestContexts. | 652 // MinLogLevel is global, shared by all URLRequestContexts. |
| 653 logging::SetMinLogLevel(static_cast<int>(jlog_level)); | 653 logging::SetMinLogLevel(static_cast<int>(jlog_level)); |
| 654 return old_log_level; | 654 return old_log_level; |
| 655 } | 655 } |
| 656 | 656 |
| 657 static ScopedJavaLocalRef<jbyteArray> GetHistogramDeltas( | 657 static ScopedJavaLocalRef<jbyteArray> GetHistogramDeltas( |
| 658 JNIEnv* env, | 658 JNIEnv* env, |
| 659 const JavaParamRef<jclass>& jcaller) { | 659 const JavaParamRef<jclass>& jcaller) { |
| 660 base::StatisticsRecorder::Initialize(); | 660 base::StatisticsRecorder::Initialize(); |
| 661 std::vector<uint8_t> data; | 661 std::vector<uint8_t> data; |
| 662 if (!HistogramManager::GetInstance()->GetDeltas(&data)) | 662 if (!HistogramManager::GetInstance()->GetDeltas(&data)) |
| 663 return ScopedJavaLocalRef<jbyteArray>(); | 663 return ScopedJavaLocalRef<jbyteArray>(); |
| 664 return base::android::ToJavaByteArray(env, &data[0], data.size()); | 664 return base::android::ToJavaByteArray(env, &data[0], data.size()); |
| 665 } | 665 } |
| 666 | 666 |
| 667 } // namespace cronet | 667 } // namespace cronet |
| OLD | NEW |