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

Side by Side Diff: components/offline_pages/offline_page_metadata_store_sql.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_METADATA_STORE_SQL_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_
6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // * Upgrade should use |UpgradeWithQuery| and simply specify SQL command to 51 // * Upgrade should use |UpgradeWithQuery| and simply specify SQL command to
52 // move data from old table (prefixed by temp_) to the new one. 52 // move data from old table (prefixed by temp_) to the new one.
53 class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore { 53 class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore {
54 public: 54 public:
55 OfflinePageMetadataStoreSQL( 55 OfflinePageMetadataStoreSQL(
56 scoped_refptr<base::SequencedTaskRunner> background_task_runner, 56 scoped_refptr<base::SequencedTaskRunner> background_task_runner,
57 const base::FilePath& database_dir); 57 const base::FilePath& database_dir);
58 ~OfflinePageMetadataStoreSQL() override; 58 ~OfflinePageMetadataStoreSQL() override;
59 59
60 // Implementation methods. 60 // Implementation methods.
61 void GetOfflinePages(const LoadCallback& callback) override; 61 void GetOfflinePages(const GetOfflinePagesCallback& callback) override;
62 void AddOfflinePage(const OfflinePageItem& offline_page, 62 void AddOfflinePage(const OfflinePageItem& offline_page,
63 const AddCallback& callback) override; 63 const AddCallback& callback) override;
64 void UpdateOfflinePages(const std::vector<OfflinePageItem>& pages, 64 void UpdateOfflinePages(const std::vector<OfflinePageItem>& pages,
65 const UpdateCallback& callback) override; 65 const UpdateCallback& callback) override;
66 void RemoveOfflinePages(const std::vector<int64_t>& offline_ids, 66 void RemoveOfflinePages(const std::vector<int64_t>& offline_ids,
67 const UpdateCallback& callback) override; 67 const UpdateCallback& callback) override;
68 void Reset(const ResetCallback& callback) override; 68 void Reset(const ResetCallback& callback) override;
69 StoreState state() const override; 69 StoreState state() const override;
70 70
71 // Helper function used to force incorrect state for testing purposes. 71 // Helper function used to force incorrect state for testing purposes.
72 void SetStateForTesting(StoreState state, bool reset_db); 72 void SetStateForTesting(StoreState state, bool reset_db);
73 73
74 private: 74 private:
75 // Used to initialize DB connection. 75 // Used to initialize DB connection.
76 void OpenConnection(); 76 void OpenConnection();
77 void OnOpenConnectionDone(StoreState state); 77 void OnOpenConnectionDone(StoreState state);
78 78
79 // Used to reset DB connection. 79 // Used to reset DB connection.
80 void OnResetDone(const ResetCallback& callback, StoreState state); 80 void OnResetDone(const ResetCallback& callback, StoreState state);
81 81
82 // Helper function that checks whether a valid DB connection is present. 82 // Helper function that checks whether a valid DB connection is present.
83 // Returns true if valid connection is present, otherwise it returns false and 83 bool CheckStoreState();
84 // calls the provided callback as a shortcut.
85 bool CheckDb(const base::Closure& callback);
86 84
87 // Background thread where all SQL access should be run. 85 // Background thread where all SQL access should be run.
88 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; 86 scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
89 87
90 // Path to the database on disk. 88 // Path to the database on disk.
91 base::FilePath db_file_path_; 89 base::FilePath db_file_path_;
92 90
93 // Database connection. 91 // Database connection.
94 std::unique_ptr<sql::Connection> db_; 92 std::unique_ptr<sql::Connection> db_;
95 93
96 // State of the store. 94 // State of the store.
97 StoreState state_; 95 StoreState state_;
98 96
99 base::WeakPtrFactory<OfflinePageMetadataStoreSQL> weak_ptr_factory_; 97 base::WeakPtrFactory<OfflinePageMetadataStoreSQL> weak_ptr_factory_;
100 98
101 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL); 99 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL);
102 }; 100 };
103 101
104 } // namespace offline_pages 102 } // namespace offline_pages
105 103
106 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ 104 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698