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

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

Issue 2434993002: Add methods to Reading List Model (Closed)
Patch Set: Remove ClearModelForTest Created 4 years, 2 months 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 #include "ios/chrome/browser/reading_list/reading_list_model_impl.h" 5 #include "ios/chrome/browser/reading_list/reading_list_model_impl.h"
6 6
7 #include "ios/chrome/browser/reading_list/reading_list_model_storage.h" 7 #include "ios/chrome/browser/reading_list/reading_list_model_storage.h"
8 #include "url/gurl.h" 8 #include "url/gurl.h"
9 9
10 ReadingListModelImpl::ReadingListModelImpl() : ReadingListModelImpl(NULL) {} 10 ReadingListModelImpl::ReadingListModelImpl() : ReadingListModelImpl(NULL) {}
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 hasUnseen_ = true; 131 hasUnseen_ = true;
132 if (storageLayer_ && !IsPerformingBatchUpdates()) { 132 if (storageLayer_ && !IsPerformingBatchUpdates()) {
133 storageLayer_->SavePersistentUnreadList(unread_); 133 storageLayer_->SavePersistentUnreadList(unread_);
134 storageLayer_->SavePersistentHasUnseen(true); 134 storageLayer_->SavePersistentHasUnseen(true);
135 } 135 }
136 for (auto& observer : observers_) 136 for (auto& observer : observers_)
137 observer.ReadingListDidApplyChanges(this); 137 observer.ReadingListDidApplyChanges(this);
138 return *unread_.begin(); 138 return *unread_.begin();
139 } 139 }
140 140
141 void ReadingListModelImpl::MarkUnreadByURL(const GURL& url) {
142 DCHECK(loaded());
143 ReadingListEntry entry(url, std::string());
144 auto result = std::find(read_.begin(), read_.end(), entry);
145 if (result == read_.end())
146 return;
147
148 for (ReadingListModelObserver& observer : observers_) {
149 observer.ReadingListWillMoveEntry(this,
150 std::distance(read_.begin(), result));
151 }
152
153 unread_.insert(unread_.begin(), std::move(*result));
154 read_.erase(result);
155
156 if (storageLayer_ && !IsPerformingBatchUpdates()) {
157 storageLayer_->SavePersistentUnreadList(read_);
158 storageLayer_->SavePersistentReadList(unread_);
159 }
160 for (ReadingListModelObserver& observer : observers_) {
161 observer.ReadingListDidApplyChanges(this);
162 }
163 }
164
141 void ReadingListModelImpl::MarkReadByURL(const GURL& url) { 165 void ReadingListModelImpl::MarkReadByURL(const GURL& url) {
142 DCHECK(loaded()); 166 DCHECK(loaded());
143 ReadingListEntry entry(url, std::string()); 167 ReadingListEntry entry(url, std::string());
144 auto result = std::find(unread_.begin(), unread_.end(), entry); 168 auto result = std::find(unread_.begin(), unread_.end(), entry);
145 if (result == unread_.end()) 169 if (result == unread_.end())
146 return; 170 return;
147 171
148 for (auto& observer : observers_) { 172 for (auto& observer : observers_) {
149 observer.ReadingListWillMoveEntry(this, 173 observer.ReadingListWillMoveEntry(this,
150 std::distance(unread_.begin(), result)); 174 std::distance(unread_.begin(), result));
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 290
267 void ReadingListModelImpl::EndBatchUpdates() { 291 void ReadingListModelImpl::EndBatchUpdates() {
268 ReadingListModel::EndBatchUpdates(); 292 ReadingListModel::EndBatchUpdates();
269 if (IsPerformingBatchUpdates() || !storageLayer_) { 293 if (IsPerformingBatchUpdates() || !storageLayer_) {
270 return; 294 return;
271 } 295 }
272 storageLayer_->SavePersistentUnreadList(unread_); 296 storageLayer_->SavePersistentUnreadList(unread_);
273 storageLayer_->SavePersistentReadList(read_); 297 storageLayer_->SavePersistentReadList(read_);
274 storageLayer_->SavePersistentHasUnseen(hasUnseen_); 298 storageLayer_->SavePersistentHasUnseen(hasUnseen_);
275 } 299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698