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 <vector> | |
| 11 | |
| 12 #include "base/files/file_path.h" | |
| 13 #include "base/memory/scoped_ptr.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 bool in_memory); | |
|
fgorski
2016/03/29 06:50:19
don't expose it here if it is only for testing.
P
bburns
2016/03/30 16:54:40
Done.
| |
| 38 virtual ~OfflinePageMetadataStoreSQL(); | |
| 39 | |
| 40 // Implementation methods | |
| 41 virtual void Load(const LoadCallback& callback); | |
| 42 virtual void AddOrUpdateOfflinePage(const OfflinePageItem& offline_page, | |
| 43 const UpdateCallback& callback); | |
| 44 virtual void RemoveOfflinePages(const std::vector<int64_t>& offline_ids, | |
| 45 const UpdateCallback& callback); | |
| 46 virtual void Reset(const ResetCallback& callback); | |
| 47 | |
| 48 private: | |
| 49 // Synchronous implementations, these are run on the background thread | |
| 50 // and actually do the work to access SQL. The implementations above | |
| 51 // simply dispatch to the corresponding *Sync method on the background thread. | |
| 52 // 'runner' is where to run the callback. | |
| 53 void LoadSync(scoped_refptr<base::SingleThreadTaskRunner> runner, | |
| 54 const LoadCallback& callback); | |
| 55 void AddOrUpdateOfflinePageSync( | |
| 56 const OfflinePageItem& offline_page, | |
| 57 scoped_refptr<base::SingleThreadTaskRunner> runner, | |
| 58 const UpdateCallback& callback); | |
| 59 void RemoveOfflinePagesSync( | |
| 60 const std::vector<int64_t>& offline_ids, | |
| 61 scoped_refptr<base::SingleThreadTaskRunner> runner, | |
| 62 const UpdateCallback& callback); | |
| 63 | |
| 64 void NotifyLoadResult(const LoadCallback& callback, | |
| 65 scoped_refptr<base::SingleThreadTaskRunner> runner, | |
| 66 LoadStatus status, | |
| 67 const std::vector<OfflinePageItem>& result); | |
| 68 | |
| 69 // Background thread where all SQL access should be run | |
| 70 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; | |
| 71 // Path to the database on disk | |
| 72 base::FilePath db_file_path_; | |
| 73 | |
| 74 scoped_ptr<sql::Connection> db_; | |
| 75 // Metadatable is used for table storage metadata (e.g. table version, etc) | |
| 76 scoped_ptr<sql::MetaTable> meta_table_; | |
| 77 | |
| 78 // only useful for testing | |
| 79 bool use_in_memory_; | |
| 80 | |
| 81 base::WeakPtrFactory<OfflinePageMetadataStoreSQL> weak_ptr_factory_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL); | |
| 84 }; | |
| 85 | |
| 86 } // namespace offline_pages | |
| 87 | |
| 88 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ | |
| OLD | NEW |