diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-22 19:50:31 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-22 19:50:31 +0000 |
commit | e2fc3d25fe020a7e7518af1aea31085adc1002a1 (patch) | |
tree | fc64854da0b8cc3ac30df1bb6a399885365fb092 /chrome/browser/profile.cc | |
parent | f09ef6740a2d3342dd41796e01916957d20b6586 (diff) | |
download | chromium_src-e2fc3d25fe020a7e7518af1aea31085adc1002a1.zip chromium_src-e2fc3d25fe020a7e7518af1aea31085adc1002a1.tar.gz chromium_src-e2fc3d25fe020a7e7518af1aea31085adc1002a1.tar.bz2 |
Fix appcache_service and request_context referencing.
There is one appcache service per profile and several request context per profile. The profile holds a reference to the appcache service. Those request contexts which are subject to retrieval from appcaches hold a reference to the appcache service too. The appcache service is provided with a pointer back to the 'main' request context, this context is used when updating appcaches.
Initialization is a little tricky because profiles can't be used on the IO thread and request contexts can't be used on the UI thread.
BUG=22597,22125
TEST=many existing tests exercise profile/context creation
Review URL: http://codereview.chromium.org/215024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26844 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/profile.cc')
-rw-r--r-- | chrome/browser/profile.cc | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index c3eea76..8655eae 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -134,13 +134,14 @@ static void CleanupRequestContext(ChromeURLRequestContext* context) { } } -static void CleanupAppCacheService(ChromeAppCacheService* service) { - if (service) { - MessageLoop* io_thread = ChromeThread::GetMessageLoop(ChromeThread::IO); +static void CleanupAppCacheService(ChromeAppCacheService* appcache_service) { + if (appcache_service) { + // The I/O thread may be NULL during testing. + base::Thread* io_thread = g_browser_process->io_thread(); if (io_thread) - io_thread->ReleaseSoon(FROM_HERE, service); + io_thread->message_loop()->ReleaseSoon(FROM_HERE, appcache_service); else - service->Release(); + appcache_service->Release(); } } @@ -203,7 +204,13 @@ class OffTheRecordProfileImpl : public Profile, : profile_(real_profile), extensions_request_context_(NULL), start_time_(Time::Now()) { - request_context_ = ChromeURLRequestContext::CreateOffTheRecord(this); + // Created here but lazily inititialized later, finally released on + // on the io thread, see CleanupAppCacheService. + appcache_service_ = new ChromeAppCacheService(); + appcache_service_->AddRef(); + + request_context_ = ChromeURLRequestContext::CreateOffTheRecord( + this, appcache_service_); request_context_->AddRef(); // Register for browser close notifications so we can detect when the last @@ -216,7 +223,7 @@ class OffTheRecordProfileImpl : public Profile, virtual ~OffTheRecordProfileImpl() { CleanupRequestContext(request_context_); CleanupRequestContext(extensions_request_context_); - CleanupAppCacheService(appcache_service_.release()); + CleanupAppCacheService(appcache_service_); } virtual FilePath GetPath() { return profile_->GetPath(); } @@ -239,12 +246,10 @@ class OffTheRecordProfileImpl : public Profile, } virtual ChromeAppCacheService* GetAppCacheService() { - if (!appcache_service_.get()) { - appcache_service_ = new ChromeAppCacheService(); - appcache_service_->InitializeOnUIThread( - GetPath(), GetRequestContext(), true); - } - return appcache_service_.get(); + DCHECK(request_context_); // should be created in ctor + if (!appcache_service_->is_initialized()) + appcache_service_->InitializeOnUIThread(GetPath(), true); + return appcache_service_; } virtual VisitedLinkMaster* GetVisitedLinkMaster() { @@ -526,7 +531,7 @@ class OffTheRecordProfileImpl : public Profile, ChromeURLRequestContext* extensions_request_context_; // Use a seperate appcache service for OTR. - scoped_refptr<ChromeAppCacheService> appcache_service_; + ChromeAppCacheService* appcache_service_; // The download manager that only stores downloaded items in memory. scoped_refptr<DownloadManager> download_manager_; @@ -579,6 +584,11 @@ ProfileImpl::ProfileImpl(const FilePath& path) extension_devtools_manager_ = new ExtensionDevToolsManager(this); } + // Created here but lazily inititialized later, finally released on + // on the io thread, see CleanupAppCacheService. + appcache_service_ = new ChromeAppCacheService(); + appcache_service_->AddRef(); + extension_process_manager_.reset(new ExtensionProcessManager(this)); extension_message_service_ = new ExtensionMessageService(this); @@ -769,7 +779,7 @@ ProfileImpl::~ProfileImpl() { CleanupRequestContext(request_context_); CleanupRequestContext(media_request_context_); CleanupRequestContext(extensions_request_context_); - CleanupAppCacheService(appcache_service_.release()); + CleanupAppCacheService(appcache_service_); // When the request contexts are gone, the blacklist wont be needed anymore. delete blacklist_; @@ -820,12 +830,11 @@ Profile* ProfileImpl::GetOriginalProfile() { } ChromeAppCacheService* ProfileImpl::GetAppCacheService() { - if (!appcache_service_.get()) { - appcache_service_ = new ChromeAppCacheService(); - appcache_service_->InitializeOnUIThread( - GetPath(), GetRequestContext(), false); + if (!appcache_service_->is_initialized()) { + EnsureRequestContextCreated(); + appcache_service_->InitializeOnUIThread(GetPath(), false); } - return appcache_service_.get(); + return appcache_service_; } VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() { @@ -926,7 +935,7 @@ URLRequestContext* ProfileImpl::GetRequestContext() { cache_path = GetCachePath(cache_path); request_context_ = ChromeURLRequestContext::CreateOriginal( - this, cookie_path, cache_path, max_size); + this, cookie_path, cache_path, max_size, appcache_service_); request_context_->AddRef(); // The first request context is always a normal (non-OTR) request context. @@ -957,7 +966,7 @@ URLRequestContext* ProfileImpl::GetRequestContextForMedia() { cache_path = GetMediaCachePath(cache_path); media_request_context_ = ChromeURLRequestContext::CreateOriginalForMedia( - this, cache_path, max_size); + this, cache_path, max_size, appcache_service_); media_request_context_->AddRef(); DCHECK(media_request_context_->cookie_store()); |