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

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

Issue 2451843002: Add Store+Sync to reading list. (Closed)
Patch Set: experimental_flags 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 #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 ReadingListModel; 18 class ReadingListModel;
19 class ReadingListStore;
19 20
20 namespace ios { 21 namespace ios {
21 class ChromeBrowserState; 22 class ChromeBrowserState;
22 } 23 }
23 24
25 namespace syncer {
26 class ModelTypeService;
27 }
28
24 // The reading list model contains two list of entries: one of unread urls, the 29 // 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 30 // 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 31 // (Usually the main thread). The observers callbacks are also sent on the main
27 // thread. 32 // thread.
28 class ReadingListModel { 33 class ReadingListModel {
29 public: 34 public:
30 class ScopedReadingListBatchUpdate; 35 class ScopedReadingListBatchUpdate;
31 // Returns true if the model finished loading. Until this returns true the 36 // Returns true if the model finished loading. Until this returns true the
32 // reading list is not ready for use. 37 // reading list is not ready for use.
33 virtual bool loaded() const = 0; 38 virtual bool loaded() const = 0;
34 39
35 // Returns true if the model is performing batch updates right now. 40 // Returns true if the model is performing batch updates right now.
36 bool IsPerformingBatchUpdates() const; 41 bool IsPerformingBatchUpdates() const;
37 42
43 virtual syncer::ModelTypeService* GetModelTypeService() = 0;
44
38 // Tells model to prepare for batch updates. 45 // Tells model to prepare for batch updates.
39 // This method is reentrant, i.e. several batch updates may take place at the 46 // This method is reentrant, i.e. several batch updates may take place at the
40 // same time. 47 // same time.
41 // Returns a scoped batch update object that should be retained while the 48 // Returns a scoped batch update object that should be retained while the
42 // batch update is performed. Deallocating this object will inform model that 49 // batch update is performed. Deallocating this object will inform model that
43 // the batch update has completed. 50 // the batch update has completed.
44 std::unique_ptr<ScopedReadingListBatchUpdate> BeginBatchUpdates(); 51 std::unique_ptr<ScopedReadingListBatchUpdate> BeginBatchUpdates();
45 52
46 // Returns the size of read and unread entries. 53 // Returns the size of read and unread entries.
47 virtual size_t unread_size() const = 0; 54 virtual size_t unread_size() const = 0;
48 virtual size_t read_size() const = 0; 55 virtual size_t read_size() const = 0;
49 56
50 // Returns true if there are entries in the model that were not seen by the 57 // 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 58 // user yet. Reset to true when new unread entries are added. Reset to false
52 // when ResetUnseenEntries is called. 59 // when ResetUnseenEntries is called.
53 virtual bool HasUnseenEntries() const = 0; 60 virtual bool HasUnseenEntries() const = 0;
54 virtual void ResetUnseenEntries() = 0; 61 virtual void ResetUnseenEntries() = 0;
55 62
56 // TODO(659099): Remove methods. 63 // TODO(659099): Remove methods.
skym 2016/11/01 18:27:25 Does that mean you won't need to sort the elements
Olivier 2016/11/02 14:57:10 No. We will always need to sort them. But we are d
57 // Returns a specific entry. 64 // Returns a specific entry.
58 virtual const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const = 0; 65 virtual const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const = 0;
59 virtual const ReadingListEntry& GetReadEntryAtIndex(size_t index) const = 0; 66 virtual const ReadingListEntry& GetReadEntryAtIndex(size_t index) const = 0;
60 67
61 // 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.
62 virtual const ReadingListEntry* GetEntryFromURL(const GURL& gurl) const = 0; 69 virtual const ReadingListEntry* GetEntryFromURL(const GURL& gurl) const = 0;
63 70
71 virtual void SyncAddEntry(std::unique_ptr<ReadingListEntry> entry,
72 bool read) = 0;
73 virtual void SyncRemoveEntry(const GURL& gurl) = 0;
74
64 // Synchronously calls the |callback| with entry associated with this |url|. 75 // Synchronously calls the |callback| with entry associated with this |url|.
65 // Does nothing if there is no entry associated. 76 // Does nothing if there is no entry associated.
66 // Returns whether the callback has been called. 77 // Returns whether the callback has been called.
67 virtual bool CallbackEntryURL( 78 virtual bool CallbackEntryURL(
68 const GURL& url, 79 const GURL& url,
69 base::Callback<void(const ReadingListEntry&)> callback) const = 0; 80 base::Callback<void(const ReadingListEntry&)> callback) const = 0;
70 81
82 // Synchronously calls the |callback| with entry associated with this |url|
83 // and its |read| status.
84 // Does nothing if there is no entry associated.
85 // Returns whether the callback has been called.
86 virtual bool CallbackEntryReadStatusURL(
87 const GURL& url,
88 base::Callback<void(const ReadingListEntry&, bool read)> callback)
89 const = 0;
90
71 // Adds |url| at the top of the unread entries, and removes entries with the 91 // Adds |url| at the top of the unread entries, and removes entries with the
72 // same |url| from everywhere else if they exist. The addition may be 92 // same |url| from everywhere else if they exist. The addition may be
73 // asynchronous, and the data will be available only once the observers are 93 // asynchronous, and the data will be available only once the observers are
74 // notified. 94 // notified.
75 virtual const ReadingListEntry& AddEntry(const GURL& url, 95 virtual const ReadingListEntry& AddEntry(const GURL& url,
76 const std::string& title) = 0; 96 const std::string& title) = 0;
77 97
78 // Removes an entry. The removal may be asynchronous, and not happen 98 // Removes an entry. The removal may be asynchronous, and not happen
79 // immediately. 99 // immediately.
80 virtual void RemoveEntryByUrl(const GURL& url) = 0; 100 virtual void RemoveEntryByUrl(const GURL& url) = 0;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 ReadingListModel(); 140 ReadingListModel();
121 virtual ~ReadingListModel(); 141 virtual ~ReadingListModel();
122 142
123 // The observers. 143 // The observers.
124 base::ObserverList<ReadingListModelObserver> observers_; 144 base::ObserverList<ReadingListModelObserver> observers_;
125 145
126 // Tells model that batch updates have completed. Called from 146 // Tells model that batch updates have completed. Called from
127 // ReadingListBatchUpdateToken dtor. 147 // ReadingListBatchUpdateToken dtor.
128 virtual void EndBatchUpdates(); 148 virtual void EndBatchUpdates();
129 149
150 // Called when model is entering batch update mode.
151 virtual void EnteringBatchUpdates();
152
153 // Called when model is leaving batch update mode.
154 virtual void LeavingBatchUpdates();
155
130 private: 156 private:
131 unsigned int current_batch_updates_count_; 157 unsigned int current_batch_updates_count_;
132 158
133 DISALLOW_COPY_AND_ASSIGN(ReadingListModel); 159 DISALLOW_COPY_AND_ASSIGN(ReadingListModel);
134 }; 160 };
135 161
136 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_H_ 162 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698