| 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" | 
|   11 #include "base/bind_helpers.h" |   11 #include "base/bind_helpers.h" | 
|   12 #include "base/command_line.h" |   12 #include "base/command_line.h" | 
|   13 #include "base/compiler_specific.h" |   13 #include "base/compiler_specific.h" | 
|   14 #include "base/logging.h" |   14 #include "base/logging.h" | 
|   15 #include "base/stl_util.h" |   15 #include "base/stl_util.h" | 
|   16 #include "base/string_number_conversions.h" |   16 #include "base/string_number_conversions.h" | 
|   17 #include "base/string_util.h" |   17 #include "base/string_util.h" | 
|   18 #include "base/stringprintf.h" |   18 #include "base/stringprintf.h" | 
|   19 #include "chrome/browser/browser_process.h" |   19 #include "chrome/browser/browser_process.h" | 
|   20 #include "chrome/browser/content_settings/cookie_settings.h" |   20 #include "chrome/browser/content_settings/cookie_settings.h" | 
|   21 #include "chrome/browser/content_settings/host_content_settings_map.h" |   21 #include "chrome/browser/content_settings/host_content_settings_map.h" | 
|   22 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |   22 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 
 |   23 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 
|   23 #include "chrome/browser/download/download_service.h" |   24 #include "chrome/browser/download/download_service.h" | 
|   24 #include "chrome/browser/download/download_service_factory.h" |   25 #include "chrome/browser/download/download_service_factory.h" | 
|   25 #include "chrome/browser/extensions/extension_info_map.h" |   26 #include "chrome/browser/extensions/extension_info_map.h" | 
|   26 #include "chrome/browser/extensions/extension_protocols.h" |   27 #include "chrome/browser/extensions/extension_protocols.h" | 
|   27 #include "chrome/browser/extensions/extension_resource_protocols.h" |   28 #include "chrome/browser/extensions/extension_resource_protocols.h" | 
|   28 #include "chrome/browser/extensions/extension_system.h" |   29 #include "chrome/browser/extensions/extension_system.h" | 
|   29 #include "chrome/browser/io_thread.h" |   30 #include "chrome/browser/io_thread.h" | 
|   30 #include "chrome/browser/net/chrome_cookie_notification_details.h" |   31 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 
|   31 #include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h" |   32 #include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h" | 
|   32 #include "chrome/browser/net/chrome_net_log.h" |   33 #include "chrome/browser/net/chrome_net_log.h" | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  110       content::NotificationService::current()->Notify( |  111       content::NotificationService::current()->Notify( | 
|  111           chrome::NOTIFICATION_COOKIE_CHANGED, |  112           chrome::NOTIFICATION_COOKIE_CHANGED, | 
|  112           content::Source<Profile>(profile), |  113           content::Source<Profile>(profile), | 
|  113           content::Details<ChromeCookieDetails>(&cookie_details)); |  114           content::Details<ChromeCookieDetails>(&cookie_details)); | 
|  114     } |  115     } | 
|  115   } |  116   } | 
|  116  |  117  | 
|  117   const base::Callback<Profile*(void)> profile_getter_; |  118   const base::Callback<Profile*(void)> profile_getter_; | 
|  118 }; |  119 }; | 
|  119  |  120  | 
|  120 class ProtocolHandlerRegistryInterceptor |  | 
|  121     : public net::URLRequestJobFactory::Interceptor { |  | 
|  122  public: |  | 
|  123   explicit ProtocolHandlerRegistryInterceptor( |  | 
|  124       ProtocolHandlerRegistry* protocol_handler_registry) |  | 
|  125       : protocol_handler_registry_(protocol_handler_registry) { |  | 
|  126     DCHECK(protocol_handler_registry_); |  | 
|  127   } |  | 
|  128  |  | 
|  129   virtual ~ProtocolHandlerRegistryInterceptor() {} |  | 
|  130  |  | 
|  131   virtual net::URLRequestJob* MaybeIntercept( |  | 
|  132       net::URLRequest* request) const OVERRIDE { |  | 
|  133     return protocol_handler_registry_->MaybeCreateJob(request); |  | 
|  134   } |  | 
|  135  |  | 
|  136   virtual bool WillHandleProtocol(const std::string& protocol) const { |  | 
|  137     return protocol_handler_registry_->IsHandledProtocolIO(protocol); |  | 
|  138   } |  | 
|  139  |  | 
|  140   virtual net::URLRequestJob* MaybeInterceptRedirect( |  | 
|  141       const GURL& url, net::URLRequest* request) const OVERRIDE { |  | 
|  142     return NULL; |  | 
|  143   } |  | 
|  144  |  | 
|  145   virtual net::URLRequestJob* MaybeInterceptResponse( |  | 
|  146       net::URLRequest* request) const OVERRIDE { |  | 
|  147     return NULL; |  | 
|  148   } |  | 
|  149  |  | 
|  150  private: |  | 
|  151   const scoped_refptr<ProtocolHandlerRegistry> protocol_handler_registry_; |  | 
|  152  |  | 
|  153   DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistryInterceptor); |  | 
|  154 }; |  | 
|  155  |  | 
|  156 Profile* GetProfileOnUI(ProfileManager* profile_manager, Profile* profile) { |  121 Profile* GetProfileOnUI(ProfileManager* profile_manager, Profile* profile) { | 
|  157   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |  122   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
|  158   DCHECK(profile); |  123   DCHECK(profile); | 
|  159   if (profile_manager->IsValidProfile(profile)) |  124   if (profile_manager->IsValidProfile(profile)) | 
|  160     return profile; |  125     return profile; | 
|  161   return NULL; |  126   return NULL; | 
|  162 } |  127 } | 
|  163  |  128  | 
|  164 }  // namespace |  129 }  // namespace | 
|  165  |  130  | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  208               profile)) { |  173               profile)) { | 
|  209     resource_prefetch_predictor_observer_.reset( |  174     resource_prefetch_predictor_observer_.reset( | 
|  210         new chrome_browser_net::ResourcePrefetchPredictorObserver(predictor)); |  175         new chrome_browser_net::ResourcePrefetchPredictorObserver(predictor)); | 
|  211   } |  176   } | 
|  212  |  177  | 
|  213 #if defined(ENABLE_NOTIFICATIONS) |  178 #if defined(ENABLE_NOTIFICATIONS) | 
|  214   params->notification_service = |  179   params->notification_service = | 
|  215       DesktopNotificationServiceFactory::GetForProfile(profile); |  180       DesktopNotificationServiceFactory::GetForProfile(profile); | 
|  216 #endif |  181 #endif | 
|  217  |  182  | 
|  218   params->protocol_handler_registry = profile->GetProtocolHandlerRegistry(); |  183   ProtocolHandlerRegistry* protocol_handler_registry = | 
 |  184       ProtocolHandlerRegistryFactory::GetForProfile(profile); | 
 |  185   DCHECK(protocol_handler_registry); | 
 |  186  | 
 |  187   // the profile instance is only available here in the InitializeOnUIThread | 
 |  188   // method, so we create the url interceptor here, then save it for | 
 |  189   // later delivery to the job factory in LazyInitialize | 
 |  190   params->protocol_handler_url_interceptor.reset( | 
 |  191       protocol_handler_registry->CreateURLInterceptor()); | 
|  219  |  192  | 
|  220   ChromeProxyConfigService* proxy_config_service = |  193   ChromeProxyConfigService* proxy_config_service = | 
|  221       ProxyServiceFactory::CreateProxyConfigService(true); |  194       ProxyServiceFactory::CreateProxyConfigService(true); | 
|  222   params->proxy_config_service.reset(proxy_config_service); |  195   params->proxy_config_service.reset(proxy_config_service); | 
|  223   profile->GetProxyConfigTracker()->SetChromeProxyConfigService( |  196   profile->GetProxyConfigTracker()->SetChromeProxyConfigService( | 
|  224       proxy_config_service); |  197       proxy_config_service); | 
|  225   params->profile = profile; |  198   params->profile = profile; | 
|  226   profile_params_.reset(params.release()); |  199   profile_params_.reset(params.release()); | 
|  227  |  200  | 
|  228   // The URLBlacklistManager has to be created on the UI thread to register |  201   // The URLBlacklistManager has to be created on the UI thread to register | 
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  538   context->set_accept_language(profile_params_->accept_language); |  511   context->set_accept_language(profile_params_->accept_language); | 
|  539   context->set_accept_charset(profile_params_->accept_charset); |  512   context->set_accept_charset(profile_params_->accept_charset); | 
|  540   context->set_referrer_charset(profile_params_->referrer_charset); |  513   context->set_referrer_charset(profile_params_->referrer_charset); | 
|  541   context->set_ssl_config_service(profile_params_->ssl_config_service); |  514   context->set_ssl_config_service(profile_params_->ssl_config_service); | 
|  542 } |  515 } | 
|  543  |  516  | 
|  544 void ProfileIOData::SetUpJobFactoryDefaults( |  517 void ProfileIOData::SetUpJobFactoryDefaults( | 
|  545     net::URLRequestJobFactory* job_factory) const { |  518     net::URLRequestJobFactory* job_factory) const { | 
|  546   // NOTE(willchan): Keep these protocol handlers in sync with |  519   // NOTE(willchan): Keep these protocol handlers in sync with | 
|  547   // ProfileIOData::IsHandledProtocol(). |  520   // ProfileIOData::IsHandledProtocol(). | 
|  548   if (profile_params_->protocol_handler_registry) { |  521  | 
 |  522   if (profile_params_->protocol_handler_url_interceptor.get()) { | 
|  549     job_factory->AddInterceptor( |  523     job_factory->AddInterceptor( | 
|  550         new ProtocolHandlerRegistryInterceptor( |  524         profile_params_->protocol_handler_url_interceptor.release()); | 
|  551             profile_params_->protocol_handler_registry)); |  | 
|  552   } |  525   } | 
 |  526  | 
|  553   bool set_protocol = job_factory->SetProtocolHandler( |  527   bool set_protocol = job_factory->SetProtocolHandler( | 
|  554       chrome::kExtensionScheme, |  528       chrome::kExtensionScheme, | 
|  555       CreateExtensionProtocolHandler(is_incognito(), |  529       CreateExtensionProtocolHandler(is_incognito(), | 
|  556                                      profile_params_->extension_info_map)); |  530                                      profile_params_->extension_info_map)); | 
|  557   DCHECK(set_protocol); |  531   DCHECK(set_protocol); | 
|  558   set_protocol = job_factory->SetProtocolHandler( |  532   set_protocol = job_factory->SetProtocolHandler( | 
|  559       chrome::kExtensionResourceScheme, |  533       chrome::kExtensionResourceScheme, | 
|  560       CreateExtensionResourceProtocolHandler()); |  534       CreateExtensionResourceProtocolHandler()); | 
|  561   DCHECK(set_protocol); |  535   DCHECK(set_protocol); | 
|  562   set_protocol = job_factory->SetProtocolHandler( |  536   set_protocol = job_factory->SetProtocolHandler( | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  602 } |  576 } | 
|  603  |  577  | 
|  604 void ProfileIOData::set_server_bound_cert_service( |  578 void ProfileIOData::set_server_bound_cert_service( | 
|  605     net::ServerBoundCertService* server_bound_cert_service) const { |  579     net::ServerBoundCertService* server_bound_cert_service) const { | 
|  606   server_bound_cert_service_.reset(server_bound_cert_service); |  580   server_bound_cert_service_.reset(server_bound_cert_service); | 
|  607 } |  581 } | 
|  608  |  582  | 
|  609 void ProfileIOData::DestroyResourceContext() { |  583 void ProfileIOData::DestroyResourceContext() { | 
|  610   resource_context_.reset(); |  584   resource_context_.reset(); | 
|  611 } |  585 } | 
| OLD | NEW |