Chromium Code Reviews| Index: ios/chrome/browser/reading_list/reading_list_model_impl.h |
| diff --git a/ios/chrome/browser/reading_list/reading_list_model_impl.h b/ios/chrome/browser/reading_list/reading_list_model_impl.h |
| index d073d3253144bd5f4631112621475b6e26658e39..c7ec70e0b97b0486efcc7e8a63a0eedeb63cc8c3 100644 |
| --- a/ios/chrome/browser/reading_list/reading_list_model_impl.h |
| +++ b/ios/chrome/browser/reading_list/reading_list_model_impl.h |
| @@ -7,27 +7,38 @@ |
| #include <memory> |
| +#include "base/threading/non_thread_safe.h" |
|
pavely
2016/11/14 07:45:33
non_thread_safe.h is not needed here.
Olivier
2016/11/14 11:36:49
Done.
|
| #include "components/keyed_service/core/keyed_service.h" |
| #include "ios/chrome/browser/reading_list/reading_list_entry.h" |
| #include "ios/chrome/browser/reading_list/reading_list_model.h" |
| +#include "ios/chrome/browser/reading_list/reading_list_model_storage.h" |
| +#include "ios/chrome/browser/reading_list/reading_list_store_delegate.h" |
| -class ReadingListModelStorage; |
| class PrefService; |
| +using ReadingListEntries = std::vector<ReadingListEntry>; |
| + |
| // Concrete implementation of a reading list model using in memory lists. |
| -class ReadingListModelImpl : public ReadingListModel, public KeyedService { |
| +class ReadingListModelImpl : public ReadingListModel, |
| + public ReadingListStoreDelegate, |
| + public KeyedService { |
| public: |
| // Initialize a ReadingListModelImpl to load and save data in |
| // |persistence_layer|. |
| - ReadingListModelImpl(std::unique_ptr<ReadingListModelStorage> storage, |
| + ReadingListModelImpl(std::unique_ptr<ReadingListModelStorage> storage_layer, |
| PrefService* pref_service); |
| // Initialize a ReadingListModelImpl without persistence. Data will not be |
| // persistent across sessions. |
| ReadingListModelImpl(); |
| + syncer::ModelTypeSyncBridge* GetModelTypeSyncBridge() override; |
| + |
| ~ReadingListModelImpl() override; |
| + void StoreLoaded(std::unique_ptr<ReadingListEntries> unread, |
| + std::unique_ptr<ReadingListEntries> read) override; |
| + |
| // KeyedService implementation. |
| void Shutdown() override; |
| @@ -43,7 +54,8 @@ class ReadingListModelImpl : public ReadingListModel, public KeyedService { |
| const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const override; |
| const ReadingListEntry& GetReadEntryAtIndex(size_t index) const override; |
| - const ReadingListEntry* GetEntryFromURL(const GURL& gurl) const override; |
| + const ReadingListEntry* GetEntryFromURL(const GURL& gurl, |
| + bool* read) const override; |
| bool CallbackEntryURL( |
| const GURL& url, |
| @@ -67,22 +79,46 @@ class ReadingListModelImpl : public ReadingListModel, public KeyedService { |
| const GURL& url, |
| ReadingListEntry::DistillationState state) override; |
| + void SyncAddEntry(std::unique_ptr<ReadingListEntry> entry, |
| + bool read) override; |
| + void SyncRemoveEntry(const GURL& gurl) override; |
| + |
| + std::unique_ptr<ReadingListModel::ScopedReadingListBatchUpdate> |
| + CreateBatchToken() override; |
| + |
| + // Helper class that is used to scope batch updates. |
| + class ScopedReadingListBatchUpdate |
| + : public ReadingListModel::ScopedReadingListBatchUpdate { |
| + public: |
| + explicit ScopedReadingListBatchUpdate(ReadingListModelImpl* model); |
| + |
| + ~ScopedReadingListBatchUpdate() override; |
| + |
| + private: |
| + std::unique_ptr<ReadingListModelStorage::ScopedBatchUpdate> storage_token_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ScopedReadingListBatchUpdate); |
| + }; |
| + |
| protected: |
| - void EndBatchUpdates() override; |
| + void EnteringBatchUpdates() override; |
| + void LeavingBatchUpdates() override; |
| private: |
| + void RemoveEntryByURLImpl(const GURL& url, bool from_sync); |
| void SetPersistentHasUnseen(bool has_unseen); |
| bool GetPersistentHasUnseen(); |
| + ReadingListEntry* GetMutableEntryFromURL(const GURL& gurl, bool* read) const; |
| + void SortEntries(); |
| + ReadingListModelStorage* StorageLayer(); |
| - typedef std::vector<ReadingListEntry> ReadingListEntries; |
| - |
| - ReadingListEntries unread_; |
| - ReadingListEntries read_; |
| + std::unique_ptr<ReadingListEntries> unread_; |
| + std::unique_ptr<ReadingListEntries> read_; |
| std::unique_ptr<ReadingListModelStorage> storage_layer_; |
| PrefService* pref_service_; |
| bool has_unseen_; |
| bool loaded_; |
| - |
| + base::WeakPtrFactory<ReadingListModelImpl> weak_ptr_factory_; |
| DISALLOW_COPY_AND_ASSIGN(ReadingListModelImpl); |
| }; |