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

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

Issue 2525663002: Refactor Reading List Model to use URL as key. (Closed)
Patch Set: format 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 #include <unordered_map>
9 10
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"
13 #include "ios/chrome/browser/reading_list/reading_list_model_storage.h" 14 #include "ios/chrome/browser/reading_list/reading_list_model_storage.h"
14 #include "ios/chrome/browser/reading_list/reading_list_store_delegate.h" 15 #include "ios/chrome/browser/reading_list/reading_list_store_delegate.h"
15 16
16 class PrefService; 17 class PrefService;
17 18
18 // Concrete implementation of a reading list model using in memory lists. 19 // Concrete implementation of a reading list model using in memory lists.
19 class ReadingListModelImpl : public ReadingListModel, 20 class ReadingListModelImpl : public ReadingListModel,
20 public ReadingListStoreDelegate, 21 public ReadingListStoreDelegate,
21 public KeyedService { 22 public KeyedService {
22 public: 23 public:
23 // Initialize a ReadingListModelImpl to load and save data in 24 // Initialize a ReadingListModelImpl to load and save data in
24 // |persistence_layer|. 25 // |persistence_layer|.
25 ReadingListModelImpl(std::unique_ptr<ReadingListModelStorage> storage_layer, 26 ReadingListModelImpl(std::unique_ptr<ReadingListModelStorage> storage_layer,
26 PrefService* pref_service); 27 PrefService* pref_service);
27 28
28 // Initialize a ReadingListModelImpl without persistence. Data will not be 29 // Initialize a ReadingListModelImpl without persistence. Data will not be
29 // persistent across sessions. 30 // persistent across sessions.
30 ReadingListModelImpl(); 31 ReadingListModelImpl();
31 32
32 syncer::ModelTypeSyncBridge* GetModelTypeSyncBridge() override; 33 syncer::ModelTypeSyncBridge* GetModelTypeSyncBridge() override;
33 34
34 ~ReadingListModelImpl() override; 35 ~ReadingListModelImpl() override;
35 36
36 void StoreLoaded(std::unique_ptr<ReadingListEntries> unread, 37 void StoreLoaded(std::unique_ptr<ReadingListEntries> entries) override;
37 std::unique_ptr<ReadingListEntries> read) override;
38 38
39 // KeyedService implementation. 39 // KeyedService implementation.
40 void Shutdown() override; 40 void Shutdown() override;
41 41
42 // ReadingListModel implementation. 42 // ReadingListModel implementation.
43 bool loaded() const override; 43 bool loaded() const override;
44 44
45 size_t size() const override;
45 size_t unread_size() const override; 46 size_t unread_size() const override;
gambard 2016/11/23 12:11:07 Will this be deleted?
Olivier 2016/11/28 14:54:15 Done.
46 size_t read_size() const override; 47 size_t read_size() const override;
47 48
48 bool HasUnseenEntries() const override; 49 bool HasUnseenEntries() const override;
49 void ResetUnseenEntries() override; 50 void ResetUnseenEntries() override;
50 51
51 const ReadingListEntry& GetUnreadEntryAtIndex(size_t index) const override; 52 const ReadingListEntry* GetEntryFromURL(const GURL& gurl) const override;
52 const ReadingListEntry& GetReadEntryAtIndex(size_t index) const override; 53 const ReadingListEntry* GetEntryAt(size_t index) const override;
53 54 const ReadingListEntry* GetReadEntryAt(size_t index) const override;
54 const ReadingListEntry* GetEntryFromURL(const GURL& gurl, 55 const ReadingListEntry* GetUnreadEntryAt(size_t index) const override;
55 bool* read) const override;
56 56
57 bool CallbackEntryURL( 57 bool CallbackEntryURL(
58 const GURL& url, 58 const GURL& url,
59 base::Callback<void(const ReadingListEntry&)> callback) const override; 59 base::Callback<void(const ReadingListEntry&)> callback) const override;
60 60
61 void RemoveEntryByURL(const GURL& url) override; 61 void RemoveEntryByURL(const GURL& url) override;
62 62
63 const ReadingListEntry& AddEntry(const GURL& url, 63 const ReadingListEntry& AddEntry(const GURL& url,
64 const std::string& title) override; 64 const std::string& title) override;
65 65
66 void MarkReadByURL(const GURL& url) override; 66 void SetReadStatus(const GURL& url, bool read) override;
67 void MarkUnreadByURL(const GURL& url) override;
68 67
69 void SetEntryTitle(const GURL& url, const std::string& title) override; 68 void SetEntryTitle(const GURL& url, const std::string& title) override;
70 void SetEntryDistilledPath(const GURL& url, 69 void SetEntryDistilledPath(const GURL& url,
71 const base::FilePath& distilled_path) override; 70 const base::FilePath& distilled_path) override;
72 void SetEntryDistilledState( 71 void SetEntryDistilledState(
73 const GURL& url, 72 const GURL& url,
74 ReadingListEntry::DistillationState state) override; 73 ReadingListEntry::DistillationState state) override;
75 74
76 void SyncAddEntry(std::unique_ptr<ReadingListEntry> entry, 75 void SyncAddEntry(std::unique_ptr<ReadingListEntry> entry) override;
77 bool read) override; 76 ReadingListEntry* SyncMergeEntry(
78 ReadingListEntry* SyncMergeEntry(std::unique_ptr<ReadingListEntry> entry, 77 std::unique_ptr<ReadingListEntry> entry) override;
79 bool read) override;
80 void SyncRemoveEntry(const GURL& url) override; 78 void SyncRemoveEntry(const GURL& url) override;
81 79
82 std::unique_ptr<ReadingListModel::ScopedReadingListBatchUpdate> 80 std::unique_ptr<ReadingListModel::ScopedReadingListBatchUpdate>
83 CreateBatchToken() override; 81 CreateBatchToken() override;
84 82
85 // Helper class that is used to scope batch updates. 83 // Helper class that is used to scope batch updates.
86 class ScopedReadingListBatchUpdate 84 class ScopedReadingListBatchUpdate
87 : public ReadingListModel::ScopedReadingListBatchUpdate { 85 : public ReadingListModel::ScopedReadingListBatchUpdate {
88 public: 86 public:
89 explicit ScopedReadingListBatchUpdate(ReadingListModelImpl* model); 87 explicit ScopedReadingListBatchUpdate(ReadingListModelImpl* model);
(...skipping 10 matching lines...) Expand all
100 void EnteringBatchUpdates() override; 98 void EnteringBatchUpdates() override;
101 void LeavingBatchUpdates() override; 99 void LeavingBatchUpdates() override;
102 100
103 private: 101 private:
104 // Sets/Loads the pref flag that indicate if some entries have never been seen 102 // Sets/Loads the pref flag that indicate if some entries have never been seen
105 // since being added to the store. 103 // since being added to the store.
106 void SetPersistentHasUnseen(bool has_unseen); 104 void SetPersistentHasUnseen(bool has_unseen);
107 bool GetPersistentHasUnseen(); 105 bool GetPersistentHasUnseen();
108 106
109 // Returns a mutable pointer to the entry with URL |gurl|. Return nullptr if 107 // Returns a mutable pointer to the entry with URL |gurl|. Return nullptr if
110 // no entry is found. If an entry is found, |read| is set to the read status 108 // no entry is found. If an entry is found, |read| is set to the read status
jif-google 2016/11/22 18:21:45 update comment.
Olivier 2016/11/28 14:54:14 Done.
111 // of the entry. 109 // of the entry.
112 ReadingListEntry* GetMutableEntryFromURL(const GURL& gurl, bool* read) const; 110 ReadingListEntry* GetMutableEntryFromURL(const GURL& gurl) const;
113
114 // Sorts the entries in |read_| and |unread_| according to their |UpdateTime|.
115 void SortEntries();
116 111
117 // Returns the |storage_layer_| of the model. 112 // Returns the |storage_layer_| of the model.
118 ReadingListModelStorage* StorageLayer(); 113 ReadingListModelStorage* StorageLayer();
119 114
120 // Remove |entry| from the |entries| vector and calls the Move notifications 115 // Remove |entry| from the |entries| vector and calls the Move notifications
121 // on observers. 116 // on observers.
122 void MoveEntryFrom(ReadingListEntries* entries, 117 void MoveEntryFrom(ReadingListEntries* entries,
gambard 2016/11/23 12:11:07 Is this still used?
Olivier 2016/11/28 14:54:14 Done.
123 const ReadingListEntry& entry, 118 const ReadingListEntry& entry,
124 bool read); 119 bool read);
125 120
126 // Remove entry |url| and propagate to store if |from_sync| is false. 121 // Remove entry |url| and propagate to store if |from_sync| is false.
127 void RemoveEntryByURLImpl(const GURL& url, bool from_sync); 122 void RemoveEntryByURLImpl(const GURL& url, bool from_sync);
128 123
129 std::unique_ptr<ReadingListEntries> unread_; 124 void RebuildIndex() const;
130 std::unique_ptr<ReadingListEntries> read_; 125
126 std::unique_ptr<ReadingListEntries> entries_;
127 size_t unread_entry_count_;
128 size_t read_entry_count_;
129
130 struct Cache {
131 Cache();
132 ~Cache();
133 std::vector<GURL> read_entries;
134 std::vector<GURL> unread_entries;
135 bool dirty;
136 };
137 std::unique_ptr<struct Cache> cache_;
138
131 std::unique_ptr<ReadingListModelStorage> storage_layer_; 139 std::unique_ptr<ReadingListModelStorage> storage_layer_;
132 PrefService* pref_service_; 140 PrefService* pref_service_;
133 bool has_unseen_; 141 bool has_unseen_;
134 bool loaded_; 142 bool loaded_;
135 base::WeakPtrFactory<ReadingListModelImpl> weak_ptr_factory_; 143 base::WeakPtrFactory<ReadingListModelImpl> weak_ptr_factory_;
136 DISALLOW_COPY_AND_ASSIGN(ReadingListModelImpl); 144 DISALLOW_COPY_AND_ASSIGN(ReadingListModelImpl);
137 }; 145 };
138 146
139 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_MEMORY_H_ 147 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_MODEL_MEMORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698