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 IOS_CHROME_BROWSER_READING_LIST_READING_LIST_STORE_H_ |
| 6 #define IOS_CHROME_BROWSER_READING_LIST_READING_LIST_STORE_H_ |
| 7 |
| 8 #include "base/memory/weak_ptr.h" |
| 9 #include "components/leveldb_proto/proto_database.h" |
| 10 #include "ios/chrome/browser/reading_list/reading_list_model_storage.h" |
| 11 |
| 12 using ReadingListDB = |
| 13 leveldb_proto::ProtoDatabase<reading_list::ReadingListLocal>; |
| 14 |
| 15 // A ReadingListModelStorage storing data in protobufs. |
| 16 class ReadingListStore : public ReadingListModelStorage { |
| 17 using EntryVector = std::vector<reading_list::ReadingListLocal>; |
| 18 |
| 19 public: |
| 20 ReadingListStore(std::unique_ptr<ReadingListDB> database, |
| 21 const base::FilePath& database_dir); |
| 22 virtual ~ReadingListStore(); |
| 23 |
| 24 // ReadingListModelStorage implementation |
| 25 void SetReadingListModel(ReadingListModelImpl* model) override; |
| 26 void BeginTransaction() override; |
| 27 void CommitTransaction() override; |
| 28 void LoadPersistentLists() override; |
| 29 void SaveEntry(const ReadingListEntry& entry, bool read) override; |
| 30 void RemoveEntry(const ReadingListEntry& entry) override; |
| 31 |
| 32 private: |
| 33 void OnDatabaseInit(bool success); |
| 34 void OnDatabaseLoad(bool success, std::unique_ptr<EntryVector> entries); |
| 35 void OnDatabaseSave(bool success); |
| 36 |
| 37 std::unique_ptr<ReadingListDB> database_; |
| 38 bool database_loaded_; |
| 39 ReadingListModelImpl* model_; |
| 40 |
| 41 int pending_transaction_; |
| 42 std::unique_ptr<ReadingListDB::KeyEntryVector> pending_keys_to_save_; |
| 43 std::unique_ptr<std::vector<std::string>> pending_keys_to_remove_; |
| 44 |
| 45 base::WeakPtrFactory<ReadingListStore> weak_ptr_factory_; |
| 46 }; |
| 47 |
| 48 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_STORE_H_ |
OLD | NEW |