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 16 matching lines...) Expand all Loading... | |
| 27 // OfflinePageMetadataStoreSQL is an instance of OfflinePageMetadataStore | 27 // OfflinePageMetadataStoreSQL is an instance of OfflinePageMetadataStore |
| 28 // which is implemented using a SQLite database. | 28 // which is implemented using a SQLite database. |
| 29 class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore { | 29 class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore { |
| 30 public: | 30 public: |
| 31 OfflinePageMetadataStoreSQL( | 31 OfflinePageMetadataStoreSQL( |
| 32 scoped_refptr<base::SequencedTaskRunner> background_task_runner, | 32 scoped_refptr<base::SequencedTaskRunner> background_task_runner, |
| 33 const base::FilePath& database_dir); | 33 const base::FilePath& database_dir); |
| 34 ~OfflinePageMetadataStoreSQL() override; | 34 ~OfflinePageMetadataStoreSQL() override; |
| 35 | 35 |
| 36 // Implementation methods. | 36 // Implementation methods. |
| 37 void Load(const LoadCallback& callback) override; | 37 void GetOfflinePages(const LoadCallback& callback) override; |
| 38 void AddOrUpdateOfflinePage(const OfflinePageItem& offline_page, | 38 void AddOrUpdateOfflinePage(const OfflinePageItem& offline_page, |
| 39 const UpdateCallback& callback) override; | 39 const UpdateCallback& callback) override; |
| 40 void RemoveOfflinePages(const std::vector<int64_t>& offline_ids, | 40 void RemoveOfflinePages(const std::vector<int64_t>& offline_ids, |
| 41 const UpdateCallback& callback) override; | 41 const UpdateCallback& callback) override; |
| 42 void Reset(const ResetCallback& callback) override; | 42 void Reset(const ResetCallback& callback) override; |
| 43 StoreState state() const override; | |
| 43 | 44 |
| 44 private: | 45 private: |
| 45 // Synchronous implementations, these are run on the background thread | 46 // Synchronous implementations, these are run on the background thread |
| 46 // and actually do the work to access SQL. The implementations above | 47 // and actually do the work to access SQL. The implementations above |
| 47 // simply dispatch to the corresponding *Sync method on the background thread. | 48 // simply dispatch to the corresponding *Sync method on the background thread. |
| 48 // 'runner' is where to run the callback. | 49 // 'runner' is where to run the callback. |
| 49 static void LoadSync(sql::Connection* db, | |
| 50 const base::FilePath& path, | |
| 51 scoped_refptr<base::SingleThreadTaskRunner> runner, | |
| 52 const LoadCallback& callback); | |
| 53 static void AddOrUpdateOfflinePageSync( | 50 static void AddOrUpdateOfflinePageSync( |
| 54 const OfflinePageItem& offline_page, | 51 const OfflinePageItem& offline_page, |
| 55 sql::Connection* db, | 52 sql::Connection* db, |
| 56 scoped_refptr<base::SingleThreadTaskRunner> runner, | 53 scoped_refptr<base::SingleThreadTaskRunner> runner, |
| 57 const UpdateCallback& callback); | 54 const UpdateCallback& callback); |
| 58 static void RemoveOfflinePagesSync( | 55 static void RemoveOfflinePagesSync( |
| 59 const std::vector<int64_t>& offline_ids, | 56 const std::vector<int64_t>& offline_ids, |
| 60 sql::Connection* db, | 57 sql::Connection* db, |
| 61 scoped_refptr<base::SingleThreadTaskRunner> runner, | 58 scoped_refptr<base::SingleThreadTaskRunner> runner, |
| 62 const UpdateCallback& callback); | 59 const UpdateCallback& callback); |
| 63 static void ResetSync(std::unique_ptr<sql::Connection> db, | |
| 64 scoped_refptr<base::SingleThreadTaskRunner> runner, | |
| 65 const ResetCallback& callback); | |
| 66 | 60 |
| 67 static void NotifyLoadResult( | 61 // Used to initialize DB connection. |
| 68 scoped_refptr<base::SingleThreadTaskRunner> runner, | 62 void OpenConnection(); |
| 69 const LoadCallback& callback, | 63 void OnOpenConnectionDone(StoreState state); |
| 70 LoadStatus status, | 64 |
| 71 const std::vector<OfflinePageItem>& result); | 65 // Used to reset DB connection. |
| 66 void OnResetDone(const ResetCallback& callback, StoreState state); | |
| 67 | |
| 68 // Helper function to return immediately if no database is found. | |
|
Dmitry Titov
2016/09/12 18:05:30
Lets add to the comment when it returns true/false
fgorski
2016/09/12 21:07:43
Done.
| |
| 69 bool CheckDb(const base::Closure& callback); | |
| 72 | 70 |
| 73 // Background thread where all SQL access should be run. | 71 // Background thread where all SQL access should be run. |
| 74 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; | 72 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; |
| 75 | 73 |
| 76 // Path to the database on disk. | 74 // Path to the database on disk. |
| 77 base::FilePath db_file_path_; | 75 base::FilePath db_file_path_; |
| 78 std::unique_ptr<sql::Connection> db_; | 76 std::unique_ptr<sql::Connection> db_; |
| 79 | 77 |
| 78 StoreState state_; | |
| 79 base::WeakPtrFactory<OfflinePageMetadataStoreSQL> weak_ptr_factory_; | |
| 80 | |
| 80 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL); | 81 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL); |
| 81 }; | 82 }; |
| 82 | 83 |
| 83 } // namespace offline_pages | 84 } // namespace offline_pages |
| 84 | 85 |
| 85 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ | 86 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ |
| OLD | NEW |