OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 std::vector<int64>::const_iterator it = response_ids.begin(); | 174 std::vector<int64>::const_iterator it = response_ids.begin(); |
175 while (it != response_ids.end()) { | 175 while (it != response_ids.end()) { |
176 doomed_response_ids_.insert(*it); | 176 doomed_response_ids_.insert(*it); |
177 ++it; | 177 ++it; |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 void MockAppCacheStorage::ProcessGetAllInfo( | 181 void MockAppCacheStorage::ProcessGetAllInfo( |
182 scoped_refptr<DelegateReference> delegate_ref) { | 182 scoped_refptr<DelegateReference> delegate_ref) { |
183 if (delegate_ref->delegate) | 183 if (delegate_ref->delegate) |
184 delegate_ref->delegate->OnAllInfo(simulated_appcache_info_); | 184 delegate_ref->delegate->OnAllInfo(simulated_appcache_info_.get()); |
185 } | 185 } |
186 | 186 |
187 void MockAppCacheStorage::ProcessLoadCache( | 187 void MockAppCacheStorage::ProcessLoadCache( |
188 int64 id, scoped_refptr<DelegateReference> delegate_ref) { | 188 int64 id, scoped_refptr<DelegateReference> delegate_ref) { |
189 AppCache* cache = working_set_.GetCache(id); | 189 AppCache* cache = working_set_.GetCache(id); |
190 if (delegate_ref->delegate) | 190 if (delegate_ref->delegate) |
191 delegate_ref->delegate->OnCacheLoaded(cache, id); | 191 delegate_ref->delegate->OnCacheLoaded(cache, id); |
192 } | 192 } |
193 | 193 |
194 void MockAppCacheStorage::ProcessLoadOrCreateGroup( | 194 void MockAppCacheStorage::ProcessLoadOrCreateGroup( |
195 const GURL& manifest_url, scoped_refptr<DelegateReference> delegate_ref) { | 195 const GURL& manifest_url, scoped_refptr<DelegateReference> delegate_ref) { |
196 scoped_refptr<AppCacheGroup> group(working_set_.GetGroup(manifest_url)); | 196 scoped_refptr<AppCacheGroup> group(working_set_.GetGroup(manifest_url)); |
197 | 197 |
198 // Newly created groups are not put in the stored_groups collection | 198 // Newly created groups are not put in the stored_groups collection |
199 // until StoreGroupAndNewestCache is called. | 199 // until StoreGroupAndNewestCache is called. |
200 if (!group) | 200 if (!group.get()) |
201 group = new AppCacheGroup(service_->storage(), manifest_url, NewGroupId()); | 201 group = new AppCacheGroup(service_->storage(), manifest_url, NewGroupId()); |
202 | 202 |
203 if (delegate_ref->delegate) | 203 if (delegate_ref->delegate) |
204 delegate_ref->delegate->OnGroupLoaded(group, manifest_url); | 204 delegate_ref->delegate->OnGroupLoaded(group.get(), manifest_url); |
205 } | 205 } |
206 | 206 |
207 void MockAppCacheStorage::ProcessStoreGroupAndNewestCache( | 207 void MockAppCacheStorage::ProcessStoreGroupAndNewestCache( |
208 scoped_refptr<AppCacheGroup> group, | 208 scoped_refptr<AppCacheGroup> group, |
209 scoped_refptr<AppCache> newest_cache, | 209 scoped_refptr<AppCache> newest_cache, |
210 scoped_refptr<DelegateReference> delegate_ref) { | 210 scoped_refptr<DelegateReference> delegate_ref) { |
211 Delegate* delegate = delegate_ref->delegate; | 211 Delegate* delegate = delegate_ref->delegate; |
212 if (simulate_store_group_and_newest_cache_failure_) { | 212 if (simulate_store_group_and_newest_cache_failure_) { |
213 if (delegate) | 213 if (delegate) |
214 delegate->OnGroupAndNewestCacheStored(group, newest_cache, false, false); | 214 delegate->OnGroupAndNewestCacheStored( |
| 215 group.get(), newest_cache.get(), false, false); |
215 return; | 216 return; |
216 } | 217 } |
217 | 218 |
218 AddStoredGroup(group); | 219 AddStoredGroup(group.get()); |
219 if (newest_cache != group->newest_complete_cache()) { | 220 if (newest_cache.get() != group->newest_complete_cache()) { |
220 newest_cache->set_complete(true); | 221 newest_cache->set_complete(true); |
221 group->AddCache(newest_cache); | 222 group->AddCache(newest_cache.get()); |
222 AddStoredCache(newest_cache); | 223 AddStoredCache(newest_cache.get()); |
223 | 224 |
224 // Copy the collection prior to removal, on final release | 225 // Copy the collection prior to removal, on final release |
225 // of a cache the group's collection will change. | 226 // of a cache the group's collection will change. |
226 AppCacheGroup::Caches copy = group->old_caches(); | 227 AppCacheGroup::Caches copy = group->old_caches(); |
227 RemoveStoredCaches(copy); | 228 RemoveStoredCaches(copy); |
228 } | 229 } |
229 | 230 |
230 if (delegate) | 231 if (delegate) |
231 delegate->OnGroupAndNewestCacheStored(group, newest_cache, true, false); | 232 delegate->OnGroupAndNewestCacheStored( |
| 233 group.get(), newest_cache.get(), true, false); |
232 } | 234 } |
233 | 235 |
234 namespace { | 236 namespace { |
235 | 237 |
236 struct FoundCandidate { | 238 struct FoundCandidate { |
237 GURL namespace_entry_url; | 239 GURL namespace_entry_url; |
238 AppCacheEntry entry; | 240 AppCacheEntry entry; |
239 int64 cache_id; | 241 int64 cache_id; |
240 int64 group_id; | 242 int64 group_id; |
241 GURL manifest_url; | 243 GURL manifest_url; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 // Didn't find anything. | 411 // Didn't find anything. |
410 delegate_ref->delegate->OnMainResponseFound( | 412 delegate_ref->delegate->OnMainResponseFound( |
411 url, AppCacheEntry(), GURL(), AppCacheEntry(), kNoCacheId, 0, GURL()); | 413 url, AppCacheEntry(), GURL(), AppCacheEntry(), kNoCacheId, 0, GURL()); |
412 } | 414 } |
413 | 415 |
414 void MockAppCacheStorage::ProcessMakeGroupObsolete( | 416 void MockAppCacheStorage::ProcessMakeGroupObsolete( |
415 scoped_refptr<AppCacheGroup> group, | 417 scoped_refptr<AppCacheGroup> group, |
416 scoped_refptr<DelegateReference> delegate_ref) { | 418 scoped_refptr<DelegateReference> delegate_ref) { |
417 if (simulate_make_group_obsolete_failure_) { | 419 if (simulate_make_group_obsolete_failure_) { |
418 if (delegate_ref->delegate) | 420 if (delegate_ref->delegate) |
419 delegate_ref->delegate->OnGroupMadeObsolete(group, false); | 421 delegate_ref->delegate->OnGroupMadeObsolete(group.get(), false); |
420 return; | 422 return; |
421 } | 423 } |
422 | 424 |
423 RemoveStoredGroup(group); | 425 RemoveStoredGroup(group.get()); |
424 if (group->newest_complete_cache()) | 426 if (group->newest_complete_cache()) |
425 RemoveStoredCache(group->newest_complete_cache()); | 427 RemoveStoredCache(group->newest_complete_cache()); |
426 | 428 |
427 // Copy the collection prior to removal, on final release | 429 // Copy the collection prior to removal, on final release |
428 // of a cache the group's collection will change. | 430 // of a cache the group's collection will change. |
429 AppCacheGroup::Caches copy = group->old_caches(); | 431 AppCacheGroup::Caches copy = group->old_caches(); |
430 RemoveStoredCaches(copy); | 432 RemoveStoredCaches(copy); |
431 | 433 |
432 group->set_obsolete(true); | 434 group->set_obsolete(true); |
433 | 435 |
434 // Also remove from the working set, caches for an 'obsolete' group | 436 // Also remove from the working set, caches for an 'obsolete' group |
435 // may linger in use, but the group itself cannot be looked up by | 437 // may linger in use, but the group itself cannot be looked up by |
436 // 'manifest_url' in the working set any longer. | 438 // 'manifest_url' in the working set any longer. |
437 working_set()->RemoveGroup(group); | 439 working_set()->RemoveGroup(group.get()); |
438 | 440 |
439 if (delegate_ref->delegate) | 441 if (delegate_ref->delegate) |
440 delegate_ref->delegate->OnGroupMadeObsolete(group, true); | 442 delegate_ref->delegate->OnGroupMadeObsolete(group.get(), true); |
441 } | 443 } |
442 | 444 |
443 void MockAppCacheStorage::ScheduleTask(const base::Closure& task) { | 445 void MockAppCacheStorage::ScheduleTask(const base::Closure& task) { |
444 pending_tasks_.push_back(task); | 446 pending_tasks_.push_back(task); |
445 base::MessageLoop::current()->PostTask( | 447 base::MessageLoop::current()->PostTask( |
446 FROM_HERE, | 448 FROM_HERE, |
447 base::Bind(&MockAppCacheStorage::RunOnePendingTask, | 449 base::Bind(&MockAppCacheStorage::RunOnePendingTask, |
448 weak_factory_.GetWeakPtr())); | 450 weak_factory_.GetWeakPtr())); |
449 } | 451 } |
450 | 452 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 bool MockAppCacheStorage::ShouldCacheLoadAppearAsync(const AppCache* cache) { | 528 bool MockAppCacheStorage::ShouldCacheLoadAppearAsync(const AppCache* cache) { |
527 if (!cache) | 529 if (!cache) |
528 return true; | 530 return true; |
529 | 531 |
530 // If the 'stored' ref is the only ref, real storage will have to load from | 532 // If the 'stored' ref is the only ref, real storage will have to load from |
531 // the database. | 533 // the database. |
532 return IsCacheStored(cache) && cache->HasOneRef(); | 534 return IsCacheStored(cache) && cache->HasOneRef(); |
533 } | 535 } |
534 | 536 |
535 } // namespace appcache | 537 } // namespace appcache |
OLD | NEW |