| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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_IMPL_H_ | |
| 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_IMPL_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/files/file_path.h" | |
| 13 #include "base/gtest_prod_util.h" | |
| 14 #include "base/macros.h" | |
| 15 #include "base/memory/ref_counted.h" | |
| 16 #include "base/memory/weak_ptr.h" | |
| 17 #include "components/leveldb_proto/proto_database.h" | |
| 18 #include "components/offline_pages/offline_page_metadata_store.h" | |
| 19 | |
| 20 namespace base { | |
| 21 class SequencedTaskRunner; | |
| 22 } | |
| 23 | |
| 24 namespace offline_pages { | |
| 25 | |
| 26 class OfflinePageEntry; | |
| 27 | |
| 28 // Implements OfflinePageMetadataStore using leveldb_proto::ProtoDatabase | |
| 29 // component. Stores metadata of offline pages as serialized protobufs in a | |
| 30 // LevelDB key/value pairs. | |
| 31 // Underlying implementation guarantees that all of the method calls will be | |
| 32 // executed sequentially, and started operations will finish even after the | |
| 33 // store is already destroyed (callbacks will be called). | |
| 34 class OfflinePageMetadataStoreImpl : public OfflinePageMetadataStore { | |
| 35 public: | |
| 36 OfflinePageMetadataStoreImpl( | |
| 37 scoped_refptr<base::SequencedTaskRunner> background_task_runner, | |
| 38 const base::FilePath& database_dir); | |
| 39 ~OfflinePageMetadataStoreImpl() override; | |
| 40 | |
| 41 // OfflinePageMetadataStore implementation: | |
| 42 void Load(const LoadCallback& callback) override; | |
| 43 void AddOrUpdateOfflinePage(const OfflinePageItem& offline_page_record, | |
| 44 const UpdateCallback& callback) override; | |
| 45 void RemoveOfflinePages(const std::vector<int64_t>& offline_ids, | |
| 46 const UpdateCallback& callback) override; | |
| 47 void Reset(const ResetCallback& callback) override; | |
| 48 | |
| 49 private: | |
| 50 friend class OfflinePageMetadataStoreImplTest; | |
| 51 | |
| 52 void LoadContinuation(const LoadCallback& callback, bool success); | |
| 53 void LoadDone(const LoadCallback& callback, | |
| 54 bool success, | |
| 55 std::unique_ptr<std::vector<OfflinePageEntry>> entries); | |
| 56 void NotifyLoadResult(const LoadCallback& callback, | |
| 57 LoadStatus status, | |
| 58 const std::vector<OfflinePageItem>& result); | |
| 59 | |
| 60 // Implements the update. | |
| 61 void UpdateEntries(std::unique_ptr<leveldb_proto::ProtoDatabase< | |
| 62 OfflinePageEntry>::KeyEntryVector> entries_to_save, | |
| 63 std::unique_ptr<std::vector<std::string>> keys_to_remove, | |
| 64 const UpdateCallback& callback); | |
| 65 | |
| 66 void UpdateDone(const OfflinePageMetadataStore::UpdateCallback& callback, | |
| 67 bool success); | |
| 68 | |
| 69 void ResetDone(const ResetCallback& callback, bool success); | |
| 70 | |
| 71 // Called when a database has to be migrated from old bookmark ids | |
| 72 // to new offline ids. | |
| 73 // TODO(bburns): Perhaps remove this eventually? | |
| 74 void DatabaseUpdateDone(const OfflinePageMetadataStore::LoadCallback& cb, | |
| 75 LoadStatus status, | |
| 76 const std::vector<OfflinePageItem>& result, | |
| 77 bool success); | |
| 78 | |
| 79 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; | |
| 80 base::FilePath database_dir_; | |
| 81 std::unique_ptr<leveldb_proto::ProtoDatabase<OfflinePageEntry>> database_; | |
| 82 | |
| 83 base::WeakPtrFactory<OfflinePageMetadataStoreImpl> weak_ptr_factory_; | |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreImpl); | |
| 86 }; | |
| 87 | |
| 88 } // namespace offline_pages | |
| 89 | |
| 90 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_IMPL_H_ | |
| OLD | NEW |