Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: components/reading_list/ios/reading_list_model.h

Issue 2525663002: Refactor Reading List Model to use URL as key. (Closed)
Patch Set: feedback Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 COMPONENTS_READING_LIST_IOS_READING_LIST_MODEL_H_ 5 #ifndef COMPONENTS_READING_LIST_IOS_READING_LIST_MODEL_H_
6 #define COMPONENTS_READING_LIST_IOS_READING_LIST_MODEL_H_ 6 #define COMPONENTS_READING_LIST_IOS_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 "base/threading/non_thread_safe.h" 14 #include "base/threading/non_thread_safe.h"
15 #include "components/reading_list/ios/reading_list_entry.h" 15 #include "components/reading_list/ios/reading_list_entry.h"
16 #include "components/reading_list/ios/reading_list_model_observer.h" 16 #include "components/reading_list/ios/reading_list_model_observer.h"
17 17
18 class GURL; 18 class GURL;
19 class ReadingListEntry;
20 class ReadingListModel; 19 class ReadingListModel;
21 class ScopedReadingListBatchUpdate; 20 class ScopedReadingListBatchUpdate;
22 21
23 namespace syncer { 22 namespace syncer {
24 class ModelTypeSyncBridge; 23 class ModelTypeSyncBridge;
25 } 24 }
26 25
27 // The reading list model contains two list of entries: one of unread urls, the 26 // The reading list model contains two list of entries: one of unread urls, the
28 // other of read ones. This object should only be accessed from one thread 27 // other of read ones. This object should only be accessed from one thread
29 // (Usually the main thread). The observers callbacks are also sent on the main 28 // (Usually the main thread). The observers callbacks are also sent on the main
(...skipping 16 matching lines...) Expand all
46 // This method is reentrant, i.e. several batch updates may take place at the 45 // This method is reentrant, i.e. several batch updates may take place at the
47 // same time. 46 // same time.
48 // Returns a scoped batch update object that should be retained while the 47 // Returns a scoped batch update object that should be retained while the
49 // batch update is performed. Deallocating this object will inform model that 48 // batch update is performed. Deallocating this object will inform model that
50 // the batch update has completed. 49 // the batch update has completed.
51 std::unique_ptr<ScopedReadingListBatchUpdate> BeginBatchUpdates(); 50 std::unique_ptr<ScopedReadingListBatchUpdate> BeginBatchUpdates();
52 51
53 // Creates a batch token that will freeze the model while in scope. 52 // Creates a batch token that will freeze the model while in scope.
54 virtual std::unique_ptr<ScopedReadingListBatchUpdate> CreateBatchToken(); 53 virtual std::unique_ptr<ScopedReadingListBatchUpdate> CreateBatchToken();
55 54
56 // Returns the size of read and unread entries. 55 // Returns iterator to allow to iterate through reading list entries.
57 virtual size_t unread_size() const = 0; 56 virtual const ReadingListEntries::iterator begin() const = 0;
58 virtual size_t read_size() const = 0; 57 virtual const ReadingListEntries::iterator end() const = 0;
noyau (Ping after 24h) 2016/11/28 15:29:32 Can this just iterate URLs instead of exposing the
Olivier 2016/11/28 15:38:10 We can, I will check how to do that.
Olivier 2016/11/28 16:16:56 It is actually not easy as ReadingListModel is an
Olivier 2016/11/30 09:15:22 After a discussion with sdefresne, it seems the st
58
59 // Returns the total number of entries in the model.
60 virtual size_t size() const = 0;
noyau (Ping after 24h) 2016/11/28 15:29:32 No need for the unread size? Isn't it what is used
Olivier 2016/11/28 15:38:10 Yes, we need it. I cleaned it too fast Added back
59 61
60 // Returns true if there are entries in the model that were not seen by the 62 // Returns true if there are entries in the model that were not seen by the
61 // user yet. Reset to true when new unread entries are added. Reset to false 63 // user yet. Reset to true when new unread entries are added. Reset to false
62 // when ResetUnseenEntries is called. 64 // when ResetUnseenEntries is called.
63 virtual bool HasUnseenEntries() const = 0; 65 virtual bool HasUnseenEntries() const = 0;
64 virtual void ResetUnseenEntries() = 0; 66 virtual void ResetUnseenEntries() = 0;
65 67
66 // TODO(659099): Remove methods.
67 // Returns a specific entry.
68 virtual const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const = 0;
69 virtual const ReadingListEntry& GetReadEntryAtIndex(size_t index) const = 0;
70
71 // Returns a specific entry. Returns null if the entry does not exist. 68 // Returns a specific entry. Returns null if the entry does not exist.
72 // If |read| is not null and the entry is found, |*read| is the read status 69 virtual const ReadingListEntry* GetEntryByURL(const GURL& gurl) const = 0;
73 // of the entry.
74 virtual const ReadingListEntry* GetEntryFromURL(const GURL& gurl,
75 bool* read) const = 0;
76
77 // Synchronously calls the |callback| with entry associated with this |url|.
78 // Does nothing if there is no entry associated.
79 // Returns whether the callback has been called.
80 virtual bool CallbackEntryURL(
81 const GURL& url,
82 base::Callback<void(const ReadingListEntry&)> callback) const = 0;
83 70
84 // Adds |url| at the top of the unread entries, and removes entries with the 71 // Adds |url| at the top of the unread entries, and removes entries with the
85 // same |url| from everywhere else if they exist. The entry title will be a 72 // same |url| from everywhere else if they exist. The entry title will be a
86 // trimmed copy of |title. 73 // trimmed copy of |title.
87 // The addition may be asynchronous, and the data will be available only once 74 // The addition may be asynchronous, and the data will be available only once
88 // the observers are notified. 75 // the observers are notified.
89 virtual const ReadingListEntry& AddEntry(const GURL& url, 76 virtual const ReadingListEntry& AddEntry(const GURL& url,
90 const std::string& title) = 0; 77 const std::string& title) = 0;
91 78
92 // Removes an entry. The removal may be asynchronous, and not happen 79 // Removes an entry. The removal may be asynchronous, and not happen
93 // immediately. 80 // immediately.
94 virtual void RemoveEntryByURL(const GURL& url) = 0; 81 virtual void RemoveEntryByURL(const GURL& url) = 0;
95 82
96 // If the |url| is in the reading list and unread, mark it read. If it is in 83 // If the |url| is in the reading list entry(|url|).read != |read|, sets the
jif-google 2016/11/28 16:28:21 missing "and"? ...reading list and entry(|url).rea
Olivier 2016/11/28 17:58:25 Done.
97 // the reading list and read, move it to the top of unread if it is not here 84 // read state of the URL to read. This will also update the update time of
98 // already. This may trigger deletion of old read entries. 85 // the entry.
99 virtual void MarkReadByURL(const GURL& url) = 0; 86 virtual void SetReadStatus(const GURL& url, bool read) = 0;
noyau (Ping after 24h) 2016/11/28 15:29:31 You removed all the comments about what's happenin
Olivier 2016/11/28 15:38:10 I changed because read/unread is now a field in th
100 // If the |url| is in the reading list and read, mark it unread. If it is in
101 // the reading list and unread, move it to the top of read if it is not here
102 // already.
103 virtual void MarkUnreadByURL(const GURL& url) = 0;
104 87
105 // Methods to mutate an entry. Will locate the relevant entry by URL. Does 88 // Methods to mutate an entry. Will locate the relevant entry by URL. Does
106 // nothing if the entry is not found. 89 // nothing if the entry is not found.
107 virtual void SetEntryTitle(const GURL& url, const std::string& title) = 0; 90 virtual void SetEntryTitle(const GURL& url, const std::string& title) = 0;
108 virtual void SetEntryDistilledPath(const GURL& url, 91 virtual void SetEntryDistilledPath(const GURL& url,
109 const base::FilePath& distilled_path) = 0; 92 const base::FilePath& distilled_path) = 0;
110 virtual void SetEntryDistilledState( 93 virtual void SetEntryDistilledState(
111 const GURL& url, 94 const GURL& url,
112 ReadingListEntry::DistillationState state) = 0; 95 ReadingListEntry::DistillationState state) = 0;
113 96
114 // Observer registration methods. The model will remove all observers upon 97 // Observer registration methods. The model will remove all observers upon
115 // destruction automatically. 98 // destruction automatically.
116 void AddObserver(ReadingListModelObserver* observer); 99 void AddObserver(ReadingListModelObserver* observer);
117 void RemoveObserver(ReadingListModelObserver* observer); 100 void RemoveObserver(ReadingListModelObserver* observer);
118 101
119 // Helper class that is used to scope batch updates. 102 // Helper class that is used to scope batch updates.
120 class ScopedReadingListBatchUpdate { 103 class ScopedReadingListBatchUpdate {
121 public: 104 public:
122 explicit ScopedReadingListBatchUpdate(ReadingListModel* model) 105 explicit ScopedReadingListBatchUpdate(ReadingListModel* model)
123 : model_(model) {} 106 : model_(model) {}
124 107
125 virtual ~ScopedReadingListBatchUpdate(); 108 virtual ~ScopedReadingListBatchUpdate();
126 109
127 private: 110 private:
128 ReadingListModel* model_; 111 ReadingListModel* model_;
129 112
130 DISALLOW_COPY_AND_ASSIGN(ScopedReadingListBatchUpdate); 113 DISALLOW_COPY_AND_ASSIGN(ScopedReadingListBatchUpdate);
131 }; 114 };
132 115
116 // TODO(crbug.com/664924): Remove temporary methods for transition.
117
118 // Allows to iterate through read entries in the model. Must be called on a
jif-google 2016/11/28 16:28:21 s/Allows to iterate/Allows iterating/
Olivier 2016/11/28 17:58:25 Done.
119 // singlerunloop to ensure no entry is returned twice and all entries are
120 // returned
121 virtual const ReadingListEntry& GetReadEntryAtIndex(size_t index) const = 0;
122 virtual const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const = 0;
123 virtual void MarkReadByURL(const GURL& url) = 0;
124 virtual void MarkUnreadByURL(const GURL& url) = 0;
125 virtual size_t unread_size() const = 0;
126 virtual size_t read_size() const = 0;
127
133 protected: 128 protected:
134 ReadingListModel(); 129 ReadingListModel();
135 virtual ~ReadingListModel(); 130 virtual ~ReadingListModel();
136 131
137 // The observers. 132 // The observers.
138 base::ObserverList<ReadingListModelObserver> observers_; 133 base::ObserverList<ReadingListModelObserver> observers_;
139 134
140 // Tells model that batch updates have completed. Called from 135 // Tells model that batch updates have completed. Called from
141 // ReadingListBatchUpdateToken dtor. 136 // ReadingListBatchUpdateToken dtor.
142 virtual void EndBatchUpdates(); 137 virtual void EndBatchUpdates();
143 138
144 // Called when model is entering batch update mode. 139 // Called when model is entering batch update mode.
145 virtual void EnteringBatchUpdates(); 140 virtual void EnteringBatchUpdates();
146 141
147 // Called when model is leaving batch update mode. 142 // Called when model is leaving batch update mode.
148 virtual void LeavingBatchUpdates(); 143 virtual void LeavingBatchUpdates();
149 144
150 private: 145 private:
151 unsigned int current_batch_updates_count_; 146 unsigned int current_batch_updates_count_;
152 147
153 DISALLOW_COPY_AND_ASSIGN(ReadingListModel); 148 DISALLOW_COPY_AND_ASSIGN(ReadingListModel);
154 }; 149 };
155 150
156 #endif // COMPONENTS_READING_LIST_IOS_READING_LIST_MODEL_H_ 151 #endif // COMPONENTS_READING_LIST_IOS_READING_LIST_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698