| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/appcache/mock_appcache_storage.h" | 5 #include "webkit/appcache/mock_appcache_storage.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
| 9 #include "webkit/appcache/appcache.h" | 9 #include "webkit/appcache/appcache.h" |
| 10 #include "webkit/appcache/appcache_backend_impl.h" | |
| 11 #include "webkit/appcache/appcache_entry.h" | 10 #include "webkit/appcache/appcache_entry.h" |
| 12 #include "webkit/appcache/appcache_group.h" | 11 #include "webkit/appcache/appcache_group.h" |
| 13 #include "webkit/appcache/appcache_response.h" | 12 #include "webkit/appcache/appcache_response.h" |
| 14 | 13 |
| 15 namespace appcache { | 14 namespace appcache { |
| 16 | 15 |
| 17 MockAppCacheStorage::MockAppCacheStorage(AppCacheService* service) | 16 MockAppCacheStorage::MockAppCacheStorage(AppCacheService* service) |
| 18 : AppCacheStorage(service) { | 17 : AppCacheStorage(service) { |
| 19 last_cache_id_ = 0; | 18 last_cache_id_ = 0; |
| 20 last_entry_id_ = 0; | 19 last_entry_id_ = 0; |
| 21 last_group_id_ = 0; | 20 last_group_id_ = 0; |
| 22 last_response_id_ = 0; | 21 last_response_id_ = 0; |
| 23 } | 22 } |
| 24 | 23 |
| 25 void MockAppCacheStorage::LoadCache(int64 id, Delegate* delegate) { | 24 void MockAppCacheStorage::LoadCache(int64 id, Delegate* delegate) { |
| 26 AppCache* cache = working_set_.GetCache(id); | 25 AppCache* cache = working_set_.GetCache(id); |
| 26 if (cache->HasOneRef()) { |
| 27 // TODO(michaeln): make the load look async |
| 28 } |
| 27 delegate->OnCacheLoaded(cache, id); | 29 delegate->OnCacheLoaded(cache, id); |
| 28 } | 30 } |
| 29 | 31 |
| 30 void MockAppCacheStorage::LoadOrCreateGroup( | 32 void MockAppCacheStorage::LoadOrCreateGroup( |
| 31 const GURL& manifest_url, Delegate* delegate) { | 33 const GURL& manifest_url, Delegate* delegate) { |
| 32 scoped_refptr<AppCacheGroup> group = working_set_.GetGroup(manifest_url); | 34 scoped_refptr<AppCacheGroup> group = working_set_.GetGroup(manifest_url); |
| 33 if (!group.get()) { | 35 if (!group.get()) { |
| 34 group = new AppCacheGroup(service_, manifest_url); | 36 group = new AppCacheGroup(service_, manifest_url); |
| 35 DCHECK(working_set_.GetGroup(manifest_url)); | 37 DCHECK(working_set_.GetGroup(manifest_url)); |
| 36 } | 38 } |
| 39 // TODO(michaeln): make the load look async if all of the groups |
| 40 // caches only have one ref |
| 37 delegate->OnGroupLoaded(group.get(), manifest_url); | 41 delegate->OnGroupLoaded(group.get(), manifest_url); |
| 38 } | 42 } |
| 39 | 43 |
| 40 void MockAppCacheStorage::LoadResponseInfo( | |
| 41 const GURL& manifest_url, int64 id, Delegate* delegate) { | |
| 42 delegate->OnResponseInfoLoaded(working_set_.GetResponseInfo(id), id); | |
| 43 } | |
| 44 | |
| 45 void MockAppCacheStorage::StoreGroupAndNewestCache( | 44 void MockAppCacheStorage::StoreGroupAndNewestCache( |
| 46 AppCacheGroup* group, Delegate* delegate) { | 45 AppCacheGroup* group, Delegate* delegate) { |
| 46 DCHECK(group->newest_complete_cache()); |
| 47 |
| 47 // TODO(michaeln): write me | 48 // TODO(michaeln): write me |
| 49 // 'store' the group + newest |
| 50 // 'unstore' the old caches |
| 51 // figure out which responses can be doomed and doom them |
| 52 // OldRepsonses - NewestResponse == ToBeDoomed |
| 53 |
| 54 // TODO(michaeln): Make this appear async |
| 55 //AddStoredGroup(group); |
| 56 //AddStoredCache(group->newest_complete_cache()); |
| 57 // |
| 58 //foreach(group->old_caches()) |
| 59 // RemoveStoredCache(old_cache); |
| 60 //std::set<int64> doomed_responses_ = responses from old caches |
| 61 //std::set<int64> needed_responses_ = responses from newest cache |
| 62 //foreach(needed_responses_) |
| 63 // doomed_responses_.remove(needed_response_); |
| 64 //DoomResponses(group->manifest_url(), doomed_responses_); |
| 65 |
| 48 delegate->OnGroupAndNewestCacheStored(group, false); | 66 delegate->OnGroupAndNewestCacheStored(group, false); |
| 49 } | 67 } |
| 50 | 68 |
| 51 void MockAppCacheStorage::FindResponseForMainRequest( | 69 void MockAppCacheStorage::FindResponseForMainRequest( |
| 52 const GURL& url, Delegate* delegate) { | 70 const GURL& url, Delegate* delegate) { |
| 53 // TODO(michaeln): write me | 71 // TODO(michaeln): write me |
| 72 // |
| 73 //foreach(stored_group) { |
| 74 // if (group->manifest_url()->origin() != url.GetOrigin()) |
| 75 // continue; |
| 76 // |
| 77 // look for an entry |
| 78 // look for a fallback namespace |
| 79 // look for a online namespace |
| 80 //} |
| 54 delegate->OnMainResponseFound( | 81 delegate->OnMainResponseFound( |
| 55 url, kNoResponseId, false, kNoCacheId, GURL::EmptyGURL()); | 82 url, kNoResponseId, false, kNoCacheId, GURL::EmptyGURL()); |
| 56 } | 83 } |
| 57 | 84 |
| 58 void MockAppCacheStorage::MarkEntryAsForeign( | 85 void MockAppCacheStorage::MarkEntryAsForeign( |
| 59 const GURL& entry_url, int64 cache_id) { | 86 const GURL& entry_url, int64 cache_id) { |
| 60 // Update the working set. | 87 // Update the working set. |
| 61 AppCache* cache = working_set_.GetCache(cache_id); | 88 AppCache* cache = working_set_.GetCache(cache_id); |
| 62 if (cache) { | 89 if (cache) { |
| 63 AppCacheEntry* entry = cache->GetEntry(entry_url); | 90 AppCacheEntry* entry = cache->GetEntry(entry_url); |
| 64 DCHECK(entry); | 91 DCHECK(entry); |
| 65 if (entry) | 92 if (entry) |
| 66 entry->add_types(AppCacheEntry::FOREIGN); | 93 entry->add_types(AppCacheEntry::FOREIGN); |
| 67 } | 94 } |
| 68 // TODO(michaeln): actually update in storage, and if this cache is | 95 // TODO(michaeln): in real storage update in storage, and if this cache is |
| 69 // being loaded be sure to update the memory cache upon load completion. | 96 // being loaded be sure to update the memory cache upon load completion. |
| 70 } | 97 } |
| 71 | 98 |
| 72 void MockAppCacheStorage::MarkGroupAsObsolete( | 99 void MockAppCacheStorage::MarkGroupAsObsolete( |
| 73 AppCacheGroup* group, Delegate* delegate) { | 100 AppCacheGroup* group, Delegate* delegate) { |
| 74 // TODO(michaeln): write me | 101 // TODO(michaeln): write me |
| 75 } | 102 // remove from working_set |
| 76 | 103 // remove from storage |
| 77 void MockAppCacheStorage::CancelDelegateCallbacks(Delegate* delegate) { | 104 // doom things |
| 78 // TODO(michaeln): remove delegate from callback list | 105 // group->set_obsolete(true); |
| 106 // TODO(michaeln): Make this appear async |
| 79 } | 107 } |
| 80 | 108 |
| 81 AppCacheResponseReader* MockAppCacheStorage::CreateResponseReader( | 109 AppCacheResponseReader* MockAppCacheStorage::CreateResponseReader( |
| 82 const GURL& origin, int64 response_id) { | 110 const GURL& origin, int64 response_id) { |
| 83 return new AppCacheResponseReader(response_id, NULL); | 111 return new AppCacheResponseReader(response_id, disk_cache()); |
| 84 // TODO(michaeln): use a disk_cache | |
| 85 } | 112 } |
| 86 | 113 |
| 87 AppCacheResponseWriter* MockAppCacheStorage::CreateResponseWriter( | 114 AppCacheResponseWriter* MockAppCacheStorage::CreateResponseWriter( |
| 88 const GURL& manifest_url) { | 115 const GURL& manifest_url) { |
| 89 return new AppCacheResponseWriter(NewResponseId(), NULL); | 116 return new AppCacheResponseWriter(NewResponseId(), disk_cache()); |
| 90 // TODO(michaeln): use a disk_cache | |
| 91 } | 117 } |
| 92 | 118 |
| 93 void MockAppCacheStorage::DoomResponses( | 119 void MockAppCacheStorage::DoomResponses( |
| 94 const GURL& manifest_url, const std::vector<int64>& response_ids) { | 120 const GURL& manifest_url, const std::vector<int64>& response_ids) { |
| 95 // TODO(michaeln): write me | 121 // We don't bother with deleting responses from mock storage. |
| 122 } |
| 123 |
| 124 void MockAppCacheStorage::AddStoredCache(AppCache* cache) { |
| 125 // cache->set_is_stored(true); |
| 126 int64 cache_id = cache->cache_id(); |
| 127 if (stored_caches_.find(cache_id) == stored_caches_.end()) |
| 128 stored_caches_.insert(StoredCacheMap::value_type(cache_id, cache)); |
| 129 } |
| 130 |
| 131 void MockAppCacheStorage::RemoveStoredCache(AppCache* cache) { |
| 132 // cache->set_is_stored(false); |
| 133 stored_caches_.erase(cache->cache_id()); |
| 134 } |
| 135 |
| 136 void MockAppCacheStorage::AddStoredGroup(AppCacheGroup* group) { |
| 137 // group->set_is_stored(true); |
| 138 const GURL& url = group->manifest_url(); |
| 139 if (stored_groups_.find(url) == stored_groups_.end()) |
| 140 stored_groups_.insert(StoredGroupMap::value_type(url, group)); |
| 141 } |
| 142 |
| 143 void MockAppCacheStorage::RemoveStoredGroup(AppCacheGroup* group) { |
| 144 // group->set_is_stored(false); |
| 145 stored_groups_.erase(group->manifest_url()); |
| 96 } | 146 } |
| 97 | 147 |
| 98 } // namespace appcache | 148 } // namespace appcache |
| OLD | NEW |