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

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

Issue 2451843002: Add Store+Sync to reading list. (Closed)
Patch Set: jif' feedback + reading_list_store_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 ReadingListEntry;
18 class ReadingListModel; 19 class ReadingListModel;
20 class ReadingListStore;
21
22 using ReadingListEntries = std::vector<ReadingListEntry>;
19 23
20 namespace ios { 24 namespace ios {
21 class ChromeBrowserState; 25 class ChromeBrowserState;
22 } 26 }
23 27
28 namespace syncer {
29 class ModelTypeService;
30 }
31
24 // The reading list model contains two list of entries: one of unread urls, the 32 // 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 33 // 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 34 // (Usually the main thread). The observers callbacks are also sent on the main
27 // thread. 35 // thread.
28 class ReadingListModel { 36 class ReadingListModel : public base::NonThreadSafe {
29 public: 37 public:
30 class ScopedReadingListBatchUpdate; 38 class ScopedReadingListBatchUpdate;
39
31 // Returns true if the model finished loading. Until this returns true the 40 // Returns true if the model finished loading. Until this returns true the
32 // reading list is not ready for use. 41 // reading list is not ready for use.
33 virtual bool loaded() const = 0; 42 virtual bool loaded() const = 0;
34 43
35 // Returns true if the model is performing batch updates right now. 44 // Returns true if the model is performing batch updates right now.
36 bool IsPerformingBatchUpdates() const; 45 bool IsPerformingBatchUpdates() const;
37 46
47 // Returns the ModelTypeService responsible for handling sync message.
48 virtual syncer::ModelTypeService* GetModelTypeService() = 0;
49
38 // Tells model to prepare for batch updates. 50 // Tells model to prepare for batch updates.
39 // 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
40 // same time. 52 // same time.
41 // 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
42 // batch update is performed. Deallocating this object will inform model that 54 // batch update is performed. Deallocating this object will inform model that
43 // the batch update has completed. 55 // the batch update has completed.
44 std::unique_ptr<ScopedReadingListBatchUpdate> BeginBatchUpdates(); 56 std::unique_ptr<ScopedReadingListBatchUpdate> BeginBatchUpdates();
45 57
46 // Returns the size of read and unread entries. 58 // Returns the size of read and unread entries.
47 virtual size_t unread_size() const = 0; 59 virtual size_t unread_size() const = 0;
(...skipping 13 matching lines...) Expand all
61 // Returns a specific entry. Returns null if the entry does not exist. 73 // Returns a specific entry. Returns null if the entry does not exist.
62 virtual const ReadingListEntry* GetEntryFromURL(const GURL& gurl) const = 0; 74 virtual const ReadingListEntry* GetEntryFromURL(const GURL& gurl) const = 0;
63 75
64 // Synchronously calls the |callback| with entry associated with this |url|. 76 // Synchronously calls the |callback| with entry associated with this |url|.
65 // Does nothing if there is no entry associated. 77 // Does nothing if there is no entry associated.
66 // Returns whether the callback has been called. 78 // Returns whether the callback has been called.
67 virtual bool CallbackEntryURL( 79 virtual bool CallbackEntryURL(
68 const GURL& url, 80 const GURL& url,
69 base::Callback<void(const ReadingListEntry&)> callback) const = 0; 81 base::Callback<void(const ReadingListEntry&)> callback) const = 0;
70 82
83 // Synchronously calls the |callback| with entry associated with this |url|
84 // and its |read| status.
85 // Does nothing if there is no entry associated.
86 // Returns whether the callback has been called.
87 virtual bool CallbackEntryReadStatusURL(
88 const GURL& url,
89 base::Callback<void(const ReadingListEntry&, bool read)> callback)
90 const = 0;
91
71 // Adds |url| at the top of the unread entries, and removes entries with the 92 // 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 93 // 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 94 // asynchronous, and the data will be available only once the observers are
74 // notified. 95 // notified.
75 virtual const ReadingListEntry& AddEntry(const GURL& url, 96 virtual const ReadingListEntry& AddEntry(const GURL& url,
76 const std::string& title) = 0; 97 const std::string& title) = 0;
77 98
78 // Removes an entry. The removal may be asynchronous, and not happen 99 // Removes an entry. The removal may be asynchronous, and not happen
79 // immediately. 100 // immediately.
80 virtual void RemoveEntryByUrl(const GURL& url) = 0; 101 virtual void RemoveEntryByURL(const GURL& url) = 0;
81 102
82 // If the |url| is in the reading list and unread, mark it read. If it is in 103 // 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 104 // 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. 105 // already. This may trigger deletion of old read entries.
85 virtual void MarkReadByURL(const GURL& url) = 0; 106 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 107 // 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 108 // the reading list and unread, move it to the top of read if it is not here
88 // already. 109 // already.
89 virtual void MarkUnreadByURL(const GURL& url) = 0; 110 virtual void MarkUnreadByURL(const GURL& url) = 0;
90 111
(...skipping 29 matching lines...) Expand all
120 ReadingListModel(); 141 ReadingListModel();
121 virtual ~ReadingListModel(); 142 virtual ~ReadingListModel();
122 143
123 // The observers. 144 // The observers.
124 base::ObserverList<ReadingListModelObserver> observers_; 145 base::ObserverList<ReadingListModelObserver> observers_;
125 146
126 // Tells model that batch updates have completed. Called from 147 // Tells model that batch updates have completed. Called from
127 // ReadingListBatchUpdateToken dtor. 148 // ReadingListBatchUpdateToken dtor.
128 virtual void EndBatchUpdates(); 149 virtual void EndBatchUpdates();
129 150
151 // Called when model is entering batch update mode.
152 virtual void EnteringBatchUpdates();
153
154 // Called when model is leaving batch update mode.
155 virtual void LeavingBatchUpdates();
156
130 private: 157 private:
131 unsigned int current_batch_updates_count_; 158 unsigned int current_batch_updates_count_;
132 159
133 DISALLOW_COPY_AND_ASSIGN(ReadingListModel); 160 DISALLOW_COPY_AND_ASSIGN(ReadingListModel);
134 }; 161 };
135 162
136 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_H_ 163 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698