OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/profiles/profile_io_data.h" | 5 #include "chrome/browser/profiles/profile_io_data.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 params->notification_service = | 166 params->notification_service = |
167 DesktopNotificationServiceFactory::GetForProfile(profile); | 167 DesktopNotificationServiceFactory::GetForProfile(profile); |
168 #endif | 168 #endif |
169 | 169 |
170 ProtocolHandlerRegistry* protocol_handler_registry = | 170 ProtocolHandlerRegistry* protocol_handler_registry = |
171 ProtocolHandlerRegistryFactory::GetForProfile(profile); | 171 ProtocolHandlerRegistryFactory::GetForProfile(profile); |
172 DCHECK(protocol_handler_registry); | 172 DCHECK(protocol_handler_registry); |
173 | 173 |
174 // The profile instance is only available here in the InitializeOnUIThread | 174 // The profile instance is only available here in the InitializeOnUIThread |
175 // method, so we create the url interceptor here, then save it for | 175 // method, so we create the url interceptor here, then save it for |
176 // later delivery to the job factory in LazyInitialize. | 176 // later delivery to the job factory in Init(). |
177 params->protocol_handler_interceptor.reset( | 177 params->protocol_handler_interceptor.reset( |
178 protocol_handler_registry->CreateURLInterceptor()); | 178 protocol_handler_registry->CreateURLInterceptor()); |
179 | 179 |
180 ChromeProxyConfigService* proxy_config_service = | 180 ChromeProxyConfigService* proxy_config_service = |
181 ProxyServiceFactory::CreateProxyConfigService(true); | 181 ProxyServiceFactory::CreateProxyConfigService(true); |
182 params->proxy_config_service.reset(proxy_config_service); | 182 params->proxy_config_service.reset(proxy_config_service); |
183 profile->GetProxyConfigTracker()->SetChromeProxyConfigService( | 183 profile->GetProxyConfigTracker()->SetChromeProxyConfigService( |
184 proxy_config_service); | 184 proxy_config_service); |
185 params->profile = profile; | 185 params->profile = profile; |
186 profile_params_.reset(params.release()); | 186 profile_params_.reset(params.release()); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 | 358 |
359 return IsHandledProtocol(url.scheme()); | 359 return IsHandledProtocol(url.scheme()); |
360 } | 360 } |
361 | 361 |
362 content::ResourceContext* ProfileIOData::GetResourceContext() const { | 362 content::ResourceContext* ProfileIOData::GetResourceContext() const { |
363 return resource_context_.get(); | 363 return resource_context_.get(); |
364 } | 364 } |
365 | 365 |
366 ChromeURLDataManagerBackend* | 366 ChromeURLDataManagerBackend* |
367 ProfileIOData::GetChromeURLDataManagerBackend() const { | 367 ProfileIOData::GetChromeURLDataManagerBackend() const { |
368 LazyInitialize(); | 368 DCHECK(initialized_); |
369 return chrome_url_data_manager_backend_.get(); | 369 return chrome_url_data_manager_backend_.get(); |
370 } | 370 } |
371 | 371 |
372 ChromeURLRequestContext* | 372 ChromeURLRequestContext* ProfileIOData::GetMainRequestContext() const { |
373 ProfileIOData::GetMainRequestContext() const { | 373 DCHECK(initialized_); |
374 LazyInitialize(); | |
375 return main_request_context_.get(); | 374 return main_request_context_.get(); |
376 } | 375 } |
377 | 376 |
378 ChromeURLRequestContext* | 377 ChromeURLRequestContext* ProfileIOData::GetMediaRequestContext() const { |
379 ProfileIOData::GetMediaRequestContext() const { | 378 DCHECK(initialized_); |
380 LazyInitialize(); | 379 ChromeURLRequestContext* context = AcquireMediaRequestContext(); |
381 ChromeURLRequestContext* context = | |
382 AcquireMediaRequestContext(); | |
383 DCHECK(context); | 380 DCHECK(context); |
384 return context; | 381 return context; |
385 } | 382 } |
386 | 383 |
387 ChromeURLRequestContext* | 384 ChromeURLRequestContext* ProfileIOData::GetExtensionsRequestContext() const { |
388 ProfileIOData::GetExtensionsRequestContext() const { | 385 DCHECK(initialized_); |
389 LazyInitialize(); | |
390 return extensions_request_context_.get(); | 386 return extensions_request_context_.get(); |
391 } | 387 } |
392 | 388 |
393 ChromeURLRequestContext* | 389 ChromeURLRequestContext* ProfileIOData::GetIsolatedAppRequestContext( |
394 ProfileIOData::GetIsolatedAppRequestContext( | |
395 ChromeURLRequestContext* main_context, | 390 ChromeURLRequestContext* main_context, |
396 const StoragePartitionDescriptor& partition_descriptor, | 391 const StoragePartitionDescriptor& partition_descriptor, |
397 scoped_ptr<net::URLRequestJobFactory::Interceptor> | 392 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
398 protocol_handler_interceptor) const { | 393 protocol_handler_interceptor, |
399 LazyInitialize(); | 394 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 395 blob_protocol_handler, |
| 396 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 397 file_system_protocol_handler, |
| 398 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 399 developer_protocol_handler) const { |
| 400 DCHECK(initialized_); |
400 ChromeURLRequestContext* context = NULL; | 401 ChromeURLRequestContext* context = NULL; |
401 if (ContainsKey(app_request_context_map_, partition_descriptor)) { | 402 if (ContainsKey(app_request_context_map_, partition_descriptor)) { |
402 context = app_request_context_map_[partition_descriptor]; | 403 context = app_request_context_map_[partition_descriptor]; |
403 } else { | 404 } else { |
404 context = AcquireIsolatedAppRequestContext( | 405 context = AcquireIsolatedAppRequestContext( |
405 main_context, partition_descriptor, | 406 main_context, partition_descriptor, protocol_handler_interceptor.Pass(), |
406 protocol_handler_interceptor.Pass()); | 407 blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), |
| 408 developer_protocol_handler.Pass()); |
407 app_request_context_map_[partition_descriptor] = context; | 409 app_request_context_map_[partition_descriptor] = context; |
408 } | 410 } |
409 DCHECK(context); | 411 DCHECK(context); |
410 return context; | 412 return context; |
411 } | 413 } |
412 | 414 |
413 ChromeURLRequestContext* | 415 ChromeURLRequestContext* ProfileIOData::GetIsolatedMediaRequestContext( |
414 ProfileIOData::GetIsolatedMediaRequestContext( | |
415 ChromeURLRequestContext* app_context, | 416 ChromeURLRequestContext* app_context, |
416 const StoragePartitionDescriptor& partition_descriptor) const { | 417 const StoragePartitionDescriptor& partition_descriptor) const { |
417 LazyInitialize(); | 418 DCHECK(initialized_); |
418 ChromeURLRequestContext* context = NULL; | 419 ChromeURLRequestContext* context = NULL; |
419 if (ContainsKey(isolated_media_request_context_map_, partition_descriptor)) { | 420 if (ContainsKey(isolated_media_request_context_map_, partition_descriptor)) { |
420 context = isolated_media_request_context_map_[partition_descriptor]; | 421 context = isolated_media_request_context_map_[partition_descriptor]; |
421 } else { | 422 } else { |
422 context = AcquireIsolatedMediaRequestContext(app_context, | 423 context = AcquireIsolatedMediaRequestContext(app_context, |
423 partition_descriptor); | 424 partition_descriptor); |
424 isolated_media_request_context_map_[partition_descriptor] = context; | 425 isolated_media_request_context_map_[partition_descriptor] = context; |
425 } | 426 } |
426 DCHECK(context); | 427 DCHECK(context); |
427 return context; | 428 return context; |
428 } | 429 } |
429 | 430 |
430 ExtensionInfoMap* ProfileIOData::GetExtensionInfoMap() const { | 431 ExtensionInfoMap* ProfileIOData::GetExtensionInfoMap() const { |
431 DCHECK(extension_info_map_) << "ExtensionSystem not initialized"; | 432 DCHECK(initialized_) << "ExtensionSystem not initialized"; |
432 return extension_info_map_; | 433 return extension_info_map_; |
433 } | 434 } |
434 | 435 |
435 CookieSettings* ProfileIOData::GetCookieSettings() const { | 436 CookieSettings* ProfileIOData::GetCookieSettings() const { |
| 437 DCHECK(initialized_); |
436 return cookie_settings_; | 438 return cookie_settings_; |
437 } | 439 } |
438 | 440 |
439 #if defined(ENABLE_NOTIFICATIONS) | 441 #if defined(ENABLE_NOTIFICATIONS) |
440 DesktopNotificationService* ProfileIOData::GetNotificationService() const { | 442 DesktopNotificationService* ProfileIOData::GetNotificationService() const { |
| 443 DCHECK(initialized_); |
441 return notification_service_; | 444 return notification_service_; |
442 } | 445 } |
443 #endif | 446 #endif |
444 | 447 |
445 void ProfileIOData::InitializeMetricsEnabledStateOnUIThread() { | 448 void ProfileIOData::InitializeMetricsEnabledStateOnUIThread() { |
446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 449 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
447 #if defined(OS_CHROMEOS) | 450 #if defined(OS_CHROMEOS) |
448 // Just fetch the value from ChromeOS' settings while we're on the UI thread. | 451 // Just fetch the value from ChromeOS' settings while we're on the UI thread. |
449 // TODO(stevet): For now, this value is only set on profile initialization. | 452 // TODO(stevet): For now, this value is only set on profile initialization. |
450 // We will want to do something similar to the PrefMember method below in the | 453 // We will want to do something similar to the PrefMember method below in the |
(...skipping 30 matching lines...) Expand all Loading... |
481 | 484 |
482 ProfileIOData::ResourceContext::ResourceContext(ProfileIOData* io_data) | 485 ProfileIOData::ResourceContext::ResourceContext(ProfileIOData* io_data) |
483 : io_data_(io_data), | 486 : io_data_(io_data), |
484 host_resolver_(NULL), | 487 host_resolver_(NULL), |
485 request_context_(NULL) { | 488 request_context_(NULL) { |
486 DCHECK(io_data); | 489 DCHECK(io_data); |
487 } | 490 } |
488 | 491 |
489 ProfileIOData::ResourceContext::~ResourceContext() {} | 492 ProfileIOData::ResourceContext::~ResourceContext() {} |
490 | 493 |
491 void ProfileIOData::ResourceContext::EnsureInitialized() { | |
492 io_data_->LazyInitialize(); | |
493 } | |
494 | |
495 net::HostResolver* ProfileIOData::ResourceContext::GetHostResolver() { | 494 net::HostResolver* ProfileIOData::ResourceContext::GetHostResolver() { |
496 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
497 EnsureInitialized(); | 496 DCHECK(io_data_->initialized_); |
498 return host_resolver_; | 497 return host_resolver_; |
499 } | 498 } |
500 | 499 |
501 net::URLRequestContext* ProfileIOData::ResourceContext::GetRequestContext() { | 500 net::URLRequestContext* ProfileIOData::ResourceContext::GetRequestContext() { |
502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 501 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
503 EnsureInitialized(); | 502 DCHECK(io_data_->initialized_); |
504 return request_context_; | 503 return request_context_; |
505 } | 504 } |
506 | 505 |
507 // static | 506 // static |
508 std::string ProfileIOData::GetSSLSessionCacheShard() { | 507 std::string ProfileIOData::GetSSLSessionCacheShard() { |
509 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 508 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
510 // The SSL session cache is partitioned by setting a string. This returns a | 509 // The SSL session cache is partitioned by setting a string. This returns a |
511 // unique string to partition the SSL session cache. Each time we create a | 510 // unique string to partition the SSL session cache. Each time we create a |
512 // new profile, we'll get a fresh SSL session cache which is separate from | 511 // new profile, we'll get a fresh SSL session cache which is separate from |
513 // the other profiles. | 512 // the other profiles. |
514 static unsigned ssl_session_cache_instance = 0; | 513 static unsigned ssl_session_cache_instance = 0; |
515 return StringPrintf("profile/%u", ssl_session_cache_instance++); | 514 return StringPrintf("profile/%u", ssl_session_cache_instance++); |
516 } | 515 } |
517 | 516 |
518 void ProfileIOData::LazyInitialize() const { | 517 void ProfileIOData::Init( |
| 518 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 519 blob_protocol_handler, |
| 520 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 521 file_system_protocol_handler, |
| 522 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 523 developer_protocol_handler) const { |
| 524 // The basic logic is implemented here. The specific initialization |
| 525 // is done in InitializeInternal(), implemented by subtypes. Static helper |
| 526 // functions have been provided to assist in common operations. |
519 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
520 if (initialized_) | 528 DCHECK(!initialized_); |
521 return; | |
522 | 529 |
523 // TODO(jhawkins): Remove once crbug.com/102004 is fixed. | 530 // TODO(jhawkins): Remove once crbug.com/102004 is fixed. |
524 CHECK(initialized_on_UI_thread_); | 531 CHECK(initialized_on_UI_thread_); |
525 | 532 |
526 // TODO(jhawkins): Return to DCHECK once crbug.com/102004 is fixed. | 533 // TODO(jhawkins): Return to DCHECK once crbug.com/102004 is fixed. |
527 CHECK(profile_params_.get()); | 534 CHECK(profile_params_.get()); |
528 | 535 |
529 IOThread* const io_thread = profile_params_->io_thread; | 536 IOThread* const io_thread = profile_params_->io_thread; |
530 IOThread::Globals* const io_thread_globals = io_thread->globals(); | 537 IOThread::Globals* const io_thread_globals = io_thread->globals(); |
531 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 538 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 extension_info_map_ = profile_params_->extension_info_map; | 590 extension_info_map_ = profile_params_->extension_info_map; |
584 | 591 |
585 resource_context_->host_resolver_ = io_thread_globals->host_resolver.get(); | 592 resource_context_->host_resolver_ = io_thread_globals->host_resolver.get(); |
586 resource_context_->request_context_ = main_request_context_.get(); | 593 resource_context_->request_context_ = main_request_context_.get(); |
587 | 594 |
588 if (profile_params_->resource_prefetch_predictor_observer_.get()) { | 595 if (profile_params_->resource_prefetch_predictor_observer_.get()) { |
589 resource_prefetch_predictor_observer_.reset( | 596 resource_prefetch_predictor_observer_.reset( |
590 profile_params_->resource_prefetch_predictor_observer_.release()); | 597 profile_params_->resource_prefetch_predictor_observer_.release()); |
591 } | 598 } |
592 | 599 |
593 LazyInitializeInternal(profile_params_.get()); | 600 InitializeInternal(profile_params_.get(), |
| 601 blob_protocol_handler.Pass(), |
| 602 file_system_protocol_handler.Pass(), |
| 603 developer_protocol_handler.Pass()); |
594 | 604 |
595 profile_params_.reset(); | 605 profile_params_.reset(); |
596 initialized_ = true; | 606 initialized_ = true; |
597 } | 607 } |
598 | 608 |
599 void ProfileIOData::ApplyProfileParamsToContext( | 609 void ProfileIOData::ApplyProfileParamsToContext( |
600 ChromeURLRequestContext* context) const { | 610 ChromeURLRequestContext* context) const { |
601 context->set_is_incognito(is_incognito()); | 611 context->set_is_incognito(is_incognito()); |
602 context->set_http_user_agent_settings( | 612 context->set_http_user_agent_settings( |
603 chrome_http_user_agent_settings_.get()); | 613 chrome_http_user_agent_settings_.get()); |
(...skipping 16 matching lines...) Expand all Loading... |
620 set_protocol = job_factory->SetProtocolHandler( | 630 set_protocol = job_factory->SetProtocolHandler( |
621 chrome::kChromeDevToolsScheme, | 631 chrome::kChromeDevToolsScheme, |
622 CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), | 632 CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), |
623 network_delegate)); | 633 network_delegate)); |
624 DCHECK(set_protocol); | 634 DCHECK(set_protocol); |
625 | 635 |
626 if (protocol_handler_interceptor.get()) { | 636 if (protocol_handler_interceptor.get()) { |
627 job_factory->AddInterceptor(protocol_handler_interceptor.release()); | 637 job_factory->AddInterceptor(protocol_handler_interceptor.release()); |
628 } | 638 } |
629 | 639 |
| 640 DCHECK(extension_info_map_); |
630 set_protocol = job_factory->SetProtocolHandler( | 641 set_protocol = job_factory->SetProtocolHandler( |
631 extensions::kExtensionScheme, | 642 extensions::kExtensionScheme, |
632 CreateExtensionProtocolHandler(is_incognito(), GetExtensionInfoMap())); | 643 CreateExtensionProtocolHandler(is_incognito(), extension_info_map_)); |
633 DCHECK(set_protocol); | 644 DCHECK(set_protocol); |
634 set_protocol = job_factory->SetProtocolHandler( | 645 set_protocol = job_factory->SetProtocolHandler( |
635 chrome::kExtensionResourceScheme, | 646 chrome::kExtensionResourceScheme, |
636 CreateExtensionResourceProtocolHandler()); | 647 CreateExtensionResourceProtocolHandler()); |
637 DCHECK(set_protocol); | 648 DCHECK(set_protocol); |
638 set_protocol = job_factory->SetProtocolHandler( | 649 set_protocol = job_factory->SetProtocolHandler( |
639 chrome::kChromeUIScheme, | 650 chrome::kChromeUIScheme, |
640 ChromeURLDataManagerBackend::CreateProtocolHandler( | 651 ChromeURLDataManagerBackend::CreateProtocolHandler( |
641 chrome_url_data_manager_backend_.get())); | 652 chrome_url_data_manager_backend_.get())); |
642 DCHECK(set_protocol); | 653 DCHECK(set_protocol); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 void ProfileIOData::SetCookieSettingsForTesting( | 739 void ProfileIOData::SetCookieSettingsForTesting( |
729 CookieSettings* cookie_settings) { | 740 CookieSettings* cookie_settings) { |
730 DCHECK(!cookie_settings_.get()); | 741 DCHECK(!cookie_settings_.get()); |
731 cookie_settings_ = cookie_settings; | 742 cookie_settings_ = cookie_settings; |
732 } | 743 } |
733 | 744 |
734 void ProfileIOData::set_signin_names_for_testing( | 745 void ProfileIOData::set_signin_names_for_testing( |
735 SigninNamesOnIOThread* signin_names) { | 746 SigninNamesOnIOThread* signin_names) { |
736 signin_names_.reset(signin_names); | 747 signin_names_.reset(signin_names); |
737 } | 748 } |
OLD | NEW |