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

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: 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_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 "base/threading/non_thread_safe.h"
pavely 2016/11/14 07:45:33 non_thread_safe.h is not needed here.
Olivier 2016/11/14 11:36:49 Done.
10 #include "components/keyed_service/core/keyed_service.h" 11 #include "components/keyed_service/core/keyed_service.h"
11 #include "ios/chrome/browser/reading_list/reading_list_entry.h" 12 #include "ios/chrome/browser/reading_list/reading_list_entry.h"
12 #include "ios/chrome/browser/reading_list/reading_list_model.h" 13 #include "ios/chrome/browser/reading_list/reading_list_model.h"
14 #include "ios/chrome/browser/reading_list/reading_list_model_storage.h"
15 #include "ios/chrome/browser/reading_list/reading_list_store_delegate.h"
13 16
14 class ReadingListModelStorage;
15 class PrefService; 17 class PrefService;
16 18
19 using ReadingListEntries = std::vector<ReadingListEntry>;
20
17 // Concrete implementation of a reading list model using in memory lists. 21 // Concrete implementation of a reading list model using in memory lists.
18 class ReadingListModelImpl : public ReadingListModel, public KeyedService { 22 class ReadingListModelImpl : public ReadingListModel,
23 public ReadingListStoreDelegate,
24 public KeyedService {
19 public: 25 public:
20 // Initialize a ReadingListModelImpl to load and save data in 26 // Initialize a ReadingListModelImpl to load and save data in
21 // |persistence_layer|. 27 // |persistence_layer|.
22 ReadingListModelImpl(std::unique_ptr<ReadingListModelStorage> storage, 28 ReadingListModelImpl(std::unique_ptr<ReadingListModelStorage> storage_layer,
23 PrefService* pref_service); 29 PrefService* pref_service);
24 30
25 // Initialize a ReadingListModelImpl without persistence. Data will not be 31 // Initialize a ReadingListModelImpl without persistence. Data will not be
26 // persistent across sessions. 32 // persistent across sessions.
27 ReadingListModelImpl(); 33 ReadingListModelImpl();
28 34
35 syncer::ModelTypeSyncBridge* GetModelTypeSyncBridge() override;
36
29 ~ReadingListModelImpl() override; 37 ~ReadingListModelImpl() override;
30 38
39 void StoreLoaded(std::unique_ptr<ReadingListEntries> unread,
40 std::unique_ptr<ReadingListEntries> read) override;
41
31 // KeyedService implementation. 42 // KeyedService implementation.
32 void Shutdown() override; 43 void Shutdown() override;
33 44
34 // ReadingListModel implementation. 45 // ReadingListModel implementation.
35 bool loaded() const override; 46 bool loaded() const override;
36 47
37 size_t unread_size() const override; 48 size_t unread_size() const override;
38 size_t read_size() const override; 49 size_t read_size() const override;
39 50
40 bool HasUnseenEntries() const override; 51 bool HasUnseenEntries() const override;
41 void ResetUnseenEntries() override; 52 void ResetUnseenEntries() override;
42 53
43 const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const override; 54 const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const override;
44 const ReadingListEntry& GetReadEntryAtIndex(size_t index) const override; 55 const ReadingListEntry& GetReadEntryAtIndex(size_t index) const override;
45 56
46 const ReadingListEntry* GetEntryFromURL(const GURL& gurl) const override; 57 const ReadingListEntry* GetEntryFromURL(const GURL& gurl,
58 bool* read) const override;
47 59
48 bool CallbackEntryURL( 60 bool CallbackEntryURL(
49 const GURL& url, 61 const GURL& url,
50 base::Callback<void(const ReadingListEntry&)> callback) const override; 62 base::Callback<void(const ReadingListEntry&)> callback) const override;
51 63
52 void RemoveEntryByURL(const GURL& url) override; 64 void RemoveEntryByURL(const GURL& url) override;
53 65
54 // Temporary method 66 // Temporary method
55 void RemoveEntryByUrl(const GURL& url) override; 67 void RemoveEntryByUrl(const GURL& url) override;
56 68
57 const ReadingListEntry& AddEntry(const GURL& url, 69 const ReadingListEntry& AddEntry(const GURL& url,
58 const std::string& title) override; 70 const std::string& title) override;
59 71
60 void MarkReadByURL(const GURL& url) override; 72 void MarkReadByURL(const GURL& url) override;
61 void MarkUnreadByURL(const GURL& url) override; 73 void MarkUnreadByURL(const GURL& url) override;
62 74
63 void SetEntryTitle(const GURL& url, const std::string& title) override; 75 void SetEntryTitle(const GURL& url, const std::string& title) override;
64 void SetEntryDistilledURL(const GURL& url, 76 void SetEntryDistilledURL(const GURL& url,
65 const GURL& distilled_url) override; 77 const GURL& distilled_url) override;
66 void SetEntryDistilledState( 78 void SetEntryDistilledState(
67 const GURL& url, 79 const GURL& url,
68 ReadingListEntry::DistillationState state) override; 80 ReadingListEntry::DistillationState state) override;
69 81
82 void SyncAddEntry(std::unique_ptr<ReadingListEntry> entry,
83 bool read) override;
84 void SyncRemoveEntry(const GURL& gurl) override;
85
86 std::unique_ptr<ReadingListModel::ScopedReadingListBatchUpdate>
87 CreateBatchToken() override;
88
89 // Helper class that is used to scope batch updates.
90 class ScopedReadingListBatchUpdate
91 : public ReadingListModel::ScopedReadingListBatchUpdate {
92 public:
93 explicit ScopedReadingListBatchUpdate(ReadingListModelImpl* model);
94
95 ~ScopedReadingListBatchUpdate() override;
96
97 private:
98 std::unique_ptr<ReadingListModelStorage::ScopedBatchUpdate> storage_token_;
99
100 DISALLOW_COPY_AND_ASSIGN(ScopedReadingListBatchUpdate);
101 };
102
70 protected: 103 protected:
71 void EndBatchUpdates() override; 104 void EnteringBatchUpdates() override;
105 void LeavingBatchUpdates() override;
72 106
73 private: 107 private:
108 void RemoveEntryByURLImpl(const GURL& url, bool from_sync);
74 void SetPersistentHasUnseen(bool has_unseen); 109 void SetPersistentHasUnseen(bool has_unseen);
75 bool GetPersistentHasUnseen(); 110 bool GetPersistentHasUnseen();
111 ReadingListEntry* GetMutableEntryFromURL(const GURL& gurl, bool* read) const;
112 void SortEntries();
113 ReadingListModelStorage* StorageLayer();
76 114
77 typedef std::vector<ReadingListEntry> ReadingListEntries; 115 std::unique_ptr<ReadingListEntries> unread_;
78 116 std::unique_ptr<ReadingListEntries> read_;
79 ReadingListEntries unread_;
80 ReadingListEntries read_;
81 std::unique_ptr<ReadingListModelStorage> storage_layer_; 117 std::unique_ptr<ReadingListModelStorage> storage_layer_;
82 PrefService* pref_service_; 118 PrefService* pref_service_;
83 bool has_unseen_; 119 bool has_unseen_;
84 bool loaded_; 120 bool loaded_;
85 121 base::WeakPtrFactory<ReadingListModelImpl> weak_ptr_factory_;
86 DISALLOW_COPY_AND_ASSIGN(ReadingListModelImpl); 122 DISALLOW_COPY_AND_ASSIGN(ReadingListModelImpl);
87 }; 123 };
88 124
89 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_MEMORY_H_ 125 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_MEMORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698