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

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

Issue 2329283002: [Offline pages] OPM SQL store: moving load to constructor, updating read to GetOfflinePages (Closed)
Patch Set: Addressing CR 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
11 namespace offline_pages { 11 namespace offline_pages {
12 12
13 OfflinePageTestStore::OfflinePageTestStore( 13 OfflinePageTestStore::OfflinePageTestStore(
14 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) 14 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
15 : task_runner_(task_runner), scenario_(TestScenario::SUCCESSFUL) {} 15 : task_runner_(task_runner), scenario_(TestScenario::SUCCESSFUL) {}
16 16
17 OfflinePageTestStore::OfflinePageTestStore( 17 OfflinePageTestStore::OfflinePageTestStore(
18 const OfflinePageTestStore& other_store) 18 const OfflinePageTestStore& other_store)
19 : task_runner_(other_store.task_runner_), 19 : task_runner_(other_store.task_runner_),
20 scenario_(other_store.scenario_), 20 scenario_(other_store.scenario_),
21 offline_pages_(other_store.offline_pages_) {} 21 offline_pages_(other_store.offline_pages_) {}
22 22
23 OfflinePageTestStore::~OfflinePageTestStore() {} 23 OfflinePageTestStore::~OfflinePageTestStore() {}
24 24
25 void OfflinePageTestStore::Load(const LoadCallback& callback) { 25 void OfflinePageTestStore::GetOfflinePages(const LoadCallback& callback) {
26 OfflinePageMetadataStore::LoadStatus load_status; 26 OfflinePageMetadataStore::LoadStatus load_status;
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 }
(...skipping 25 matching lines...) Expand all
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 OfflinePageMetadataStore::StoreState OfflinePageTestStore::state() const {
72 return LOADED;
73 }
74
71 void OfflinePageTestStore::UpdateLastAccessTime( 75 void OfflinePageTestStore::UpdateLastAccessTime(
72 int64_t offline_id, 76 int64_t offline_id,
73 const base::Time& last_access_time) { 77 const base::Time& last_access_time) {
74 auto iter = offline_pages_.find(offline_id); 78 auto iter = offline_pages_.find(offline_id);
75 if (iter == offline_pages_.end()) 79 if (iter == offline_pages_.end())
76 return; 80 return;
77 iter->second.last_access_time = last_access_time; 81 iter->second.last_access_time = last_access_time;
78 } 82 }
79 83
80 std::vector<OfflinePageItem> OfflinePageTestStore::GetAllPages() const { 84 std::vector<OfflinePageItem> OfflinePageTestStore::GetAllPages() const {
81 std::vector<OfflinePageItem> offline_pages; 85 std::vector<OfflinePageItem> offline_pages;
82 for (const auto& id_page_pair : offline_pages_) 86 for (const auto& id_page_pair : offline_pages_)
83 offline_pages.push_back(id_page_pair.second); 87 offline_pages.push_back(id_page_pair.second);
84 return offline_pages; 88 return offline_pages;
85 } 89 }
86 90
87 void OfflinePageTestStore::ClearAllPages() { 91 void OfflinePageTestStore::ClearAllPages() {
88 offline_pages_.clear(); 92 offline_pages_.clear();
89 } 93 }
90 94
91 } // namespace offline_pages 95 } // 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