| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 DCHECK(loaded()); | 60 DCHECK(loaded()); |
| 61 return unread_[index]; | 61 return unread_[index]; |
| 62 } | 62 } |
| 63 | 63 |
| 64 const ReadingListEntry& ReadingListModelImpl::GetReadEntryAtIndex( | 64 const ReadingListEntry& ReadingListModelImpl::GetReadEntryAtIndex( |
| 65 size_t index) const { | 65 size_t index) const { |
| 66 DCHECK(loaded()); | 66 DCHECK(loaded()); |
| 67 return read_[index]; | 67 return read_[index]; |
| 68 } | 68 } |
| 69 | 69 |
| 70 bool ReadingListModelImpl::CallbackEntryURL( |
| 71 const GURL& url, |
| 72 base::Callback<void(const ReadingListEntry&)> callback) const { |
| 73 DCHECK(loaded()); |
| 74 ReadingListEntry entry(url, std::string()); |
| 75 auto resultUnread = std::find(unread_.begin(), unread_.end(), entry); |
| 76 if (resultUnread != unread_.end()) { |
| 77 callback.Run(*resultUnread); |
| 78 return true; |
| 79 } |
| 80 |
| 81 auto resultRead = std::find(read_.begin(), read_.end(), entry); |
| 82 if (resultRead != read_.end()) { |
| 83 callback.Run(*resultRead); |
| 84 return true; |
| 85 } |
| 86 return false; |
| 87 } |
| 88 |
| 70 void ReadingListModelImpl::RemoveEntryByUrl(const GURL& url) { | 89 void ReadingListModelImpl::RemoveEntryByUrl(const GURL& url) { |
| 71 DCHECK(loaded()); | 90 DCHECK(loaded()); |
| 72 const ReadingListEntry entry(url, std::string()); | 91 const ReadingListEntry entry(url, std::string()); |
| 73 | 92 |
| 74 auto result = std::find(unread_.begin(), unread_.end(), entry); | 93 auto result = std::find(unread_.begin(), unread_.end(), entry); |
| 75 if (result != unread_.end()) { | 94 if (result != unread_.end()) { |
| 76 FOR_EACH_OBSERVER(ReadingListModelObserver, observers_, | 95 FOR_EACH_OBSERVER(ReadingListModelObserver, observers_, |
| 77 ReadingListWillRemoveUnreadEntry( | 96 ReadingListWillRemoveUnreadEntry( |
| 78 this, std::distance(unread_.begin(), result))); | 97 this, std::distance(unread_.begin(), result))); |
| 79 unread_.erase(result); | 98 unread_.erase(result); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 257 |
| 239 void ReadingListModelImpl::EndBatchUpdates() { | 258 void ReadingListModelImpl::EndBatchUpdates() { |
| 240 ReadingListModel::EndBatchUpdates(); | 259 ReadingListModel::EndBatchUpdates(); |
| 241 if (IsPerformingBatchUpdates() || !storageLayer_) { | 260 if (IsPerformingBatchUpdates() || !storageLayer_) { |
| 242 return; | 261 return; |
| 243 } | 262 } |
| 244 storageLayer_->SavePersistentUnreadList(unread_); | 263 storageLayer_->SavePersistentUnreadList(unread_); |
| 245 storageLayer_->SavePersistentReadList(read_); | 264 storageLayer_->SavePersistentReadList(read_); |
| 246 storageLayer_->SavePersistentHasUnseen(hasUnseen_); | 265 storageLayer_->SavePersistentHasUnseen(hasUnseen_); |
| 247 } | 266 } |
| OLD | NEW |