| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/offline_pages/offline_page_test_store.h" | 5 #include "components/offline_pages/offline_page_test_store.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 task_runner_->PostTask(FROM_HERE, | 33 task_runner_->PostTask(FROM_HERE, |
| 34 base::Bind(callback, load_status, GetAllPages())); | 34 base::Bind(callback, load_status, GetAllPages())); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void OfflinePageTestStore::AddOrUpdateOfflinePage( | 37 void OfflinePageTestStore::AddOrUpdateOfflinePage( |
| 38 const OfflinePageItem& offline_page, | 38 const OfflinePageItem& offline_page, |
| 39 const UpdateCallback& callback) { | 39 const UpdateCallback& callback) { |
| 40 last_saved_page_ = offline_page; | 40 last_saved_page_ = offline_page; |
| 41 bool result = scenario_ != TestScenario::WRITE_FAILED; | 41 bool result = scenario_ != TestScenario::WRITE_FAILED; |
| 42 if (result) | 42 if (result) |
| 43 offline_pages_[offline_page.bookmark_id] = offline_page; | 43 offline_pages_[offline_page.offline_id] = offline_page; |
| 44 if (!callback.is_null()) | 44 if (!callback.is_null()) |
| 45 task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); | 45 task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void OfflinePageTestStore::RemoveOfflinePages( | 48 void OfflinePageTestStore::RemoveOfflinePages( |
| 49 const std::vector<int64_t>& bookmark_ids, | 49 const std::vector<int64_t>& offline_ids, |
| 50 const UpdateCallback& callback) { | 50 const UpdateCallback& callback) { |
| 51 ASSERT_FALSE(bookmark_ids.empty()); | 51 ASSERT_FALSE(offline_ids.empty()); |
| 52 bool result = false; | 52 bool result = false; |
| 53 if (scenario_ != TestScenario::REMOVE_FAILED) { | 53 if (scenario_ != TestScenario::REMOVE_FAILED) { |
| 54 for (const auto& bookmark_id : bookmark_ids) { | 54 for (const auto& offline_id : offline_ids) { |
| 55 auto iter = offline_pages_.find(bookmark_id); | 55 auto iter = offline_pages_.find(offline_id); |
| 56 if (iter != offline_pages_.end()) { | 56 if (iter != offline_pages_.end()) { |
| 57 offline_pages_.erase(iter); | 57 offline_pages_.erase(iter); |
| 58 result = true; | 58 result = true; |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); | 63 task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void OfflinePageTestStore::Reset(const ResetCallback& callback) { | 66 void OfflinePageTestStore::Reset(const ResetCallback& callback) { |
| 67 offline_pages_.clear(); | 67 offline_pages_.clear(); |
| 68 task_runner_->PostTask(FROM_HERE, base::Bind(callback, true)); | 68 task_runner_->PostTask(FROM_HERE, base::Bind(callback, true)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void OfflinePageTestStore::UpdateLastAccessTime( | 71 void OfflinePageTestStore::UpdateLastAccessTime( |
| 72 int64_t bookmark_id, | 72 int64_t offline_id, |
| 73 const base::Time& last_access_time) { | 73 const base::Time& last_access_time) { |
| 74 auto iter = offline_pages_.find(bookmark_id); | 74 auto iter = offline_pages_.find(offline_id); |
| 75 if (iter == offline_pages_.end()) | 75 if (iter == offline_pages_.end()) |
| 76 return; | 76 return; |
| 77 iter->second.last_access_time = last_access_time; | 77 iter->second.last_access_time = last_access_time; |
| 78 } | 78 } |
| 79 | 79 |
| 80 std::vector<OfflinePageItem> OfflinePageTestStore::GetAllPages() const { | 80 std::vector<OfflinePageItem> OfflinePageTestStore::GetAllPages() const { |
| 81 std::vector<OfflinePageItem> offline_pages; | 81 std::vector<OfflinePageItem> offline_pages; |
| 82 for (const auto& id_page_pair : offline_pages_) | 82 for (const auto& id_page_pair : offline_pages_) |
| 83 offline_pages.push_back(id_page_pair.second); | 83 offline_pages.push_back(id_page_pair.second); |
| 84 return offline_pages; | 84 return offline_pages; |
| 85 } | 85 } |
| 86 | 86 |
| 87 } // namespace offline_pages | 87 } // namespace offline_pages |
| OLD | NEW |