| 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_impl_io_data.h" | 5 #include "chrome/browser/profiles/profile_impl_io_data.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 11 #include "base/prefs/pref_member.h" | 11 #include "base/prefs/pref_member.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/threading/sequenced_worker_pool.h" | 16 #include "base/threading/sequenced_worker_pool.h" |
| 17 #include "base/threading/worker_pool.h" | 17 #include "base/threading/worker_pool.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 19 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 20 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 20 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| 21 #include "chrome/browser/io_thread.h" | 21 #include "chrome/browser/io_thread.h" |
| 22 #include "chrome/browser/net/chrome_net_log.h" | 22 #include "chrome/browser/net/chrome_net_log.h" |
| 23 #include "chrome/browser/net/chrome_network_delegate.h" | 23 #include "chrome/browser/net/chrome_network_delegate.h" |
| 24 #include "chrome/browser/net/connect_interceptor.h" | 24 #include "chrome/browser/net/connect_interceptor.h" |
| 25 #include "chrome/browser/net/cookie_store_util.h" | |
| 26 #include "chrome/browser/net/http_server_properties_manager.h" | 25 #include "chrome/browser/net/http_server_properties_manager.h" |
| 27 #include "chrome/browser/net/predictor.h" | 26 #include "chrome/browser/net/predictor.h" |
| 28 #include "chrome/browser/net/sqlite_server_bound_cert_store.h" | 27 #include "chrome/browser/net/sqlite_server_bound_cert_store.h" |
| 29 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 30 #include "chrome/common/chrome_constants.h" | 29 #include "chrome/common/chrome_constants.h" |
| 31 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 32 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 33 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 34 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 35 #include "content/public/browser/cookie_store_factory.h" | 34 #include "content/public/browser/cookie_store_factory.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 PrefService* user_prefs = profile_->GetPrefs(); | 89 PrefService* user_prefs = profile_->GetPrefs(); |
| 91 io_data_->predictor_->ShutdownOnUIThread(user_prefs); | 90 io_data_->predictor_->ShutdownOnUIThread(user_prefs); |
| 92 } | 91 } |
| 93 | 92 |
| 94 if (io_data_->http_server_properties_manager_) | 93 if (io_data_->http_server_properties_manager_) |
| 95 io_data_->http_server_properties_manager_->ShutdownOnUIThread(); | 94 io_data_->http_server_properties_manager_->ShutdownOnUIThread(); |
| 96 io_data_->ShutdownOnUIThread(); | 95 io_data_->ShutdownOnUIThread(); |
| 97 } | 96 } |
| 98 | 97 |
| 99 void ProfileImplIOData::Handle::Init( | 98 void ProfileImplIOData::Handle::Init( |
| 99 const base::FilePath& cookie_path, |
| 100 const base::FilePath& server_bound_cert_path, | 100 const base::FilePath& server_bound_cert_path, |
| 101 const base::FilePath& cache_path, | 101 const base::FilePath& cache_path, |
| 102 int cache_max_size, | 102 int cache_max_size, |
| 103 const base::FilePath& media_cache_path, | 103 const base::FilePath& media_cache_path, |
| 104 int media_cache_max_size, | 104 int media_cache_max_size, |
| 105 const base::FilePath& extensions_cookie_path, |
| 105 const base::FilePath& profile_path, | 106 const base::FilePath& profile_path, |
| 106 const base::FilePath& infinite_cache_path, | 107 const base::FilePath& infinite_cache_path, |
| 107 chrome_browser_net::Predictor* predictor, | 108 chrome_browser_net::Predictor* predictor, |
| 109 bool restore_old_session_cookies, |
| 108 quota::SpecialStoragePolicy* special_storage_policy) { | 110 quota::SpecialStoragePolicy* special_storage_policy) { |
| 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 110 DCHECK(!io_data_->lazy_params_); | 112 DCHECK(!io_data_->lazy_params_); |
| 111 DCHECK(predictor); | 113 DCHECK(predictor); |
| 112 | 114 |
| 113 LazyParams* lazy_params = new LazyParams(); | 115 LazyParams* lazy_params = new LazyParams; |
| 114 | 116 |
| 117 lazy_params->cookie_path = cookie_path; |
| 115 lazy_params->server_bound_cert_path = server_bound_cert_path; | 118 lazy_params->server_bound_cert_path = server_bound_cert_path; |
| 116 lazy_params->cache_path = cache_path; | 119 lazy_params->cache_path = cache_path; |
| 117 lazy_params->cache_max_size = cache_max_size; | 120 lazy_params->cache_max_size = cache_max_size; |
| 118 lazy_params->media_cache_path = media_cache_path; | 121 lazy_params->media_cache_path = media_cache_path; |
| 119 lazy_params->media_cache_max_size = media_cache_max_size; | 122 lazy_params->media_cache_max_size = media_cache_max_size; |
| 123 lazy_params->extensions_cookie_path = extensions_cookie_path; |
| 120 lazy_params->infinite_cache_path = infinite_cache_path; | 124 lazy_params->infinite_cache_path = infinite_cache_path; |
| 125 lazy_params->restore_old_session_cookies = restore_old_session_cookies; |
| 121 lazy_params->special_storage_policy = special_storage_policy; | 126 lazy_params->special_storage_policy = special_storage_policy; |
| 122 | 127 |
| 123 io_data_->lazy_params_.reset(lazy_params); | 128 io_data_->lazy_params_.reset(lazy_params); |
| 124 | 129 |
| 125 // Keep track of profile path and cache sizes separately so we can use them | 130 // Keep track of profile path and cache sizes separately so we can use them |
| 126 // on demand when creating storage isolated URLRequestContextGetters. | 131 // on demand when creating storage isolated URLRequestContextGetters. |
| 127 io_data_->profile_path_ = profile_path; | 132 io_data_->profile_path_ = profile_path; |
| 128 io_data_->app_cache_max_size_ = cache_max_size; | 133 io_data_->app_cache_max_size_ = cache_max_size; |
| 129 io_data_->app_media_cache_max_size_ = media_cache_max_size; | 134 io_data_->app_media_cache_max_size_ = media_cache_max_size; |
| 130 | 135 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 LazyInitialize(); | 184 LazyInitialize(); |
| 180 if (!media_request_context_getter_.get()) { | 185 if (!media_request_context_getter_.get()) { |
| 181 media_request_context_getter_ = | 186 media_request_context_getter_ = |
| 182 ChromeURLRequestContextGetter::CreateOriginalForMedia(profile_, | 187 ChromeURLRequestContextGetter::CreateOriginalForMedia(profile_, |
| 183 io_data_); | 188 io_data_); |
| 184 } | 189 } |
| 185 return media_request_context_getter_; | 190 return media_request_context_getter_; |
| 186 } | 191 } |
| 187 | 192 |
| 188 scoped_refptr<ChromeURLRequestContextGetter> | 193 scoped_refptr<ChromeURLRequestContextGetter> |
| 194 ProfileImplIOData::Handle::GetExtensionsRequestContextGetter() const { |
| 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 196 LazyInitialize(); |
| 197 if (!extensions_request_context_getter_.get()) { |
| 198 extensions_request_context_getter_ = |
| 199 ChromeURLRequestContextGetter::CreateOriginalForExtensions(profile_, |
| 200 io_data_); |
| 201 } |
| 202 return extensions_request_context_getter_; |
| 203 } |
| 204 |
| 205 scoped_refptr<ChromeURLRequestContextGetter> |
| 189 ProfileImplIOData::Handle::CreateIsolatedAppRequestContextGetter( | 206 ProfileImplIOData::Handle::CreateIsolatedAppRequestContextGetter( |
| 190 const base::FilePath& partition_path, | 207 const base::FilePath& partition_path, |
| 191 bool in_memory, | 208 bool in_memory, |
| 192 content::ProtocolHandlerMap* protocol_handlers) const { | 209 content::ProtocolHandlerMap* protocol_handlers) const { |
| 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 194 // Check that the partition_path is not the same as the base profile path. We | 211 // Check that the partition_path is not the same as the base profile path. We |
| 195 // expect isolated partition, which will never go to the default profile path. | 212 // expect isolated partition, which will never go to the default profile path. |
| 196 CHECK(partition_path != profile_->GetPath()); | 213 CHECK(partition_path != profile_->GetPath()); |
| 197 LazyInitialize(); | 214 LazyInitialize(); |
| 198 | 215 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 io_data_->safe_browsing_enabled()->Init(prefs::kSafeBrowsingEnabled, | 301 io_data_->safe_browsing_enabled()->Init(prefs::kSafeBrowsingEnabled, |
| 285 pref_service); | 302 pref_service); |
| 286 io_data_->safe_browsing_enabled()->MoveToThread( | 303 io_data_->safe_browsing_enabled()->MoveToThread( |
| 287 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | 304 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 288 #endif | 305 #endif |
| 289 io_data_->InitializeOnUIThread(profile_); | 306 io_data_->InitializeOnUIThread(profile_); |
| 290 } | 307 } |
| 291 | 308 |
| 292 ProfileImplIOData::LazyParams::LazyParams() | 309 ProfileImplIOData::LazyParams::LazyParams() |
| 293 : cache_max_size(0), | 310 : cache_max_size(0), |
| 294 media_cache_max_size(0) {} | 311 media_cache_max_size(0), |
| 312 restore_old_session_cookies(false) {} |
| 295 | 313 |
| 296 ProfileImplIOData::LazyParams::~LazyParams() {} | 314 ProfileImplIOData::LazyParams::~LazyParams() {} |
| 297 | 315 |
| 298 ProfileImplIOData::ProfileImplIOData() | 316 ProfileImplIOData::ProfileImplIOData() |
| 299 : ProfileIOData(false), | 317 : ProfileIOData(false), |
| 300 http_server_properties_manager_(NULL) {} | 318 http_server_properties_manager_(NULL) {} |
| 301 ProfileImplIOData::~ProfileImplIOData() { | 319 ProfileImplIOData::~ProfileImplIOData() { |
| 302 DestroyResourceContext(); | 320 DestroyResourceContext(); |
| 303 | 321 |
| 304 if (media_request_context_) | 322 if (media_request_context_) |
| 305 media_request_context_->AssertNoURLRequests(); | 323 media_request_context_->AssertNoURLRequests(); |
| 306 } | 324 } |
| 307 | 325 |
| 308 void ProfileImplIOData::InitializeInternal( | 326 void ProfileImplIOData::InitializeInternal( |
| 309 ProfileParams* profile_params, | 327 ProfileParams* profile_params, |
| 310 content::ProtocolHandlerMap* protocol_handlers) const { | 328 content::ProtocolHandlerMap* protocol_handlers) const { |
| 311 ChromeURLRequestContext* main_context = main_request_context(); | 329 ChromeURLRequestContext* main_context = main_request_context(); |
| 312 | 330 |
| 313 IOThread* const io_thread = profile_params->io_thread; | 331 IOThread* const io_thread = profile_params->io_thread; |
| 314 IOThread::Globals* const io_thread_globals = io_thread->globals(); | 332 IOThread::Globals* const io_thread_globals = io_thread->globals(); |
| 333 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 334 // Only allow Record Mode if we are in a Debug build or where we are running |
| 335 // a cycle, and the user has limited control. |
| 336 bool record_mode = command_line.HasSwitch(switches::kRecordMode) && |
| 337 (chrome::kRecordModeEnabled || |
| 338 command_line.HasSwitch(switches::kVisitURLs)); |
| 339 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); |
| 315 | 340 |
| 316 network_delegate()->set_predictor(predictor_.get()); | 341 network_delegate()->set_predictor(predictor_.get()); |
| 317 | 342 |
| 318 // Initialize context members. | 343 // Initialize context members. |
| 319 | 344 |
| 320 ApplyProfileParamsToContext(main_context); | 345 ApplyProfileParamsToContext(main_context); |
| 321 | 346 |
| 322 if (http_server_properties_manager_) | 347 if (http_server_properties_manager_) |
| 323 http_server_properties_manager_->InitializeOnIOThread(); | 348 http_server_properties_manager_->InitializeOnIOThread(); |
| 324 | 349 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 336 io_thread_globals->http_auth_handler_factory.get()); | 361 io_thread_globals->http_auth_handler_factory.get()); |
| 337 | 362 |
| 338 main_context->set_fraudulent_certificate_reporter( | 363 main_context->set_fraudulent_certificate_reporter( |
| 339 fraudulent_certificate_reporter()); | 364 fraudulent_certificate_reporter()); |
| 340 | 365 |
| 341 main_context->set_throttler_manager( | 366 main_context->set_throttler_manager( |
| 342 io_thread_globals->throttler_manager.get()); | 367 io_thread_globals->throttler_manager.get()); |
| 343 | 368 |
| 344 main_context->set_proxy_service(proxy_service()); | 369 main_context->set_proxy_service(proxy_service()); |
| 345 | 370 |
| 371 scoped_refptr<net::CookieStore> cookie_store = NULL; |
| 346 net::ServerBoundCertService* server_bound_cert_service = NULL; | 372 net::ServerBoundCertService* server_bound_cert_service = NULL; |
| 347 if (chrome_browser_net::ShouldUseInMemoryCookiesAndCache()) { | 373 if (record_mode || playback_mode) { |
| 374 // Don't use existing cookies and use an in-memory store. |
| 375 cookie_store = new net::CookieMonster( |
| 376 NULL, profile_params->cookie_monster_delegate.get()); |
| 348 // Don't use existing server-bound certs and use an in-memory store. | 377 // Don't use existing server-bound certs and use an in-memory store. |
| 349 server_bound_cert_service = new net::ServerBoundCertService( | 378 server_bound_cert_service = new net::ServerBoundCertService( |
| 350 new net::DefaultServerBoundCertStore(NULL), | 379 new net::DefaultServerBoundCertStore(NULL), |
| 351 base::WorkerPool::GetTaskRunner(true)); | 380 base::WorkerPool::GetTaskRunner(true)); |
| 352 } | 381 } |
| 353 | 382 |
| 383 // setup cookie store |
| 384 if (!cookie_store.get()) { |
| 385 DCHECK(!lazy_params_->cookie_path.empty()); |
| 386 |
| 387 cookie_store = content::CreatePersistentCookieStore( |
| 388 lazy_params_->cookie_path, |
| 389 lazy_params_->restore_old_session_cookies, |
| 390 lazy_params_->special_storage_policy.get(), |
| 391 profile_params->cookie_monster_delegate.get()); |
| 392 cookie_store->GetCookieMonster()->SetPersistSessionCookies(true); |
| 393 } |
| 394 |
| 395 main_context->set_cookie_store(cookie_store.get()); |
| 396 |
| 354 // Setup server bound cert service. | 397 // Setup server bound cert service. |
| 355 if (!server_bound_cert_service) { | 398 if (!server_bound_cert_service) { |
| 356 DCHECK(!lazy_params_->server_bound_cert_path.empty()); | 399 DCHECK(!lazy_params_->server_bound_cert_path.empty()); |
| 357 | 400 |
| 358 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = | 401 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = |
| 359 new SQLiteServerBoundCertStore( | 402 new SQLiteServerBoundCertStore( |
| 360 lazy_params_->server_bound_cert_path, | 403 lazy_params_->server_bound_cert_path, |
| 361 lazy_params_->special_storage_policy.get()); | 404 lazy_params_->special_storage_policy.get()); |
| 362 server_bound_cert_service = new net::ServerBoundCertService( | 405 server_bound_cert_service = new net::ServerBoundCertService( |
| 363 new net::DefaultServerBoundCertStore(server_bound_cert_db.get()), | 406 new net::DefaultServerBoundCertStore(server_bound_cert_db.get()), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 378 net::HttpNetworkSession::Params network_session_params; | 421 net::HttpNetworkSession::Params network_session_params; |
| 379 PopulateNetworkSessionParams(profile_params, &network_session_params); | 422 PopulateNetworkSessionParams(profile_params, &network_session_params); |
| 380 net::HttpCache* main_cache = new net::HttpCache( | 423 net::HttpCache* main_cache = new net::HttpCache( |
| 381 network_session_params, main_backend); | 424 network_session_params, main_backend); |
| 382 main_cache->InitializeInfiniteCache(lazy_params_->infinite_cache_path); | 425 main_cache->InitializeInfiniteCache(lazy_params_->infinite_cache_path); |
| 383 | 426 |
| 384 #if defined(OS_ANDROID) | 427 #if defined(OS_ANDROID) |
| 385 ChromeDataReductionProxyAndroid::Init(main_cache->GetSession()); | 428 ChromeDataReductionProxyAndroid::Init(main_cache->GetSession()); |
| 386 #endif | 429 #endif |
| 387 | 430 |
| 388 if (chrome_browser_net::ShouldUseInMemoryCookiesAndCache()) { | 431 if (record_mode || playback_mode) { |
| 389 main_cache->set_mode( | 432 main_cache->set_mode( |
| 390 chrome_browser_net::IsCookieRecordMode() ? | 433 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); |
| 391 net::HttpCache::RECORD : net::HttpCache::PLAYBACK); | |
| 392 } | 434 } |
| 393 | 435 |
| 394 main_http_factory_.reset(main_cache); | 436 main_http_factory_.reset(main_cache); |
| 395 main_context->set_http_transaction_factory(main_cache); | 437 main_context->set_http_transaction_factory(main_cache); |
| 396 | 438 |
| 397 #if !defined(DISABLE_FTP_SUPPORT) | 439 #if !defined(DISABLE_FTP_SUPPORT) |
| 398 ftp_factory_.reset( | 440 ftp_factory_.reset( |
| 399 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); | 441 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); |
| 400 #endif // !defined(DISABLE_FTP_SUPPORT) | 442 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 401 | 443 |
| 402 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( | 444 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( |
| 403 new net::URLRequestJobFactoryImpl()); | 445 new net::URLRequestJobFactoryImpl()); |
| 404 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); | 446 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); |
| 405 main_job_factory_ = SetUpJobFactoryDefaults( | 447 main_job_factory_ = SetUpJobFactoryDefaults( |
| 406 main_job_factory.Pass(), | 448 main_job_factory.Pass(), |
| 407 profile_params->protocol_handler_interceptor.Pass(), | 449 profile_params->protocol_handler_interceptor.Pass(), |
| 408 network_delegate(), | 450 network_delegate(), |
| 409 ftp_factory_.get()); | 451 ftp_factory_.get()); |
| 410 main_context->set_job_factory(main_job_factory_.get()); | 452 main_context->set_job_factory(main_job_factory_.get()); |
| 411 | 453 |
| 454 #if defined(ENABLE_EXTENSIONS) |
| 455 InitializeExtensionsRequestContext(profile_params); |
| 456 #endif |
| 457 |
| 412 // Create a media request context based on the main context, but using a | 458 // Create a media request context based on the main context, but using a |
| 413 // media cache. It shares the same job factory as the main context. | 459 // media cache. It shares the same job factory as the main context. |
| 414 StoragePartitionDescriptor details(profile_path_, false); | 460 StoragePartitionDescriptor details(profile_path_, false); |
| 415 media_request_context_.reset(InitializeMediaRequestContext(main_context, | 461 media_request_context_.reset(InitializeMediaRequestContext(main_context, |
| 416 details)); | 462 details)); |
| 417 | 463 |
| 418 lazy_params_.reset(); | 464 lazy_params_.reset(); |
| 419 } | 465 } |
| 420 | 466 |
| 467 void ProfileImplIOData:: |
| 468 InitializeExtensionsRequestContext(ProfileParams* profile_params) const { |
| 469 ChromeURLRequestContext* extensions_context = extensions_request_context(); |
| 470 IOThread* const io_thread = profile_params->io_thread; |
| 471 IOThread::Globals* const io_thread_globals = io_thread->globals(); |
| 472 ApplyProfileParamsToContext(extensions_context); |
| 473 |
| 474 extensions_context->set_transport_security_state(transport_security_state()); |
| 475 |
| 476 extensions_context->set_net_log(io_thread->net_log()); |
| 477 |
| 478 extensions_context->set_throttler_manager( |
| 479 io_thread_globals->throttler_manager.get()); |
| 480 |
| 481 net::CookieStore* extensions_cookie_store = |
| 482 content::CreatePersistentCookieStore( |
| 483 lazy_params_->extensions_cookie_path, |
| 484 lazy_params_->restore_old_session_cookies, |
| 485 NULL, |
| 486 NULL); |
| 487 // Enable cookies for devtools and extension URLs. |
| 488 const char* schemes[] = {chrome::kChromeDevToolsScheme, |
| 489 extensions::kExtensionScheme}; |
| 490 extensions_cookie_store->GetCookieMonster()->SetCookieableSchemes(schemes, 2); |
| 491 extensions_context->set_cookie_store(extensions_cookie_store); |
| 492 |
| 493 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( |
| 494 new net::URLRequestJobFactoryImpl()); |
| 495 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. |
| 496 // Without a network_delegate, this protocol handler will never |
| 497 // handle file: requests, but as a side effect it makes |
| 498 // job_factory::IsHandledProtocol return true, which prevents attempts to |
| 499 // handle the protocol externally. We pass NULL in to |
| 500 // SetUpJobFactory() to get this effect. |
| 501 extensions_job_factory_ = SetUpJobFactoryDefaults( |
| 502 extensions_job_factory.Pass(), |
| 503 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>(), |
| 504 NULL, |
| 505 ftp_factory_.get()); |
| 506 extensions_context->set_job_factory(extensions_job_factory_.get()); |
| 507 } |
| 508 |
| 421 ChromeURLRequestContext* | 509 ChromeURLRequestContext* |
| 422 ProfileImplIOData::InitializeAppRequestContext( | 510 ProfileImplIOData::InitializeAppRequestContext( |
| 423 ChromeURLRequestContext* main_context, | 511 ChromeURLRequestContext* main_context, |
| 424 const StoragePartitionDescriptor& partition_descriptor, | 512 const StoragePartitionDescriptor& partition_descriptor, |
| 425 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 513 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 426 protocol_handler_interceptor, | 514 protocol_handler_interceptor, |
| 427 content::ProtocolHandlerMap* protocol_handlers) const { | 515 content::ProtocolHandlerMap* protocol_handlers) const { |
| 428 // Copy most state from the main context. | 516 // Copy most state from the main context. |
| 429 AppRequestContext* context = new AppRequestContext(load_time_stats()); | 517 AppRequestContext* context = new AppRequestContext(load_time_stats()); |
| 430 context->CopyFrom(main_context); | 518 context->CopyFrom(main_context); |
| 431 | 519 |
| 520 base::FilePath cookie_path = partition_descriptor.path.Append( |
| 521 chrome::kCookieFilename); |
| 432 base::FilePath cache_path = | 522 base::FilePath cache_path = |
| 433 partition_descriptor.path.Append(chrome::kCacheDirname); | 523 partition_descriptor.path.Append(chrome::kCacheDirname); |
| 434 | 524 |
| 525 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 526 // Only allow Record Mode if we are in a Debug build or where we are running |
| 527 // a cycle, and the user has limited control. |
| 528 bool record_mode = command_line.HasSwitch(switches::kRecordMode) && |
| 529 (chrome::kRecordModeEnabled || |
| 530 command_line.HasSwitch(switches::kVisitURLs)); |
| 531 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); |
| 532 |
| 435 // Use a separate HTTP disk cache for isolated apps. | 533 // Use a separate HTTP disk cache for isolated apps. |
| 436 net::HttpCache::BackendFactory* app_backend = NULL; | 534 net::HttpCache::BackendFactory* app_backend = NULL; |
| 437 if (partition_descriptor.in_memory) { | 535 if (partition_descriptor.in_memory) { |
| 438 app_backend = net::HttpCache::DefaultBackend::InMemory(0); | 536 app_backend = net::HttpCache::DefaultBackend::InMemory(0); |
| 439 } else { | 537 } else { |
| 440 app_backend = new net::HttpCache::DefaultBackend( | 538 app_backend = new net::HttpCache::DefaultBackend( |
| 441 net::DISK_CACHE, | 539 net::DISK_CACHE, |
| 442 ChooseCacheBackendType(), | 540 ChooseCacheBackendType(), |
| 443 cache_path, | 541 cache_path, |
| 444 app_cache_max_size_, | 542 app_cache_max_size_, |
| 445 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE) | 543 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE) |
| 446 .get()); | 544 .get()); |
| 447 } | 545 } |
| 448 net::HttpNetworkSession* main_network_session = | 546 net::HttpNetworkSession* main_network_session = |
| 449 main_http_factory_->GetSession(); | 547 main_http_factory_->GetSession(); |
| 450 net::HttpCache* app_http_cache = | 548 net::HttpCache* app_http_cache = |
| 451 new net::HttpCache(main_network_session, app_backend); | 549 new net::HttpCache(main_network_session, app_backend); |
| 452 | 550 |
| 453 if (chrome_browser_net::ShouldUseInMemoryCookiesAndCache()) { | 551 scoped_refptr<net::CookieStore> cookie_store = NULL; |
| 552 if (partition_descriptor.in_memory) { |
| 553 cookie_store = new net::CookieMonster(NULL, NULL); |
| 554 } else if (record_mode || playback_mode) { |
| 555 // Don't use existing cookies and use an in-memory store. |
| 556 // TODO(creis): We should have a cookie delegate for notifying the cookie |
| 557 // extensions API, but we need to update it to understand isolated apps |
| 558 // first. |
| 559 cookie_store = new net::CookieMonster(NULL, NULL); |
| 454 app_http_cache->set_mode( | 560 app_http_cache->set_mode( |
| 455 chrome_browser_net::IsCookieRecordMode() ? | 561 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); |
| 456 net::HttpCache::RECORD : net::HttpCache::PLAYBACK); | |
| 457 } | 562 } |
| 458 | 563 |
| 564 // Use an app-specific cookie store. |
| 565 if (!cookie_store.get()) { |
| 566 DCHECK(!cookie_path.empty()); |
| 567 |
| 568 // TODO(creis): We should have a cookie delegate for notifying the cookie |
| 569 // extensions API, but we need to update it to understand isolated apps |
| 570 // first. |
| 571 cookie_store = content::CreatePersistentCookieStore( |
| 572 cookie_path, |
| 573 false, |
| 574 NULL, |
| 575 NULL); |
| 576 } |
| 577 |
| 578 // Transfer ownership of the cookies and cache to AppRequestContext. |
| 579 context->SetCookieStore(cookie_store.get()); |
| 459 context->SetHttpTransactionFactory( | 580 context->SetHttpTransactionFactory( |
| 460 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); | 581 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); |
| 461 | 582 |
| 462 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( | 583 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( |
| 463 new net::URLRequestJobFactoryImpl()); | 584 new net::URLRequestJobFactoryImpl()); |
| 464 InstallProtocolHandlers(job_factory.get(), protocol_handlers); | 585 InstallProtocolHandlers(job_factory.get(), protocol_handlers); |
| 465 scoped_ptr<net::URLRequestJobFactory> top_job_factory; | 586 scoped_ptr<net::URLRequestJobFactory> top_job_factory; |
| 466 // Overwrite the job factory that we inherit from the main context so | 587 // Overwrite the job factory that we inherit from the main context so |
| 467 // that we can later provide our own handlers for storage related protocols. | 588 // that we can later provide our own handlers for storage related protocols. |
| 468 // Install all the usual protocol handlers unless we are in a browser plugin | 589 // Install all the usual protocol handlers unless we are in a browser plugin |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 const base::Closure& completion) { | 696 const base::Closure& completion) { |
| 576 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 697 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 577 DCHECK(initialized()); | 698 DCHECK(initialized()); |
| 578 | 699 |
| 579 DCHECK(transport_security_state()); | 700 DCHECK(transport_security_state()); |
| 580 // Completes synchronously. | 701 // Completes synchronously. |
| 581 transport_security_state()->DeleteAllDynamicDataSince(time); | 702 transport_security_state()->DeleteAllDynamicDataSince(time); |
| 582 DCHECK(http_server_properties_manager_); | 703 DCHECK(http_server_properties_manager_); |
| 583 http_server_properties_manager_->Clear(completion); | 704 http_server_properties_manager_->Clear(completion); |
| 584 } | 705 } |
| OLD | NEW |