OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/test/appcache_util.h" |
| 6 |
| 7 #include "base/message_loop.h" |
| 8 #include "content/browser/appcache/chrome_appcache_service.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "webkit/appcache/appcache.h" |
| 11 #include "webkit/appcache/appcache_entry.h" |
| 12 #include "webkit/appcache/appcache_group.h" |
| 13 |
| 14 AppCacheInserter::AppCacheInserter() |
| 15 : group_id_(0), |
| 16 appcache_id_(0), |
| 17 response_id_(0) {} |
| 18 |
| 19 AppCacheInserter::~AppCacheInserter() {} |
| 20 |
| 21 void AppCacheInserter::OnGroupAndNewestCacheStored( |
| 22 appcache::AppCacheGroup* /*group*/, |
| 23 appcache::AppCache* /*newest_cache*/, |
| 24 bool success, |
| 25 bool /*would_exceed_quota*/) { |
| 26 ASSERT_TRUE(success); |
| 27 MessageLoop::current()->Quit(); |
| 28 } |
| 29 |
| 30 void AppCacheInserter::AddGroupAndCache(ChromeAppCacheService* appcache_service, |
| 31 const GURL& manifest_url) { |
| 32 appcache::AppCacheGroup* appcache_group = |
| 33 new appcache::AppCacheGroup(appcache_service, |
| 34 manifest_url, |
| 35 ++group_id_); |
| 36 appcache::AppCache* appcache = new appcache::AppCache(appcache_service, |
| 37 ++appcache_id_); |
| 38 appcache::AppCacheEntry entry(appcache::AppCacheEntry::MANIFEST, |
| 39 ++response_id_); |
| 40 appcache->AddEntry(manifest_url, entry); |
| 41 appcache->set_complete(true); |
| 42 appcache_group->AddCache(appcache); |
| 43 appcache_service->storage()->StoreGroupAndNewestCache(appcache_group, |
| 44 appcache, |
| 45 this); |
| 46 // OnGroupAndNewestCacheStored will quit the message loop. |
| 47 MessageLoop::current()->Run(); |
| 48 } |
| 49 |
| 50 AppCacheReader::AppCacheReader(ChromeAppCacheService* appcache_service) |
| 51 : appcache_service_(appcache_service), |
| 52 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_got_info_callback_( |
| 53 this, &AppCacheReader::OnGotAppCacheInfo)) { |
| 54 } |
| 55 |
| 56 AppCacheReader::~AppCacheReader() {} |
| 57 |
| 58 std::set<GURL>* AppCacheReader::ReadAppCaches() { |
| 59 appcache_info_ = new appcache::AppCacheInfoCollection; |
| 60 appcache_service_->GetAllAppCacheInfo( |
| 61 appcache_info_, &appcache_got_info_callback_); |
| 62 |
| 63 MessageLoop::current()->Run(); |
| 64 return &origins_; |
| 65 } |
| 66 |
| 67 void AppCacheReader::OnGotAppCacheInfo(int rv) { |
| 68 typedef std::map<GURL, appcache::AppCacheInfoVector> InfoByOrigin; |
| 69 |
| 70 origins_.clear(); |
| 71 for (InfoByOrigin::const_iterator origin = |
| 72 appcache_info_->infos_by_origin.begin(); |
| 73 origin != appcache_info_->infos_by_origin.end(); ++origin) { |
| 74 origins_.insert(origin->first); |
| 75 } |
| 76 MessageLoop::current()->Quit(); |
| 77 } |
OLD | NEW |