Chromium Code Reviews| 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_H_ | 5 #ifndef IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_H_ |
| 6 #define IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_H_ | 6 #define IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "ios/chrome/browser/reading_list/reading_list_entry.h" | 14 #include "ios/chrome/browser/reading_list/reading_list_entry.h" |
| 15 #include "ios/chrome/browser/reading_list/reading_list_model_observer.h" | 15 #include "ios/chrome/browser/reading_list/reading_list_model_observer.h" |
| 16 | 16 |
| 17 class GURL; | 17 class GURL; |
| 18 class ReadingListEntry; | |
| 18 class ReadingListModel; | 19 class ReadingListModel; |
| 20 class ReadingListStore; | |
| 21 class ScopedReadingListBatchUpdate; | |
| 22 | |
| 23 using ReadingListEntries = std::vector<ReadingListEntry>; | |
|
pavely
2016/11/14 07:45:33
reading_list_model.h, reading_list_store_delegate.
Olivier
2016/11/14 11:36:48
Done.
| |
| 19 | 24 |
| 20 namespace ios { | 25 namespace ios { |
| 21 class ChromeBrowserState; | 26 class ChromeBrowserState; |
| 22 } | 27 } |
| 23 | 28 |
| 29 namespace syncer { | |
| 30 class ModelTypeSyncBridge; | |
| 31 } | |
| 32 | |
| 24 // The reading list model contains two list of entries: one of unread urls, the | 33 // The reading list model contains two list of entries: one of unread urls, the |
| 25 // other of read ones. This object should only be accessed from one thread | 34 // other of read ones. This object should only be accessed from one thread |
| 26 // (Usually the main thread). The observers callbacks are also sent on the main | 35 // (Usually the main thread). The observers callbacks are also sent on the main |
| 27 // thread. | 36 // thread. |
| 28 class ReadingListModel { | 37 class ReadingListModel : public base::NonThreadSafe { |
|
pavely
2016/11/14 07:45:33
You need to include non_thread_safe.h.
Olivier
2016/11/14 11:36:48
Done.
| |
| 29 public: | 38 public: |
| 30 class ScopedReadingListBatchUpdate; | 39 class ScopedReadingListBatchUpdate; |
| 40 | |
| 31 // Returns true if the model finished loading. Until this returns true the | 41 // Returns true if the model finished loading. Until this returns true the |
| 32 // reading list is not ready for use. | 42 // reading list is not ready for use. |
| 33 virtual bool loaded() const = 0; | 43 virtual bool loaded() const = 0; |
| 34 | 44 |
| 35 // Returns true if the model is performing batch updates right now. | 45 // Returns true if the model is performing batch updates right now. |
| 36 bool IsPerformingBatchUpdates() const; | 46 bool IsPerformingBatchUpdates() const; |
| 37 | 47 |
| 48 // Returns the ModelTypeSyncBridge responsible for handling sync message. | |
| 49 virtual syncer::ModelTypeSyncBridge* GetModelTypeSyncBridge() = 0; | |
| 50 | |
| 38 // Tells model to prepare for batch updates. | 51 // Tells model to prepare for batch updates. |
| 39 // This method is reentrant, i.e. several batch updates may take place at the | 52 // This method is reentrant, i.e. several batch updates may take place at the |
| 40 // same time. | 53 // same time. |
| 41 // Returns a scoped batch update object that should be retained while the | 54 // Returns a scoped batch update object that should be retained while the |
| 42 // batch update is performed. Deallocating this object will inform model that | 55 // batch update is performed. Deallocating this object will inform model that |
| 43 // the batch update has completed. | 56 // the batch update has completed. |
| 44 std::unique_ptr<ScopedReadingListBatchUpdate> BeginBatchUpdates(); | 57 std::unique_ptr<ScopedReadingListBatchUpdate> BeginBatchUpdates(); |
| 45 | 58 |
| 59 // Creates a batch token that will freeze the model while in scope. | |
| 60 virtual std::unique_ptr<ScopedReadingListBatchUpdate> CreateBatchToken(); | |
| 61 | |
| 46 // Returns the size of read and unread entries. | 62 // Returns the size of read and unread entries. |
| 47 virtual size_t unread_size() const = 0; | 63 virtual size_t unread_size() const = 0; |
| 48 virtual size_t read_size() const = 0; | 64 virtual size_t read_size() const = 0; |
| 49 | 65 |
| 50 // Returns true if there are entries in the model that were not seen by the | 66 // Returns true if there are entries in the model that were not seen by the |
| 51 // user yet. Reset to true when new unread entries are added. Reset to false | 67 // user yet. Reset to true when new unread entries are added. Reset to false |
| 52 // when ResetUnseenEntries is called. | 68 // when ResetUnseenEntries is called. |
| 53 virtual bool HasUnseenEntries() const = 0; | 69 virtual bool HasUnseenEntries() const = 0; |
| 54 virtual void ResetUnseenEntries() = 0; | 70 virtual void ResetUnseenEntries() = 0; |
| 55 | 71 |
| 56 // TODO(659099): Remove methods. | 72 // TODO(659099): Remove methods. |
| 57 // Returns a specific entry. | 73 // Returns a specific entry. |
| 58 virtual const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const = 0; | 74 virtual const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const = 0; |
| 59 virtual const ReadingListEntry& GetReadEntryAtIndex(size_t index) const = 0; | 75 virtual const ReadingListEntry& GetReadEntryAtIndex(size_t index) const = 0; |
| 60 | 76 |
| 61 // Returns a specific entry. Returns null if the entry does not exist. | 77 // Returns a specific entry. Returns null if the entry does not exist. |
| 62 virtual const ReadingListEntry* GetEntryFromURL(const GURL& gurl) const = 0; | 78 // If |read| is not null and the entry is found, |*read| is the read status |
| 79 // of the entry. | |
| 80 virtual const ReadingListEntry* GetEntryFromURL(const GURL& gurl, | |
| 81 bool* read) const = 0; | |
| 63 | 82 |
| 64 // Synchronously calls the |callback| with entry associated with this |url|. | 83 // Synchronously calls the |callback| with entry associated with this |url|. |
| 65 // Does nothing if there is no entry associated. | 84 // Does nothing if there is no entry associated. |
| 66 // Returns whether the callback has been called. | 85 // Returns whether the callback has been called. |
| 67 virtual bool CallbackEntryURL( | 86 virtual bool CallbackEntryURL( |
| 68 const GURL& url, | 87 const GURL& url, |
| 69 base::Callback<void(const ReadingListEntry&)> callback) const = 0; | 88 base::Callback<void(const ReadingListEntry&)> callback) const = 0; |
| 70 | 89 |
| 71 // Adds |url| at the top of the unread entries, and removes entries with the | 90 // Adds |url| at the top of the unread entries, and removes entries with the |
| 72 // same |url| from everywhere else if they exist. The entry title will be a | 91 // same |url| from everywhere else if they exist. The entry title will be a |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 // destruction automatically. | 124 // destruction automatically. |
| 106 void AddObserver(ReadingListModelObserver* observer); | 125 void AddObserver(ReadingListModelObserver* observer); |
| 107 void RemoveObserver(ReadingListModelObserver* observer); | 126 void RemoveObserver(ReadingListModelObserver* observer); |
| 108 | 127 |
| 109 // Helper class that is used to scope batch updates. | 128 // Helper class that is used to scope batch updates. |
| 110 class ScopedReadingListBatchUpdate { | 129 class ScopedReadingListBatchUpdate { |
| 111 public: | 130 public: |
| 112 explicit ScopedReadingListBatchUpdate(ReadingListModel* model) | 131 explicit ScopedReadingListBatchUpdate(ReadingListModel* model) |
| 113 : model_(model) {} | 132 : model_(model) {} |
| 114 | 133 |
| 115 ~ScopedReadingListBatchUpdate() { model_->EndBatchUpdates(); } | 134 virtual ~ScopedReadingListBatchUpdate(); |
| 116 | 135 |
| 117 private: | 136 private: |
| 118 ReadingListModel* model_; | 137 ReadingListModel* model_; |
| 119 | 138 |
| 120 DISALLOW_COPY_AND_ASSIGN(ScopedReadingListBatchUpdate); | 139 DISALLOW_COPY_AND_ASSIGN(ScopedReadingListBatchUpdate); |
| 121 }; | 140 }; |
| 122 | 141 |
| 123 protected: | 142 protected: |
| 124 ReadingListModel(); | 143 ReadingListModel(); |
| 125 virtual ~ReadingListModel(); | 144 virtual ~ReadingListModel(); |
| 126 | 145 |
| 127 // The observers. | 146 // The observers. |
| 128 base::ObserverList<ReadingListModelObserver> observers_; | 147 base::ObserverList<ReadingListModelObserver> observers_; |
| 129 | 148 |
| 130 // Tells model that batch updates have completed. Called from | 149 // Tells model that batch updates have completed. Called from |
| 131 // ReadingListBatchUpdateToken dtor. | 150 // ReadingListBatchUpdateToken dtor. |
| 132 virtual void EndBatchUpdates(); | 151 virtual void EndBatchUpdates(); |
| 133 | 152 |
| 153 // Called when model is entering batch update mode. | |
| 154 virtual void EnteringBatchUpdates(); | |
| 155 | |
| 156 // Called when model is leaving batch update mode. | |
| 157 virtual void LeavingBatchUpdates(); | |
| 158 | |
| 134 private: | 159 private: |
| 135 unsigned int current_batch_updates_count_; | 160 unsigned int current_batch_updates_count_; |
| 136 | 161 |
| 137 DISALLOW_COPY_AND_ASSIGN(ReadingListModel); | 162 DISALLOW_COPY_AND_ASSIGN(ReadingListModel); |
| 138 }; | 163 }; |
| 139 | 164 |
| 140 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_H_ | 165 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_H_ |
| OLD | NEW |