Chromium Code Reviews| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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; |
|
jianli
2016/11/16 01:34:50
Will this be ResetCallback?
fgorski
2016/11/16 19:10:13
Done.
| |
| 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/resetting DB connection. |
| 76 void OpenConnection(); | 77 void OnOpenConnectionDone(const InitializeCallback& callback, bool success); |
| 77 void OnOpenConnectionDone(StoreState state); | 78 void OnResetDone(const ResetCallback& callback, bool success); |
| 78 | 79 |
| 79 // Used to reset DB connection. | 80 // Checks whether a valid DB connection is present and store state is LOADED. |
| 80 void OnResetDone(const ResetCallback& callback, StoreState state); | 81 bool CheckDb(); |
| 81 | |
| 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 | |
| 84 // calls the provided callback as a shortcut. | |
| 85 bool CheckDb(const base::Closure& callback); | |
| 86 | 82 |
| 87 // Background thread where all SQL access should be run. | 83 // Background thread where all SQL access should be run. |
| 88 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; | 84 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; |
| 89 | 85 |
| 90 // Path to the database on disk. | 86 // Path to the database on disk. |
| 91 base::FilePath db_file_path_; | 87 base::FilePath db_file_path_; |
| 92 | 88 |
| 93 // Database connection. | 89 // Database connection. |
| 94 std::unique_ptr<sql::Connection> db_; | 90 std::unique_ptr<sql::Connection> db_; |
| 95 | 91 |
| 96 // State of the store. | 92 // State of the store. |
| 97 StoreState state_; | 93 StoreState state_; |
| 98 | 94 |
| 99 base::WeakPtrFactory<OfflinePageMetadataStoreSQL> weak_ptr_factory_; | 95 base::WeakPtrFactory<OfflinePageMetadataStoreSQL> weak_ptr_factory_; |
| 100 | 96 |
| 101 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL); | 97 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL); |
| 102 }; | 98 }; |
| 103 | 99 |
| 104 } // namespace offline_pages | 100 } // namespace offline_pages |
| 105 | 101 |
| 106 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ | 102 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ |
| OLD | NEW |