diff options
author | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 22:02:28 +0000 |
---|---|---|
committer | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 22:02:28 +0000 |
commit | fd2885ab79962663f474a39b13cfbfdb4827534e (patch) | |
tree | 1ce0e0967d005178a64cf0d4a7e11e16a76fd3d8 /webkit/appcache/appcache_disk_cache.h | |
parent | 9348c1f762db498d399d07c0295e36d75ee7fa08 (diff) | |
download | chromium_src-fd2885ab79962663f474a39b13cfbfdb4827534e.zip chromium_src-fd2885ab79962663f474a39b13cfbfdb4827534e.tar.gz chromium_src-fd2885ab79962663f474a39b13cfbfdb4827534e.tar.bz2 |
AppCache: Migrate to the DiskCache's async interface and use the CacheType::APP_CACHE value.
BUG=38273
TEST=existing layout tests and unit tests apply
Review URL: http://codereview.chromium.org/886003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41884 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_disk_cache.h')
-rw-r--r-- | webkit/appcache/appcache_disk_cache.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/webkit/appcache/appcache_disk_cache.h b/webkit/appcache/appcache_disk_cache.h new file mode 100644 index 0000000..cc54fd9 --- /dev/null +++ b/webkit/appcache/appcache_disk_cache.h @@ -0,0 +1,99 @@ +// Copyright (c) 2010 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. + +#ifndef WEBKIT_APPCACHE_APPCACHE_DISK_CACHE_H_ +#define WEBKIT_APPCACHE_APPCACHE_DISK_CACHE_H_ + +#include <vector> + +#include "base/scoped_ptr.h" +#include "net/disk_cache/disk_cache.h" + +namespace appcache { + +// A thin wrapper around net::DiskCache that does a couple of things for us. +// +// 1. Translates int64 keys used by the appcache into std::string +// keys used by net::DiskCache. +// 2. Allows CreateEntry, OpenEntry, and DoomEntry to be called +// immediately after construction, without waiting for the +// underlying disk_cache::Backend to be fully constructed. Early +// calls are queued up and serviced once the disk_cache::Backend is +// really ready to go. +class AppCacheDiskCache { + public: + AppCacheDiskCache(); + ~AppCacheDiskCache(); + + // Initializes the object to use disk backed storage. + int InitWithDiskBackend(const FilePath& disk_cache_directory, + int disk_cache_size, bool force, + net::CompletionCallback* callback); + + // Initializes the object to use memory only storage. + // This is used for Chrome's incognito browsing. + int InitWithMemBackend(int disk_cache_size, + net::CompletionCallback* callback); + + void Disable(); + bool is_disabled() const { return is_disabled_; } + + int CreateEntry(int64 key, disk_cache::Entry** entry, + net::CompletionCallback* callback); + int OpenEntry(int64 key, disk_cache::Entry** entry, + net::CompletionCallback* callback); + int DoomEntry(int64 key, net::CompletionCallback* callback); + + private: + class CreateBackendCallback + : public net::CancelableCompletionCallback<AppCacheDiskCache> { + public: + typedef net::CancelableCompletionCallback<AppCacheDiskCache> BaseClass; + CreateBackendCallback(AppCacheDiskCache* object, + void (AppCacheDiskCache::* method)(int)) + : BaseClass(object, method), backend_ptr_(NULL) {} + + disk_cache::Backend* backend_ptr_; // Accessed directly. + private: + ~CreateBackendCallback() { + delete backend_ptr_; + } + }; + + enum PendingCallType { + CREATE, + OPEN, + DOOM + }; + struct PendingCall { + PendingCallType call_type; + int64 key; + disk_cache::Entry** entry; + net::CompletionCallback* callback; + + PendingCall() + : call_type(CREATE), key(0), entry(NULL), callback(NULL) {} + + PendingCall(PendingCallType call_type, int64 key, + disk_cache::Entry** entry, net::CompletionCallback* callback) + : call_type(call_type), key(key), entry(entry), callback(callback) {} + }; + typedef std::vector<PendingCall> PendingCalls; + + bool is_initializing() const { return create_backend_callback_.get(); } + int Init(net::CacheType cache_type, const FilePath& directory, + int cache_size, bool force, net::CompletionCallback* callback); + void OnCreateBackendComplete(int rv); + + bool is_disabled_; + net::CompletionCallback* init_callback_; + scoped_refptr<CreateBackendCallback> create_backend_callback_; + PendingCalls pending_calls_; + scoped_ptr<disk_cache::Backend> disk_cache_; +}; + +} // namespace appcache + +#endif // WEBKIT_APPCACHE_APPCACHE_DISK_CACHE_H_ + |