OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_STORE_H_ | |
6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_STORE_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <map> | |
11 #include <vector> | |
12 | |
13 #include "base/macros.h" | |
14 #include "base/memory/ref_counted.h" | |
15 #include "base/single_thread_task_runner.h" | |
16 #include "components/offline_pages/offline_page_item.h" | |
17 #include "components/offline_pages/offline_page_metadata_store.h" | |
18 | |
19 namespace offline_pages { | |
20 | |
21 // Offline page store to be used for testing purposes. It stores offline pages | |
22 // in memory. All callbacks are posted immediately through a provided | |
23 // |task_runner|. | |
24 class OfflinePageTestStore : public OfflinePageMetadataStore { | |
25 public: | |
26 enum class TestScenario { | |
27 SUCCESSFUL, | |
28 WRITE_FAILED, | |
29 LOAD_FAILED, | |
30 REMOVE_FAILED, | |
31 }; | |
32 | |
33 explicit OfflinePageTestStore( | |
34 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | |
35 explicit OfflinePageTestStore(const OfflinePageTestStore& other_store); | |
36 ~OfflinePageTestStore() override; | |
37 | |
38 // OfflinePageMetadataStore overrides: | |
39 void GetOfflinePages(const LoadCallback& callback) override; | |
40 void AddOfflinePage(const OfflinePageItem& offline_page, | |
41 const AddCallback& callback) override; | |
42 void UpdateOfflinePages(const std::vector<OfflinePageItem>& pages, | |
43 const UpdateCallback& callback) override; | |
44 void RemoveOfflinePages(const std::vector<int64_t>& offline_ids, | |
45 const UpdateCallback& callback) override; | |
46 void Reset(const ResetCallback& callback) override; | |
47 StoreState state() const override; | |
48 | |
49 void UpdateLastAccessTime(int64_t offline_id, | |
50 const base::Time& last_access_time); | |
51 | |
52 // Returns all pages, regardless their states. | |
53 std::vector<OfflinePageItem> GetAllPages() const; | |
54 | |
55 // Clear all pages in the store. | |
56 void ClearAllPages(); | |
57 | |
58 const OfflinePageItem& last_saved_page() const { return last_saved_page_; } | |
59 | |
60 void set_test_scenario(TestScenario scenario) { scenario_ = scenario; }; | |
61 | |
62 private: | |
63 OfflinePageItem last_saved_page_; | |
64 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
65 TestScenario scenario_; | |
66 | |
67 std::map<int64_t, OfflinePageItem> offline_pages_; | |
68 | |
69 DISALLOW_ASSIGN(OfflinePageTestStore); | |
70 }; | |
71 | |
72 } // namespace offline_pages | |
73 | |
74 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_STORE_H_ | |
OLD | NEW |