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 0660fb9a771b9b390bb422ac2534f7fc92af6da2..e755f34df44b1769c5c52baa49066433ae8737a6 100644 |
--- a/ios/chrome/browser/reading_list/reading_list_model_impl.h |
+++ b/ios/chrome/browser/reading_list/reading_list_model_impl.h |
@@ -10,24 +10,32 @@ |
#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; |
// 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 +51,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, |
@@ -64,22 +73,66 @@ class ReadingListModelImpl : public ReadingListModel, public KeyedService { |
const GURL& url, |
ReadingListEntry::DistillationState state) override; |
+ void SyncAddEntry(std::unique_ptr<ReadingListEntry> entry, |
+ bool read) override; |
+ ReadingListEntry* SyncMergeEntry(std::unique_ptr<ReadingListEntry> entry, |
+ bool read) override; |
+ void SyncRemoveEntry(const GURL& url) 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: |
+ // Sets/Loads the pref flag that indicate if some entries have never been seen |
+ // since being added to the store. |
void SetPersistentHasUnseen(bool has_unseen); |
bool GetPersistentHasUnseen(); |
- typedef std::vector<ReadingListEntry> ReadingListEntries; |
+ // Returns a mutable pointer to the entry with URL |gurl|. Return nullptr if |
+ // no entry is found. If an entry is found, |read| is set to the read status |
+ // of the entry. |
+ ReadingListEntry* GetMutableEntryFromURL(const GURL& gurl, bool* read) const; |
+ |
+ // Sorts the entries in |read_| and |unread_| according to their |UpdateTime|. |
+ void SortEntries(); |
+ |
+ // Returns the |storage_layer_| of the model. |
+ ReadingListModelStorage* StorageLayer(); |
- ReadingListEntries unread_; |
- ReadingListEntries read_; |
+ // Remove |entry| from the |entries| vector and calls the Move notifications |
+ // on observers. |
+ void MoveEntryFrom(ReadingListEntries* entries, |
+ const ReadingListEntry& entry, |
+ bool read); |
+ |
+ // Remove entry |url| and propagate to store if |from_sync| is false. |
+ void RemoveEntryByURLImpl(const GURL& url, bool from_sync); |
+ |
+ 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); |
}; |