Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(662)

Side by Side Diff: components/offline_pages/offline_page_test_store.cc

Issue 2339693002: [Offline pages] Splitting Add and Update methods in OPMStore (Closed)
Patch Set: Addressing feedback Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/offline_pages/offline_page_test_store.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 16 matching lines...) Expand all
27 if (scenario_ == TestScenario::LOAD_FAILED) { 27 if (scenario_ == TestScenario::LOAD_FAILED) {
28 load_status = OfflinePageMetadataStore::STORE_LOAD_FAILED; 28 load_status = OfflinePageMetadataStore::STORE_LOAD_FAILED;
29 offline_pages_.clear(); 29 offline_pages_.clear();
30 } else { 30 } else {
31 load_status = OfflinePageMetadataStore::LOAD_SUCCEEDED; 31 load_status = OfflinePageMetadataStore::LOAD_SUCCEEDED;
32 } 32 }
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::AddOfflinePage(const OfflinePageItem& offline_page,
38 const OfflinePageItem& offline_page, 38 const AddCallback& callback) {
39 const UpdateCallback& callback) { 39 // TODO(fgorski): Add and cover scenario with existing item.
40 last_saved_page_ = offline_page; 40 OfflinePageMetadataStore::ItemActionStatus result;
41 bool result = scenario_ != TestScenario::WRITE_FAILED; 41 if (scenario_ == TestScenario::SUCCESSFUL) {
42 if (result)
43 offline_pages_[offline_page.offline_id] = offline_page; 42 offline_pages_[offline_page.offline_id] = offline_page;
43 last_saved_page_ = offline_page;
44 result = OfflinePageMetadataStore::SUCCESS;
45 } else if (scenario_ == TestScenario::WRITE_FAILED) {
46 result = OfflinePageMetadataStore::STORE_ERROR;
47 }
44 if (!callback.is_null()) 48 if (!callback.is_null())
45 task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); 49 task_runner_->PostTask(FROM_HERE, base::Bind(callback, result));
46 } 50 }
51
52 void OfflinePageTestStore::UpdateOfflinePages(
53 const std::vector<OfflinePageItem>& pages,
54 const UpdateCallback& callback) {
55 bool result = scenario_ != TestScenario::WRITE_FAILED;
56 if (result) {
57 // TODO(fgorski): Cover scenario, where new items are being created, while
58 // they shouldn't.
59 for (auto& page : pages) {
60 offline_pages_[page.offline_id] = page;
61 last_saved_page_ = page;
62 }
63 }
64 if (!callback.is_null())
65 task_runner_->PostTask(FROM_HERE, base::Bind(callback, result));
66 }
47 67
48 void OfflinePageTestStore::RemoveOfflinePages( 68 void OfflinePageTestStore::RemoveOfflinePages(
49 const std::vector<int64_t>& offline_ids, 69 const std::vector<int64_t>& offline_ids,
50 const UpdateCallback& callback) { 70 const UpdateCallback& callback) {
51 ASSERT_FALSE(offline_ids.empty()); 71 ASSERT_FALSE(offline_ids.empty());
52 bool result = false; 72 bool result = false;
53 if (scenario_ != TestScenario::REMOVE_FAILED) { 73 if (scenario_ != TestScenario::REMOVE_FAILED) {
54 for (const auto& offline_id : offline_ids) { 74 for (const auto& offline_id : offline_ids) {
55 auto iter = offline_pages_.find(offline_id); 75 auto iter = offline_pages_.find(offline_id);
56 if (iter != offline_pages_.end()) { 76 if (iter != offline_pages_.end()) {
(...skipping 29 matching lines...) Expand all
86 for (const auto& id_page_pair : offline_pages_) 106 for (const auto& id_page_pair : offline_pages_)
87 offline_pages.push_back(id_page_pair.second); 107 offline_pages.push_back(id_page_pair.second);
88 return offline_pages; 108 return offline_pages;
89 } 109 }
90 110
91 void OfflinePageTestStore::ClearAllPages() { 111 void OfflinePageTestStore::ClearAllPages() {
92 offline_pages_.clear(); 112 offline_pages_.clear();
93 } 113 }
94 114
95 } // namespace offline_pages 115 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_test_store.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698