summaryrefslogtreecommitdiffstats
path: root/webkit/appcache/appcache_disk_cache.h
diff options
context:
space:
mode:
authormichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-19 19:34:17 +0000
committermichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-19 19:34:17 +0000
commitf5a73e0706b4cdaab833aedccd47b5843449e916 (patch)
treef5301e2939d4e6cf6650359b16f066287ea5414c /webkit/appcache/appcache_disk_cache.h
parent82af894c82bcd3f328939f4f1907a5548ecfeff6 (diff)
downloadchromium_src-f5a73e0706b4cdaab833aedccd47b5843449e916.zip
chromium_src-f5a73e0706b4cdaab833aedccd47b5843449e916.tar.gz
chromium_src-f5a73e0706b4cdaab833aedccd47b5843449e916.tar.bz2
Better encapsulate usage of the disk_cache backend within the appcache library.
BUG=78359 Review URL: http://codereview.chromium.org/7888069 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101795 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_disk_cache.h')
-rw-r--r--webkit/appcache/appcache_disk_cache.h46
1 files changed, 27 insertions, 19 deletions
diff --git a/webkit/appcache/appcache_disk_cache.h b/webkit/appcache/appcache_disk_cache.h
index 404da05..c2dfe57 100644
--- a/webkit/appcache/appcache_disk_cache.h
+++ b/webkit/appcache/appcache_disk_cache.h
@@ -5,26 +5,21 @@
#ifndef WEBKIT_APPCACHE_APPCACHE_DISK_CACHE_H_
#define WEBKIT_APPCACHE_APPCACHE_DISK_CACHE_H_
+#include <set>
#include <vector>
#include "base/memory/scoped_ptr.h"
#include "net/disk_cache/disk_cache.h"
+#include "webkit/appcache/appcache_response.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 {
+// An implementation of AppCacheDiskCacheInterface that
+// uses net::DiskCache as the backing store.
+class AppCacheDiskCache : public AppCacheDiskCacheInterface {
public:
AppCacheDiskCache();
- ~AppCacheDiskCache();
+ virtual ~AppCacheDiskCache();
// Initializes the object to use disk backed storage.
int InitWithDiskBackend(const FilePath& disk_cache_directory,
@@ -40,13 +35,15 @@ class AppCacheDiskCache {
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);
+ virtual int CreateEntry(int64 key, Entry** entry,
+ net::CompletionCallback* callback);
+ virtual int OpenEntry(int64 key, Entry** entry,
+ net::CompletionCallback* callback);
+ virtual int DoomEntry(int64 key, net::CompletionCallback* callback);
private:
+ class EntryImpl;
+
class CreateBackendCallback
: public net::CancelableCompletionCallback<AppCacheDiskCache> {
public:
@@ -62,6 +59,11 @@ class AppCacheDiskCache {
}
};
+ // PendingCalls allow 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.
enum PendingCallType {
CREATE,
OPEN,
@@ -70,30 +72,36 @@ class AppCacheDiskCache {
struct PendingCall {
PendingCallType call_type;
int64 key;
- disk_cache::Entry** entry;
+ 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)
+ Entry** entry, net::CompletionCallback* callback)
: call_type(call_type), key(key), entry(entry), callback(callback) {}
};
typedef std::vector<PendingCall> PendingCalls;
+ class ActiveCall;
+ typedef std::set<ActiveCall*> ActiveCalls;
+
bool is_initializing() const {
return create_backend_callback_.get() != NULL;
}
+ disk_cache::Backend* disk_cache() { return disk_cache_.get(); }
int Init(net::CacheType cache_type, const FilePath& directory,
int cache_size, bool force, base::MessageLoopProxy* cache_thread,
net::CompletionCallback* callback);
void OnCreateBackendComplete(int rv);
+ void AddActiveCall(ActiveCall* call) { active_calls_.insert(call); }
+ void RemoveActiveCall(ActiveCall* call) { active_calls_.erase(call); }
bool is_disabled_;
net::CompletionCallback* init_callback_;
scoped_refptr<CreateBackendCallback> create_backend_callback_;
PendingCalls pending_calls_;
+ ActiveCalls active_calls_;
scoped_ptr<disk_cache::Backend> disk_cache_;
};