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; | |
| 22 } | |
| 23 | |
| 24 namespace base { | |
| 25 class SequencedTaskRunner; | |
| 26 } | |
| 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); | |
| 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. | |
| 57 void LoadSync(scoped_refptr<base::SingleThreadTaskRunner> runner, | |
| 58 const LoadCallback& callback); | |
| 59 void AddOrUpdateOfflinePageSync( | |
| 60 const OfflinePageItem& offline_page, | |
| 61 scoped_refptr<base::SingleThreadTaskRunner> runner, | |
| 62 const UpdateCallback& callback); | |
| 63 void RemoveOfflinePagesSync( | |
| 64 const std::vector<int64_t>& offline_ids, | |
| 65 scoped_refptr<base::SingleThreadTaskRunner> runner, | |
| 66 const UpdateCallback& callback); | |
| 67 void ResetSync(scoped_refptr<base::SingleThreadTaskRunner> runner, | |
| 68 const ResetCallback& callback); | |
| 69 | |
| 70 void NotifyLoadResult(scoped_refptr<base::SingleThreadTaskRunner> runner, | |
| 71 const LoadCallback& callback, | |
| 72 LoadStatus status, | |
| 73 const std::vector<OfflinePageItem>& result); | |
| 74 | |
| 75 // Background thread where all SQL access should be run. | |
| 76 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; | |
| 77 // Path to the database on disk. | |
| 78 base::FilePath db_file_path_; | |
| 79 | |
| 80 std::unique_ptr<sql::Connection> db_; | |
| 81 | |
| 82 // only useful for testing. | |
| 83 bool use_in_memory_; | |
| 84 | |
| 85 base::WeakPtrFactory<OfflinePageMetadataStoreSQL> weak_ptr_factory_; | |
|
Scott Hess - ex-Googler
2016/04/25 19:57:55
I am not entirely able to follow whether this adhe
bburns
2016/04/26 23:27:02
I believe that this is covered by the fact that in
Scott Hess - ex-Googler
2016/04/27 15:21:00
My understanding is that you can't run is_valid()
bburns
2016/04/27 19:59:21
So I think that this is covered because all of the
Scott Hess - ex-Googler
2016/04/27 21:16:45
base::Bind knows how to use a weak pointer as a ta
| |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL); | |
| 88 }; | |
| 89 | |
| 90 } // namespace offline_pages | |
| 91 | |
| 92 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ | |
| OLD | NEW |