| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <memory> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/files/file_path.h" |
| 14 #include "base/memory/weak_ptr.h" |
| 15 #include "components/offline_pages/offline_page_metadata_store.h" |
| 16 |
| 17 namespace base { |
| 18 class SequencedTaskRunner; |
| 19 } |
| 20 |
| 21 namespace sql { |
| 22 class Connection; |
| 23 } |
| 24 |
| 25 namespace offline_pages { |
| 26 |
| 27 // OfflinePageMetadataStoreSQL is an instance of OfflinePageMetadataStore |
| 28 // which is implemented using a SQLite database. |
| 29 class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore { |
| 30 public: |
| 31 OfflinePageMetadataStoreSQL( |
| 32 scoped_refptr<base::SequencedTaskRunner> background_task_runner, |
| 33 const base::FilePath& database_dir); |
| 34 ~OfflinePageMetadataStoreSQL() override; |
| 35 |
| 36 // Implementation methods. |
| 37 void Load(const LoadCallback& callback) override; |
| 38 void AddOrUpdateOfflinePage(const OfflinePageItem& offline_page, |
| 39 const UpdateCallback& callback) override; |
| 40 void RemoveOfflinePages(const std::vector<int64_t>& offline_ids, |
| 41 const UpdateCallback& callback) override; |
| 42 void Reset(const ResetCallback& callback) override; |
| 43 |
| 44 private: |
| 45 // Synchronous implementations, these are run on the background thread |
| 46 // and actually do the work to access SQL. The implementations above |
| 47 // simply dispatch to the corresponding *Sync method on the background thread. |
| 48 // '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( |
| 54 const OfflinePageItem& offline_page, |
| 55 sql::Connection* db, |
| 56 scoped_refptr<base::SingleThreadTaskRunner> runner, |
| 57 const UpdateCallback& callback); |
| 58 static void RemoveOfflinePagesSync( |
| 59 const std::vector<int64_t>& offline_ids, |
| 60 sql::Connection* db, |
| 61 scoped_refptr<base::SingleThreadTaskRunner> runner, |
| 62 const UpdateCallback& callback); |
| 63 static void ResetSync(sql::Connection* db, |
| 64 scoped_refptr<base::SingleThreadTaskRunner> runner, |
| 65 const ResetCallback& callback); |
| 66 |
| 67 static void NotifyLoadResult( |
| 68 scoped_refptr<base::SingleThreadTaskRunner> runner, |
| 69 const LoadCallback& callback, |
| 70 LoadStatus status, |
| 71 const std::vector<OfflinePageItem>& result); |
| 72 |
| 73 // Background thread where all SQL access should be run. |
| 74 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; |
| 75 |
| 76 // Path to the database on disk. |
| 77 base::FilePath db_file_path_; |
| 78 std::unique_ptr<sql::Connection> db_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL); |
| 81 }; |
| 82 |
| 83 } // namespace offline_pages |
| 84 |
| 85 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ |
| OLD | NEW |