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/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
11 #include "webkit/appcache/appcache.h" | 11 #include "webkit/appcache/appcache.h" |
12 #include "webkit/appcache/appcache_entry.h" | 12 #include "webkit/appcache/appcache_entry.h" |
13 #include "webkit/appcache/appcache_group.h" | 13 #include "webkit/appcache/appcache_group.h" |
14 #include "webkit/appcache/appcache_response.h" | 14 #include "webkit/appcache/appcache_response.h" |
15 | 15 |
16 // This is a quick and easy 'mock' implementation of the storage interface | 16 // This is a quick and easy 'mock' implementation of the storage interface |
17 // that doesn't put anything to disk. | 17 // that doesn't put anything to disk. |
18 // | 18 // |
19 // We simply add an extra reference to objects when they're put in storage, | 19 // We simply add an extra reference to objects when they're put in storage, |
20 // and remove the extra reference when they are removed from storage. | 20 // and remove the extra reference when they are removed from storage. |
21 // Responses are never really removed from the in-memory disk cache. | 21 // Responses are never really removed from the in-memory disk cache. |
22 // Delegate callbacks are made asyncly to appropiately mimic what will | 22 // Delegate callbacks are made asyncly to appropiately mimic what will |
23 // happen with a real disk-backed storage impl that involves IO on a | 23 // happen with a real disk-backed storage impl that involves IO on a |
24 // background thread. | 24 // background thread. |
25 | 25 |
26 namespace appcache { | 26 namespace appcache { |
27 | 27 |
28 MockAppCacheStorage::MockAppCacheStorage(AppCacheService* service) | 28 MockAppCacheStorage::MockAppCacheStorage(AppCacheService* service) |
29 : AppCacheStorage(service), | 29 : AppCacheStorage(service), |
30 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 30 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
| 31 simulate_make_group_obsolete_failure_(false), |
| 32 simulate_store_group_and_newest_cache_failure_(false) { |
31 last_cache_id_ = 0; | 33 last_cache_id_ = 0; |
32 last_entry_id_ = 0; | 34 last_entry_id_ = 0; |
33 last_group_id_ = 0; | 35 last_group_id_ = 0; |
34 last_response_id_ = 0; | 36 last_response_id_ = 0; |
35 } | 37 } |
36 | 38 |
37 MockAppCacheStorage::~MockAppCacheStorage() { | 39 MockAppCacheStorage::~MockAppCacheStorage() { |
38 STLDeleteElements(&pending_tasks_); | 40 STLDeleteElements(&pending_tasks_); |
39 } | 41 } |
40 | 42 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 if (delegate_ref->delegate) | 151 if (delegate_ref->delegate) |
150 delegate_ref->delegate->OnGroupLoaded(group, manifest_url); | 152 delegate_ref->delegate->OnGroupLoaded(group, manifest_url); |
151 } | 153 } |
152 | 154 |
153 void MockAppCacheStorage::ProcessStoreGroupAndNewestCache( | 155 void MockAppCacheStorage::ProcessStoreGroupAndNewestCache( |
154 scoped_refptr<AppCacheGroup> group, | 156 scoped_refptr<AppCacheGroup> group, |
155 scoped_refptr<AppCache> newest_cache, | 157 scoped_refptr<AppCache> newest_cache, |
156 scoped_refptr<DelegateReference> delegate_ref) { | 158 scoped_refptr<DelegateReference> delegate_ref) { |
157 DCHECK(group->newest_complete_cache() == newest_cache.get()); | 159 DCHECK(group->newest_complete_cache() == newest_cache.get()); |
158 | 160 |
| 161 if (simulate_store_group_and_newest_cache_failure_) { |
| 162 if (delegate_ref->delegate) |
| 163 delegate_ref->delegate->OnGroupAndNewestCacheStored(group, false); |
| 164 return; |
| 165 } |
| 166 |
159 AddStoredGroup(group); | 167 AddStoredGroup(group); |
160 AddStoredCache(group->newest_complete_cache()); | 168 AddStoredCache(group->newest_complete_cache()); |
161 | 169 |
162 // Copy the collection prior to removal, on final release | 170 // Copy the collection prior to removal, on final release |
163 // of a cache the group's collection will change. | 171 // of a cache the group's collection will change. |
164 AppCacheGroup::Caches copy = group->old_caches(); | 172 AppCacheGroup::Caches copy = group->old_caches(); |
165 RemoveStoredCaches(copy); | 173 RemoveStoredCaches(copy); |
166 | 174 |
167 if (delegate_ref->delegate) | 175 if (delegate_ref->delegate) |
168 delegate_ref->delegate->OnGroupAndNewestCacheStored(group, true); | 176 delegate_ref->delegate->OnGroupAndNewestCacheStored(group, true); |
(...skipping 19 matching lines...) Expand all Loading... |
188 // } | 196 // } |
189 if (delegate_ref->delegate) { | 197 if (delegate_ref->delegate) { |
190 delegate_ref->delegate->OnMainResponseFound( | 198 delegate_ref->delegate->OnMainResponseFound( |
191 url, AppCacheEntry(), kNoCacheId, GURL()); | 199 url, AppCacheEntry(), kNoCacheId, GURL()); |
192 } | 200 } |
193 } | 201 } |
194 | 202 |
195 void MockAppCacheStorage::ProcessMakeGroupObsolete( | 203 void MockAppCacheStorage::ProcessMakeGroupObsolete( |
196 scoped_refptr<AppCacheGroup> group, | 204 scoped_refptr<AppCacheGroup> group, |
197 scoped_refptr<DelegateReference> delegate_ref) { | 205 scoped_refptr<DelegateReference> delegate_ref) { |
| 206 if (simulate_make_group_obsolete_failure_) { |
| 207 if (delegate_ref->delegate) |
| 208 delegate_ref->delegate->OnGroupMadeObsolete(group, false); |
| 209 return; |
| 210 } |
| 211 |
198 RemoveStoredGroup(group); | 212 RemoveStoredGroup(group); |
199 if (group->newest_complete_cache()) | 213 if (group->newest_complete_cache()) |
200 RemoveStoredCache(group->newest_complete_cache()); | 214 RemoveStoredCache(group->newest_complete_cache()); |
201 | 215 |
202 // Copy the collection prior to removal, on final release | 216 // Copy the collection prior to removal, on final release |
203 // of a cache the group's collection will change. | 217 // of a cache the group's collection will change. |
204 AppCacheGroup::Caches copy = group->old_caches(); | 218 AppCacheGroup::Caches copy = group->old_caches(); |
205 RemoveStoredCaches(copy); | 219 RemoveStoredCaches(copy); |
206 | 220 |
207 group->set_obsolete(true); | 221 group->set_obsolete(true); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 bool MockAppCacheStorage::ShouldCacheLoadAppearAsync(const AppCache* cache) { | 310 bool MockAppCacheStorage::ShouldCacheLoadAppearAsync(const AppCache* cache) { |
297 if (!cache) | 311 if (!cache) |
298 return true; | 312 return true; |
299 | 313 |
300 // If the 'stored' ref is the only ref, real storage will have to load from | 314 // If the 'stored' ref is the only ref, real storage will have to load from |
301 // the database. | 315 // the database. |
302 return IsCacheStored(cache) && cache->HasOneRef(); | 316 return IsCacheStored(cache) && cache->HasOneRef(); |
303 } | 317 } |
304 | 318 |
305 } // namespace appcache | 319 } // namespace appcache |
OLD | NEW |