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

Side by Side Diff: ios/chrome/browser/reading_list/reading_list_model.h

Issue 2525663002: Refactor Reading List Model to use URL as key. (Closed)
Patch Set: format 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 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>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // This method is reentrant, i.e. several batch updates may take place at the 51 // This method is reentrant, i.e. several batch updates may take place at the
52 // same time. 52 // same time.
53 // Returns a scoped batch update object that should be retained while the 53 // Returns a scoped batch update object that should be retained while the
54 // batch update is performed. Deallocating this object will inform model that 54 // batch update is performed. Deallocating this object will inform model that
55 // the batch update has completed. 55 // the batch update has completed.
56 std::unique_ptr<ScopedReadingListBatchUpdate> BeginBatchUpdates(); 56 std::unique_ptr<ScopedReadingListBatchUpdate> BeginBatchUpdates();
57 57
58 // Creates a batch token that will freeze the model while in scope. 58 // Creates a batch token that will freeze the model while in scope.
59 virtual std::unique_ptr<ScopedReadingListBatchUpdate> CreateBatchToken(); 59 virtual std::unique_ptr<ScopedReadingListBatchUpdate> CreateBatchToken();
60 60
61 // Returns the size of read and unread entries. 61 // Returns the total number of entries in the model.
62 virtual size_t size() const = 0;
63
64 // Returns the total number of unread entries in the model.
62 virtual size_t unread_size() const = 0; 65 virtual size_t unread_size() const = 0;
66
67 // Returns the total number of read entries in the model.
63 virtual size_t read_size() const = 0; 68 virtual size_t read_size() const = 0;
gambard 2016/11/23 12:11:06 This can probably be removed.
Olivier 2016/11/28 14:54:14 Done.
64 69
65 // Returns true if there are entries in the model that were not seen by the 70 // Returns true if there are entries in the model that were not seen by the
66 // user yet. Reset to true when new unread entries are added. Reset to false 71 // user yet. Reset to true when new unread entries are added. Reset to false
67 // when ResetUnseenEntries is called. 72 // when ResetUnseenEntries is called.
68 virtual bool HasUnseenEntries() const = 0; 73 virtual bool HasUnseenEntries() const = 0;
69 virtual void ResetUnseenEntries() = 0; 74 virtual void ResetUnseenEntries() = 0;
70 75
71 // TODO(659099): Remove methods. 76 // Returns a specific entry. Returns null if the entry does not exist.
72 // Returns a specific entry. 77 virtual const ReadingListEntry* GetEntryFromURL(const GURL& gurl) const = 0;
73 virtual const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const = 0;
74 virtual const ReadingListEntry& GetReadEntryAtIndex(size_t index) const = 0;
gambard 2016/11/23 12:11:06 You are breaking downstream by renaming them no?
Olivier 2016/11/28 14:54:14 Done.
75 78
76 // Returns a specific entry. Returns null if the entry does not exist. 79 // Allows to iterate through entries in the model. Must be called on a single
77 // If |read| is not null and the entry is found, |*read| is the read status 80 // runloop to ensure no entry is returned twice and all entries are returned.
78 // of the entry. 81 virtual const ReadingListEntry* GetEntryAt(size_t index) const = 0;
jif-google 2016/11/22 18:21:45 I think it would be useful to offer range based fo
Olivier 2016/11/28 14:54:14 Done.
79 virtual const ReadingListEntry* GetEntryFromURL(const GURL& gurl, 82 // Allows to iterate through read entries in the model. Must be called on a
80 bool* read) const = 0; 83 // singlerunloop to ensure no entry is returned twice and all entries are
84 // returned
85 virtual const ReadingListEntry* GetReadEntryAt(size_t index) const = 0;
jif-google 2016/11/22 18:21:45 this will be removed, right?
Olivier 2016/11/28 14:54:14 Done.
86 // Allows to iterate through unread entries in the model. Must be called on a
87 // singlerunloop to ensure no entry is returned twice and all entries are
88 // returned
89 virtual const ReadingListEntry* GetUnreadEntryAt(size_t index) const = 0;
jif-google 2016/11/22 18:21:45 this will be removed, right?
Olivier 2016/11/28 14:54:14 Done.
81 90
82 // Synchronously calls the |callback| with entry associated with this |url|. 91 // Synchronously calls the |callback| with entry associated with this |url|.
83 // Does nothing if there is no entry associated. 92 // Does nothing if there is no entry associated.
84 // Returns whether the callback has been called. 93 // Returns whether the callback has been called.
85 virtual bool CallbackEntryURL( 94 virtual bool CallbackEntryURL(
gambard 2016/11/23 12:11:06 This can probably be removed, it was a workaround
Olivier 2016/11/28 14:54:14 Done.
86 const GURL& url, 95 const GURL& url,
87 base::Callback<void(const ReadingListEntry&)> callback) const = 0; 96 base::Callback<void(const ReadingListEntry&)> callback) const = 0;
88 97
89 // Adds |url| at the top of the unread entries, and removes entries with the 98 // Adds |url| at the top of the unread entries, and removes entries with the
90 // same |url| from everywhere else if they exist. The entry title will be a 99 // same |url| from everywhere else if they exist. The entry title will be a
91 // trimmed copy of |title. 100 // trimmed copy of |title.
92 // The addition may be asynchronous, and the data will be available only once 101 // The addition may be asynchronous, and the data will be available only once
93 // the observers are notified. 102 // the observers are notified.
94 virtual const ReadingListEntry& AddEntry(const GURL& url, 103 virtual const ReadingListEntry& AddEntry(const GURL& url,
95 const std::string& title) = 0; 104 const std::string& title) = 0;
96 105
97 // Removes an entry. The removal may be asynchronous, and not happen 106 // Removes an entry. The removal may be asynchronous, and not happen
98 // immediately. 107 // immediately.
99 virtual void RemoveEntryByURL(const GURL& url) = 0; 108 virtual void RemoveEntryByURL(const GURL& url) = 0;
100 109
101 // If the |url| is in the reading list and unread, mark it read. If it is in 110 // If the |url| is in the reading list entry(|url|).read != |read|, sets the
102 // the reading list and read, move it to the top of unread if it is not here 111 // read state of the URL to read. This will also update the update time of
103 // already. This may trigger deletion of old read entries. 112 // the entry.
104 virtual void MarkReadByURL(const GURL& url) = 0; 113 virtual void SetReadStatus(const GURL& url, bool read) = 0;
105 // If the |url| is in the reading list and read, mark it unread. If it is in
106 // the reading list and unread, move it to the top of read if it is not here
107 // already.
108 virtual void MarkUnreadByURL(const GURL& url) = 0;
109 114
110 // Methods to mutate an entry. Will locate the relevant entry by URL. Does 115 // Methods to mutate an entry. Will locate the relevant entry by URL. Does
111 // nothing if the entry is not found. 116 // nothing if the entry is not found.
112 virtual void SetEntryTitle(const GURL& url, const std::string& title) = 0; 117 virtual void SetEntryTitle(const GURL& url, const std::string& title) = 0;
113 virtual void SetEntryDistilledPath(const GURL& url, 118 virtual void SetEntryDistilledPath(const GURL& url,
114 const base::FilePath& distilled_path) = 0; 119 const base::FilePath& distilled_path) = 0;
115 virtual void SetEntryDistilledState( 120 virtual void SetEntryDistilledState(
116 const GURL& url, 121 const GURL& url,
117 ReadingListEntry::DistillationState state) = 0; 122 ReadingListEntry::DistillationState state) = 0;
118 123
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 // Called when model is leaving batch update mode. 157 // Called when model is leaving batch update mode.
153 virtual void LeavingBatchUpdates(); 158 virtual void LeavingBatchUpdates();
154 159
155 private: 160 private:
156 unsigned int current_batch_updates_count_; 161 unsigned int current_batch_updates_count_;
157 162
158 DISALLOW_COPY_AND_ASSIGN(ReadingListModel); 163 DISALLOW_COPY_AND_ASSIGN(ReadingListModel);
159 }; 164 };
160 165
161 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_H_ 166 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698