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

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

Issue 2514333003: Componentize Reading List (Closed)
Patch Set: rebase Created 4 years, 1 month 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 // This is a temporary convenience file.
9 #include <string> 9 #include "components/reading_list/reading_list_model.h"
10 #include <vector>
11
12 #include "base/callback.h"
13 #include "base/observer_list.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "ios/chrome/browser/reading_list/reading_list_entry.h"
16 #include "ios/chrome/browser/reading_list/reading_list_model_observer.h"
17
18 class GURL;
19 class ReadingListEntry;
20 class ReadingListModel;
21 class ReadingListStore;
22 class ScopedReadingListBatchUpdate;
23
24 namespace ios {
25 class ChromeBrowserState;
26 }
27
28 namespace syncer {
29 class ModelTypeSyncBridge;
30 }
31
32 // The reading list model contains two list of entries: one of unread urls, the
33 // other of read ones. This object should only be accessed from one thread
34 // (Usually the main thread). The observers callbacks are also sent on the main
35 // thread.
36 class ReadingListModel : public base::NonThreadSafe {
37 public:
38 class ScopedReadingListBatchUpdate;
39
40 // Returns true if the model finished loading. Until this returns true the
41 // reading list is not ready for use.
42 virtual bool loaded() const = 0;
43
44 // Returns true if the model is performing batch updates right now.
45 bool IsPerformingBatchUpdates() const;
46
47 // Returns the ModelTypeSyncBridge responsible for handling sync message.
48 virtual syncer::ModelTypeSyncBridge* GetModelTypeSyncBridge() = 0;
49
50 // Tells model to prepare for batch updates.
51 // This method is reentrant, i.e. several batch updates may take place at the
52 // same time.
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
55 // the batch update has completed.
56 std::unique_ptr<ScopedReadingListBatchUpdate> BeginBatchUpdates();
57
58 // Creates a batch token that will freeze the model while in scope.
59 virtual std::unique_ptr<ScopedReadingListBatchUpdate> CreateBatchToken();
60
61 // Returns the size of read and unread entries.
62 virtual size_t unread_size() const = 0;
63 virtual size_t read_size() const = 0;
64
65 // 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
67 // when ResetUnseenEntries is called.
68 virtual bool HasUnseenEntries() const = 0;
69 virtual void ResetUnseenEntries() = 0;
70
71 // TODO(659099): Remove methods.
72 // Returns a specific entry.
73 virtual const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const = 0;
74 virtual const ReadingListEntry& GetReadEntryAtIndex(size_t index) const = 0;
75
76 // Returns a specific entry. Returns null if the entry does not exist.
77 // If |read| is not null and the entry is found, |*read| is the read status
78 // of the entry.
79 virtual const ReadingListEntry* GetEntryFromURL(const GURL& gurl,
80 bool* read) const = 0;
81
82 // Synchronously calls the |callback| with entry associated with this |url|.
83 // Does nothing if there is no entry associated.
84 // Returns whether the callback has been called.
85 virtual bool CallbackEntryURL(
86 const GURL& url,
87 base::Callback<void(const ReadingListEntry&)> callback) const = 0;
88
89 // 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
91 // trimmed copy of |title.
92 // The addition may be asynchronous, and the data will be available only once
93 // the observers are notified.
94 virtual const ReadingListEntry& AddEntry(const GURL& url,
95 const std::string& title) = 0;
96
97 // Removes an entry. The removal may be asynchronous, and not happen
98 // immediately.
99 virtual void RemoveEntryByURL(const GURL& url) = 0;
100
101 // If the |url| is in the reading list and unread, mark it read. If it is in
102 // the reading list and read, move it to the top of unread if it is not here
103 // already. This may trigger deletion of old read entries.
104 virtual void MarkReadByURL(const GURL& url) = 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
110 // Methods to mutate an entry. Will locate the relevant entry by URL. Does
111 // nothing if the entry is not found.
112 virtual void SetEntryTitle(const GURL& url, const std::string& title) = 0;
113 virtual void SetEntryDistilledPath(const GURL& url,
114 const base::FilePath& distilled_path) = 0;
115 virtual void SetEntryDistilledState(
116 const GURL& url,
117 ReadingListEntry::DistillationState state) = 0;
118
119 // Observer registration methods. The model will remove all observers upon
120 // destruction automatically.
121 void AddObserver(ReadingListModelObserver* observer);
122 void RemoveObserver(ReadingListModelObserver* observer);
123
124 // Helper class that is used to scope batch updates.
125 class ScopedReadingListBatchUpdate {
126 public:
127 explicit ScopedReadingListBatchUpdate(ReadingListModel* model)
128 : model_(model) {}
129
130 virtual ~ScopedReadingListBatchUpdate();
131
132 private:
133 ReadingListModel* model_;
134
135 DISALLOW_COPY_AND_ASSIGN(ScopedReadingListBatchUpdate);
136 };
137
138 protected:
139 ReadingListModel();
140 virtual ~ReadingListModel();
141
142 // The observers.
143 base::ObserverList<ReadingListModelObserver> observers_;
144
145 // Tells model that batch updates have completed. Called from
146 // ReadingListBatchUpdateToken dtor.
147 virtual void EndBatchUpdates();
148
149 // Called when model is entering batch update mode.
150 virtual void EnteringBatchUpdates();
151
152 // Called when model is leaving batch update mode.
153 virtual void LeavingBatchUpdates();
154
155 private:
156 unsigned int current_batch_updates_count_;
157
158 DISALLOW_COPY_AND_ASSIGN(ReadingListModel);
159 };
160 10
161 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_H_ 11 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_H_
OLDNEW
« no previous file with comments | « ios/chrome/browser/reading_list/reading_list_entry_unittest.cc ('k') | ios/chrome/browser/reading_list/reading_list_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698