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

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

Issue 6825038: Create a content::ResourceContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test. Created 9 years, 8 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) 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
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 // static 128 void ProfileIOData::InitializeProfileParams(Profile* profile) {
125 void ProfileIOData::InitializeProfileParams(Profile* profile,
126 ProfileParams* params) {
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
128 PrefService* pref_service = profile->GetPrefs(); 130 PrefService* pref_service = profile->GetPrefs();
129 131
132 scoped_ptr<ProfileParams> params(new ProfileParams);
130 params->is_incognito = profile->IsOffTheRecord(); 133 params->is_incognito = profile->IsOffTheRecord();
131 params->clear_local_state_on_exit = 134 params->clear_local_state_on_exit =
132 pref_service->GetBoolean(prefs::kClearSiteDataOnExit); 135 pref_service->GetBoolean(prefs::kClearSiteDataOnExit);
133 136
134 params->appcache_service = profile->GetAppCacheService(); 137 params->appcache_service = profile->GetAppCacheService();
135 138
136 // Set up Accept-Language and Accept-Charset header values 139 // Set up Accept-Language and Accept-Charset header values
137 params->accept_language = net::HttpUtil::GenerateAcceptLanguageHeader( 140 params->accept_language = net::HttpUtil::GenerateAcceptLanguageHeader(
138 pref_service->GetString(prefs::kAcceptLanguages)); 141 pref_service->GetString(prefs::kAcceptLanguages));
139 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
170 params->blob_storage_context = profile->GetBlobStorageContext(); 173 params->blob_storage_context = profile->GetBlobStorageContext();
171 params->file_system_context = profile->GetFileSystemContext(); 174 params->file_system_context = profile->GetFileSystemContext();
172 params->extension_info_map = profile->GetExtensionInfoMap(); 175 params->extension_info_map = profile->GetExtensionInfoMap();
173 params->prerender_manager = profile->GetPrerenderManager(); 176 params->prerender_manager = profile->GetPrerenderManager();
174 params->protocol_handler_registry = profile->GetProtocolHandlerRegistry(); 177 params->protocol_handler_registry = profile->GetProtocolHandlerRegistry();
175 178
176 params->proxy_config_service.reset( 179 params->proxy_config_service.reset(
177 ProxyServiceFactory::CreateProxyConfigService( 180 ProxyServiceFactory::CreateProxyConfigService(
178 profile->GetProxyConfigTracker())); 181 profile->GetProxyConfigTracker()));
179 params->profile_id = profile->GetRuntimeId(); 182 params->profile_id = profile->GetRuntimeId();
183 profile_params_.reset(params.release());
180 } 184 }
181 185
182 ProfileIOData::RequestContext::RequestContext() {} 186 ProfileIOData::RequestContext::RequestContext() {}
183 ProfileIOData::RequestContext::~RequestContext() {} 187 ProfileIOData::RequestContext::~RequestContext() {}
184 188
185 ProfileIOData::ProfileParams::ProfileParams() 189 ProfileIOData::ProfileParams::ProfileParams()
186 : is_incognito(false), 190 : is_incognito(false),
187 clear_local_state_on_exit(false), 191 clear_local_state_on_exit(false),
188 profile_id(Profile::kInvalidProfileId) {} 192 profile_id(Profile::kInvalidProfileId) {}
189 ProfileIOData::ProfileParams::~ProfileParams() {} 193 ProfileIOData::ProfileParams::~ProfileParams() {}
190 194
191 ProfileIOData::ProfileIOData(bool is_incognito) 195 ProfileIOData::ProfileIOData(bool is_incognito)
192 : initialized_(false) { 196 : initialized_(false),
197 ALLOW_THIS_IN_INITIALIZER_LIST(resource_context_(this)) {
193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
194 } 199 }
195 200
196 ProfileIOData::~ProfileIOData() { 201 ProfileIOData::~ProfileIOData() {
197 // 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
198 // 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
199 // initialized yet, because the lazily initialized variables are supposed to 204 // initialized yet, because the lazily initialized variables are supposed to
200 // live on the IO thread. 205 // live on the IO thread.
201 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) 206 if (BrowserThread::CurrentlyOn(BrowserThread::UI))
202 DCHECK(!initialized_); 207 DCHECK(!initialized_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 ProfileIOData::GetIsolatedAppRequestContext( 240 ProfileIOData::GetIsolatedAppRequestContext(
236 scoped_refptr<ChromeURLRequestContext> main_context, 241 scoped_refptr<ChromeURLRequestContext> main_context,
237 const std::string& app_id) const { 242 const std::string& app_id) const {
238 LazyInitialize(); 243 LazyInitialize();
239 scoped_refptr<ChromeURLRequestContext> context = 244 scoped_refptr<ChromeURLRequestContext> context =
240 AcquireIsolatedAppRequestContext(main_context, app_id); 245 AcquireIsolatedAppRequestContext(main_context, app_id);
241 DCHECK(context); 246 DCHECK(context);
242 return context; 247 return context;
243 } 248 }
244 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
259 ProfileIOData::ResourceContext::~ResourceContext() {}
260
261 void ProfileIOData::ResourceContext::EnsureInitialized() const {
262 io_data_->LazyInitialize();
263 }
264
245 void ProfileIOData::LazyInitialize() const { 265 void ProfileIOData::LazyInitialize() const {
246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
247 if (initialized_) 267 if (initialized_)
248 return; 268 return;
249 LazyInitializeInternal(); 269 DCHECK(profile_params_.get());
270 database_tracker_ = profile_params_->database_tracker;
271 resource_context_.set_database_tracker(database_tracker_);
272 LazyInitializeInternal(profile_params_.get());
273 profile_params_.reset();
250 initialized_ = true; 274 initialized_ = true;
251 } 275 }
252 276
253 // static
254 void ProfileIOData::ApplyProfileParamsToContext( 277 void ProfileIOData::ApplyProfileParamsToContext(
255 const ProfileParams& profile_params, 278 ChromeURLRequestContext* context) const {
256 ChromeURLRequestContext* context) { 279 context->set_is_incognito(profile_params_->is_incognito);
257 context->set_is_incognito(profile_params.is_incognito); 280 context->set_accept_language(profile_params_->accept_language);
258 context->set_accept_language(profile_params.accept_language); 281 context->set_accept_charset(profile_params_->accept_charset);
259 context->set_accept_charset(profile_params.accept_charset); 282 context->set_referrer_charset(profile_params_->referrer_charset);
260 context->set_referrer_charset(profile_params.referrer_charset); 283 context->set_user_script_dir_path(profile_params_->user_script_dir_path);
261 context->set_user_script_dir_path(profile_params.user_script_dir_path);
262 context->set_host_content_settings_map( 284 context->set_host_content_settings_map(
263 profile_params.host_content_settings_map); 285 profile_params_->host_content_settings_map);
264 context->set_host_zoom_map(profile_params.host_zoom_map); 286 context->set_host_zoom_map(profile_params_->host_zoom_map);
265 context->set_transport_security_state( 287 context->set_transport_security_state(
266 profile_params.transport_security_state); 288 profile_params_->transport_security_state);
267 context->set_ssl_config_service(profile_params.ssl_config_service); 289 context->set_ssl_config_service(profile_params_->ssl_config_service);
268 context->set_database_tracker(profile_params.database_tracker); 290 context->set_appcache_service(profile_params_->appcache_service);
269 context->set_appcache_service(profile_params.appcache_service); 291 context->set_blob_storage_context(profile_params_->blob_storage_context);
270 context->set_blob_storage_context(profile_params.blob_storage_context); 292 context->set_file_system_context(profile_params_->file_system_context);
271 context->set_file_system_context(profile_params.file_system_context); 293 context->set_extension_info_map(profile_params_->extension_info_map);
272 context->set_extension_info_map(profile_params.extension_info_map); 294 context->set_prerender_manager(profile_params_->prerender_manager);
273 context->set_prerender_manager(profile_params.prerender_manager);
274 } 295 }
275 296
276 void ProfileIOData::ShutdownOnUIThread() { 297 void ProfileIOData::ShutdownOnUIThread() {
277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
278 enable_referrers_.Destroy(); 299 enable_referrers_.Destroy();
279 } 300 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_io_data.h ('k') | chrome/browser/renderer_host/browser_render_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698