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