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