| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_IMPL_H_ | 5 #ifndef IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_IMPL_H_ |
| 6 #define IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_IMPL_H_ | 6 #define IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/threading/non_thread_safe.h" |
| 10 #include "components/keyed_service/core/keyed_service.h" | 11 #include "components/keyed_service/core/keyed_service.h" |
| 11 #include "ios/chrome/browser/reading_list/reading_list_entry.h" | 12 #include "ios/chrome/browser/reading_list/reading_list_entry.h" |
| 12 #include "ios/chrome/browser/reading_list/reading_list_model.h" | 13 #include "ios/chrome/browser/reading_list/reading_list_model.h" |
| 13 | 14 |
| 14 class ReadingListModelStorage; | 15 class ReadingListModelStorage; |
| 16 class PrefService; |
| 17 |
| 18 using ReadingListEntries = std::vector<ReadingListEntry>; |
| 15 | 19 |
| 16 // Concrete implementation of a reading list model using in memory lists. | 20 // Concrete implementation of a reading list model using in memory lists. |
| 17 class ReadingListModelImpl : public ReadingListModel, public KeyedService { | 21 class ReadingListModelImpl : public ReadingListModel, public KeyedService { |
| 18 public: | 22 public: |
| 19 // Initialize a ReadingListModelImpl to load and save data in | 23 // Initialize a ReadingListModelImpl to load and save data in |
| 20 // |persistence_layer|. | 24 // |persistence_layer|. |
| 21 ReadingListModelImpl(std::unique_ptr<ReadingListModelStorage> storage_layer); | 25 ReadingListModelImpl(std::unique_ptr<ReadingListModelStorage> storage_layer, |
| 26 PrefService* pref_service); |
| 22 | 27 |
| 23 // Initialize a ReadingListModelImpl without persistence. Data will not be | 28 // Initialize a ReadingListModelImpl without persistence. Data will not be |
| 24 // persistent across sessions. | 29 // persistent across sessions. |
| 25 ReadingListModelImpl(); | 30 ReadingListModelImpl(); |
| 26 | 31 |
| 32 syncer::ModelTypeService* GetModelTypeService() override; |
| 33 |
| 27 ~ReadingListModelImpl() override; | 34 ~ReadingListModelImpl() override; |
| 28 | 35 |
| 29 // KeyedService implementation. | 36 // KeyedService implementation. |
| 30 void Shutdown() override; | 37 void Shutdown() override; |
| 31 | 38 |
| 32 // ReadingListModel implementation. | 39 // ReadingListModel implementation. |
| 33 bool loaded() const override; | 40 bool loaded() const override; |
| 34 | 41 |
| 42 virtual void ModelLoaded(std::unique_ptr<ReadingListEntries> unread, |
| 43 std::unique_ptr<ReadingListEntries> read); |
| 44 |
| 35 size_t unread_size() const override; | 45 size_t unread_size() const override; |
| 36 size_t read_size() const override; | 46 size_t read_size() const override; |
| 37 | 47 |
| 38 bool HasUnseenEntries() const override; | 48 bool HasUnseenEntries() const override; |
| 39 void ResetUnseenEntries() override; | 49 void ResetUnseenEntries() override; |
| 40 | 50 |
| 41 const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const override; | 51 const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const override; |
| 42 const ReadingListEntry& GetReadEntryAtIndex(size_t index) const override; | 52 const ReadingListEntry& GetReadEntryAtIndex(size_t index) const override; |
| 43 | 53 |
| 44 const ReadingListEntry* GetEntryFromURL(const GURL& gurl) const override; | 54 const ReadingListEntry* GetEntryFromURL(const GURL& gurl) const override; |
| 45 | 55 |
| 46 bool CallbackEntryURL( | 56 bool CallbackEntryURL( |
| 47 const GURL& url, | 57 const GURL& url, |
| 48 base::Callback<void(const ReadingListEntry&)> callback) const override; | 58 base::Callback<void(const ReadingListEntry&)> callback) const override; |
| 49 | 59 |
| 50 void RemoveEntryByUrl(const GURL& url) override; | 60 bool CallbackEntryReadStatusURL( |
| 61 const GURL& url, |
| 62 base::Callback<void(const ReadingListEntry&, bool read)> callback) |
| 63 const override; |
| 64 |
| 65 void RemoveEntryByURL(const GURL& url) override; |
| 51 | 66 |
| 52 const ReadingListEntry& AddEntry(const GURL& url, | 67 const ReadingListEntry& AddEntry(const GURL& url, |
| 53 const std::string& title) override; | 68 const std::string& title) override; |
| 54 | 69 |
| 55 void MarkReadByURL(const GURL& url) override; | 70 void MarkReadByURL(const GURL& url) override; |
| 56 void MarkUnreadByURL(const GURL& url) override; | 71 void MarkUnreadByURL(const GURL& url) override; |
| 57 | 72 |
| 58 void SetEntryTitle(const GURL& url, const std::string& title) override; | 73 void SetEntryTitle(const GURL& url, const std::string& title) override; |
| 59 void SetEntryDistilledURL(const GURL& url, | 74 void SetEntryDistilledURL(const GURL& url, |
| 60 const GURL& distilled_url) override; | 75 const GURL& distilled_url) override; |
| 61 void SetEntryDistilledState( | 76 void SetEntryDistilledState( |
| 62 const GURL& url, | 77 const GURL& url, |
| 63 ReadingListEntry::DistillationState state) override; | 78 ReadingListEntry::DistillationState state) override; |
| 64 | 79 |
| 80 void SyncAddEntry(std::unique_ptr<ReadingListEntry> entry, |
| 81 bool read) override; |
| 82 void SyncRemoveEntry(const GURL& gurl) override; |
| 83 |
| 65 protected: | 84 protected: |
| 66 void EndBatchUpdates() override; | 85 void EnteringBatchUpdates() override; |
| 86 void LeavingBatchUpdates() override; |
| 67 | 87 |
| 68 private: | 88 private: |
| 69 typedef std::vector<ReadingListEntry> ReadingListEntries; | 89 void RemoveEntryByURLImpl(const GURL& url, bool from_sync); |
| 90 void SavePersistentHasUnseen(bool has_unseen); |
| 91 bool LoadPersistentHasUnseen(); |
| 92 ReadingListEntry* GetMutableEntryFromURL(const GURL& gurl, bool* read) const; |
| 93 void SortEntries(); |
| 70 | 94 |
| 71 ReadingListEntries unread_; | 95 std::unique_ptr<ReadingListEntries> unread_; |
| 72 ReadingListEntries read_; | 96 std::unique_ptr<ReadingListEntries> read_; |
| 73 std::unique_ptr<ReadingListModelStorage> storageLayer_; | 97 std::unique_ptr<ReadingListModelStorage> storage_layer_; |
| 74 bool hasUnseen_; | 98 PrefService* pref_service_; |
| 99 bool has_unseen_; |
| 75 bool loaded_; | 100 bool loaded_; |
| 76 | 101 base::WeakPtrFactory<ReadingListModelImpl> weak_ptr_factory_; |
| 77 DISALLOW_COPY_AND_ASSIGN(ReadingListModelImpl); | 102 DISALLOW_COPY_AND_ASSIGN(ReadingListModelImpl); |
| 78 }; | 103 }; |
| 79 | 104 |
| 80 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_MEMORY_H_ | 105 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_MEMORY_H_ |
| OLD | NEW |