OLD | NEW |
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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 unread_.erase(result); | 151 unread_.erase(result); |
152 | 152 |
153 if (storageLayer_ && !IsPerformingBatchUpdates()) { | 153 if (storageLayer_ && !IsPerformingBatchUpdates()) { |
154 storageLayer_->SavePersistentUnreadList(unread_); | 154 storageLayer_->SavePersistentUnreadList(unread_); |
155 storageLayer_->SavePersistentReadList(read_); | 155 storageLayer_->SavePersistentReadList(read_); |
156 } | 156 } |
157 FOR_EACH_OBSERVER(ReadingListModelObserver, observers_, | 157 FOR_EACH_OBSERVER(ReadingListModelObserver, observers_, |
158 ReadingListDidApplyChanges(this)); | 158 ReadingListDidApplyChanges(this)); |
159 } | 159 } |
160 | 160 |
| 161 ReadingListModel::EntryState ReadingListModelImpl::EntryPositionByURL( |
| 162 const GURL& url) { |
| 163 ReadingListEntry entry(url, std::string()); |
| 164 auto result = std::find(unread_.begin(), unread_.end(), entry); |
| 165 if (result != unread_.end()) |
| 166 return UNREAD; |
| 167 |
| 168 result = std::find(read_.begin(), read_.end(), entry); |
| 169 if (result != read_.end()) |
| 170 return READ; |
| 171 |
| 172 return NOTPRESENT; |
| 173 } |
| 174 |
161 void ReadingListModelImpl::SetEntryTitle(const GURL& url, | 175 void ReadingListModelImpl::SetEntryTitle(const GURL& url, |
162 const std::string& title) { | 176 const std::string& title) { |
163 DCHECK(loaded()); | 177 DCHECK(loaded()); |
164 const ReadingListEntry entry(url, std::string()); | 178 const ReadingListEntry entry(url, std::string()); |
165 | 179 |
166 auto result = std::find(unread_.begin(), unread_.end(), entry); | 180 auto result = std::find(unread_.begin(), unread_.end(), entry); |
167 if (result != unread_.end()) { | 181 if (result != unread_.end()) { |
168 FOR_EACH_OBSERVER(ReadingListModelObserver, observers_, | 182 FOR_EACH_OBSERVER(ReadingListModelObserver, observers_, |
169 ReadingListWillUpdateUnreadEntry( | 183 ReadingListWillUpdateUnreadEntry( |
170 this, std::distance(unread_.begin(), result))); | 184 this, std::distance(unread_.begin(), result))); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 271 |
258 void ReadingListModelImpl::EndBatchUpdates() { | 272 void ReadingListModelImpl::EndBatchUpdates() { |
259 ReadingListModel::EndBatchUpdates(); | 273 ReadingListModel::EndBatchUpdates(); |
260 if (IsPerformingBatchUpdates() || !storageLayer_) { | 274 if (IsPerformingBatchUpdates() || !storageLayer_) { |
261 return; | 275 return; |
262 } | 276 } |
263 storageLayer_->SavePersistentUnreadList(unread_); | 277 storageLayer_->SavePersistentUnreadList(unread_); |
264 storageLayer_->SavePersistentReadList(read_); | 278 storageLayer_->SavePersistentReadList(read_); |
265 storageLayer_->SavePersistentHasUnseen(hasUnseen_); | 279 storageLayer_->SavePersistentHasUnseen(hasUnseen_); |
266 } | 280 } |
OLD | NEW |