| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_impl_io_data.h" | 5 #include "chrome/browser/profiles/profile_impl_io_data.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/io_thread.h" | 12 #include "chrome/browser/io_thread.h" |
| 13 #include "chrome/browser/net/chrome_cookie_policy.h" | 13 #include "chrome/browser/net/chrome_cookie_policy.h" |
| 14 #include "chrome/browser/net/chrome_dns_cert_provenance_checker_factory.h" | 14 #include "chrome/browser/net/chrome_dns_cert_provenance_checker_factory.h" |
| 15 #include "chrome/browser/net/chrome_net_log.h" | 15 #include "chrome/browser/net/chrome_net_log.h" |
| 16 #include "chrome/browser/net/chrome_network_delegate.h" | 16 #include "chrome/browser/net/chrome_network_delegate.h" |
| 17 #include "chrome/browser/net/proxy_service_factory.h" | 17 #include "chrome/browser/net/proxy_service_factory.h" |
| 18 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" | 18 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" |
| 19 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
| 20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 23 #include "content/browser/browser_thread.h" | 23 #include "content/browser/browser_thread.h" |
| 24 #include "content/browser/resource_context.h" |
| 24 #include "net/ftp/ftp_network_layer.h" | 25 #include "net/ftp/ftp_network_layer.h" |
| 25 #include "net/http/http_cache.h" | 26 #include "net/http/http_cache.h" |
| 26 | 27 |
| 27 ProfileImplIOData::Handle::Handle(Profile* profile) | 28 ProfileImplIOData::Handle::Handle(Profile* profile) |
| 28 : io_data_(new ProfileImplIOData), | 29 : io_data_(new ProfileImplIOData), |
| 29 profile_(profile), | 30 profile_(profile), |
| 30 initialized_(false) { | 31 initialized_(false) { |
| 31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 32 DCHECK(profile); | 33 DCHECK(profile); |
| 33 } | 34 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 lazy_params->extensions_cookie_path = extensions_cookie_path; | 72 lazy_params->extensions_cookie_path = extensions_cookie_path; |
| 72 | 73 |
| 73 lazy_params->io_thread = g_browser_process->io_thread(); | 74 lazy_params->io_thread = g_browser_process->io_thread(); |
| 74 | 75 |
| 75 io_data_->lazy_params_.reset(lazy_params); | 76 io_data_->lazy_params_.reset(lazy_params); |
| 76 | 77 |
| 77 // Keep track of isolated app path separately so we can use it on demand. | 78 // Keep track of isolated app path separately so we can use it on demand. |
| 78 io_data_->app_path_ = app_path; | 79 io_data_->app_path_ = app_path; |
| 79 } | 80 } |
| 80 | 81 |
| 82 const content::ResourceContext& |
| 83 ProfileImplIOData::Handle::GetResourceContext() const { |
| 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 85 LazyInitialize(); |
| 86 return io_data_->GetResourceContext(); |
| 87 } |
| 88 |
| 81 scoped_refptr<ChromeURLRequestContextGetter> | 89 scoped_refptr<ChromeURLRequestContextGetter> |
| 82 ProfileImplIOData::Handle::GetMainRequestContextGetter() const { | 90 ProfileImplIOData::Handle::GetMainRequestContextGetter() const { |
| 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 84 LazyInitialize(); | 92 LazyInitialize(); |
| 85 if (!main_request_context_getter_) { | 93 if (!main_request_context_getter_) { |
| 86 main_request_context_getter_ = | 94 main_request_context_getter_ = |
| 87 ChromeURLRequestContextGetter::CreateOriginal( | 95 ChromeURLRequestContextGetter::CreateOriginal( |
| 88 profile_, io_data_); | 96 profile_, io_data_); |
| 89 } | 97 } |
| 90 return main_request_context_getter_; | 98 return main_request_context_getter_; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 ChromeURLRequestContextGetter* context = | 138 ChromeURLRequestContextGetter* context = |
| 131 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( | 139 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( |
| 132 profile_, io_data_, app_id); | 140 profile_, io_data_, app_id); |
| 133 app_request_context_getter_map_[app_id] = context; | 141 app_request_context_getter_map_[app_id] = context; |
| 134 | 142 |
| 135 return context; | 143 return context; |
| 136 } | 144 } |
| 137 | 145 |
| 138 void ProfileImplIOData::Handle::LazyInitialize() const { | 146 void ProfileImplIOData::Handle::LazyInitialize() const { |
| 139 if (!initialized_) { | 147 if (!initialized_) { |
| 140 InitializeProfileParams(profile_, &io_data_->lazy_params_->profile_params); | 148 io_data_->InitializeProfileParams(profile_); |
| 141 // Keep track of clear_local_state_on_exit for isolated apps. | |
| 142 io_data_->clear_local_state_on_exit_ = | |
| 143 io_data_->lazy_params_->profile_params.clear_local_state_on_exit; | |
| 144 ChromeNetworkDelegate::InitializeReferrersEnabled( | 149 ChromeNetworkDelegate::InitializeReferrersEnabled( |
| 145 io_data_->enable_referrers(), profile_->GetPrefs()); | 150 io_data_->enable_referrers(), profile_->GetPrefs()); |
| 146 initialized_ = true; | 151 initialized_ = true; |
| 147 } | 152 } |
| 148 } | 153 } |
| 149 | 154 |
| 150 ProfileImplIOData::LazyParams::LazyParams() | 155 ProfileImplIOData::LazyParams::LazyParams() |
| 151 : cache_max_size(0), | 156 : cache_max_size(0), |
| 152 media_cache_max_size(0), | 157 media_cache_max_size(0), |
| 153 io_thread(NULL) {} | 158 io_thread(NULL) {} |
| 154 ProfileImplIOData::LazyParams::~LazyParams() {} | 159 ProfileImplIOData::LazyParams::~LazyParams() {} |
| 155 | 160 |
| 156 ProfileImplIOData::ProfileImplIOData() | 161 ProfileImplIOData::ProfileImplIOData() |
| 157 : ProfileIOData(false), | 162 : ProfileIOData(false), |
| 158 clear_local_state_on_exit_(false) {} | 163 clear_local_state_on_exit_(false) {} |
| 159 ProfileImplIOData::~ProfileImplIOData() { | 164 ProfileImplIOData::~ProfileImplIOData() { |
| 160 STLDeleteValues(&app_http_factory_map_); | 165 STLDeleteValues(&app_http_factory_map_); |
| 161 } | 166 } |
| 162 | 167 |
| 163 void ProfileImplIOData::LazyInitializeInternal() const { | 168 void ProfileImplIOData::LazyInitializeInternal( |
| 169 ProfileParams* profile_params) const { |
| 170 // Keep track of clear_local_state_on_exit for isolated apps. |
| 171 clear_local_state_on_exit_ = profile_params->clear_local_state_on_exit; |
| 172 |
| 164 main_request_context_ = new RequestContext; | 173 main_request_context_ = new RequestContext; |
| 165 media_request_context_ = new RequestContext; | 174 media_request_context_ = new RequestContext; |
| 166 extensions_request_context_ = new RequestContext; | 175 extensions_request_context_ = new RequestContext; |
| 167 | 176 |
| 168 IOThread* const io_thread = lazy_params_->io_thread; | 177 IOThread* const io_thread = lazy_params_->io_thread; |
| 169 IOThread::Globals* const io_thread_globals = io_thread->globals(); | 178 IOThread::Globals* const io_thread_globals = io_thread->globals(); |
| 170 const ProfileParams& profile_params = lazy_params_->profile_params; | |
| 171 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 179 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 172 bool record_mode = chrome::kRecordModeEnabled && | 180 bool record_mode = chrome::kRecordModeEnabled && |
| 173 command_line.HasSwitch(switches::kRecordMode); | 181 command_line.HasSwitch(switches::kRecordMode); |
| 174 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); | 182 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); |
| 175 | 183 |
| 176 // Initialize context members. | 184 // Initialize context members. |
| 177 | 185 |
| 178 ApplyProfileParamsToContext(profile_params, main_request_context_); | 186 ApplyProfileParamsToContext(main_request_context_); |
| 179 ApplyProfileParamsToContext(profile_params, media_request_context_); | 187 ApplyProfileParamsToContext(media_request_context_); |
| 180 ApplyProfileParamsToContext(profile_params, extensions_request_context_); | 188 ApplyProfileParamsToContext(extensions_request_context_); |
| 181 profile_params.appcache_service->set_request_context(main_request_context_); | 189 profile_params->appcache_service->set_request_context(main_request_context_); |
| 182 | 190 |
| 183 cookie_policy_.reset( | 191 cookie_policy_.reset( |
| 184 new ChromeCookiePolicy(profile_params.host_content_settings_map)); | 192 new ChromeCookiePolicy(profile_params->host_content_settings_map)); |
| 185 main_request_context_->set_cookie_policy(cookie_policy_.get()); | 193 main_request_context_->set_cookie_policy(cookie_policy_.get()); |
| 186 media_request_context_->set_cookie_policy(cookie_policy_.get()); | 194 media_request_context_->set_cookie_policy(cookie_policy_.get()); |
| 187 extensions_request_context_->set_cookie_policy(cookie_policy_.get()); | 195 extensions_request_context_->set_cookie_policy(cookie_policy_.get()); |
| 188 | 196 |
| 189 main_request_context_->set_net_log(lazy_params_->io_thread->net_log()); | 197 main_request_context_->set_net_log(lazy_params_->io_thread->net_log()); |
| 190 media_request_context_->set_net_log(lazy_params_->io_thread->net_log()); | 198 media_request_context_->set_net_log(lazy_params_->io_thread->net_log()); |
| 191 extensions_request_context_->set_net_log(lazy_params_->io_thread->net_log()); | 199 extensions_request_context_->set_net_log(lazy_params_->io_thread->net_log()); |
| 192 | 200 |
| 193 network_delegate_.reset(new ChromeNetworkDelegate( | 201 network_delegate_.reset(new ChromeNetworkDelegate( |
| 194 io_thread_globals->extension_event_router_forwarder.get(), | 202 io_thread_globals->extension_event_router_forwarder.get(), |
| 195 profile_params.profile_id, | 203 profile_params->profile_id, |
| 196 enable_referrers(), | 204 enable_referrers(), |
| 197 profile_params.protocol_handler_registry)); | 205 profile_params->protocol_handler_registry)); |
| 198 main_request_context_->set_network_delegate(network_delegate_.get()); | 206 main_request_context_->set_network_delegate(network_delegate_.get()); |
| 199 media_request_context_->set_network_delegate(network_delegate_.get()); | 207 media_request_context_->set_network_delegate(network_delegate_.get()); |
| 200 | 208 |
| 201 main_request_context_->set_host_resolver( | 209 main_request_context_->set_host_resolver( |
| 202 io_thread_globals->host_resolver.get()); | 210 io_thread_globals->host_resolver.get()); |
| 203 media_request_context_->set_host_resolver( | 211 media_request_context_->set_host_resolver( |
| 204 io_thread_globals->host_resolver.get()); | 212 io_thread_globals->host_resolver.get()); |
| 205 main_request_context_->set_cert_verifier( | 213 main_request_context_->set_cert_verifier( |
| 206 io_thread_globals->cert_verifier.get()); | 214 io_thread_globals->cert_verifier.get()); |
| 207 media_request_context_->set_cert_verifier( | 215 media_request_context_->set_cert_verifier( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 218 dns_cert_checker_.reset( | 226 dns_cert_checker_.reset( |
| 219 CreateDnsCertProvenanceChecker(io_thread_globals->dnsrr_resolver.get(), | 227 CreateDnsCertProvenanceChecker(io_thread_globals->dnsrr_resolver.get(), |
| 220 main_request_context_)); | 228 main_request_context_)); |
| 221 main_request_context_->set_dns_cert_checker(dns_cert_checker_.get()); | 229 main_request_context_->set_dns_cert_checker(dns_cert_checker_.get()); |
| 222 media_request_context_->set_dns_cert_checker(dns_cert_checker_.get()); | 230 media_request_context_->set_dns_cert_checker(dns_cert_checker_.get()); |
| 223 | 231 |
| 224 net::ProxyService* proxy_service = | 232 net::ProxyService* proxy_service = |
| 225 ProxyServiceFactory::CreateProxyService( | 233 ProxyServiceFactory::CreateProxyService( |
| 226 io_thread->net_log(), | 234 io_thread->net_log(), |
| 227 io_thread_globals->proxy_script_fetcher_context.get(), | 235 io_thread_globals->proxy_script_fetcher_context.get(), |
| 228 lazy_params_->profile_params.proxy_config_service.release(), | 236 profile_params->proxy_config_service.release(), |
| 229 command_line); | 237 command_line); |
| 230 main_request_context_->set_proxy_service(proxy_service); | 238 main_request_context_->set_proxy_service(proxy_service); |
| 231 media_request_context_->set_proxy_service(proxy_service); | 239 media_request_context_->set_proxy_service(proxy_service); |
| 232 | 240 |
| 233 net::HttpCache::DefaultBackend* main_backend = | 241 net::HttpCache::DefaultBackend* main_backend = |
| 234 new net::HttpCache::DefaultBackend( | 242 new net::HttpCache::DefaultBackend( |
| 235 net::DISK_CACHE, | 243 net::DISK_CACHE, |
| 236 lazy_params_->cache_path, | 244 lazy_params_->cache_path, |
| 237 lazy_params_->cache_max_size, | 245 lazy_params_->cache_max_size, |
| 238 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | 246 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 254 lazy_params_->media_cache_max_size, | 262 lazy_params_->media_cache_max_size, |
| 255 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | 263 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
| 256 net::HttpNetworkSession* main_network_session = main_cache->GetSession(); | 264 net::HttpNetworkSession* main_network_session = main_cache->GetSession(); |
| 257 net::HttpCache* media_cache = | 265 net::HttpCache* media_cache = |
| 258 new net::HttpCache(main_network_session, media_backend); | 266 new net::HttpCache(main_network_session, media_backend); |
| 259 | 267 |
| 260 scoped_refptr<net::CookieStore> cookie_store = NULL; | 268 scoped_refptr<net::CookieStore> cookie_store = NULL; |
| 261 if (record_mode || playback_mode) { | 269 if (record_mode || playback_mode) { |
| 262 // Don't use existing cookies and use an in-memory store. | 270 // Don't use existing cookies and use an in-memory store. |
| 263 cookie_store = new net::CookieMonster( | 271 cookie_store = new net::CookieMonster( |
| 264 NULL, profile_params.cookie_monster_delegate); | 272 NULL, profile_params->cookie_monster_delegate); |
| 265 main_cache->set_mode( | 273 main_cache->set_mode( |
| 266 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); | 274 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); |
| 267 } | 275 } |
| 268 | 276 |
| 269 // setup cookie store | 277 // setup cookie store |
| 270 if (!cookie_store) { | 278 if (!cookie_store) { |
| 271 DCHECK(!lazy_params_->cookie_path.empty()); | 279 DCHECK(!lazy_params_->cookie_path.empty()); |
| 272 | 280 |
| 273 scoped_refptr<SQLitePersistentCookieStore> cookie_db = | 281 scoped_refptr<SQLitePersistentCookieStore> cookie_db = |
| 274 new SQLitePersistentCookieStore(lazy_params_->cookie_path); | 282 new SQLitePersistentCookieStore(lazy_params_->cookie_path); |
| 275 cookie_db->SetClearLocalStateOnExit( | 283 cookie_db->SetClearLocalStateOnExit( |
| 276 profile_params.clear_local_state_on_exit); | 284 profile_params->clear_local_state_on_exit); |
| 277 cookie_store = | 285 cookie_store = |
| 278 new net::CookieMonster(cookie_db.get(), | 286 new net::CookieMonster(cookie_db.get(), |
| 279 profile_params.cookie_monster_delegate); | 287 profile_params->cookie_monster_delegate); |
| 280 } | 288 } |
| 281 | 289 |
| 282 net::CookieMonster* extensions_cookie_store = | 290 net::CookieMonster* extensions_cookie_store = |
| 283 new net::CookieMonster( | 291 new net::CookieMonster( |
| 284 new SQLitePersistentCookieStore( | 292 new SQLitePersistentCookieStore( |
| 285 lazy_params_->extensions_cookie_path), NULL); | 293 lazy_params_->extensions_cookie_path), NULL); |
| 286 // Enable cookies for devtools and extension URLs. | 294 // Enable cookies for devtools and extension URLs. |
| 287 const char* schemes[] = {chrome::kChromeDevToolsScheme, | 295 const char* schemes[] = {chrome::kChromeDevToolsScheme, |
| 288 chrome::kExtensionScheme}; | 296 chrome::kExtensionScheme}; |
| 289 extensions_cookie_store->SetCookieableSchemes(schemes, 2); | 297 extensions_cookie_store->SetCookieableSchemes(schemes, 2); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 ProfileImplIOData::AcquireIsolatedAppRequestContext( | 409 ProfileImplIOData::AcquireIsolatedAppRequestContext( |
| 402 scoped_refptr<ChromeURLRequestContext> main_context, | 410 scoped_refptr<ChromeURLRequestContext> main_context, |
| 403 const std::string& app_id) const { | 411 const std::string& app_id) const { |
| 404 // We create per-app contexts on demand, unlike the others above. | 412 // We create per-app contexts on demand, unlike the others above. |
| 405 scoped_refptr<RequestContext> app_request_context = | 413 scoped_refptr<RequestContext> app_request_context = |
| 406 InitializeAppRequestContext(main_context, app_id); | 414 InitializeAppRequestContext(main_context, app_id); |
| 407 DCHECK(app_request_context); | 415 DCHECK(app_request_context); |
| 408 app_request_context->set_profile_io_data(this); | 416 app_request_context->set_profile_io_data(this); |
| 409 return app_request_context; | 417 return app_request_context; |
| 410 } | 418 } |
| OLD | NEW |