OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/appcache/mock_appcache_storage.h" | 5 #include "content/browser/appcache/mock_appcache_storage.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
10 #include "base/message_loop/message_loop.h" | 11 #include "base/single_thread_task_runner.h" |
11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/thread_task_runner_handle.h" |
12 #include "content/browser/appcache/appcache.h" | 14 #include "content/browser/appcache/appcache.h" |
13 #include "content/browser/appcache/appcache_entry.h" | 15 #include "content/browser/appcache/appcache_entry.h" |
14 #include "content/browser/appcache/appcache_group.h" | 16 #include "content/browser/appcache/appcache_group.h" |
15 #include "content/browser/appcache/appcache_response.h" | 17 #include "content/browser/appcache/appcache_response.h" |
16 #include "content/browser/appcache/appcache_service_impl.h" | 18 #include "content/browser/appcache/appcache_service_impl.h" |
17 | 19 |
18 // This is a quick and easy 'mock' implementation of the storage interface | 20 // This is a quick and easy 'mock' implementation of the storage interface |
19 // that doesn't put anything to disk. | 21 // that doesn't put anything to disk. |
20 // | 22 // |
21 // We simply add an extra reference to objects when they're put in storage, | 23 // We simply add an extra reference to objects when they're put in storage, |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 // 'manifest_url' in the working set any longer. | 453 // 'manifest_url' in the working set any longer. |
452 working_set()->RemoveGroup(group.get()); | 454 working_set()->RemoveGroup(group.get()); |
453 | 455 |
454 if (delegate_ref->delegate) | 456 if (delegate_ref->delegate) |
455 delegate_ref->delegate->OnGroupMadeObsolete( | 457 delegate_ref->delegate->OnGroupMadeObsolete( |
456 group.get(), true, response_code); | 458 group.get(), true, response_code); |
457 } | 459 } |
458 | 460 |
459 void MockAppCacheStorage::ScheduleTask(const base::Closure& task) { | 461 void MockAppCacheStorage::ScheduleTask(const base::Closure& task) { |
460 pending_tasks_.push_back(task); | 462 pending_tasks_.push_back(task); |
461 base::MessageLoop::current()->PostTask( | 463 base::ThreadTaskRunnerHandle::Get()->PostTask( |
462 FROM_HERE, | 464 FROM_HERE, base::Bind(&MockAppCacheStorage::RunOnePendingTask, |
463 base::Bind(&MockAppCacheStorage::RunOnePendingTask, | 465 weak_factory_.GetWeakPtr())); |
464 weak_factory_.GetWeakPtr())); | |
465 } | 466 } |
466 | 467 |
467 void MockAppCacheStorage::RunOnePendingTask() { | 468 void MockAppCacheStorage::RunOnePendingTask() { |
468 DCHECK(!pending_tasks_.empty()); | 469 DCHECK(!pending_tasks_.empty()); |
469 base::Closure task = pending_tasks_.front(); | 470 base::Closure task = pending_tasks_.front(); |
470 pending_tasks_.pop_front(); | 471 pending_tasks_.pop_front(); |
471 task.Run(); | 472 task.Run(); |
472 } | 473 } |
473 | 474 |
474 void MockAppCacheStorage::AddStoredCache(AppCache* cache) { | 475 void MockAppCacheStorage::AddStoredCache(AppCache* cache) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 bool MockAppCacheStorage::ShouldCacheLoadAppearAsync(const AppCache* cache) { | 543 bool MockAppCacheStorage::ShouldCacheLoadAppearAsync(const AppCache* cache) { |
543 if (!cache) | 544 if (!cache) |
544 return true; | 545 return true; |
545 | 546 |
546 // If the 'stored' ref is the only ref, real storage will have to load from | 547 // If the 'stored' ref is the only ref, real storage will have to load from |
547 // the database. | 548 // the database. |
548 return IsCacheStored(cache) && cache->HasOneRef(); | 549 return IsCacheStored(cache) && cache->HasOneRef(); |
549 } | 550 } |
550 | 551 |
551 } // namespace content | 552 } // namespace content |
OLD | NEW |