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

Side by Side Diff: ios/chrome/browser/reading_list/reading_list_model_impl.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_IMPL_H_ 5 #ifndef IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_IMPL_H_
6 #define IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_IMPL_H_ 6 #define IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_IMPL_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "components/keyed_service/core/keyed_service.h" 10 #include "components/keyed_service/core/keyed_service.h"
11 #include "ios/chrome/browser/reading_list/reading_list_entry.h" 11 #include "ios/chrome/browser/reading_list/reading_list_entry.h"
12 #include "ios/chrome/browser/reading_list/reading_list_model.h" 12 #include "ios/chrome/browser/reading_list/reading_list_model.h"
13 13
14 class ReadingListModelStorage; 14 class ReadingListModelStorage;
15 class PrefService;
16
17 using ReadingListEntries = std::vector<ReadingListEntry>;
15 18
16 // Concrete implementation of a reading list model using in memory lists. 19 // Concrete implementation of a reading list model using in memory lists.
17 class ReadingListModelImpl : public ReadingListModel, public KeyedService { 20 class ReadingListModelImpl : public ReadingListModel, public KeyedService {
18 public: 21 public:
19 // Initialize a ReadingListModelImpl to load and save data in 22 // Initialize a ReadingListModelImpl to load and save data in
20 // |persistence_layer|. 23 // |persistence_layer|.
21 ReadingListModelImpl(std::unique_ptr<ReadingListModelStorage> storage_layer); 24 ReadingListModelImpl(std::unique_ptr<ReadingListModelStorage> storage_layer,
25 PrefService* pref_service);
22 26
23 // Initialize a ReadingListModelImpl without persistence. Data will not be 27 // Initialize a ReadingListModelImpl without persistence. Data will not be
24 // persistent across sessions. 28 // persistent across sessions.
25 ReadingListModelImpl(); 29 ReadingListModelImpl();
26 30
31 syncer::ModelTypeService* GetModelTypeService() override;
32
27 ~ReadingListModelImpl() override; 33 ~ReadingListModelImpl() override;
28 34
29 // KeyedService implementation. 35 // KeyedService implementation.
30 void Shutdown() override; 36 void Shutdown() override;
31 37
32 // ReadingListModel implementation. 38 // ReadingListModel implementation.
33 bool loaded() const override; 39 bool loaded() const override;
34 40
35 size_t unread_size() const override; 41 size_t unread_size() const override;
36 size_t read_size() const override; 42 size_t read_size() const override;
37 43
38 bool HasUnseenEntries() const override; 44 bool HasUnseenEntries() const override;
39 void ResetUnseenEntries() override; 45 void ResetUnseenEntries() override;
40 46
41 const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const override; 47 const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const override;
42 const ReadingListEntry& GetReadEntryAtIndex(size_t index) const override; 48 const ReadingListEntry& GetReadEntryAtIndex(size_t index) const override;
43 49
44 const ReadingListEntry* GetEntryFromURL(const GURL& gurl) const override; 50 const ReadingListEntry* GetEntryFromURL(const GURL& gurl) const override;
45 51
46 bool CallbackEntryURL( 52 bool CallbackEntryURL(
47 const GURL& url, 53 const GURL& url,
48 base::Callback<void(const ReadingListEntry&)> callback) const override; 54 base::Callback<void(const ReadingListEntry&)> callback) const override;
49 55
56 bool CallbackEntryReadStatusURL(
57 const GURL& url,
58 base::Callback<void(const ReadingListEntry&, bool read)> callback)
59 const override;
60
50 void RemoveEntryByUrl(const GURL& url) override; 61 void RemoveEntryByUrl(const GURL& url) override;
51 62
52 const ReadingListEntry& AddEntry(const GURL& url, 63 const ReadingListEntry& AddEntry(const GURL& url,
53 const std::string& title) override; 64 const std::string& title) override;
54 65
55 void MarkReadByURL(const GURL& url) override; 66 void MarkReadByURL(const GURL& url) override;
56 void MarkUnreadByURL(const GURL& url) override; 67 void MarkUnreadByURL(const GURL& url) override;
57 68
58 void SetEntryTitle(const GURL& url, const std::string& title) override; 69 void SetEntryTitle(const GURL& url, const std::string& title) override;
59 void SetEntryDistilledURL(const GURL& url, 70 void SetEntryDistilledURL(const GURL& url,
60 const GURL& distilled_url) override; 71 const GURL& distilled_url) override;
61 void SetEntryDistilledState( 72 void SetEntryDistilledState(
62 const GURL& url, 73 const GURL& url,
63 ReadingListEntry::DistillationState state) override; 74 ReadingListEntry::DistillationState state) override;
64 75
76 virtual void ModelLoaded(std::unique_ptr<ReadingListEntries> unread,
77 std::unique_ptr<ReadingListEntries> read);
78
79 void SyncAddEntry(std::unique_ptr<ReadingListEntry> entry,
80 bool read) override;
81 void SyncRemoveEntry(const GURL& gurl) override;
82
65 protected: 83 protected:
66 void EndBatchUpdates() override; 84 void EnteringBatchUpdates() override;
85 void LeavingBatchUpdates() override;
67 86
68 private: 87 private:
69 typedef std::vector<ReadingListEntry> ReadingListEntries; 88 void RemoveEntryByUrlImpl(const GURL& url, bool from_sync);
89 void SavePersistentHasUnseen(bool has_unseen);
90 bool LoadPersistentHasUnseen();
91 ReadingListEntry* GetMutableEntryFromURL(const GURL& gurl, bool& read) const;
92 void SortEntries();
70 93
71 ReadingListEntries unread_; 94 std::unique_ptr<ReadingListEntries> unread_;
72 ReadingListEntries read_; 95 std::unique_ptr<ReadingListEntries> read_;
73 std::unique_ptr<ReadingListModelStorage> storageLayer_; 96 std::unique_ptr<ReadingListModelStorage> storage_layer_;
74 bool hasUnseen_; 97 PrefService* pref_service_;
98 bool has_unseen_;
75 bool loaded_; 99 bool loaded_;
76 100 base::WeakPtrFactory<ReadingListModelImpl> weak_ptr_factory_;
77 DISALLOW_COPY_AND_ASSIGN(ReadingListModelImpl); 101 DISALLOW_COPY_AND_ASSIGN(ReadingListModelImpl);
78 }; 102 };
79 103
80 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_MEMORY_H_ 104 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_MEMORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698