Chromium Code Reviews| 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 sql { | |
| 18 class Connection; | |
| 19 class MetaTable; | |
| 20 class Statement; | |
| 21 class StatementID; | |
|
Scott Hess - ex-Googler
2016/05/02 20:36:19
Of these, AFAICT only Connection is necessary here
bburns
2016/05/02 21:44:18
Done.
| |
| 22 } | |
| 23 | |
| 24 namespace base { | |
| 25 class SequencedTaskRunner; | |
| 26 } | |
|
Scott Hess - ex-Googler
2016/05/02 20:36:19
I'd put the base namespace before sql namespace.
bburns
2016/05/02 21:44:18
Done.
| |
| 27 | |
| 28 namespace offline_pages { | |
| 29 | |
| 30 // OfflinePageMetadataStoreSQL is an instance of OfflinePageMetadataStore | |
| 31 // which is implemented using a SQLite database. | |
| 32 class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore { | |
| 33 public: | |
| 34 OfflinePageMetadataStoreSQL( | |
| 35 scoped_refptr<base::SequencedTaskRunner> background_task_runner, | |
| 36 const base::FilePath& database_dir); | |
| 37 ~OfflinePageMetadataStoreSQL() override; | |
| 38 | |
| 39 // Implementation methods. | |
| 40 void Load(const LoadCallback& callback) override; | |
| 41 void AddOrUpdateOfflinePage(const OfflinePageItem& offline_page, | |
| 42 const UpdateCallback& callback) override; | |
| 43 void RemoveOfflinePages(const std::vector<int64_t>& offline_ids, | |
| 44 const UpdateCallback& callback) override; | |
| 45 void Reset(const ResetCallback& callback) override; | |
| 46 | |
| 47 // If true, use an in-memory database to make testing easier. | |
| 48 // Only has an effect if you call it before a call to Load(...). | |
| 49 // Should only be used for testing. | |
| 50 void SetInMemoryDatabaseForTesting(bool in_memory); | |
|
Scott Hess - ex-Googler
2016/05/02 20:36:19
I was going to suggest making this private and usi
bburns
2016/05/02 21:44:18
Removed.
| |
| 51 | |
| 52 private: | |
| 53 // Synchronous implementations, these are run on the background thread | |
| 54 // and actually do the work to access SQL. The implementations above | |
| 55 // simply dispatch to the corresponding *Sync method on the background thread. | |
| 56 // 'runner' is where to run the callback. | |
|
Scott Hess - ex-Googler
2016/05/02 20:36:19
Is there any benefit to a private static method ov
bburns
2016/05/02 21:44:18
I think that actually I prefer it since it makes t
Scott Hess - ex-Googler
2016/05/02 23:33:31
I was more thinking in terms of not exposing any i
bburns
2016/05/03 17:15:55
Acknowledged.
| |
| 57 static void LoadSync(sql::Connection* db, | |
| 58 const base::FilePath& path, | |
| 59 bool use_in_memory, | |
| 60 scoped_refptr<base::SingleThreadTaskRunner> runner, | |
| 61 const LoadCallback& callback); | |
| 62 static void AddOrUpdateOfflinePageSync( | |
| 63 const OfflinePageItem& offline_page, | |
| 64 sql::Connection* db, | |
| 65 scoped_refptr<base::SingleThreadTaskRunner> runner, | |
| 66 const UpdateCallback& callback); | |
| 67 static void RemoveOfflinePagesSync( | |
| 68 const std::vector<int64_t>& offline_ids, | |
| 69 sql::Connection* db, | |
| 70 scoped_refptr<base::SingleThreadTaskRunner> runner, | |
| 71 const UpdateCallback& callback); | |
| 72 static void ResetSync(sql::Connection* db, | |
| 73 scoped_refptr<base::SingleThreadTaskRunner> runner, | |
| 74 const ResetCallback& callback); | |
| 75 | |
| 76 static void NotifyLoadResult( | |
| 77 scoped_refptr<base::SingleThreadTaskRunner> runner, | |
| 78 const LoadCallback& callback, | |
| 79 LoadStatus status, | |
| 80 const std::vector<OfflinePageItem>& result); | |
| 81 | |
| 82 // Background thread where all SQL access should be run. | |
| 83 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; | |
|
Scott Hess - ex-Googler
2016/05/02 20:36:18
Either a blank line here, or consistently run all
bburns
2016/05/02 21:44:18
Done.
| |
| 84 // Path to the database on disk. | |
| 85 base::FilePath db_file_path_; | |
| 86 | |
| 87 std::unique_ptr<sql::Connection> db_; | |
| 88 | |
| 89 // only useful for testing. | |
| 90 bool use_in_memory_; | |
| 91 | |
| 92 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL); | |
| 93 }; | |
| 94 | |
| 95 } // namespace offline_pages | |
| 96 | |
| 97 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ | |
| OLD | NEW |