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_RESET_SUCCESS, | |
30 LOAD_FAILED_RESET_FAILED, | |
31 REMOVE_FAILED, | |
32 }; | |
33 | |
34 explicit OfflinePageTestStore( | |
35 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | |
36 explicit OfflinePageTestStore(const OfflinePageTestStore& other_store); | |
37 ~OfflinePageTestStore() override; | |
38 | |
39 // OfflinePageMetadataStore overrides: | |
40 void Initialize(const InitializeCallback& callback) override; | |
41 void GetOfflinePages(const LoadCallback& callback) override; | |
42 void AddOfflinePage(const OfflinePageItem& offline_page, | |
43 const AddCallback& callback) override; | |
44 void UpdateOfflinePages(const std::vector<OfflinePageItem>& pages, | |
45 const UpdateCallback& callback) override; | |
46 void RemoveOfflinePages(const std::vector<int64_t>& offline_ids, | |
47 const UpdateCallback& callback) override; | |
48 void Reset(const ResetCallback& callback) override; | |
49 StoreState state() const override; | |
50 | |
51 void UpdateLastAccessTime(int64_t offline_id, | |
52 const base::Time& last_access_time); | |
53 | |
54 // Returns all pages, regardless their states. | |
55 std::vector<OfflinePageItem> GetAllPages() const; | |
56 | |
57 // Clear all pages in the store. | |
58 void ClearAllPages(); | |
59 | |
60 const OfflinePageItem& last_saved_page() const { return last_saved_page_; } | |
61 | |
62 void set_test_scenario(TestScenario scenario) { scenario_ = scenario; }; | |
63 | |
64 private: | |
65 OfflinePageItem last_saved_page_; | |
66 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
67 TestScenario scenario_; | |
68 StoreState store_state_; | |
69 | |
70 std::map<int64_t, OfflinePageItem> offline_pages_; | |
71 | |
72 DISALLOW_ASSIGN(OfflinePageTestStore); | |
73 }; | |
74 | |
75 } // namespace offline_pages | |
76 | |
77 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_STORE_H_ | |
OLD | NEW |