| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 lazy_params->extensions_cookie_path = extensions_cookie_path; | 70 lazy_params->extensions_cookie_path = extensions_cookie_path; |
| 70 | 71 |
| 71 lazy_params->io_thread = g_browser_process->io_thread(); | 72 lazy_params->io_thread = g_browser_process->io_thread(); |
| 72 | 73 |
| 73 io_data_->lazy_params_.reset(lazy_params); | 74 io_data_->lazy_params_.reset(lazy_params); |
| 74 | 75 |
| 75 // Keep track of isolated app path separately so we can use it on demand. | 76 // Keep track of isolated app path separately so we can use it on demand. |
| 76 io_data_->app_path_ = app_path; | 77 io_data_->app_path_ = app_path; |
| 77 } | 78 } |
| 78 | 79 |
| 80 const content::ResourceContext& |
| 81 ProfileImplIOData::Handle::GetResourceContext() const { |
| 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 83 LazyInitialize(); |
| 84 return io_data_->GetResourceContext(); |
| 85 } |
| 86 |
| 79 scoped_refptr<ChromeURLRequestContextGetter> | 87 scoped_refptr<ChromeURLRequestContextGetter> |
| 80 ProfileImplIOData::Handle::GetMainRequestContextGetter() const { | 88 ProfileImplIOData::Handle::GetMainRequestContextGetter() const { |
| 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 82 LazyInitialize(); | 90 LazyInitialize(); |
| 83 if (!main_request_context_getter_) { | 91 if (!main_request_context_getter_) { |
| 84 main_request_context_getter_ = | 92 main_request_context_getter_ = |
| 85 ChromeURLRequestContextGetter::CreateOriginal( | 93 ChromeURLRequestContextGetter::CreateOriginal( |
| 86 profile_, io_data_); | 94 profile_, io_data_); |
| 87 } | 95 } |
| 88 return main_request_context_getter_; | 96 return main_request_context_getter_; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 ChromeURLRequestContextGetter* context = | 136 ChromeURLRequestContextGetter* context = |
| 129 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( | 137 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( |
| 130 profile_, io_data_, app_id); | 138 profile_, io_data_, app_id); |
| 131 app_request_context_getter_map_[app_id] = context; | 139 app_request_context_getter_map_[app_id] = context; |
| 132 | 140 |
| 133 return context; | 141 return context; |
| 134 } | 142 } |
| 135 | 143 |
| 136 void ProfileImplIOData::Handle::LazyInitialize() const { | 144 void ProfileImplIOData::Handle::LazyInitialize() const { |
| 137 if (!initialized_) { | 145 if (!initialized_) { |
| 138 InitializeProfileParams(profile_, &io_data_->lazy_params_->profile_params); | 146 io_data_->InitializeProfileParams(profile_); |
| 139 // Keep track of clear_local_state_on_exit for isolated apps. | |
| 140 io_data_->clear_local_state_on_exit_ = | |
| 141 io_data_->lazy_params_->profile_params.clear_local_state_on_exit; | |
| 142 initialized_ = true; | 147 initialized_ = true; |
| 143 } | 148 } |
| 144 } | 149 } |
| 145 | 150 |
| 146 ProfileImplIOData::LazyParams::LazyParams() | 151 ProfileImplIOData::LazyParams::LazyParams() |
| 147 : cache_max_size(0), | 152 : cache_max_size(0), |
| 148 media_cache_max_size(0), | 153 media_cache_max_size(0), |
| 149 io_thread(NULL) {} | 154 io_thread(NULL) {} |
| 150 ProfileImplIOData::LazyParams::~LazyParams() {} | 155 ProfileImplIOData::LazyParams::~LazyParams() {} |
| 151 | 156 |
| 152 ProfileImplIOData::ProfileImplIOData() | 157 ProfileImplIOData::ProfileImplIOData() |
| 153 : ProfileIOData(false), | 158 : ProfileIOData(false), |
| 154 clear_local_state_on_exit_(false) {} | 159 clear_local_state_on_exit_(false) {} |
| 155 ProfileImplIOData::~ProfileImplIOData() { | 160 ProfileImplIOData::~ProfileImplIOData() { |
| 156 STLDeleteValues(&app_http_factory_map_); | 161 STLDeleteValues(&app_http_factory_map_); |
| 157 } | 162 } |
| 158 | 163 |
| 159 void ProfileImplIOData::LazyInitializeInternal() const { | 164 void ProfileImplIOData::LazyInitializeInternal( |
| 165 ProfileParams* profile_params) const { |
| 166 // Keep track of clear_local_state_on_exit for isolated apps. |
| 167 clear_local_state_on_exit_ = profile_params->clear_local_state_on_exit; |
| 168 |
| 160 main_request_context_ = new RequestContext; | 169 main_request_context_ = new RequestContext; |
| 161 media_request_context_ = new RequestContext; | 170 media_request_context_ = new RequestContext; |
| 162 extensions_request_context_ = new RequestContext; | 171 extensions_request_context_ = new RequestContext; |
| 163 | 172 |
| 164 IOThread* const io_thread = lazy_params_->io_thread; | 173 IOThread* const io_thread = lazy_params_->io_thread; |
| 165 IOThread::Globals* const io_thread_globals = io_thread->globals(); | 174 IOThread::Globals* const io_thread_globals = io_thread->globals(); |
| 166 const ProfileParams& profile_params = lazy_params_->profile_params; | |
| 167 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 175 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 168 bool record_mode = chrome::kRecordModeEnabled && | 176 bool record_mode = chrome::kRecordModeEnabled && |
| 169 command_line.HasSwitch(switches::kRecordMode); | 177 command_line.HasSwitch(switches::kRecordMode); |
| 170 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); | 178 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); |
| 171 | 179 |
| 172 // Initialize context members. | 180 // Initialize context members. |
| 173 | 181 |
| 174 ApplyProfileParamsToContext(profile_params, main_request_context_); | 182 ApplyProfileParamsToContext(main_request_context_); |
| 175 ApplyProfileParamsToContext(profile_params, media_request_context_); | 183 ApplyProfileParamsToContext(media_request_context_); |
| 176 ApplyProfileParamsToContext(profile_params, extensions_request_context_); | 184 ApplyProfileParamsToContext(extensions_request_context_); |
| 177 profile_params.appcache_service->set_request_context(main_request_context_); | 185 profile_params->appcache_service->set_request_context(main_request_context_); |
| 178 | 186 |
| 179 cookie_policy_.reset( | 187 cookie_policy_.reset( |
| 180 new ChromeCookiePolicy(profile_params.host_content_settings_map)); | 188 new ChromeCookiePolicy(profile_params->host_content_settings_map)); |
| 181 main_request_context_->set_cookie_policy(cookie_policy_.get()); | 189 main_request_context_->set_cookie_policy(cookie_policy_.get()); |
| 182 media_request_context_->set_cookie_policy(cookie_policy_.get()); | 190 media_request_context_->set_cookie_policy(cookie_policy_.get()); |
| 183 extensions_request_context_->set_cookie_policy(cookie_policy_.get()); | 191 extensions_request_context_->set_cookie_policy(cookie_policy_.get()); |
| 184 | 192 |
| 185 main_request_context_->set_net_log(lazy_params_->io_thread->net_log()); | 193 main_request_context_->set_net_log(lazy_params_->io_thread->net_log()); |
| 186 media_request_context_->set_net_log(lazy_params_->io_thread->net_log()); | 194 media_request_context_->set_net_log(lazy_params_->io_thread->net_log()); |
| 187 extensions_request_context_->set_net_log(lazy_params_->io_thread->net_log()); | 195 extensions_request_context_->set_net_log(lazy_params_->io_thread->net_log()); |
| 188 | 196 |
| 189 network_delegate_.reset(new ChromeNetworkDelegate( | 197 network_delegate_.reset(new ChromeNetworkDelegate( |
| 190 io_thread_globals->extension_event_router_forwarder.get(), | 198 io_thread_globals->extension_event_router_forwarder.get(), |
| 191 profile_params.profile_id, | 199 profile_params->profile_id, |
| 192 profile_params.protocol_handler_registry)); | 200 profile_params->protocol_handler_registry)); |
| 193 main_request_context_->set_network_delegate(network_delegate_.get()); | 201 main_request_context_->set_network_delegate(network_delegate_.get()); |
| 194 media_request_context_->set_network_delegate(network_delegate_.get()); | 202 media_request_context_->set_network_delegate(network_delegate_.get()); |
| 195 | 203 |
| 196 main_request_context_->set_host_resolver( | 204 main_request_context_->set_host_resolver( |
| 197 io_thread_globals->host_resolver.get()); | 205 io_thread_globals->host_resolver.get()); |
| 198 media_request_context_->set_host_resolver( | 206 media_request_context_->set_host_resolver( |
| 199 io_thread_globals->host_resolver.get()); | 207 io_thread_globals->host_resolver.get()); |
| 200 main_request_context_->set_cert_verifier( | 208 main_request_context_->set_cert_verifier( |
| 201 io_thread_globals->cert_verifier.get()); | 209 io_thread_globals->cert_verifier.get()); |
| 202 media_request_context_->set_cert_verifier( | 210 media_request_context_->set_cert_verifier( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 213 dns_cert_checker_.reset( | 221 dns_cert_checker_.reset( |
| 214 CreateDnsCertProvenanceChecker(io_thread_globals->dnsrr_resolver.get(), | 222 CreateDnsCertProvenanceChecker(io_thread_globals->dnsrr_resolver.get(), |
| 215 main_request_context_)); | 223 main_request_context_)); |
| 216 main_request_context_->set_dns_cert_checker(dns_cert_checker_.get()); | 224 main_request_context_->set_dns_cert_checker(dns_cert_checker_.get()); |
| 217 media_request_context_->set_dns_cert_checker(dns_cert_checker_.get()); | 225 media_request_context_->set_dns_cert_checker(dns_cert_checker_.get()); |
| 218 | 226 |
| 219 net::ProxyService* proxy_service = | 227 net::ProxyService* proxy_service = |
| 220 ProxyServiceFactory::CreateProxyService( | 228 ProxyServiceFactory::CreateProxyService( |
| 221 io_thread->net_log(), | 229 io_thread->net_log(), |
| 222 io_thread_globals->proxy_script_fetcher_context.get(), | 230 io_thread_globals->proxy_script_fetcher_context.get(), |
| 223 lazy_params_->profile_params.proxy_config_service.release(), | 231 profile_params->proxy_config_service.release(), |
| 224 command_line); | 232 command_line); |
| 225 main_request_context_->set_proxy_service(proxy_service); | 233 main_request_context_->set_proxy_service(proxy_service); |
| 226 media_request_context_->set_proxy_service(proxy_service); | 234 media_request_context_->set_proxy_service(proxy_service); |
| 227 | 235 |
| 228 net::HttpCache::DefaultBackend* main_backend = | 236 net::HttpCache::DefaultBackend* main_backend = |
| 229 new net::HttpCache::DefaultBackend( | 237 new net::HttpCache::DefaultBackend( |
| 230 net::DISK_CACHE, | 238 net::DISK_CACHE, |
| 231 lazy_params_->cache_path, | 239 lazy_params_->cache_path, |
| 232 lazy_params_->cache_max_size, | 240 lazy_params_->cache_max_size, |
| 233 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | 241 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 249 lazy_params_->media_cache_max_size, | 257 lazy_params_->media_cache_max_size, |
| 250 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | 258 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
| 251 net::HttpNetworkSession* main_network_session = main_cache->GetSession(); | 259 net::HttpNetworkSession* main_network_session = main_cache->GetSession(); |
| 252 net::HttpCache* media_cache = | 260 net::HttpCache* media_cache = |
| 253 new net::HttpCache(main_network_session, media_backend); | 261 new net::HttpCache(main_network_session, media_backend); |
| 254 | 262 |
| 255 scoped_refptr<net::CookieStore> cookie_store = NULL; | 263 scoped_refptr<net::CookieStore> cookie_store = NULL; |
| 256 if (record_mode || playback_mode) { | 264 if (record_mode || playback_mode) { |
| 257 // Don't use existing cookies and use an in-memory store. | 265 // Don't use existing cookies and use an in-memory store. |
| 258 cookie_store = new net::CookieMonster( | 266 cookie_store = new net::CookieMonster( |
| 259 NULL, profile_params.cookie_monster_delegate); | 267 NULL, profile_params->cookie_monster_delegate); |
| 260 main_cache->set_mode( | 268 main_cache->set_mode( |
| 261 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); | 269 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); |
| 262 } | 270 } |
| 263 | 271 |
| 264 // setup cookie store | 272 // setup cookie store |
| 265 if (!cookie_store) { | 273 if (!cookie_store) { |
| 266 DCHECK(!lazy_params_->cookie_path.empty()); | 274 DCHECK(!lazy_params_->cookie_path.empty()); |
| 267 | 275 |
| 268 scoped_refptr<SQLitePersistentCookieStore> cookie_db = | 276 scoped_refptr<SQLitePersistentCookieStore> cookie_db = |
| 269 new SQLitePersistentCookieStore(lazy_params_->cookie_path); | 277 new SQLitePersistentCookieStore(lazy_params_->cookie_path); |
| 270 cookie_db->SetClearLocalStateOnExit( | 278 cookie_db->SetClearLocalStateOnExit( |
| 271 profile_params.clear_local_state_on_exit); | 279 profile_params->clear_local_state_on_exit); |
| 272 cookie_store = | 280 cookie_store = |
| 273 new net::CookieMonster(cookie_db.get(), | 281 new net::CookieMonster(cookie_db.get(), |
| 274 profile_params.cookie_monster_delegate); | 282 profile_params->cookie_monster_delegate); |
| 275 } | 283 } |
| 276 | 284 |
| 277 net::CookieMonster* extensions_cookie_store = | 285 net::CookieMonster* extensions_cookie_store = |
| 278 new net::CookieMonster( | 286 new net::CookieMonster( |
| 279 new SQLitePersistentCookieStore( | 287 new SQLitePersistentCookieStore( |
| 280 lazy_params_->extensions_cookie_path), NULL); | 288 lazy_params_->extensions_cookie_path), NULL); |
| 281 // Enable cookies for devtools and extension URLs. | 289 // Enable cookies for devtools and extension URLs. |
| 282 const char* schemes[] = {chrome::kChromeDevToolsScheme, | 290 const char* schemes[] = {chrome::kChromeDevToolsScheme, |
| 283 chrome::kExtensionScheme}; | 291 chrome::kExtensionScheme}; |
| 284 extensions_cookie_store->SetCookieableSchemes(schemes, 2); | 292 extensions_cookie_store->SetCookieableSchemes(schemes, 2); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 ProfileImplIOData::AcquireIsolatedAppRequestContext( | 404 ProfileImplIOData::AcquireIsolatedAppRequestContext( |
| 397 scoped_refptr<ChromeURLRequestContext> main_context, | 405 scoped_refptr<ChromeURLRequestContext> main_context, |
| 398 const std::string& app_id) const { | 406 const std::string& app_id) const { |
| 399 // We create per-app contexts on demand, unlike the others above. | 407 // We create per-app contexts on demand, unlike the others above. |
| 400 scoped_refptr<RequestContext> app_request_context = | 408 scoped_refptr<RequestContext> app_request_context = |
| 401 InitializeAppRequestContext(main_context, app_id); | 409 InitializeAppRequestContext(main_context, app_id); |
| 402 DCHECK(app_request_context); | 410 DCHECK(app_request_context); |
| 403 app_request_context->set_profile_io_data(this); | 411 app_request_context->set_profile_io_data(this); |
| 404 return app_request_context; | 412 return app_request_context; |
| 405 } | 413 } |
| OLD | NEW |