From 8a4892d8d5ef84d8be7c47ac5e1b5e601f2a77b7 Mon Sep 17 00:00:00 2001 From: "michaeln@google.com" Date: Mon, 23 Nov 2009 20:40:57 +0000 Subject: The appcache system uses two threads, an IO thread and a DB thread. It does not create these threads, the embedder is responsible for providing them to the appcache library by implementing the class declared in appcache_thread.h. Also in this CL are two implementations, one for Chrome and another for test_shell. TEST=none BUG=none Review URL: http://codereview.chromium.org/409005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32846 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/common/appcache/chrome_appcache_service.cc | 50 +++++++++++++++++++++++ chrome/common/appcache/chrome_appcache_service.h | 22 +++------- 2 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 chrome/common/appcache/chrome_appcache_service.cc (limited to 'chrome/common') diff --git a/chrome/common/appcache/chrome_appcache_service.cc b/chrome/common/appcache/chrome_appcache_service.cc new file mode 100644 index 0000000..c1016cb --- /dev/null +++ b/chrome/common/appcache/chrome_appcache_service.cc @@ -0,0 +1,50 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/appcache/chrome_appcache_service.h" + +#include "base/file_path.h" +#include "chrome/browser/chrome_thread.h" +#include "chrome/common/chrome_constants.h" +#include "webkit/appcache/appcache_thread.h" + +static bool has_initialized_thread_ids; + +ChromeAppCacheService::ChromeAppCacheService(const FilePath& data_directory, + bool is_incognito) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + if (!has_initialized_thread_ids) { + has_initialized_thread_ids = true; + appcache::AppCacheThread::InitIDs(ChromeThread::DB, ChromeThread::IO); + } + Initialize(is_incognito ? FilePath() + : data_directory.Append(chrome::kAppCacheDirname)); +} + +ChromeAppCacheService::~ChromeAppCacheService() { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); +} + +static ChromeThread::ID ToChromeThreadID(int id) { + DCHECK(has_initialized_thread_ids); + DCHECK(id == ChromeThread::DB || id == ChromeThread::IO); + return static_cast(id); +} + +namespace appcache { + +// An impl of AppCacheThread we need to provide to the appcache lib. + +bool AppCacheThread::PostTask( + int id, + const tracked_objects::Location& from_here, + Task* task) { + return ChromeThread::PostTask(ToChromeThreadID(id), from_here, task); +} + +bool AppCacheThread::CurrentlyOn(int id) { + return ChromeThread::CurrentlyOn(ToChromeThreadID(id)); +} + +} // namespace appcache diff --git a/chrome/common/appcache/chrome_appcache_service.h b/chrome/common/appcache/chrome_appcache_service.h index 37e0dcb..509afd2 100644 --- a/chrome/common/appcache/chrome_appcache_service.h +++ b/chrome/common/appcache/chrome_appcache_service.h @@ -5,38 +5,28 @@ #ifndef CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_ #define CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_ -#include "base/file_path.h" -#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" +class FilePath; + // An AppCacheService subclass used by the chrome. There is an instance // associated with each Profile. This derivation adds refcounting semantics // since a profile has multiple URLRequestContexts which refer to the same // object, and those URLRequestContexts are refcounted independently of the // owning profile. // -// All methods, including the dtor, are expected to be called on the IO thread. +// All methods, including the ctor and dtor, are expected to be called on +// the IO thread. class ChromeAppCacheService : public base::RefCounted, public appcache::AppCacheService { public: - ChromeAppCacheService(const FilePath& data_directory, - bool is_incognito) { - Initialize(is_incognito ? FilePath() - : data_directory.Append(chrome::kAppCacheDirname)); - } + bool is_incognito); private: friend class base::RefCounted; - - virtual ~ChromeAppCacheService() { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - } + virtual ~ChromeAppCacheService(); }; #endif // CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_ -- cgit v1.1