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

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

Powered by Google App Engine
This is Rietveld 408576698