diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-23 20:40:57 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-23 20:40:57 +0000 |
commit | 8a4892d8d5ef84d8be7c47ac5e1b5e601f2a77b7 (patch) | |
tree | dd56c3b7fb32d93154b58616e4e8368cc2702341 /chrome/common/appcache | |
parent | d6b7266a83b8fffe30fd79c9ebe7c155cb5b687d (diff) | |
download | chromium_src-8a4892d8d5ef84d8be7c47ac5e1b5e601f2a77b7.zip chromium_src-8a4892d8d5ef84d8be7c47ac5e1b5e601f2a77b7.tar.gz chromium_src-8a4892d8d5ef84d8be7c47ac5e1b5e601f2a77b7.tar.bz2 |
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
Diffstat (limited to 'chrome/common/appcache')
-rw-r--r-- | chrome/common/appcache/chrome_appcache_service.cc | 50 | ||||
-rw-r--r-- | chrome/common/appcache/chrome_appcache_service.h | 22 |
2 files changed, 56 insertions, 16 deletions
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<ChromeThread::ID>(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<ChromeAppCacheService>, 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<ChromeAppCacheService>; - - virtual ~ChromeAppCacheService() { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - } + virtual ~ChromeAppCacheService(); }; #endif // CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_ |