From e2fc3d25fe020a7e7518af1aea31085adc1002a1 Mon Sep 17 00:00:00 2001 From: "michaeln@google.com" Date: Tue, 22 Sep 2009 19:50:31 +0000 Subject: 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 --- chrome/common/appcache/chrome_appcache_service.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'chrome/common/appcache') diff --git a/chrome/common/appcache/chrome_appcache_service.h b/chrome/common/appcache/chrome_appcache_service.h index 3dd6082..213a347 100644 --- a/chrome/common/appcache/chrome_appcache_service.h +++ b/chrome/common/appcache/chrome_appcache_service.h @@ -9,6 +9,7 @@ #include "base/message_loop.h" #include "base/ref_counted.h" #include "base/task.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_thread.h" #include "chrome/common/chrome_constants.h" #include "webkit/appcache/appcache_service.h" @@ -28,21 +29,21 @@ class ChromeAppCacheService public: explicit ChromeAppCacheService() - : was_initialized_with_io_thread_(false) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + : is_initialized_(false), was_initialized_with_io_thread_(false) { } + bool is_initialized() const { return is_initialized_; } + void InitializeOnUIThread(const FilePath& data_directory, - URLRequestContext* request_context, bool is_incognito) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - set_request_context(request_context); + DCHECK(!is_initialized_); + is_initialized_ = true; - // Some test cases run without an IO thread. - MessageLoop* io_thread = ChromeThread::GetMessageLoop(ChromeThread::IO); + // The I/O thread may be NULL during testing. + base::Thread* io_thread = g_browser_process->io_thread(); if (io_thread) { was_initialized_with_io_thread_ = true; - io_thread->PostTask(FROM_HERE, + io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &ChromeAppCacheService::InitializeOnIOThread, data_directory, is_incognito)); } @@ -63,6 +64,7 @@ class ChromeAppCacheService : data_directory.Append(chrome::kAppCacheDirname)); } + bool is_initialized_; bool was_initialized_with_io_thread_; }; -- cgit v1.1