| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 10 #include "base/command_line.h" | 
|  | 11 #include "base/compiler_specific.h" | 
| 11 #include "base/logging.h" | 12 #include "base/logging.h" | 
|  | 13 #include "base/stl_util-inl.h" | 
| 12 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" | 
| 13 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" | 
| 14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 16 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 
| 15 #include "chrome/browser/extensions/user_script_master.h" | 17 #include "chrome/browser/extensions/user_script_master.h" | 
| 16 #include "chrome/browser/io_thread.h" | 18 #include "chrome/browser/io_thread.h" | 
| 17 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 19 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 
| 18 #include "chrome/browser/net/pref_proxy_config_service.h" | 20 #include "chrome/browser/net/pref_proxy_config_service.h" | 
| 19 #include "chrome/browser/net/proxy_service_factory.h" | 21 #include "chrome/browser/net/proxy_service_factory.h" | 
| 20 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" | 
| 21 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" | 
| 22 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" | 
| 23 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" | 
| 24 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" | 
| 25 #include "content/browser/browser_thread.h" | 27 #include "content/browser/browser_thread.h" | 
|  | 28 #include "content/browser/resource_context.h" | 
| 26 #include "content/common/notification_service.h" | 29 #include "content/common/notification_service.h" | 
| 27 #include "net/http/http_util.h" | 30 #include "net/http/http_util.h" | 
| 28 #include "net/proxy/proxy_config_service_fixed.h" | 31 #include "net/proxy/proxy_config_service_fixed.h" | 
| 29 #include "net/proxy/proxy_script_fetcher_impl.h" | 32 #include "net/proxy/proxy_script_fetcher_impl.h" | 
| 30 #include "net/proxy/proxy_service.h" | 33 #include "net/proxy/proxy_service.h" | 
|  | 34 #include "webkit/database/database_tracker.h" | 
| 31 | 35 | 
| 32 namespace { | 36 namespace { | 
| 33 | 37 | 
| 34 // ---------------------------------------------------------------------------- | 38 // ---------------------------------------------------------------------------- | 
| 35 // CookieMonster::Delegate implementation | 39 // CookieMonster::Delegate implementation | 
| 36 // ---------------------------------------------------------------------------- | 40 // ---------------------------------------------------------------------------- | 
| 37 class ChromeCookieMonsterDelegate : public net::CookieMonster::Delegate { | 41 class ChromeCookieMonsterDelegate : public net::CookieMonster::Delegate { | 
| 38  public: | 42  public: | 
| 39   explicit ChromeCookieMonsterDelegate(Profile* profile) { | 43   explicit ChromeCookieMonsterDelegate(Profile* profile) { | 
| 40     DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 44     DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 114           Source<Profile>(profile_getter_->get()), | 118           Source<Profile>(profile_getter_->get()), | 
| 115           Details<ChromeCookieDetails>(&cookie_details)); | 119           Details<ChromeCookieDetails>(&cookie_details)); | 
| 116     } | 120     } | 
| 117   } | 121   } | 
| 118 | 122 | 
| 119   scoped_refptr<ProfileGetter> profile_getter_; | 123   scoped_refptr<ProfileGetter> profile_getter_; | 
| 120 }; | 124 }; | 
| 121 | 125 | 
| 122 }  // namespace | 126 }  // namespace | 
| 123 | 127 | 
| 124 void ProfileIOData::InitializeProfileParams(Profile* profile, | 128 void ProfileIOData::InitializeProfileParams(Profile* profile) { | 
| 125                                             ProfileParams* params) { |  | 
| 126   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 129   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| 127   PrefService* pref_service = profile->GetPrefs(); | 130   PrefService* pref_service = profile->GetPrefs(); | 
| 128 | 131 | 
|  | 132   scoped_ptr<ProfileParams> params(new ProfileParams); | 
| 129   params->is_incognito = profile->IsOffTheRecord(); | 133   params->is_incognito = profile->IsOffTheRecord(); | 
| 130   params->clear_local_state_on_exit = | 134   params->clear_local_state_on_exit = | 
| 131       pref_service->GetBoolean(prefs::kClearSiteDataOnExit); | 135       pref_service->GetBoolean(prefs::kClearSiteDataOnExit); | 
| 132 | 136 | 
| 133   params->appcache_service = profile->GetAppCacheService(); | 137   params->appcache_service = profile->GetAppCacheService(); | 
| 134 | 138 | 
| 135   // Set up Accept-Language and Accept-Charset header values | 139   // Set up Accept-Language and Accept-Charset header values | 
| 136   params->accept_language = net::HttpUtil::GenerateAcceptLanguageHeader( | 140   params->accept_language = net::HttpUtil::GenerateAcceptLanguageHeader( | 
| 137       pref_service->GetString(prefs::kAcceptLanguages)); | 141       pref_service->GetString(prefs::kAcceptLanguages)); | 
| 138   std::string default_charset = pref_service->GetString(prefs::kDefaultCharset); | 142   std::string default_charset = pref_service->GetString(prefs::kDefaultCharset); | 
| (...skipping 30 matching lines...) Expand all  Loading... | 
| 169   params->blob_storage_context = profile->GetBlobStorageContext(); | 173   params->blob_storage_context = profile->GetBlobStorageContext(); | 
| 170   params->file_system_context = profile->GetFileSystemContext(); | 174   params->file_system_context = profile->GetFileSystemContext(); | 
| 171   params->extension_info_map = profile->GetExtensionInfoMap(); | 175   params->extension_info_map = profile->GetExtensionInfoMap(); | 
| 172   params->prerender_manager = profile->GetPrerenderManager(); | 176   params->prerender_manager = profile->GetPrerenderManager(); | 
| 173   params->protocol_handler_registry = profile->GetProtocolHandlerRegistry(); | 177   params->protocol_handler_registry = profile->GetProtocolHandlerRegistry(); | 
| 174 | 178 | 
| 175   params->proxy_config_service.reset( | 179   params->proxy_config_service.reset( | 
| 176       ProxyServiceFactory::CreateProxyConfigService( | 180       ProxyServiceFactory::CreateProxyConfigService( | 
| 177           profile->GetProxyConfigTracker())); | 181           profile->GetProxyConfigTracker())); | 
| 178   params->profile_id = profile->GetRuntimeId(); | 182   params->profile_id = profile->GetRuntimeId(); | 
|  | 183   profile_params_.reset(params.release()); | 
| 179 } | 184 } | 
| 180 | 185 | 
| 181 ProfileIOData::RequestContext::RequestContext() {} | 186 ProfileIOData::RequestContext::RequestContext() {} | 
| 182 ProfileIOData::RequestContext::~RequestContext() {} | 187 ProfileIOData::RequestContext::~RequestContext() {} | 
| 183 | 188 | 
| 184 ProfileIOData::ProfileParams::ProfileParams() | 189 ProfileIOData::ProfileParams::ProfileParams() | 
| 185     : is_incognito(false), | 190     : is_incognito(false), | 
| 186       clear_local_state_on_exit(false), | 191       clear_local_state_on_exit(false), | 
| 187       profile_id(Profile::kInvalidProfileId) {} | 192       profile_id(Profile::kInvalidProfileId) {} | 
| 188 ProfileIOData::ProfileParams::~ProfileParams() {} | 193 ProfileIOData::ProfileParams::~ProfileParams() {} | 
| 189 | 194 | 
| 190 ProfileIOData::ProfileIOData(bool is_incognito) | 195 ProfileIOData::ProfileIOData(bool is_incognito) | 
| 191     : initialized_(false) { | 196     : initialized_(false), | 
|  | 197       ALLOW_THIS_IN_INITIALIZER_LIST(resource_context_(this)) { | 
| 192   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 198   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| 193 } | 199 } | 
| 194 | 200 | 
| 195 ProfileIOData::~ProfileIOData() { | 201 ProfileIOData::~ProfileIOData() { | 
| 196   // If we have never initialized ProfileIOData, then Handle may hold the only | 202   // If we have never initialized ProfileIOData, then Handle may hold the only | 
| 197   // reference to it. The important thing is to make sure it hasn't been | 203   // reference to it. The important thing is to make sure it hasn't been | 
| 198   // initialized yet, because the lazily initialized variables are supposed to | 204   // initialized yet, because the lazily initialized variables are supposed to | 
| 199   // live on the IO thread. | 205   // live on the IO thread. | 
| 200   if (BrowserThread::CurrentlyOn(BrowserThread::UI)) | 206   if (BrowserThread::CurrentlyOn(BrowserThread::UI)) | 
| 201     DCHECK(!initialized_); | 207     DCHECK(!initialized_); | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 234 ProfileIOData::GetIsolatedAppRequestContext( | 240 ProfileIOData::GetIsolatedAppRequestContext( | 
| 235     scoped_refptr<ChromeURLRequestContext> main_context, | 241     scoped_refptr<ChromeURLRequestContext> main_context, | 
| 236     const std::string& app_id) const { | 242     const std::string& app_id) const { | 
| 237   LazyInitialize(); | 243   LazyInitialize(); | 
| 238   scoped_refptr<ChromeURLRequestContext> context = | 244   scoped_refptr<ChromeURLRequestContext> context = | 
| 239       AcquireIsolatedAppRequestContext(main_context, app_id); | 245       AcquireIsolatedAppRequestContext(main_context, app_id); | 
| 240   DCHECK(context); | 246   DCHECK(context); | 
| 241   return context; | 247   return context; | 
| 242 } | 248 } | 
| 243 | 249 | 
|  | 250 const content::ResourceContext& ProfileIOData::GetResourceContext() const { | 
|  | 251   return resource_context_; | 
|  | 252 } | 
|  | 253 | 
|  | 254 ProfileIOData::ResourceContext::ResourceContext(const ProfileIOData* io_data) | 
|  | 255     : io_data_(io_data) { | 
|  | 256   DCHECK(io_data); | 
|  | 257 } | 
|  | 258 ProfileIOData::ResourceContext::~ResourceContext() {} | 
|  | 259 | 
|  | 260 void ProfileIOData::ResourceContext::EnsureInitialized() const { | 
|  | 261   io_data_->LazyInitialize(); | 
|  | 262 } | 
|  | 263 | 
| 244 void ProfileIOData::LazyInitialize() const { | 264 void ProfileIOData::LazyInitialize() const { | 
| 245   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 265   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 
| 246   if (initialized_) | 266   if (initialized_) | 
| 247     return; | 267     return; | 
| 248   LazyInitializeInternal(); | 268   DCHECK(profile_params_.get()); | 
|  | 269   resource_context_.set_database_tracker(profile_params_->database_tracker); | 
|  | 270   LazyInitializeInternal(profile_params_.get()); | 
|  | 271   profile_params_.reset(); | 
| 249   initialized_ = true; | 272   initialized_ = true; | 
| 250 } | 273 } | 
| 251 | 274 | 
| 252 // static |  | 
| 253 void ProfileIOData::ApplyProfileParamsToContext( | 275 void ProfileIOData::ApplyProfileParamsToContext( | 
| 254     const ProfileParams& profile_params, | 276     ChromeURLRequestContext* context) const { | 
| 255     ChromeURLRequestContext* context) { | 277   context->set_is_incognito(profile_params_->is_incognito); | 
| 256   context->set_is_incognito(profile_params.is_incognito); | 278   context->set_accept_language(profile_params_->accept_language); | 
| 257   context->set_accept_language(profile_params.accept_language); | 279   context->set_accept_charset(profile_params_->accept_charset); | 
| 258   context->set_accept_charset(profile_params.accept_charset); | 280   context->set_referrer_charset(profile_params_->referrer_charset); | 
| 259   context->set_referrer_charset(profile_params.referrer_charset); | 281   context->set_user_script_dir_path(profile_params_->user_script_dir_path); | 
| 260   context->set_user_script_dir_path(profile_params.user_script_dir_path); |  | 
| 261   context->set_host_content_settings_map( | 282   context->set_host_content_settings_map( | 
| 262       profile_params.host_content_settings_map); | 283       profile_params_->host_content_settings_map); | 
| 263   context->set_host_zoom_map(profile_params.host_zoom_map); | 284   context->set_host_zoom_map(profile_params_->host_zoom_map); | 
| 264   context->set_transport_security_state( | 285   context->set_transport_security_state( | 
| 265       profile_params.transport_security_state); | 286       profile_params_->transport_security_state); | 
| 266   context->set_ssl_config_service(profile_params.ssl_config_service); | 287   context->set_ssl_config_service(profile_params_->ssl_config_service); | 
| 267   context->set_database_tracker(profile_params.database_tracker); | 288   context->set_appcache_service(profile_params_->appcache_service); | 
| 268   context->set_appcache_service(profile_params.appcache_service); | 289   context->set_blob_storage_context(profile_params_->blob_storage_context); | 
| 269   context->set_blob_storage_context(profile_params.blob_storage_context); | 290   context->set_file_system_context(profile_params_->file_system_context); | 
| 270   context->set_file_system_context(profile_params.file_system_context); | 291   context->set_extension_info_map(profile_params_->extension_info_map); | 
| 271   context->set_extension_info_map(profile_params.extension_info_map); | 292   context->set_prerender_manager(profile_params_->prerender_manager); | 
| 272   context->set_prerender_manager(profile_params.prerender_manager); |  | 
| 273 } | 293 } | 
| OLD | NEW | 
|---|