summaryrefslogtreecommitdiffstats
path: root/webkit/appcache/mock_appcache_storage.cc
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.cc
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.cc')
-rw-r--r--webkit/appcache/mock_appcache_storage.cc82
1 files changed, 66 insertions, 16 deletions
diff --git a/webkit/appcache/mock_appcache_storage.cc b/webkit/appcache/mock_appcache_storage.cc
index 4dfb8c9..3144179 100644
--- a/webkit/appcache/mock_appcache_storage.cc
+++ b/webkit/appcache/mock_appcache_storage.cc
@@ -7,7 +7,6 @@
#include "base/logging.h"
#include "base/ref_counted.h"
#include "webkit/appcache/appcache.h"
-#include "webkit/appcache/appcache_backend_impl.h"
#include "webkit/appcache/appcache_entry.h"
#include "webkit/appcache/appcache_group.h"
#include "webkit/appcache/appcache_response.h"
@@ -24,6 +23,9 @@ MockAppCacheStorage::MockAppCacheStorage(AppCacheService* service)
void MockAppCacheStorage::LoadCache(int64 id, Delegate* delegate) {
AppCache* cache = working_set_.GetCache(id);
+ if (cache->HasOneRef()) {
+ // TODO(michaeln): make the load look async
+ }
delegate->OnCacheLoaded(cache, id);
}
@@ -34,23 +36,48 @@ void MockAppCacheStorage::LoadOrCreateGroup(
group = new AppCacheGroup(service_, manifest_url);
DCHECK(working_set_.GetGroup(manifest_url));
}
+ // TODO(michaeln): make the load look async if all of the groups
+ // caches only have one ref
delegate->OnGroupLoaded(group.get(), manifest_url);
}
-void MockAppCacheStorage::LoadResponseInfo(
- const GURL& manifest_url, int64 id, Delegate* delegate) {
- delegate->OnResponseInfoLoaded(working_set_.GetResponseInfo(id), id);
-}
-
void MockAppCacheStorage::StoreGroupAndNewestCache(
AppCacheGroup* group, Delegate* delegate) {
+ DCHECK(group->newest_complete_cache());
+
// TODO(michaeln): write me
+ // 'store' the group + newest
+ // 'unstore' the old caches
+ // figure out which responses can be doomed and doom them
+ // OldRepsonses - NewestResponse == ToBeDoomed
+
+ // TODO(michaeln): Make this appear async
+ //AddStoredGroup(group);
+ //AddStoredCache(group->newest_complete_cache());
+ //
+ //foreach(group->old_caches())
+ // RemoveStoredCache(old_cache);
+ //std::set<int64> doomed_responses_ = responses from old caches
+ //std::set<int64> needed_responses_ = responses from newest cache
+ //foreach(needed_responses_)
+ // doomed_responses_.remove(needed_response_);
+ //DoomResponses(group->manifest_url(), doomed_responses_);
+
delegate->OnGroupAndNewestCacheStored(group, false);
}
void MockAppCacheStorage::FindResponseForMainRequest(
const GURL& url, Delegate* delegate) {
// TODO(michaeln): write me
+ //
+ //foreach(stored_group) {
+ // if (group->manifest_url()->origin() != url.GetOrigin())
+ // continue;
+ //
+ // look for an entry
+ // look for a fallback namespace
+ // look for a online namespace
+ //}
delegate->OnMainResponseFound(
url, kNoResponseId, false, kNoCacheId, GURL::EmptyGURL());
}
@@ -65,34 +92,57 @@ void MockAppCacheStorage::MarkEntryAsForeign(
if (entry)
entry->add_types(AppCacheEntry::FOREIGN);
}
- // TODO(michaeln): actually update in storage, and if this cache is
+ // TODO(michaeln): in real storage update in storage, and if this cache is
// being loaded be sure to update the memory cache upon load completion.
}
void MockAppCacheStorage::MarkGroupAsObsolete(
AppCacheGroup* group, Delegate* delegate) {
// TODO(michaeln): write me
-}
-
-void MockAppCacheStorage::CancelDelegateCallbacks(Delegate* delegate) {
- // TODO(michaeln): remove delegate from callback list
+ // remove from working_set
+ // remove from storage
+ // doom things
+ // group->set_obsolete(true);
+ // TODO(michaeln): Make this appear async
}
AppCacheResponseReader* MockAppCacheStorage::CreateResponseReader(
const GURL& origin, int64 response_id) {
- return new AppCacheResponseReader(response_id, NULL);
- // TODO(michaeln): use a disk_cache
+ return new AppCacheResponseReader(response_id, disk_cache());
}
AppCacheResponseWriter* MockAppCacheStorage::CreateResponseWriter(
const GURL& manifest_url) {
- return new AppCacheResponseWriter(NewResponseId(), NULL);
- // TODO(michaeln): use a disk_cache
+ return new AppCacheResponseWriter(NewResponseId(), disk_cache());
}
void MockAppCacheStorage::DoomResponses(
const GURL& manifest_url, const std::vector<int64>& response_ids) {
- // TODO(michaeln): write me
+ // We don't bother with deleting responses from mock storage.
+}
+
+void MockAppCacheStorage::AddStoredCache(AppCache* cache) {
+// cache->set_is_stored(true);
+ int64 cache_id = cache->cache_id();
+ if (stored_caches_.find(cache_id) == stored_caches_.end())
+ stored_caches_.insert(StoredCacheMap::value_type(cache_id, cache));
+}
+
+void MockAppCacheStorage::RemoveStoredCache(AppCache* cache) {
+// cache->set_is_stored(false);
+ stored_caches_.erase(cache->cache_id());
+}
+
+void MockAppCacheStorage::AddStoredGroup(AppCacheGroup* group) {
+// group->set_is_stored(true);
+ const GURL& url = group->manifest_url();
+ if (stored_groups_.find(url) == stored_groups_.end())
+ stored_groups_.insert(StoredGroupMap::value_type(url, group));
+}
+
+void MockAppCacheStorage::RemoveStoredGroup(AppCacheGroup* group) {
+// group->set_is_stored(false);
+ stored_groups_.erase(group->manifest_url());
}
} // namespace appcache