Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7071)

Unified Diff: chrome/test/appcache_util.cc

Issue 7210006: AppCaches which belong to hosted apps are not protected from deletion (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: More cleanup. Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/appcache_util.cc
diff --git a/chrome/test/appcache_util.cc b/chrome/test/appcache_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..878c4edf59f379222176b39a1539c02374ce649e
--- /dev/null
+++ b/chrome/test/appcache_util.cc
@@ -0,0 +1,77 @@
+// Copyright (c) 2011 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/test/appcache_util.h"
+
+#include "base/message_loop.h"
+#include "content/browser/appcache/chrome_appcache_service.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/appcache/appcache.h"
+#include "webkit/appcache/appcache_entry.h"
+#include "webkit/appcache/appcache_group.h"
+
+AppCacheInserter::AppCacheInserter()
+ : group_id_(0),
+ appcache_id_(0),
+ response_id_(0) {}
+
+AppCacheInserter::~AppCacheInserter() {}
+
+void AppCacheInserter::OnGroupAndNewestCacheStored(
+ appcache::AppCacheGroup* /*group*/,
+ appcache::AppCache* /*newest_cache*/,
+ bool success,
+ bool /*would_exceed_quota*/) {
+ ASSERT_TRUE(success);
+ MessageLoop::current()->Quit();
+}
+
+void AppCacheInserter::AddGroupAndCache(ChromeAppCacheService* appcache_service,
+ const GURL& manifest_url) {
+ appcache::AppCacheGroup* appcache_group =
+ new appcache::AppCacheGroup(appcache_service,
+ manifest_url,
+ ++group_id_);
+ appcache::AppCache* appcache = new appcache::AppCache(appcache_service,
+ ++appcache_id_);
+ appcache::AppCacheEntry entry(appcache::AppCacheEntry::MANIFEST,
+ ++response_id_);
+ appcache->AddEntry(manifest_url, entry);
+ appcache->set_complete(true);
+ appcache_group->AddCache(appcache);
+ appcache_service->storage()->StoreGroupAndNewestCache(appcache_group,
+ appcache,
+ this);
+ // OnGroupAndNewestCacheStored will quit the message loop.
+ MessageLoop::current()->Run();
+}
+
+AppCacheReader::AppCacheReader(ChromeAppCacheService* appcache_service)
+ : appcache_service_(appcache_service),
+ ALLOW_THIS_IN_INITIALIZER_LIST(appcache_got_info_callback_(
+ this, &AppCacheReader::OnGotAppCacheInfo)) {
+}
+
+AppCacheReader::~AppCacheReader() {}
+
+std::set<GURL>* AppCacheReader::ReadAppCaches() {
+ appcache_info_ = new appcache::AppCacheInfoCollection;
+ appcache_service_->GetAllAppCacheInfo(
+ appcache_info_, &appcache_got_info_callback_);
+
+ MessageLoop::current()->Run();
+ return &origins_;
+}
+
+void AppCacheReader::OnGotAppCacheInfo(int rv) {
+ typedef std::map<GURL, appcache::AppCacheInfoVector> InfoByOrigin;
+
+ origins_.clear();
+ for (InfoByOrigin::const_iterator origin =
+ appcache_info_->infos_by_origin.begin();
+ origin != appcache_info_->infos_by_origin.end(); ++origin) {
+ origins_.insert(origin->first);
+ }
+ MessageLoop::current()->Quit();
+}

Powered by Google App Engine
This is Rietveld 408576698