| 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 job factory here, then save it for | 175 // method, so we create the url job factory 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 = | 177 params->protocol_handler_interceptor = |
| 178 protocol_handler_registry->CreateJobInterceptorFactory(); | 178 protocol_handler_registry->CreateJobInterceptorFactory(); |
| 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<ProtocolHandlerRegistry::JobInterceptorFactory> | 392 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 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_http_user_agent_settings( | 611 context->set_http_user_agent_settings( |
| 602 chrome_http_user_agent_settings_.get()); | 612 chrome_http_user_agent_settings_.get()); |
| 603 context->set_ssl_config_service(profile_params_->ssl_config_service); | 613 context->set_ssl_config_service(profile_params_->ssl_config_service); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 614 // ProfileIOData::IsHandledProtocol(). | 624 // ProfileIOData::IsHandledProtocol(). |
| 615 bool set_protocol = job_factory->SetProtocolHandler( | 625 bool set_protocol = job_factory->SetProtocolHandler( |
| 616 chrome::kFileScheme, new net::FileProtocolHandler()); | 626 chrome::kFileScheme, new net::FileProtocolHandler()); |
| 617 DCHECK(set_protocol); | 627 DCHECK(set_protocol); |
| 618 | 628 |
| 619 set_protocol = job_factory->SetProtocolHandler( | 629 set_protocol = job_factory->SetProtocolHandler( |
| 620 chrome::kChromeDevToolsScheme, | 630 chrome::kChromeDevToolsScheme, |
| 621 CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), | 631 CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), |
| 622 network_delegate, is_incognito())); | 632 network_delegate, is_incognito())); |
| 623 DCHECK(set_protocol); | 633 DCHECK(set_protocol); |
| 634 DCHECK(extension_info_map_); |
| 624 set_protocol = job_factory->SetProtocolHandler( | 635 set_protocol = job_factory->SetProtocolHandler( |
| 625 extensions::kExtensionScheme, | 636 extensions::kExtensionScheme, |
| 626 CreateExtensionProtocolHandler(is_incognito(), GetExtensionInfoMap())); | 637 CreateExtensionProtocolHandler(is_incognito(), extension_info_map_)); |
| 627 DCHECK(set_protocol); | 638 DCHECK(set_protocol); |
| 628 set_protocol = job_factory->SetProtocolHandler( | 639 set_protocol = job_factory->SetProtocolHandler( |
| 629 chrome::kExtensionResourceScheme, | 640 chrome::kExtensionResourceScheme, |
| 630 CreateExtensionResourceProtocolHandler()); | 641 CreateExtensionResourceProtocolHandler()); |
| 631 DCHECK(set_protocol); | 642 DCHECK(set_protocol); |
| 632 set_protocol = job_factory->SetProtocolHandler( | 643 set_protocol = job_factory->SetProtocolHandler( |
| 633 chrome::kChromeUIScheme, | 644 chrome::kChromeUIScheme, |
| 634 ChromeURLDataManagerBackend::CreateProtocolHandler( | 645 ChromeURLDataManagerBackend::CreateProtocolHandler( |
| 635 chrome_url_data_manager_backend_.get(), | 646 chrome_url_data_manager_backend_.get(), |
| 636 is_incognito())); | 647 is_incognito())); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 void ProfileIOData::SetCookieSettingsForTesting( | 744 void ProfileIOData::SetCookieSettingsForTesting( |
| 734 CookieSettings* cookie_settings) { | 745 CookieSettings* cookie_settings) { |
| 735 DCHECK(!cookie_settings_.get()); | 746 DCHECK(!cookie_settings_.get()); |
| 736 cookie_settings_ = cookie_settings; | 747 cookie_settings_ = cookie_settings; |
| 737 } | 748 } |
| 738 | 749 |
| 739 void ProfileIOData::set_signin_names_for_testing( | 750 void ProfileIOData::set_signin_names_for_testing( |
| 740 SigninNamesOnIOThread* signin_names) { | 751 SigninNamesOnIOThread* signin_names) { |
| 741 signin_names_.reset(signin_names); | 752 signin_names_.reset(signin_names); |
| 742 } | 753 } |
| OLD | NEW |