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

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

Issue 2451843002: Add Store+Sync to reading list. (Closed)
Patch Set: reading_list_model_unittests 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 : public base::NonThreadSafe {
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 // Returns the ModelTypeService responsible for handling sync message.
44 virtual syncer::ModelTypeService* GetModelTypeService() = 0;
45
38 // Tells model to prepare for batch updates. 46 // Tells model to prepare for batch updates.
39 // This method is reentrant, i.e. several batch updates may take place at the 47 // This method is reentrant, i.e. several batch updates may take place at the
40 // same time. 48 // same time.
41 // Returns a scoped batch update object that should be retained while the 49 // Returns a scoped batch update object that should be retained while the
42 // batch update is performed. Deallocating this object will inform model that 50 // batch update is performed. Deallocating this object will inform model that
43 // the batch update has completed. 51 // the batch update has completed.
44 std::unique_ptr<ScopedReadingListBatchUpdate> BeginBatchUpdates(); 52 std::unique_ptr<ScopedReadingListBatchUpdate> BeginBatchUpdates();
45 53
46 // Returns the size of read and unread entries. 54 // Returns the size of read and unread entries.
47 virtual size_t unread_size() const = 0; 55 virtual size_t unread_size() const = 0;
48 virtual size_t read_size() const = 0; 56 virtual size_t read_size() const = 0;
49 57
50 // Returns true if there are entries in the model that were not seen by the 58 // 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 59 // user yet. Reset to true when new unread entries are added. Reset to false
52 // when ResetUnseenEntries is called. 60 // when ResetUnseenEntries is called.
53 virtual bool HasUnseenEntries() const = 0; 61 virtual bool HasUnseenEntries() const = 0;
54 virtual void ResetUnseenEntries() = 0; 62 virtual void ResetUnseenEntries() = 0;
55 63
56 // TODO(659099): Remove methods. 64 // TODO(659099): Remove methods.
57 // Returns a specific entry. 65 // Returns a specific entry.
58 virtual const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const = 0; 66 virtual const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const = 0;
59 virtual const ReadingListEntry& GetReadEntryAtIndex(size_t index) const = 0; 67 virtual const ReadingListEntry& GetReadEntryAtIndex(size_t index) const = 0;
60 68
61 // Returns a specific entry. Returns null if the entry does not exist. 69 // Returns a specific entry. Returns null if the entry does not exist.
62 virtual const ReadingListEntry* GetEntryFromURL(const GURL& gurl) const = 0; 70 virtual const ReadingListEntry* GetEntryFromURL(const GURL& gurl) const = 0;
63 71
72 // Handle sync events.
73 virtual void SyncAddEntry(std::unique_ptr<ReadingListEntry> entry,
74 bool read) = 0;
75 virtual void SyncRemoveEntry(const GURL& gurl) = 0;
76
64 // Synchronously calls the |callback| with entry associated with this |url|. 77 // Synchronously calls the |callback| with entry associated with this |url|.
65 // Does nothing if there is no entry associated. 78 // Does nothing if there is no entry associated.
66 // Returns whether the callback has been called. 79 // Returns whether the callback has been called.
67 virtual bool CallbackEntryURL( 80 virtual bool CallbackEntryURL(
68 const GURL& url, 81 const GURL& url,
69 base::Callback<void(const ReadingListEntry&)> callback) const = 0; 82 base::Callback<void(const ReadingListEntry&)> callback) const = 0;
70 83
84 // Synchronously calls the |callback| with entry associated with this |url|
85 // and its |read| status.
86 // Does nothing if there is no entry associated.
87 // Returns whether the callback has been called.
88 virtual bool CallbackEntryReadStatusURL(
89 const GURL& url,
90 base::Callback<void(const ReadingListEntry&, bool read)> callback)
91 const = 0;
92
71 // Adds |url| at the top of the unread entries, and removes entries with the 93 // 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 94 // 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 95 // asynchronous, and the data will be available only once the observers are
74 // notified. 96 // notified.
75 virtual const ReadingListEntry& AddEntry(const GURL& url, 97 virtual const ReadingListEntry& AddEntry(const GURL& url,
76 const std::string& title) = 0; 98 const std::string& title) = 0;
77 99
78 // Removes an entry. The removal may be asynchronous, and not happen 100 // Removes an entry. The removal may be asynchronous, and not happen
79 // immediately. 101 // immediately.
80 virtual void RemoveEntryByUrl(const GURL& url) = 0; 102 virtual void RemoveEntryByURL(const GURL& url) = 0;
81 103
82 // If the |url| is in the reading list and unread, mark it read. If it is in 104 // If the |url| is in the reading list and unread, mark it read. If it is in
83 // the reading list and read, move it to the top of unread if it is not here 105 // the reading list and read, move it to the top of unread if it is not here
84 // already. This may trigger deletion of old read entries. 106 // already. This may trigger deletion of old read entries.
85 virtual void MarkReadByURL(const GURL& url) = 0; 107 virtual void MarkReadByURL(const GURL& url) = 0;
86 // If the |url| is in the reading list and read, mark it unread. If it is in 108 // If the |url| is in the reading list and read, mark it unread. If it is in
87 // the reading list and unread, move it to the top of read if it is not here 109 // the reading list and unread, move it to the top of read if it is not here
88 // already. 110 // already.
89 virtual void MarkUnreadByURL(const GURL& url) = 0; 111 virtual void MarkUnreadByURL(const GURL& url) = 0;
90 112
(...skipping 29 matching lines...) Expand all
120 ReadingListModel(); 142 ReadingListModel();
121 virtual ~ReadingListModel(); 143 virtual ~ReadingListModel();
122 144
123 // The observers. 145 // The observers.
124 base::ObserverList<ReadingListModelObserver> observers_; 146 base::ObserverList<ReadingListModelObserver> observers_;
125 147
126 // Tells model that batch updates have completed. Called from 148 // Tells model that batch updates have completed. Called from
127 // ReadingListBatchUpdateToken dtor. 149 // ReadingListBatchUpdateToken dtor.
128 virtual void EndBatchUpdates(); 150 virtual void EndBatchUpdates();
129 151
152 // Called when model is entering batch update mode.
153 virtual void EnteringBatchUpdates();
154
155 // Called when model is leaving batch update mode.
156 virtual void LeavingBatchUpdates();
157
130 private: 158 private:
131 unsigned int current_batch_updates_count_; 159 unsigned int current_batch_updates_count_;
132 160
133 DISALLOW_COPY_AND_ASSIGN(ReadingListModel); 161 DISALLOW_COPY_AND_ASSIGN(ReadingListModel);
134 }; 162 };
135 163
136 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_H_ 164 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698