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

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: Oops, inverted the assertions. 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
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();
179 } 183 }
180 184
181 ProfileIOData::RequestContext::RequestContext() {} 185 ProfileIOData::RequestContext::RequestContext() {}
182 ProfileIOData::RequestContext::~RequestContext() {} 186 ProfileIOData::RequestContext::~RequestContext() {}
183 187
188 ProfileIOData::ProfileResourceContextGetter::ProfileResourceContextGetter(
189 ProfileIOData* profile_io_data)
190 : profile_io_data_(profile_io_data) {
191 base::AutoLock auto_lock(profile_io_data_->lock_);
192 std::set<const ProfileResourceContextGetter*>& getters =
193 profile_io_data_->resource_context_getters_;
194 DCHECK(!ContainsKey(getters, this));
195 getters.insert(this);
196 }
197
198 ProfileIOData::ProfileResourceContextGetter::~ProfileResourceContextGetter() {
199 base::AutoLock auto_lock(profile_io_data_->lock_);
200 std::set<const ProfileResourceContextGetter*>& getters =
201 profile_io_data_->resource_context_getters_;
202 DCHECK(ContainsKey(getters, this));
203 getters.erase(this);
204 }
205
206 #ifndef NDEBUG
207 void ProfileIOData::ProfileResourceContextGetter::PrintStacktrace() const {
208 stacktrace_.PrintBacktrace();
209 }
210 #endif
211
212 const content::ResourceContext&
213 ProfileIOData::ProfileResourceContextGetter::GetImpl() {
214 return profile_io_data_->GetResourceContext();
215 }
216
184 ProfileIOData::ProfileParams::ProfileParams() 217 ProfileIOData::ProfileParams::ProfileParams()
185 : is_incognito(false), 218 : is_incognito(false),
186 clear_local_state_on_exit(false), 219 clear_local_state_on_exit(false),
187 profile_id(Profile::kInvalidProfileId) {} 220 profile_id(Profile::kInvalidProfileId) {}
188 ProfileIOData::ProfileParams::~ProfileParams() {} 221 ProfileIOData::ProfileParams::~ProfileParams() {}
189 222
190 ProfileIOData::ProfileIOData(bool is_incognito) 223 ProfileIOData::ProfileIOData(bool is_incognito)
191 : initialized_(false) { 224 : initialized_(false) {
192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
193 } 226 }
194 227
195 ProfileIOData::~ProfileIOData() { 228 ProfileIOData::~ProfileIOData() {
196 // If we have never initialized ProfileIOData, then Handle may hold the only 229 // 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 230 // 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 231 // initialized yet, because the lazily initialized variables are supposed to
199 // live on the IO thread. 232 // live on the IO thread.
200 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) 233 if (BrowserThread::CurrentlyOn(BrowserThread::UI))
201 DCHECK(!initialized_); 234 DCHECK(!initialized_);
202 else 235 else
203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
237
238 base::AutoLock auto_lock(lock_);
239 #ifndef NDEBUG
240 for (std::set<const ProfileResourceContextGetter*>::const_iterator it =
241 resource_context_getters_.begin(); it != resource_context_getters_.end();
242 ++it) {
243 LOG(ERROR) << "Leaked ProfileResourceContextGetter with allocation: ";
244 (*it)->PrintStacktrace();
245 }
246 #endif
247 DCHECK(resource_context_getters_.empty());
204 } 248 }
205 249
206 scoped_refptr<ChromeURLRequestContext> 250 scoped_refptr<ChromeURLRequestContext>
207 ProfileIOData::GetMainRequestContext() const { 251 ProfileIOData::GetMainRequestContext() const {
208 LazyInitialize(); 252 LazyInitialize();
209 scoped_refptr<ChromeURLRequestContext> context = 253 scoped_refptr<ChromeURLRequestContext> context =
210 AcquireMainRequestContext(); 254 AcquireMainRequestContext();
211 DCHECK(context); 255 DCHECK(context);
212 return context; 256 return context;
213 } 257 }
(...skipping 20 matching lines...) Expand all
234 ProfileIOData::GetIsolatedAppRequestContext( 278 ProfileIOData::GetIsolatedAppRequestContext(
235 scoped_refptr<ChromeURLRequestContext> main_context, 279 scoped_refptr<ChromeURLRequestContext> main_context,
236 const std::string& app_id) const { 280 const std::string& app_id) const {
237 LazyInitialize(); 281 LazyInitialize();
238 scoped_refptr<ChromeURLRequestContext> context = 282 scoped_refptr<ChromeURLRequestContext> context =
239 AcquireIsolatedAppRequestContext(main_context, app_id); 283 AcquireIsolatedAppRequestContext(main_context, app_id);
240 DCHECK(context); 284 DCHECK(context);
241 return context; 285 return context;
242 } 286 }
243 287
288 const content::ResourceContext& ProfileIOData::GetResourceContext() const {
289 LazyInitialize();
290 DCHECK(resource_context_.get());
291 return *resource_context_;
292 }
293
294 void ProfileIOData::set_resource_context(
295 const content::ResourceContext* resource_context) const {
296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
297 DCHECK(!resource_context_.get());
298 resource_context_.reset(resource_context);
299 }
300
244 void ProfileIOData::LazyInitialize() const { 301 void ProfileIOData::LazyInitialize() const {
245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
246 if (initialized_) 303 if (initialized_)
247 return; 304 return;
248 LazyInitializeInternal(); 305 LazyInitializeInternal();
249 initialized_ = true; 306 initialized_ = true;
250 } 307 }
251 308
252 // static 309 // static
253 void ProfileIOData::ApplyProfileParamsToContext( 310 void ProfileIOData::ApplyProfileParamsToContext(
254 const ProfileParams& profile_params, 311 const ProfileParams& profile_params,
255 ChromeURLRequestContext* context) { 312 ChromeURLRequestContext* context) {
256 context->set_is_incognito(profile_params.is_incognito); 313 context->set_is_incognito(profile_params.is_incognito);
257 context->set_accept_language(profile_params.accept_language); 314 context->set_accept_language(profile_params.accept_language);
258 context->set_accept_charset(profile_params.accept_charset); 315 context->set_accept_charset(profile_params.accept_charset);
259 context->set_referrer_charset(profile_params.referrer_charset); 316 context->set_referrer_charset(profile_params.referrer_charset);
260 context->set_user_script_dir_path(profile_params.user_script_dir_path); 317 context->set_user_script_dir_path(profile_params.user_script_dir_path);
261 context->set_host_content_settings_map( 318 context->set_host_content_settings_map(
262 profile_params.host_content_settings_map); 319 profile_params.host_content_settings_map);
263 context->set_host_zoom_map(profile_params.host_zoom_map); 320 context->set_host_zoom_map(profile_params.host_zoom_map);
264 context->set_transport_security_state( 321 context->set_transport_security_state(
265 profile_params.transport_security_state); 322 profile_params.transport_security_state);
266 context->set_ssl_config_service(profile_params.ssl_config_service); 323 context->set_ssl_config_service(profile_params.ssl_config_service);
267 context->set_database_tracker(profile_params.database_tracker);
268 context->set_appcache_service(profile_params.appcache_service); 324 context->set_appcache_service(profile_params.appcache_service);
269 context->set_blob_storage_context(profile_params.blob_storage_context); 325 context->set_blob_storage_context(profile_params.blob_storage_context);
270 context->set_file_system_context(profile_params.file_system_context); 326 context->set_file_system_context(profile_params.file_system_context);
271 context->set_extension_info_map(profile_params.extension_info_map); 327 context->set_extension_info_map(profile_params.extension_info_map);
272 context->set_prerender_manager(profile_params.prerender_manager); 328 context->set_prerender_manager(profile_params.prerender_manager);
273 } 329 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698