OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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" |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 void MockAppCacheStorage::RunOnePendingTask() { | 383 void MockAppCacheStorage::RunOnePendingTask() { |
384 DCHECK(!pending_tasks_.empty()); | 384 DCHECK(!pending_tasks_.empty()); |
385 Task* task = pending_tasks_.front(); | 385 Task* task = pending_tasks_.front(); |
386 pending_tasks_.pop_front(); | 386 pending_tasks_.pop_front(); |
387 task->Run(); | 387 task->Run(); |
388 delete task; | 388 delete task; |
389 } | 389 } |
390 | 390 |
391 void MockAppCacheStorage::AddStoredCache(AppCache* cache) { | 391 void MockAppCacheStorage::AddStoredCache(AppCache* cache) { |
392 int64 cache_id = cache->cache_id(); | 392 int64 cache_id = cache->cache_id(); |
393 if (stored_caches_.find(cache_id) == stored_caches_.end()) | 393 if (stored_caches_.find(cache_id) == stored_caches_.end()) { |
394 stored_caches_.insert(StoredCacheMap::value_type(cache_id, cache)); | 394 stored_caches_.insert( |
| 395 StoredCacheMap::value_type(cache_id, make_scoped_refptr(cache))); |
| 396 } |
395 } | 397 } |
396 | 398 |
397 void MockAppCacheStorage::RemoveStoredCache(AppCache* cache) { | 399 void MockAppCacheStorage::RemoveStoredCache(AppCache* cache) { |
398 // Do not remove from the working set, active caches are still usable | 400 // Do not remove from the working set, active caches are still usable |
399 // and may be looked up by id until they fall out of use. | 401 // and may be looked up by id until they fall out of use. |
400 stored_caches_.erase(cache->cache_id()); | 402 stored_caches_.erase(cache->cache_id()); |
401 } | 403 } |
402 | 404 |
403 void MockAppCacheStorage::RemoveStoredCaches( | 405 void MockAppCacheStorage::RemoveStoredCaches( |
404 const AppCacheGroup::Caches& caches) { | 406 const AppCacheGroup::Caches& caches) { |
405 AppCacheGroup::Caches::const_iterator it = caches.begin(); | 407 AppCacheGroup::Caches::const_iterator it = caches.begin(); |
406 while (it != caches.end()) { | 408 while (it != caches.end()) { |
407 RemoveStoredCache(*it); | 409 RemoveStoredCache(*it); |
408 ++it; | 410 ++it; |
409 } | 411 } |
410 } | 412 } |
411 | 413 |
412 void MockAppCacheStorage::AddStoredGroup(AppCacheGroup* group) { | 414 void MockAppCacheStorage::AddStoredGroup(AppCacheGroup* group) { |
413 const GURL& url = group->manifest_url(); | 415 const GURL& url = group->manifest_url(); |
414 if (stored_groups_.find(url) == stored_groups_.end()) | 416 if (stored_groups_.find(url) == stored_groups_.end()) { |
415 stored_groups_.insert(StoredGroupMap::value_type(url, group)); | 417 stored_groups_.insert( |
| 418 StoredGroupMap::value_type(url, make_scoped_refptr(group))); |
| 419 } |
416 } | 420 } |
417 | 421 |
418 void MockAppCacheStorage::RemoveStoredGroup(AppCacheGroup* group) { | 422 void MockAppCacheStorage::RemoveStoredGroup(AppCacheGroup* group) { |
419 stored_groups_.erase(group->manifest_url()); | 423 stored_groups_.erase(group->manifest_url()); |
420 } | 424 } |
421 | 425 |
422 bool MockAppCacheStorage::ShouldGroupLoadAppearAsync( | 426 bool MockAppCacheStorage::ShouldGroupLoadAppearAsync( |
423 const AppCacheGroup* group) { | 427 const AppCacheGroup* group) { |
424 // We'll have to query the database to see if a group for the | 428 // We'll have to query the database to see if a group for the |
425 // manifest_url exists on disk. So return true for async. | 429 // manifest_url exists on disk. So return true for async. |
(...skipping 29 matching lines...) Expand all Loading... |
455 bool MockAppCacheStorage::ShouldCacheLoadAppearAsync(const AppCache* cache) { | 459 bool MockAppCacheStorage::ShouldCacheLoadAppearAsync(const AppCache* cache) { |
456 if (!cache) | 460 if (!cache) |
457 return true; | 461 return true; |
458 | 462 |
459 // If the 'stored' ref is the only ref, real storage will have to load from | 463 // If the 'stored' ref is the only ref, real storage will have to load from |
460 // the database. | 464 // the database. |
461 return IsCacheStored(cache) && cache->HasOneRef(); | 465 return IsCacheStored(cache) && cache->HasOneRef(); |
462 } | 466 } |
463 | 467 |
464 } // namespace appcache | 468 } // namespace appcache |
OLD | NEW |