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

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

Issue 2384423003: [Offline pages] Resetting offline page metadata store if initial load fails (Closed)
Patch Set: Rebased and comments addressed Created 4 years, 2 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
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 #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>
(...skipping 10 matching lines...) Expand all
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,
30 REMOVE_FAILED, 30 REMOVE_FAILED,
31 RESET_SUCCESS,
32 RESET_FAILED,
31 }; 33 };
32 34
33 explicit OfflinePageTestStore( 35 explicit OfflinePageTestStore(
34 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); 36 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
35 explicit OfflinePageTestStore(const OfflinePageTestStore& other_store); 37 explicit OfflinePageTestStore(const OfflinePageTestStore& other_store);
36 ~OfflinePageTestStore() override; 38 ~OfflinePageTestStore() override;
37 39
38 // OfflinePageMetadataStore overrides: 40 // OfflinePageMetadataStore overrides:
39 void GetOfflinePages(const LoadCallback& callback) override; 41 void GetOfflinePages(const GetOfflinePagesCallback& 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; };
63 bool reset_called() const { return reset_called_; }
61 64
62 private: 65 private:
63 OfflinePageItem last_saved_page_; 66 OfflinePageItem last_saved_page_;
64 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 67 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
65 TestScenario scenario_; 68 TestScenario scenario_;
69 bool reset_called_;
70 StoreState store_state_;
66 71
67 std::map<int64_t, OfflinePageItem> offline_pages_; 72 std::map<int64_t, OfflinePageItem> offline_pages_;
68 73
69 DISALLOW_ASSIGN(OfflinePageTestStore); 74 DISALLOW_ASSIGN(OfflinePageTestStore);
70 }; 75 };
71 76
72 } // namespace offline_pages 77 } // namespace offline_pages
73 78
74 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_STORE_H_ 79 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698