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