summaryrefslogtreecommitdiffstats
path: root/webkit/appcache/mock_appcache_storage.h
diff options
context:
space:
mode:
authormichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-21 18:09:33 +0000
committermichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-21 18:09:33 +0000
commit073aabe9e48306216d979f03d6c2fc37d25d42e9 (patch)
treea9088a3c8be87fa57208074c7de65e998b865f94 /webkit/appcache/mock_appcache_storage.h
parentc54d269e0b8a057533c1a1455a2acea0659629b9 (diff)
downloadchromium_src-073aabe9e48306216d979f03d6c2fc37d25d42e9.zip
chromium_src-073aabe9e48306216d979f03d6c2fc37d25d42e9.tar.gz
chromium_src-073aabe9e48306216d979f03d6c2fc37d25d42e9.tar.bz2
AppCacheResponse storage implementation
* classes AppCacheResponseReader and AppCacheResponseWriter * also implements AppCacheStorage.LoadResponseInfo() * using a memory-backed disk_cache for now, so not really on disk yet TEST=appcache_response_unittest.cc BUG=none Review URL: http://codereview.chromium.org/269062 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29670 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/mock_appcache_storage.h')
-rw-r--r--webkit/appcache/mock_appcache_storage.h41
1 files changed, 38 insertions, 3 deletions
diff --git a/webkit/appcache/mock_appcache_storage.h b/webkit/appcache/mock_appcache_storage.h
index 95cc082..8efb7d9 100644
--- a/webkit/appcache/mock_appcache_storage.h
+++ b/webkit/appcache/mock_appcache_storage.h
@@ -5,6 +5,13 @@
#ifndef WEBKIT_APPCACHE_MOCK_APPCACHE_STORAGE_H_
#define WEBKIT_APPCACHE_MOCK_APPCACHE_STORAGE_H_
+#include <map>
+
+#include "base/hash_tables.h"
+#include "base/scoped_ptr.h"
+#include "net/disk_cache/disk_cache.h"
+#include "webkit/appcache/appcache.h"
+#include "webkit/appcache/appcache_group.h"
#include "webkit/appcache/appcache_storage.h"
namespace appcache {
@@ -18,12 +25,9 @@ class MockAppCacheStorage : public AppCacheStorage {
explicit MockAppCacheStorage(AppCacheService* service);
virtual void LoadCache(int64 id, Delegate* delegate);
virtual void LoadOrCreateGroup(const GURL& manifest_url, Delegate* delegate);
- virtual void LoadResponseInfo(
- const GURL& manifest_url, int64 response_id, Delegate* delegate);
virtual void StoreGroupAndNewestCache(
AppCacheGroup* group, Delegate* delegate);
virtual void FindResponseForMainRequest(const GURL& url, Delegate* delegate);
- virtual void CancelDelegateCallbacks(Delegate* delegate);
virtual void MarkEntryAsForeign(const GURL& entry_url, int64 cache_id);
virtual void MarkGroupAsObsolete(AppCacheGroup* group, Delegate* delegate);
virtual AppCacheResponseReader* CreateResponseReader(
@@ -31,6 +35,37 @@ class MockAppCacheStorage : public AppCacheStorage {
virtual AppCacheResponseWriter* CreateResponseWriter(const GURL& origin);
virtual void DoomResponses(
const GURL& manifest_url, const std::vector<int64>& response_ids);
+
+ private:
+ typedef base::hash_map<int64, scoped_refptr<AppCache> > StoredCacheMap;
+ typedef std::map<GURL, scoped_refptr<AppCacheGroup> > StoredGroupMap;
+
+ void AddStoredCache(AppCache* cache);
+ void RemoveStoredCache(AppCache* cache);
+ AppCache* GetStoredCache(int64 id) {
+ StoredCacheMap::iterator it = stored_caches_.find(id);
+ return (it != stored_caches_.end()) ? it->second : NULL;
+ }
+
+ void AddStoredGroup(AppCacheGroup* group);
+ void RemoveStoredGroup(AppCacheGroup* group);
+ AppCacheGroup* GetStoredGroup(const GURL& manifest_url) {
+ StoredGroupMap::iterator it = stored_groups_.find(manifest_url);
+ return (it != stored_groups_.end()) ? it->second : NULL;
+ }
+
+ // Lazily constructed in-memory disk cache.
+ disk_cache::Backend* disk_cache() {
+ if (!disk_cache_.get()) {
+ const int kMaxCacheSize = 10 * 1024 * 1024;
+ disk_cache_.reset(disk_cache::CreateInMemoryCacheBackend(kMaxCacheSize));
+ }
+ return disk_cache_.get();
+ }
+
+ StoredCacheMap stored_caches_;
+ StoredGroupMap stored_groups_;
+ scoped_ptr<disk_cache::Backend> disk_cache_;
};
} // namespace appcache