Chromium Code Reviews| Index: components/offline_pages/offline_page_test_store.cc |
| diff --git a/components/offline_pages/offline_page_test_store.cc b/components/offline_pages/offline_page_test_store.cc |
| index 19d2dd2e581900880a3cf36a5e8b1b73f5e8aba2..5429706438d478b1167d7518faf3ab14729912ed 100644 |
| --- a/components/offline_pages/offline_page_test_store.cc |
| +++ b/components/offline_pages/offline_page_test_store.cc |
| @@ -4,6 +4,8 @@ |
| #include "components/offline_pages/offline_page_test_store.h" |
| +#include <map> |
| + |
| #include "base/bind.h" |
| #include "base/location.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -52,35 +54,48 @@ void OfflinePageTestStore::AddOfflinePage(const OfflinePageItem& offline_page, |
| void OfflinePageTestStore::UpdateOfflinePages( |
| const std::vector<OfflinePageItem>& pages, |
| const UpdateCallback& callback) { |
| - bool result = scenario_ != TestScenario::WRITE_FAILED; |
| - if (result) { |
| - // TODO(fgorski): Cover scenario, where new items are being created, while |
| - // they shouldn't. |
| - for (auto& page : pages) { |
| + // TODO(fgorski): Cover scenario, where new items are being created, while |
|
Pete Williamson
2016/09/15 18:05:43
nit - this sentence would read better with no comm
fgorski
2016/09/19 23:24:30
Done.
|
| + // they shouldn't. |
| + std::map<int64_t, ItemActionStatus> failed_results; |
| + std::vector<OfflinePageItem> updated_items; |
| + if (scenario_ == TestScenario::WRITE_FAILED) { |
| + for (const auto& page : pages) |
| + failed_results[page.offline_id] = STORE_ERROR; |
| + } else { |
| + for (const auto& page : pages) { |
| offline_pages_[page.offline_id] = page; |
| last_saved_page_ = page; |
| } |
| + updated_items.insert(updated_items.begin(), pages.begin(), pages.end()); |
| } |
| if (!callback.is_null()) |
| - task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); |
| + task_runner_->PostTask(FROM_HERE, |
| + base::Bind(callback, failed_results, updated_items)); |
| } |
| void OfflinePageTestStore::RemoveOfflinePages( |
| const std::vector<int64_t>& offline_ids, |
| const UpdateCallback& callback) { |
| + std::map<int64_t, ItemActionStatus> failed_results; |
| + std::vector<OfflinePageItem> deleted_items; |
| ASSERT_FALSE(offline_ids.empty()); |
| - bool result = false; |
| - if (scenario_ != TestScenario::REMOVE_FAILED) { |
| + if (scenario_ == TestScenario::REMOVE_FAILED) { |
| + for (const auto& offline_id : offline_ids) |
| + failed_results[offline_id] = STORE_ERROR; |
| + } else { |
| for (const auto& offline_id : offline_ids) { |
| auto iter = offline_pages_.find(offline_id); |
| if (iter != offline_pages_.end()) { |
| + deleted_items.push_back(iter->second); |
| offline_pages_.erase(iter); |
| - result = true; |
| + } else { |
| + failed_results[offline_id] = DOESNT_EXIST; |
| } |
| } |
| } |
| - task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); |
| + task_runner_->PostTask(FROM_HERE, |
| + base::Bind(callback, failed_results, deleted_items)); |
| } |
| void OfflinePageTestStore::Reset(const ResetCallback& callback) { |