| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/profiles/profile_io_data.h" | 5 #include "chrome/browser/profiles/profile_io_data.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 #include "net/http/http_util.h" | 64 #include "net/http/http_util.h" |
| 65 #include "net/http/transport_security_persister.h" | 65 #include "net/http/transport_security_persister.h" |
| 66 #include "net/proxy/proxy_config_service_fixed.h" | 66 #include "net/proxy/proxy_config_service_fixed.h" |
| 67 #include "net/proxy/proxy_script_fetcher_impl.h" | 67 #include "net/proxy/proxy_script_fetcher_impl.h" |
| 68 #include "net/proxy/proxy_service.h" | 68 #include "net/proxy/proxy_service.h" |
| 69 #include "net/ssl/client_cert_store.h" | 69 #include "net/ssl/client_cert_store.h" |
| 70 #include "net/ssl/server_bound_cert_service.h" | 70 #include "net/ssl/server_bound_cert_service.h" |
| 71 #include "net/url_request/data_protocol_handler.h" | 71 #include "net/url_request/data_protocol_handler.h" |
| 72 #include "net/url_request/file_protocol_handler.h" | 72 #include "net/url_request/file_protocol_handler.h" |
| 73 #include "net/url_request/ftp_protocol_handler.h" | 73 #include "net/url_request/ftp_protocol_handler.h" |
| 74 #include "net/url_request/protocol_intercept_job_factory.h" | |
| 75 #include "net/url_request/url_request.h" | 74 #include "net/url_request/url_request.h" |
| 76 #include "net/url_request/url_request_file_job.h" | 75 #include "net/url_request/url_request_file_job.h" |
| 76 #include "net/url_request/url_request_intercepting_job_factory.h" |
| 77 #include "net/url_request/url_request_interceptor.h" |
| 77 #include "net/url_request/url_request_job_factory_impl.h" | 78 #include "net/url_request/url_request_job_factory_impl.h" |
| 78 | 79 |
| 79 #if defined(ENABLE_CONFIGURATION_POLICY) | 80 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 80 #include "chrome/browser/policy/cloud/policy_header_service_factory.h" | 81 #include "chrome/browser/policy/cloud/policy_header_service_factory.h" |
| 81 #include "chrome/browser/policy/policy_helpers.h" | 82 #include "chrome/browser/policy/policy_helpers.h" |
| 82 #include "components/policy/core/browser/url_blacklist_manager.h" | 83 #include "components/policy/core/browser/url_blacklist_manager.h" |
| 83 #include "components/policy/core/common/cloud/policy_header_io_helper.h" | 84 #include "components/policy/core/common/cloud/policy_header_io_helper.h" |
| 84 #include "components/policy/core/common/cloud/policy_header_service.h" | 85 #include "components/policy/core/common/cloud/policy_header_service.h" |
| 85 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" | 86 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" |
| 86 #endif | 87 #endif |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 if (!PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) | 172 if (!PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) |
| 172 return false; | 173 return false; |
| 173 | 174 |
| 174 if (inspector_dir.empty()) | 175 if (inspector_dir.empty()) |
| 175 return false; | 176 return false; |
| 176 | 177 |
| 177 *path = inspector_dir.AppendASCII(relative_path); | 178 *path = inspector_dir.AppendASCII(relative_path); |
| 178 return true; | 179 return true; |
| 179 } | 180 } |
| 180 | 181 |
| 181 class DebugDevToolsInterceptor | 182 class DebugDevToolsInterceptor : public net::URLRequestInterceptor { |
| 182 : public net::URLRequestJobFactory::ProtocolHandler { | |
| 183 public: | 183 public: |
| 184 DebugDevToolsInterceptor() {} | 184 DebugDevToolsInterceptor() {} |
| 185 virtual ~DebugDevToolsInterceptor() {} | 185 virtual ~DebugDevToolsInterceptor() {} |
| 186 | 186 |
| 187 virtual net::URLRequestJob* MaybeCreateJob( | 187 // net::URLRequestInterceptor implementation. |
| 188 virtual net::URLRequestJob* MaybeInterceptRequest( |
| 188 net::URLRequest* request, | 189 net::URLRequest* request, |
| 189 net::NetworkDelegate* network_delegate) const OVERRIDE { | 190 net::NetworkDelegate* network_delegate) const OVERRIDE { |
| 190 base::FilePath path; | 191 base::FilePath path; |
| 191 if (IsSupportedDevToolsURL(request->url(), &path)) | 192 if (IsSupportedDevToolsURL(request->url(), &path)) |
| 192 return new net::URLRequestFileJob( | 193 return new net::URLRequestFileJob( |
| 193 request, network_delegate, path, | 194 request, network_delegate, path, |
| 194 content::BrowserThread::GetBlockingPool()-> | 195 content::BrowserThread::GetBlockingPool()-> |
| 195 GetTaskRunnerWithShutdownBehavior( | 196 GetTaskRunnerWithShutdownBehavior( |
| 196 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | 197 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 197 | 198 |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 DCHECK(initialized_); | 684 DCHECK(initialized_); |
| 684 return extensions_request_context_.get(); | 685 return extensions_request_context_.get(); |
| 685 } | 686 } |
| 686 | 687 |
| 687 ChromeURLRequestContext* ProfileIOData::GetIsolatedAppRequestContext( | 688 ChromeURLRequestContext* ProfileIOData::GetIsolatedAppRequestContext( |
| 688 ChromeURLRequestContext* main_context, | 689 ChromeURLRequestContext* main_context, |
| 689 const StoragePartitionDescriptor& partition_descriptor, | 690 const StoragePartitionDescriptor& partition_descriptor, |
| 690 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 691 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 691 protocol_handler_interceptor, | 692 protocol_handler_interceptor, |
| 692 content::ProtocolHandlerMap* protocol_handlers, | 693 content::ProtocolHandlerMap* protocol_handlers, |
| 693 content::ProtocolHandlerScopedVector protocol_interceptors) const { | 694 content::URLRequestInterceptorScopedVector request_interceptors) const { |
| 694 DCHECK(initialized_); | 695 DCHECK(initialized_); |
| 695 ChromeURLRequestContext* context = NULL; | 696 ChromeURLRequestContext* context = NULL; |
| 696 if (ContainsKey(app_request_context_map_, partition_descriptor)) { | 697 if (ContainsKey(app_request_context_map_, partition_descriptor)) { |
| 697 context = app_request_context_map_[partition_descriptor]; | 698 context = app_request_context_map_[partition_descriptor]; |
| 698 } else { | 699 } else { |
| 699 context = | 700 context = |
| 700 AcquireIsolatedAppRequestContext(main_context, | 701 AcquireIsolatedAppRequestContext(main_context, |
| 701 partition_descriptor, | 702 partition_descriptor, |
| 702 protocol_handler_interceptor.Pass(), | 703 protocol_handler_interceptor.Pass(), |
| 703 protocol_handlers, | 704 protocol_handlers, |
| 704 protocol_interceptors.Pass()); | 705 request_interceptors.Pass()); |
| 705 app_request_context_map_[partition_descriptor] = context; | 706 app_request_context_map_[partition_descriptor] = context; |
| 706 } | 707 } |
| 707 DCHECK(context); | 708 DCHECK(context); |
| 708 return context; | 709 return context; |
| 709 } | 710 } |
| 710 | 711 |
| 711 ChromeURLRequestContext* ProfileIOData::GetIsolatedMediaRequestContext( | 712 ChromeURLRequestContext* ProfileIOData::GetIsolatedMediaRequestContext( |
| 712 ChromeURLRequestContext* app_context, | 713 ChromeURLRequestContext* app_context, |
| 713 const StoragePartitionDescriptor& partition_descriptor) const { | 714 const StoragePartitionDescriptor& partition_descriptor) const { |
| 714 DCHECK(initialized_); | 715 DCHECK(initialized_); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 // The SSL session cache is partitioned by setting a string. This returns a | 903 // The SSL session cache is partitioned by setting a string. This returns a |
| 903 // unique string to partition the SSL session cache. Each time we create a | 904 // unique string to partition the SSL session cache. Each time we create a |
| 904 // new profile, we'll get a fresh SSL session cache which is separate from | 905 // new profile, we'll get a fresh SSL session cache which is separate from |
| 905 // the other profiles. | 906 // the other profiles. |
| 906 static unsigned ssl_session_cache_instance = 0; | 907 static unsigned ssl_session_cache_instance = 0; |
| 907 return base::StringPrintf("profile/%u", ssl_session_cache_instance++); | 908 return base::StringPrintf("profile/%u", ssl_session_cache_instance++); |
| 908 } | 909 } |
| 909 | 910 |
| 910 void ProfileIOData::Init( | 911 void ProfileIOData::Init( |
| 911 content::ProtocolHandlerMap* protocol_handlers, | 912 content::ProtocolHandlerMap* protocol_handlers, |
| 912 content::ProtocolHandlerScopedVector protocol_interceptors) const { | 913 content::URLRequestInterceptorScopedVector request_interceptors) const { |
| 913 // The basic logic is implemented here. The specific initialization | 914 // The basic logic is implemented here. The specific initialization |
| 914 // is done in InitializeInternal(), implemented by subtypes. Static helper | 915 // is done in InitializeInternal(), implemented by subtypes. Static helper |
| 915 // functions have been provided to assist in common operations. | 916 // functions have been provided to assist in common operations. |
| 916 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 917 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 917 DCHECK(!initialized_); | 918 DCHECK(!initialized_); |
| 918 | 919 |
| 919 startup_metric_utils::ScopedSlowStartupUMA | 920 startup_metric_utils::ScopedSlowStartupUMA |
| 920 scoped_timer("Startup.SlowStartupProfileIODataInit"); | 921 scoped_timer("Startup.SlowStartupProfileIODataInit"); |
| 921 | 922 |
| 922 // TODO(jhawkins): Remove once crbug.com/102004 is fixed. | 923 // TODO(jhawkins): Remove once crbug.com/102004 is fixed. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 } else { | 1002 } else { |
| 1002 main_request_context_->set_cert_verifier( | 1003 main_request_context_->set_cert_verifier( |
| 1003 new net::MultiThreadedCertVerifier(verify_proc.get())); | 1004 new net::MultiThreadedCertVerifier(verify_proc.get())); |
| 1004 } | 1005 } |
| 1005 #else | 1006 #else |
| 1006 main_request_context_->set_cert_verifier( | 1007 main_request_context_->set_cert_verifier( |
| 1007 io_thread_globals->cert_verifier.get()); | 1008 io_thread_globals->cert_verifier.get()); |
| 1008 #endif | 1009 #endif |
| 1009 | 1010 |
| 1010 InitializeInternal( | 1011 InitializeInternal( |
| 1011 profile_params_.get(), protocol_handlers, protocol_interceptors.Pass()); | 1012 profile_params_.get(), protocol_handlers, request_interceptors.Pass()); |
| 1012 | 1013 |
| 1013 profile_params_.reset(); | 1014 profile_params_.reset(); |
| 1014 initialized_ = true; | 1015 initialized_ = true; |
| 1015 } | 1016 } |
| 1016 | 1017 |
| 1017 void ProfileIOData::ApplyProfileParamsToContext( | 1018 void ProfileIOData::ApplyProfileParamsToContext( |
| 1018 ChromeURLRequestContext* context) const { | 1019 ChromeURLRequestContext* context) const { |
| 1019 context->set_http_user_agent_settings( | 1020 context->set_http_user_agent_settings( |
| 1020 chrome_http_user_agent_settings_.get()); | 1021 chrome_http_user_agent_settings_.get()); |
| 1021 context->set_ssl_config_service(profile_params_->ssl_config_service.get()); | 1022 context->set_ssl_config_service(profile_params_->ssl_config_service.get()); |
| 1022 } | 1023 } |
| 1023 | 1024 |
| 1024 scoped_ptr<net::URLRequestJobFactory> ProfileIOData::SetUpJobFactoryDefaults( | 1025 scoped_ptr<net::URLRequestJobFactory> ProfileIOData::SetUpJobFactoryDefaults( |
| 1025 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory, | 1026 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory, |
| 1026 content::ProtocolHandlerScopedVector protocol_interceptors, | 1027 content::URLRequestInterceptorScopedVector request_interceptors, |
| 1027 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 1028 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 1028 protocol_handler_interceptor, | 1029 protocol_handler_interceptor, |
| 1029 net::NetworkDelegate* network_delegate, | 1030 net::NetworkDelegate* network_delegate, |
| 1030 net::FtpTransactionFactory* ftp_transaction_factory) const { | 1031 net::FtpTransactionFactory* ftp_transaction_factory) const { |
| 1031 // NOTE(willchan): Keep these protocol handlers in sync with | 1032 // NOTE(willchan): Keep these protocol handlers in sync with |
| 1032 // ProfileIOData::IsHandledProtocol(). | 1033 // ProfileIOData::IsHandledProtocol(). |
| 1033 bool set_protocol = job_factory->SetProtocolHandler( | 1034 bool set_protocol = job_factory->SetProtocolHandler( |
| 1034 content::kFileScheme, | 1035 content::kFileScheme, |
| 1035 new net::FileProtocolHandler( | 1036 new net::FileProtocolHandler( |
| 1036 content::BrowserThread::GetBlockingPool()-> | 1037 content::BrowserThread::GetBlockingPool()-> |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1065 job_factory->SetProtocolHandler( | 1066 job_factory->SetProtocolHandler( |
| 1066 content::kAboutScheme, new chrome_browser_net::AboutProtocolHandler()); | 1067 content::kAboutScheme, new chrome_browser_net::AboutProtocolHandler()); |
| 1067 #if !defined(DISABLE_FTP_SUPPORT) | 1068 #if !defined(DISABLE_FTP_SUPPORT) |
| 1068 DCHECK(ftp_transaction_factory); | 1069 DCHECK(ftp_transaction_factory); |
| 1069 job_factory->SetProtocolHandler( | 1070 job_factory->SetProtocolHandler( |
| 1070 content::kFtpScheme, | 1071 content::kFtpScheme, |
| 1071 new net::FtpProtocolHandler(ftp_transaction_factory)); | 1072 new net::FtpProtocolHandler(ftp_transaction_factory)); |
| 1072 #endif // !defined(DISABLE_FTP_SUPPORT) | 1073 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 1073 | 1074 |
| 1074 #if defined(DEBUG_DEVTOOLS) | 1075 #if defined(DEBUG_DEVTOOLS) |
| 1075 protocol_interceptors.push_back(new DebugDevToolsInterceptor); | 1076 request_interceptors.push_back(new DebugDevToolsInterceptor); |
| 1076 #endif | 1077 #endif |
| 1077 | 1078 |
| 1078 // Set up interceptors in the reverse order. | 1079 // Set up interceptors in the reverse order. |
| 1079 scoped_ptr<net::URLRequestJobFactory> top_job_factory = | 1080 scoped_ptr<net::URLRequestJobFactory> top_job_factory = |
| 1080 job_factory.PassAs<net::URLRequestJobFactory>(); | 1081 job_factory.PassAs<net::URLRequestJobFactory>(); |
| 1081 for (content::ProtocolHandlerScopedVector::reverse_iterator i = | 1082 for (content::URLRequestInterceptorScopedVector::reverse_iterator i = |
| 1082 protocol_interceptors.rbegin(); | 1083 request_interceptors.rbegin(); |
| 1083 i != protocol_interceptors.rend(); | 1084 i != request_interceptors.rend(); |
| 1084 ++i) { | 1085 ++i) { |
| 1085 top_job_factory.reset(new net::ProtocolInterceptJobFactory( | 1086 top_job_factory.reset(new net::URLRequestInterceptingJobFactory( |
| 1086 top_job_factory.Pass(), make_scoped_ptr(*i))); | 1087 top_job_factory.Pass(), make_scoped_ptr(*i))); |
| 1087 } | 1088 } |
| 1088 protocol_interceptors.weak_clear(); | 1089 request_interceptors.weak_clear(); |
| 1089 | 1090 |
| 1090 if (protocol_handler_interceptor) { | 1091 if (protocol_handler_interceptor) { |
| 1091 protocol_handler_interceptor->Chain(top_job_factory.Pass()); | 1092 protocol_handler_interceptor->Chain(top_job_factory.Pass()); |
| 1092 return protocol_handler_interceptor.PassAs<net::URLRequestJobFactory>(); | 1093 return protocol_handler_interceptor.PassAs<net::URLRequestJobFactory>(); |
| 1093 } else { | 1094 } else { |
| 1094 return top_job_factory.Pass(); | 1095 return top_job_factory.Pass(); |
| 1095 } | 1096 } |
| 1096 } | 1097 } |
| 1097 | 1098 |
| 1098 void ProfileIOData::ShutdownOnUIThread() { | 1099 void ProfileIOData::ShutdownOnUIThread() { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1169 void ProfileIOData::SetCookieSettingsForTesting( | 1170 void ProfileIOData::SetCookieSettingsForTesting( |
| 1170 CookieSettings* cookie_settings) { | 1171 CookieSettings* cookie_settings) { |
| 1171 DCHECK(!cookie_settings_.get()); | 1172 DCHECK(!cookie_settings_.get()); |
| 1172 cookie_settings_ = cookie_settings; | 1173 cookie_settings_ = cookie_settings; |
| 1173 } | 1174 } |
| 1174 | 1175 |
| 1175 void ProfileIOData::set_signin_names_for_testing( | 1176 void ProfileIOData::set_signin_names_for_testing( |
| 1176 SigninNamesOnIOThread* signin_names) { | 1177 SigninNamesOnIOThread* signin_names) { |
| 1177 signin_names_.reset(signin_names); | 1178 signin_names_.reset(signin_names); |
| 1178 } | 1179 } |
| OLD | NEW |