Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: chrome/browser/profiles/profile_io_data.cc

Issue 11308362: Add StoragePartition's ProtocolHandlers at URLRequestContext construction time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync (r181485) Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 params->notification_service = 255 params->notification_service =
256 DesktopNotificationServiceFactory::GetForProfile(profile); 256 DesktopNotificationServiceFactory::GetForProfile(profile);
257 #endif 257 #endif
258 258
259 ProtocolHandlerRegistry* protocol_handler_registry = 259 ProtocolHandlerRegistry* protocol_handler_registry =
260 ProtocolHandlerRegistryFactory::GetForProfile(profile); 260 ProtocolHandlerRegistryFactory::GetForProfile(profile);
261 DCHECK(protocol_handler_registry); 261 DCHECK(protocol_handler_registry);
262 262
263 // The profile instance is only available here in the InitializeOnUIThread 263 // The profile instance is only available here in the InitializeOnUIThread
264 // method, so we create the url job factory here, then save it for 264 // method, so we create the url job factory here, then save it for
265 // later delivery to the job factory in LazyInitialize. 265 // later delivery to the job factory in Init().
266 params->protocol_handler_interceptor = 266 params->protocol_handler_interceptor =
267 protocol_handler_registry->CreateJobInterceptorFactory(); 267 protocol_handler_registry->CreateJobInterceptorFactory();
268 268
269 ChromeProxyConfigService* proxy_config_service = 269 ChromeProxyConfigService* proxy_config_service =
270 ProxyServiceFactory::CreateProxyConfigService(); 270 ProxyServiceFactory::CreateProxyConfigService();
271 params->proxy_config_service.reset(proxy_config_service); 271 params->proxy_config_service.reset(proxy_config_service);
272 profile->GetProxyConfigTracker()->SetChromeProxyConfigService( 272 profile->GetProxyConfigTracker()->SetChromeProxyConfigService(
273 proxy_config_service); 273 proxy_config_service);
274 #if defined(ENABLE_MANAGED_USERS) 274 #if defined(ENABLE_MANAGED_USERS)
275 ManagedUserService* managed_user_service = 275 ManagedUserService* managed_user_service =
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 return true; 452 return true;
453 } 453 }
454 454
455 return IsHandledProtocol(url.scheme()); 455 return IsHandledProtocol(url.scheme());
456 } 456 }
457 457
458 content::ResourceContext* ProfileIOData::GetResourceContext() const { 458 content::ResourceContext* ProfileIOData::GetResourceContext() const {
459 return resource_context_.get(); 459 return resource_context_.get();
460 } 460 }
461 461
462 ChromeURLRequestContext* 462 ChromeURLRequestContext* ProfileIOData::GetMainRequestContext() const {
463 ProfileIOData::GetMainRequestContext() const { 463 DCHECK(initialized_);
464 LazyInitialize();
465 return main_request_context_.get(); 464 return main_request_context_.get();
466 } 465 }
467 466
468 ChromeURLRequestContext* 467 ChromeURLRequestContext* ProfileIOData::GetMediaRequestContext() const {
469 ProfileIOData::GetMediaRequestContext() const { 468 DCHECK(initialized_);
470 LazyInitialize(); 469 ChromeURLRequestContext* context = AcquireMediaRequestContext();
471 ChromeURLRequestContext* context =
472 AcquireMediaRequestContext();
473 DCHECK(context); 470 DCHECK(context);
474 return context; 471 return context;
475 } 472 }
476 473
477 ChromeURLRequestContext* 474 ChromeURLRequestContext* ProfileIOData::GetExtensionsRequestContext() const {
478 ProfileIOData::GetExtensionsRequestContext() const { 475 DCHECK(initialized_);
479 LazyInitialize();
480 return extensions_request_context_.get(); 476 return extensions_request_context_.get();
481 } 477 }
482 478
483 ChromeURLRequestContext* 479 ChromeURLRequestContext* ProfileIOData::GetIsolatedAppRequestContext(
484 ProfileIOData::GetIsolatedAppRequestContext(
485 ChromeURLRequestContext* main_context, 480 ChromeURLRequestContext* main_context,
486 const StoragePartitionDescriptor& partition_descriptor, 481 const StoragePartitionDescriptor& partition_descriptor,
487 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> 482 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
488 protocol_handler_interceptor) const { 483 protocol_handler_interceptor,
489 LazyInitialize(); 484 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
485 blob_protocol_handler,
486 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
487 file_system_protocol_handler,
488 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
489 developer_protocol_handler,
490 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
491 chrome_protocol_handler,
492 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
493 chrome_devtools_protocol_handler) const {
494 DCHECK(initialized_);
490 ChromeURLRequestContext* context = NULL; 495 ChromeURLRequestContext* context = NULL;
491 if (ContainsKey(app_request_context_map_, partition_descriptor)) { 496 if (ContainsKey(app_request_context_map_, partition_descriptor)) {
492 context = app_request_context_map_[partition_descriptor]; 497 context = app_request_context_map_[partition_descriptor];
493 } else { 498 } else {
494 context = AcquireIsolatedAppRequestContext( 499 context = AcquireIsolatedAppRequestContext(
495 main_context, partition_descriptor, 500 main_context, partition_descriptor, protocol_handler_interceptor.Pass(),
496 protocol_handler_interceptor.Pass()); 501 blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(),
502 developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(),
503 chrome_devtools_protocol_handler.Pass());
497 app_request_context_map_[partition_descriptor] = context; 504 app_request_context_map_[partition_descriptor] = context;
498 } 505 }
499 DCHECK(context); 506 DCHECK(context);
500 return context; 507 return context;
501 } 508 }
502 509
503 ChromeURLRequestContext* 510 ChromeURLRequestContext* ProfileIOData::GetIsolatedMediaRequestContext(
504 ProfileIOData::GetIsolatedMediaRequestContext(
505 ChromeURLRequestContext* app_context, 511 ChromeURLRequestContext* app_context,
506 const StoragePartitionDescriptor& partition_descriptor) const { 512 const StoragePartitionDescriptor& partition_descriptor) const {
507 LazyInitialize(); 513 DCHECK(initialized_);
508 ChromeURLRequestContext* context = NULL; 514 ChromeURLRequestContext* context = NULL;
509 if (ContainsKey(isolated_media_request_context_map_, partition_descriptor)) { 515 if (ContainsKey(isolated_media_request_context_map_, partition_descriptor)) {
510 context = isolated_media_request_context_map_[partition_descriptor]; 516 context = isolated_media_request_context_map_[partition_descriptor];
511 } else { 517 } else {
512 context = AcquireIsolatedMediaRequestContext(app_context, 518 context = AcquireIsolatedMediaRequestContext(app_context,
513 partition_descriptor); 519 partition_descriptor);
514 isolated_media_request_context_map_[partition_descriptor] = context; 520 isolated_media_request_context_map_[partition_descriptor] = context;
515 } 521 }
516 DCHECK(context); 522 DCHECK(context);
517 return context; 523 return context;
518 } 524 }
519 525
520 ExtensionInfoMap* ProfileIOData::GetExtensionInfoMap() const { 526 ExtensionInfoMap* ProfileIOData::GetExtensionInfoMap() const {
521 DCHECK(extension_info_map_) << "ExtensionSystem not initialized"; 527 DCHECK(initialized_) << "ExtensionSystem not initialized";
522 return extension_info_map_; 528 return extension_info_map_;
523 } 529 }
524 530
525 CookieSettings* ProfileIOData::GetCookieSettings() const { 531 CookieSettings* ProfileIOData::GetCookieSettings() const {
532 // Allow either Init() or SetCookieSettingsForTesting() to initialize.
533 DCHECK(initialized_ || cookie_settings_);
526 return cookie_settings_; 534 return cookie_settings_;
527 } 535 }
528 536
529 #if defined(ENABLE_NOTIFICATIONS) 537 #if defined(ENABLE_NOTIFICATIONS)
530 DesktopNotificationService* ProfileIOData::GetNotificationService() const { 538 DesktopNotificationService* ProfileIOData::GetNotificationService() const {
539 DCHECK(initialized_);
531 return notification_service_; 540 return notification_service_;
532 } 541 }
533 #endif 542 #endif
534 543
535 void ProfileIOData::InitializeMetricsEnabledStateOnUIThread() { 544 void ProfileIOData::InitializeMetricsEnabledStateOnUIThread() {
536 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 545 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
537 #if defined(OS_CHROMEOS) 546 #if defined(OS_CHROMEOS)
538 // Just fetch the value from ChromeOS' settings while we're on the UI thread. 547 // Just fetch the value from ChromeOS' settings while we're on the UI thread.
539 // TODO(stevet): For now, this value is only set on profile initialization. 548 // TODO(stevet): For now, this value is only set on profile initialization.
540 // We will want to do something similar to the PrefMember method below in the 549 // We will want to do something similar to the PrefMember method below in the
(...skipping 30 matching lines...) Expand all
571 580
572 ProfileIOData::ResourceContext::ResourceContext(ProfileIOData* io_data) 581 ProfileIOData::ResourceContext::ResourceContext(ProfileIOData* io_data)
573 : io_data_(io_data), 582 : io_data_(io_data),
574 host_resolver_(NULL), 583 host_resolver_(NULL),
575 request_context_(NULL) { 584 request_context_(NULL) {
576 DCHECK(io_data); 585 DCHECK(io_data);
577 } 586 }
578 587
579 ProfileIOData::ResourceContext::~ResourceContext() {} 588 ProfileIOData::ResourceContext::~ResourceContext() {}
580 589
581 void ProfileIOData::ResourceContext::EnsureInitialized() {
582 io_data_->LazyInitialize();
583 }
584
585 net::HostResolver* ProfileIOData::ResourceContext::GetHostResolver() { 590 net::HostResolver* ProfileIOData::ResourceContext::GetHostResolver() {
586 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 591 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
587 EnsureInitialized(); 592 DCHECK(io_data_->initialized_);
588 return host_resolver_; 593 return host_resolver_;
589 } 594 }
590 595
591 net::URLRequestContext* ProfileIOData::ResourceContext::GetRequestContext() { 596 net::URLRequestContext* ProfileIOData::ResourceContext::GetRequestContext() {
592 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
593 EnsureInitialized(); 598 DCHECK(io_data_->initialized_);
594 return request_context_; 599 return request_context_;
595 } 600 }
596 601
597 // static 602 // static
598 std::string ProfileIOData::GetSSLSessionCacheShard() { 603 std::string ProfileIOData::GetSSLSessionCacheShard() {
599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 604 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
600 // The SSL session cache is partitioned by setting a string. This returns a 605 // The SSL session cache is partitioned by setting a string. This returns a
601 // unique string to partition the SSL session cache. Each time we create a 606 // unique string to partition the SSL session cache. Each time we create a
602 // new profile, we'll get a fresh SSL session cache which is separate from 607 // new profile, we'll get a fresh SSL session cache which is separate from
603 // the other profiles. 608 // the other profiles.
604 static unsigned ssl_session_cache_instance = 0; 609 static unsigned ssl_session_cache_instance = 0;
605 return StringPrintf("profile/%u", ssl_session_cache_instance++); 610 return StringPrintf("profile/%u", ssl_session_cache_instance++);
606 } 611 }
607 612
608 void ProfileIOData::LazyInitialize() const { 613 void ProfileIOData::Init(
614 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
615 blob_protocol_handler,
616 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
617 file_system_protocol_handler,
618 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
619 developer_protocol_handler,
620 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
621 chrome_protocol_handler,
622 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
623 chrome_devtools_protocol_handler) const {
624 // The basic logic is implemented here. The specific initialization
625 // is done in InitializeInternal(), implemented by subtypes. Static helper
626 // functions have been provided to assist in common operations.
609 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 627 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
610 if (initialized_) 628 DCHECK(!initialized_);
611 return;
612 629
613 startup_metric_utils::ScopedSlowStartupUMA 630 startup_metric_utils::ScopedSlowStartupUMA
614 scoped_timer("Startup.SlowStartupProfileIODataInit"); 631 scoped_timer("Startup.SlowStartupProfileIODataInit");
615 632
616 // TODO(jhawkins): Remove once crbug.com/102004 is fixed. 633 // TODO(jhawkins): Remove once crbug.com/102004 is fixed.
617 CHECK(initialized_on_UI_thread_); 634 CHECK(initialized_on_UI_thread_);
618 635
619 // TODO(jhawkins): Return to DCHECK once crbug.com/102004 is fixed. 636 // TODO(jhawkins): Return to DCHECK once crbug.com/102004 is fixed.
620 CHECK(profile_params_.get()); 637 CHECK(profile_params_.get());
621 638
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 695
679 if (profile_params_->resource_prefetch_predictor_observer_.get()) { 696 if (profile_params_->resource_prefetch_predictor_observer_.get()) {
680 resource_prefetch_predictor_observer_.reset( 697 resource_prefetch_predictor_observer_.reset(
681 profile_params_->resource_prefetch_predictor_observer_.release()); 698 profile_params_->resource_prefetch_predictor_observer_.release());
682 } 699 }
683 700
684 #if defined(ENABLE_MANAGED_USERS) 701 #if defined(ENABLE_MANAGED_USERS)
685 managed_mode_url_filter_ = profile_params_->managed_mode_url_filter; 702 managed_mode_url_filter_ = profile_params_->managed_mode_url_filter;
686 #endif 703 #endif
687 704
688 LazyInitializeInternal(profile_params_.get()); 705 InitializeInternal(profile_params_.get(),
706 blob_protocol_handler.Pass(),
707 file_system_protocol_handler.Pass(),
708 developer_protocol_handler.Pass(),
709 chrome_protocol_handler.Pass(),
710 chrome_devtools_protocol_handler.Pass());
689 711
690 profile_params_.reset(); 712 profile_params_.reset();
691 initialized_ = true; 713 initialized_ = true;
692 } 714 }
693 715
694 void ProfileIOData::ApplyProfileParamsToContext( 716 void ProfileIOData::ApplyProfileParamsToContext(
695 ChromeURLRequestContext* context) const { 717 ChromeURLRequestContext* context) const {
696 context->set_http_user_agent_settings( 718 context->set_http_user_agent_settings(
697 chrome_http_user_agent_settings_.get()); 719 chrome_http_user_agent_settings_.get());
698 context->set_ssl_config_service(profile_params_->ssl_config_service); 720 context->set_ssl_config_service(profile_params_->ssl_config_service);
699 } 721 }
700 722
701 scoped_ptr<net::URLRequestJobFactory> ProfileIOData::SetUpJobFactoryDefaults( 723 scoped_ptr<net::URLRequestJobFactory> ProfileIOData::SetUpJobFactoryDefaults(
702 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory, 724 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory,
703 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> 725 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
704 protocol_handler_interceptor, 726 protocol_handler_interceptor,
705 net::NetworkDelegate* network_delegate, 727 net::NetworkDelegate* network_delegate,
706 net::FtpTransactionFactory* ftp_transaction_factory, 728 net::FtpTransactionFactory* ftp_transaction_factory,
707 net::FtpAuthCache* ftp_auth_cache) const { 729 net::FtpAuthCache* ftp_auth_cache) const {
708 // NOTE(willchan): Keep these protocol handlers in sync with 730 // NOTE(willchan): Keep these protocol handlers in sync with
709 // ProfileIOData::IsHandledProtocol(). 731 // ProfileIOData::IsHandledProtocol().
710 bool set_protocol = job_factory->SetProtocolHandler( 732 bool set_protocol = job_factory->SetProtocolHandler(
711 chrome::kFileScheme, new net::FileProtocolHandler()); 733 chrome::kFileScheme, new net::FileProtocolHandler());
712 DCHECK(set_protocol); 734 DCHECK(set_protocol);
713 735
736 DCHECK(extension_info_map_);
714 set_protocol = job_factory->SetProtocolHandler( 737 set_protocol = job_factory->SetProtocolHandler(
715 extensions::kExtensionScheme, 738 extensions::kExtensionScheme,
716 CreateExtensionProtocolHandler(is_incognito(), GetExtensionInfoMap())); 739 CreateExtensionProtocolHandler(is_incognito(), extension_info_map_));
717 DCHECK(set_protocol); 740 DCHECK(set_protocol);
718 set_protocol = job_factory->SetProtocolHandler( 741 set_protocol = job_factory->SetProtocolHandler(
719 chrome::kExtensionResourceScheme, 742 chrome::kExtensionResourceScheme,
720 CreateExtensionResourceProtocolHandler()); 743 CreateExtensionResourceProtocolHandler());
721 DCHECK(set_protocol); 744 DCHECK(set_protocol);
722 set_protocol = job_factory->SetProtocolHandler( 745 set_protocol = job_factory->SetProtocolHandler(
723 chrome::kDataScheme, new net::DataProtocolHandler()); 746 chrome::kDataScheme, new net::DataProtocolHandler());
724 DCHECK(set_protocol); 747 DCHECK(set_protocol);
725 #if defined(OS_CHROMEOS) 748 #if defined(OS_CHROMEOS)
726 if (!is_incognito() && profile_params_.get()) { 749 if (!is_incognito() && profile_params_.get()) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 void ProfileIOData::SetCookieSettingsForTesting( 844 void ProfileIOData::SetCookieSettingsForTesting(
822 CookieSettings* cookie_settings) { 845 CookieSettings* cookie_settings) {
823 DCHECK(!cookie_settings_.get()); 846 DCHECK(!cookie_settings_.get());
824 cookie_settings_ = cookie_settings; 847 cookie_settings_ = cookie_settings;
825 } 848 }
826 849
827 void ProfileIOData::set_signin_names_for_testing( 850 void ProfileIOData::set_signin_names_for_testing(
828 SigninNamesOnIOThread* signin_names) { 851 SigninNamesOnIOThread* signin_names) {
829 signin_names_.reset(signin_names); 852 signin_names_.reset(signin_names);
830 } 853 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_io_data.h ('k') | chrome/browser/ui/sync/one_click_signin_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698