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" |
25 #include "chrome/browser/net/http_server_properties_manager.h" | 26 #include "chrome/browser/net/http_server_properties_manager.h" |
26 #include "chrome/browser/net/predictor.h" | 27 #include "chrome/browser/net/predictor.h" |
27 #include "chrome/browser/net/sqlite_server_bound_cert_store.h" | 28 #include "chrome/browser/net/sqlite_server_bound_cert_store.h" |
28 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
29 #include "chrome/common/chrome_constants.h" | 30 #include "chrome/common/chrome_constants.h" |
30 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
31 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
32 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
33 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
34 #include "content/public/browser/cookie_store_factory.h" | 35 #include "content/public/browser/cookie_store_factory.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 PrefService* user_prefs = profile_->GetPrefs(); | 90 PrefService* user_prefs = profile_->GetPrefs(); |
90 io_data_->predictor_->ShutdownOnUIThread(user_prefs); | 91 io_data_->predictor_->ShutdownOnUIThread(user_prefs); |
91 } | 92 } |
92 | 93 |
93 if (io_data_->http_server_properties_manager_) | 94 if (io_data_->http_server_properties_manager_) |
94 io_data_->http_server_properties_manager_->ShutdownOnUIThread(); | 95 io_data_->http_server_properties_manager_->ShutdownOnUIThread(); |
95 io_data_->ShutdownOnUIThread(); | 96 io_data_->ShutdownOnUIThread(); |
96 } | 97 } |
97 | 98 |
98 void ProfileImplIOData::Handle::Init( | 99 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, | |
106 const base::FilePath& profile_path, | 105 const base::FilePath& profile_path, |
107 const base::FilePath& infinite_cache_path, | 106 const base::FilePath& infinite_cache_path, |
108 chrome_browser_net::Predictor* predictor, | 107 chrome_browser_net::Predictor* predictor, |
109 bool restore_old_session_cookies, | |
110 quota::SpecialStoragePolicy* special_storage_policy) { | 108 quota::SpecialStoragePolicy* special_storage_policy) { |
111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
112 DCHECK(!io_data_->lazy_params_); | 110 DCHECK(!io_data_->lazy_params_); |
113 DCHECK(predictor); | 111 DCHECK(predictor); |
114 | 112 |
115 LazyParams* lazy_params = new LazyParams; | 113 LazyParams* lazy_params = new LazyParams(); |
116 | 114 |
117 lazy_params->cookie_path = cookie_path; | |
118 lazy_params->server_bound_cert_path = server_bound_cert_path; | 115 lazy_params->server_bound_cert_path = server_bound_cert_path; |
119 lazy_params->cache_path = cache_path; | 116 lazy_params->cache_path = cache_path; |
120 lazy_params->cache_max_size = cache_max_size; | 117 lazy_params->cache_max_size = cache_max_size; |
121 lazy_params->media_cache_path = media_cache_path; | 118 lazy_params->media_cache_path = media_cache_path; |
122 lazy_params->media_cache_max_size = media_cache_max_size; | 119 lazy_params->media_cache_max_size = media_cache_max_size; |
123 lazy_params->extensions_cookie_path = extensions_cookie_path; | |
124 lazy_params->infinite_cache_path = infinite_cache_path; | 120 lazy_params->infinite_cache_path = infinite_cache_path; |
125 lazy_params->restore_old_session_cookies = restore_old_session_cookies; | |
126 lazy_params->special_storage_policy = special_storage_policy; | 121 lazy_params->special_storage_policy = special_storage_policy; |
127 | 122 |
128 io_data_->lazy_params_.reset(lazy_params); | 123 io_data_->lazy_params_.reset(lazy_params); |
129 | 124 |
130 // Keep track of profile path and cache sizes separately so we can use them | 125 // Keep track of profile path and cache sizes separately so we can use them |
131 // on demand when creating storage isolated URLRequestContextGetters. | 126 // on demand when creating storage isolated URLRequestContextGetters. |
132 io_data_->profile_path_ = profile_path; | 127 io_data_->profile_path_ = profile_path; |
133 io_data_->app_cache_max_size_ = cache_max_size; | 128 io_data_->app_cache_max_size_ = cache_max_size; |
134 io_data_->app_media_cache_max_size_ = media_cache_max_size; | 129 io_data_->app_media_cache_max_size_ = media_cache_max_size; |
135 | 130 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 LazyInitialize(); | 179 LazyInitialize(); |
185 if (!media_request_context_getter_.get()) { | 180 if (!media_request_context_getter_.get()) { |
186 media_request_context_getter_ = | 181 media_request_context_getter_ = |
187 ChromeURLRequestContextGetter::CreateOriginalForMedia(profile_, | 182 ChromeURLRequestContextGetter::CreateOriginalForMedia(profile_, |
188 io_data_); | 183 io_data_); |
189 } | 184 } |
190 return media_request_context_getter_; | 185 return media_request_context_getter_; |
191 } | 186 } |
192 | 187 |
193 scoped_refptr<ChromeURLRequestContextGetter> | 188 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> | |
206 ProfileImplIOData::Handle::CreateIsolatedAppRequestContextGetter( | 189 ProfileImplIOData::Handle::CreateIsolatedAppRequestContextGetter( |
207 const base::FilePath& partition_path, | 190 const base::FilePath& partition_path, |
208 bool in_memory, | 191 bool in_memory, |
209 content::ProtocolHandlerMap* protocol_handlers) const { | 192 content::ProtocolHandlerMap* protocol_handlers) const { |
210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
211 // Check that the partition_path is not the same as the base profile path. We | 194 // Check that the partition_path is not the same as the base profile path. We |
212 // expect isolated partition, which will never go to the default profile path. | 195 // expect isolated partition, which will never go to the default profile path. |
213 CHECK(partition_path != profile_->GetPath()); | 196 CHECK(partition_path != profile_->GetPath()); |
214 LazyInitialize(); | 197 LazyInitialize(); |
215 | 198 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 io_data_->safe_browsing_enabled()->Init(prefs::kSafeBrowsingEnabled, | 284 io_data_->safe_browsing_enabled()->Init(prefs::kSafeBrowsingEnabled, |
302 pref_service); | 285 pref_service); |
303 io_data_->safe_browsing_enabled()->MoveToThread( | 286 io_data_->safe_browsing_enabled()->MoveToThread( |
304 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | 287 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
305 #endif | 288 #endif |
306 io_data_->InitializeOnUIThread(profile_); | 289 io_data_->InitializeOnUIThread(profile_); |
307 } | 290 } |
308 | 291 |
309 ProfileImplIOData::LazyParams::LazyParams() | 292 ProfileImplIOData::LazyParams::LazyParams() |
310 : cache_max_size(0), | 293 : cache_max_size(0), |
311 media_cache_max_size(0), | 294 media_cache_max_size(0) {} |
312 restore_old_session_cookies(false) {} | |
313 | 295 |
314 ProfileImplIOData::LazyParams::~LazyParams() {} | 296 ProfileImplIOData::LazyParams::~LazyParams() {} |
315 | 297 |
316 ProfileImplIOData::ProfileImplIOData() | 298 ProfileImplIOData::ProfileImplIOData() |
317 : ProfileIOData(false), | 299 : ProfileIOData(false), |
318 http_server_properties_manager_(NULL) {} | 300 http_server_properties_manager_(NULL) {} |
319 ProfileImplIOData::~ProfileImplIOData() { | 301 ProfileImplIOData::~ProfileImplIOData() { |
320 DestroyResourceContext(); | 302 DestroyResourceContext(); |
321 | 303 |
322 if (media_request_context_) | 304 if (media_request_context_) |
323 media_request_context_->AssertNoURLRequests(); | 305 media_request_context_->AssertNoURLRequests(); |
324 } | 306 } |
325 | 307 |
326 void ProfileImplIOData::InitializeInternal( | 308 void ProfileImplIOData::InitializeInternal( |
327 ProfileParams* profile_params, | 309 ProfileParams* profile_params, |
328 content::ProtocolHandlerMap* protocol_handlers) const { | 310 content::ProtocolHandlerMap* protocol_handlers) const { |
329 ChromeURLRequestContext* main_context = main_request_context(); | 311 ChromeURLRequestContext* main_context = main_request_context(); |
330 | 312 |
331 IOThread* const io_thread = profile_params->io_thread; | 313 IOThread* const io_thread = profile_params->io_thread; |
332 IOThread::Globals* const io_thread_globals = io_thread->globals(); | 314 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); | |
340 | 315 |
341 network_delegate()->set_predictor(predictor_.get()); | 316 network_delegate()->set_predictor(predictor_.get()); |
342 | 317 |
343 // Initialize context members. | 318 // Initialize context members. |
344 | 319 |
345 ApplyProfileParamsToContext(main_context); | 320 ApplyProfileParamsToContext(main_context); |
346 | 321 |
347 if (http_server_properties_manager_) | 322 if (http_server_properties_manager_) |
348 http_server_properties_manager_->InitializeOnIOThread(); | 323 http_server_properties_manager_->InitializeOnIOThread(); |
349 | 324 |
(...skipping 11 matching lines...) Expand all Loading... |
361 io_thread_globals->http_auth_handler_factory.get()); | 336 io_thread_globals->http_auth_handler_factory.get()); |
362 | 337 |
363 main_context->set_fraudulent_certificate_reporter( | 338 main_context->set_fraudulent_certificate_reporter( |
364 fraudulent_certificate_reporter()); | 339 fraudulent_certificate_reporter()); |
365 | 340 |
366 main_context->set_throttler_manager( | 341 main_context->set_throttler_manager( |
367 io_thread_globals->throttler_manager.get()); | 342 io_thread_globals->throttler_manager.get()); |
368 | 343 |
369 main_context->set_proxy_service(proxy_service()); | 344 main_context->set_proxy_service(proxy_service()); |
370 | 345 |
371 scoped_refptr<net::CookieStore> cookie_store = NULL; | |
372 net::ServerBoundCertService* server_bound_cert_service = NULL; | 346 net::ServerBoundCertService* server_bound_cert_service = NULL; |
373 if (record_mode || playback_mode) { | 347 if (chrome_browser_net::ShouldUseInMemoryCookiesAndCache()) { |
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()); | |
377 // Don't use existing server-bound certs and use an in-memory store. | 348 // Don't use existing server-bound certs and use an in-memory store. |
378 server_bound_cert_service = new net::ServerBoundCertService( | 349 server_bound_cert_service = new net::ServerBoundCertService( |
379 new net::DefaultServerBoundCertStore(NULL), | 350 new net::DefaultServerBoundCertStore(NULL), |
380 base::WorkerPool::GetTaskRunner(true)); | 351 base::WorkerPool::GetTaskRunner(true)); |
381 } | 352 } |
382 | 353 |
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 | |
397 // Setup server bound cert service. | 354 // Setup server bound cert service. |
398 if (!server_bound_cert_service) { | 355 if (!server_bound_cert_service) { |
399 DCHECK(!lazy_params_->server_bound_cert_path.empty()); | 356 DCHECK(!lazy_params_->server_bound_cert_path.empty()); |
400 | 357 |
401 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = | 358 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = |
402 new SQLiteServerBoundCertStore( | 359 new SQLiteServerBoundCertStore( |
403 lazy_params_->server_bound_cert_path, | 360 lazy_params_->server_bound_cert_path, |
404 lazy_params_->special_storage_policy.get()); | 361 lazy_params_->special_storage_policy.get()); |
405 server_bound_cert_service = new net::ServerBoundCertService( | 362 server_bound_cert_service = new net::ServerBoundCertService( |
406 new net::DefaultServerBoundCertStore(server_bound_cert_db.get()), | 363 new net::DefaultServerBoundCertStore(server_bound_cert_db.get()), |
(...skipping 14 matching lines...) Expand all Loading... |
421 net::HttpNetworkSession::Params network_session_params; | 378 net::HttpNetworkSession::Params network_session_params; |
422 PopulateNetworkSessionParams(profile_params, &network_session_params); | 379 PopulateNetworkSessionParams(profile_params, &network_session_params); |
423 net::HttpCache* main_cache = new net::HttpCache( | 380 net::HttpCache* main_cache = new net::HttpCache( |
424 network_session_params, main_backend); | 381 network_session_params, main_backend); |
425 main_cache->InitializeInfiniteCache(lazy_params_->infinite_cache_path); | 382 main_cache->InitializeInfiniteCache(lazy_params_->infinite_cache_path); |
426 | 383 |
427 #if defined(OS_ANDROID) | 384 #if defined(OS_ANDROID) |
428 ChromeDataReductionProxyAndroid::Init(main_cache->GetSession()); | 385 ChromeDataReductionProxyAndroid::Init(main_cache->GetSession()); |
429 #endif | 386 #endif |
430 | 387 |
431 if (record_mode || playback_mode) { | 388 if (chrome_browser_net::ShouldUseInMemoryCookiesAndCache()) { |
432 main_cache->set_mode( | 389 main_cache->set_mode( |
433 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); | 390 chrome_browser_net::IsCookieRecordMode() ? |
| 391 net::HttpCache::RECORD : net::HttpCache::PLAYBACK); |
434 } | 392 } |
435 | 393 |
436 main_http_factory_.reset(main_cache); | 394 main_http_factory_.reset(main_cache); |
437 main_context->set_http_transaction_factory(main_cache); | 395 main_context->set_http_transaction_factory(main_cache); |
438 | 396 |
439 #if !defined(DISABLE_FTP_SUPPORT) | 397 #if !defined(DISABLE_FTP_SUPPORT) |
440 ftp_factory_.reset( | 398 ftp_factory_.reset( |
441 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); | 399 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); |
442 #endif // !defined(DISABLE_FTP_SUPPORT) | 400 #endif // !defined(DISABLE_FTP_SUPPORT) |
443 | 401 |
444 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( | 402 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( |
445 new net::URLRequestJobFactoryImpl()); | 403 new net::URLRequestJobFactoryImpl()); |
446 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); | 404 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); |
447 main_job_factory_ = SetUpJobFactoryDefaults( | 405 main_job_factory_ = SetUpJobFactoryDefaults( |
448 main_job_factory.Pass(), | 406 main_job_factory.Pass(), |
449 profile_params->protocol_handler_interceptor.Pass(), | 407 profile_params->protocol_handler_interceptor.Pass(), |
450 network_delegate(), | 408 network_delegate(), |
451 ftp_factory_.get()); | 409 ftp_factory_.get()); |
452 main_context->set_job_factory(main_job_factory_.get()); | 410 main_context->set_job_factory(main_job_factory_.get()); |
453 | 411 |
454 #if defined(ENABLE_EXTENSIONS) | |
455 InitializeExtensionsRequestContext(profile_params); | |
456 #endif | |
457 | |
458 // Create a media request context based on the main context, but using a | 412 // Create a media request context based on the main context, but using a |
459 // media cache. It shares the same job factory as the main context. | 413 // media cache. It shares the same job factory as the main context. |
460 StoragePartitionDescriptor details(profile_path_, false); | 414 StoragePartitionDescriptor details(profile_path_, false); |
461 media_request_context_.reset(InitializeMediaRequestContext(main_context, | 415 media_request_context_.reset(InitializeMediaRequestContext(main_context, |
462 details)); | 416 details)); |
463 | 417 |
464 lazy_params_.reset(); | 418 lazy_params_.reset(); |
465 } | 419 } |
466 | 420 |
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 | |
509 ChromeURLRequestContext* | 421 ChromeURLRequestContext* |
510 ProfileImplIOData::InitializeAppRequestContext( | 422 ProfileImplIOData::InitializeAppRequestContext( |
511 ChromeURLRequestContext* main_context, | 423 ChromeURLRequestContext* main_context, |
512 const StoragePartitionDescriptor& partition_descriptor, | 424 const StoragePartitionDescriptor& partition_descriptor, |
513 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 425 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
514 protocol_handler_interceptor, | 426 protocol_handler_interceptor, |
515 content::ProtocolHandlerMap* protocol_handlers) const { | 427 content::ProtocolHandlerMap* protocol_handlers) const { |
516 // Copy most state from the main context. | 428 // Copy most state from the main context. |
517 AppRequestContext* context = new AppRequestContext(load_time_stats()); | 429 AppRequestContext* context = new AppRequestContext(load_time_stats()); |
518 context->CopyFrom(main_context); | 430 context->CopyFrom(main_context); |
519 | 431 |
520 base::FilePath cookie_path = partition_descriptor.path.Append( | |
521 chrome::kCookieFilename); | |
522 base::FilePath cache_path = | 432 base::FilePath cache_path = |
523 partition_descriptor.path.Append(chrome::kCacheDirname); | 433 partition_descriptor.path.Append(chrome::kCacheDirname); |
524 | 434 |
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 | |
533 // Use a separate HTTP disk cache for isolated apps. | 435 // Use a separate HTTP disk cache for isolated apps. |
534 net::HttpCache::BackendFactory* app_backend = NULL; | 436 net::HttpCache::BackendFactory* app_backend = NULL; |
535 if (partition_descriptor.in_memory) { | 437 if (partition_descriptor.in_memory) { |
536 app_backend = net::HttpCache::DefaultBackend::InMemory(0); | 438 app_backend = net::HttpCache::DefaultBackend::InMemory(0); |
537 } else { | 439 } else { |
538 app_backend = new net::HttpCache::DefaultBackend( | 440 app_backend = new net::HttpCache::DefaultBackend( |
539 net::DISK_CACHE, | 441 net::DISK_CACHE, |
540 ChooseCacheBackendType(), | 442 ChooseCacheBackendType(), |
541 cache_path, | 443 cache_path, |
542 app_cache_max_size_, | 444 app_cache_max_size_, |
543 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE) | 445 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE) |
544 .get()); | 446 .get()); |
545 } | 447 } |
546 net::HttpNetworkSession* main_network_session = | 448 net::HttpNetworkSession* main_network_session = |
547 main_http_factory_->GetSession(); | 449 main_http_factory_->GetSession(); |
548 net::HttpCache* app_http_cache = | 450 net::HttpCache* app_http_cache = |
549 new net::HttpCache(main_network_session, app_backend); | 451 new net::HttpCache(main_network_session, app_backend); |
550 | 452 |
551 scoped_refptr<net::CookieStore> cookie_store = NULL; | 453 if (chrome_browser_net::ShouldUseInMemoryCookiesAndCache()) { |
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); | |
560 app_http_cache->set_mode( | 454 app_http_cache->set_mode( |
561 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); | 455 chrome_browser_net::IsCookieRecordMode() ? |
| 456 net::HttpCache::RECORD : net::HttpCache::PLAYBACK); |
562 } | 457 } |
563 | 458 |
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()); | |
580 context->SetHttpTransactionFactory( | 459 context->SetHttpTransactionFactory( |
581 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); | 460 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); |
582 | 461 |
583 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( | 462 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( |
584 new net::URLRequestJobFactoryImpl()); | 463 new net::URLRequestJobFactoryImpl()); |
585 InstallProtocolHandlers(job_factory.get(), protocol_handlers); | 464 InstallProtocolHandlers(job_factory.get(), protocol_handlers); |
586 scoped_ptr<net::URLRequestJobFactory> top_job_factory; | 465 scoped_ptr<net::URLRequestJobFactory> top_job_factory; |
587 // Overwrite the job factory that we inherit from the main context so | 466 // Overwrite the job factory that we inherit from the main context so |
588 // that we can later provide our own handlers for storage related protocols. | 467 // that we can later provide our own handlers for storage related protocols. |
589 // Install all the usual protocol handlers unless we are in a browser plugin | 468 // 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... |
696 const base::Closure& completion) { | 575 const base::Closure& completion) { |
697 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 576 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
698 DCHECK(initialized()); | 577 DCHECK(initialized()); |
699 | 578 |
700 DCHECK(transport_security_state()); | 579 DCHECK(transport_security_state()); |
701 // Completes synchronously. | 580 // Completes synchronously. |
702 transport_security_state()->DeleteAllDynamicDataSince(time); | 581 transport_security_state()->DeleteAllDynamicDataSince(time); |
703 DCHECK(http_server_properties_manager_); | 582 DCHECK(http_server_properties_manager_); |
704 http_server_properties_manager_->Clear(completion); | 583 http_server_properties_manager_->Clear(completion); |
705 } | 584 } |
OLD | NEW |