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

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

Issue 2497703002: [Offline pages] Resetting offline page metadata store to handle LOAD/INIT failures (Closed)
Patch Set: Addressing STORE_INIT_FAILED Created 4 years, 1 month 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 Initialize(const InitializeCallback& callback) override;
61 void GetOfflinePages(const LoadCallback& callback) override; 62 void GetOfflinePages(const LoadCallback& callback) override;
62 void AddOfflinePage(const OfflinePageItem& offline_page, 63 void AddOfflinePage(const OfflinePageItem& offline_page,
63 const AddCallback& callback) override; 64 const AddCallback& callback) override;
64 void UpdateOfflinePages(const std::vector<OfflinePageItem>& pages, 65 void UpdateOfflinePages(const std::vector<OfflinePageItem>& pages,
65 const UpdateCallback& callback) override; 66 const UpdateCallback& callback) override;
66 void RemoveOfflinePages(const std::vector<int64_t>& offline_ids, 67 void RemoveOfflinePages(const std::vector<int64_t>& offline_ids,
67 const UpdateCallback& callback) override; 68 const UpdateCallback& callback) override;
68 void Reset(const ResetCallback& callback) override; 69 void Reset(const InitializeCallback& callback) override;
69 StoreState state() const override; 70 StoreState state() const override;
70 71
71 // Helper function used to force incorrect state for testing purposes. 72 // Helper function used to force incorrect state for testing purposes.
72 void SetStateForTesting(StoreState state, bool reset_db); 73 void SetStateForTesting(StoreState state, bool reset_db);
73 74
74 private: 75 private:
75 // Used to initialize DB connection. 76 // Used to conclude opening DB connection.
76 void OpenConnection(); 77 void OnOpenConnectionDone(const InitializeCallback& callback,
77 void OnOpenConnectionDone(StoreState state); 78 StoreState state);
78 79
79 // Used to reset DB connection. 80 // Used to reset DB connection.
80 void OnResetDone(const ResetCallback& callback, StoreState state); 81 void OnResetDone(const InitializeCallback& callback, StoreState state);
fgorski 2016/11/14 21:59:47 needs to be removed.
fgorski 2016/11/14 22:24:09 Done.
81 82
82 // Helper function that checks whether a valid DB connection is present. 83 // Helper function that checks whether a valid DB connection is present.
83 // Returns true if valid connection is present, otherwise it returns false and 84 // Returns true if valid connection is present, otherwise it returns false and
84 // calls the provided callback as a shortcut. 85 // calls the provided callback as a shortcut.
85 bool CheckDb(const base::Closure& callback); 86 bool CheckDb(const base::Closure& callback);
86 87
87 // Background thread where all SQL access should be run. 88 // Background thread where all SQL access should be run.
88 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; 89 scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
89 90
90 // Path to the database on disk. 91 // Path to the database on disk.
91 base::FilePath db_file_path_; 92 base::FilePath db_file_path_;
92 93
93 // Database connection. 94 // Database connection.
94 std::unique_ptr<sql::Connection> db_; 95 std::unique_ptr<sql::Connection> db_;
95 96
96 // State of the store. 97 // State of the store.
97 StoreState state_; 98 StoreState state_;
98 99
99 base::WeakPtrFactory<OfflinePageMetadataStoreSQL> weak_ptr_factory_; 100 base::WeakPtrFactory<OfflinePageMetadataStoreSQL> weak_ptr_factory_;
100 101
101 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL); 102 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL);
102 }; 103 };
103 104
104 } // namespace offline_pages 105 } // namespace offline_pages
105 106
106 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ 107 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698