| Index: ios/chrome/browser/reading_list/reading_list_model_impl.cc
|
| diff --git a/ios/chrome/browser/reading_list/reading_list_model_impl.cc b/ios/chrome/browser/reading_list/reading_list_model_impl.cc
|
| index c3e068d65f0249a30a6ce1c36dbd381cdf56d260..a9d29cc59c014fb4b71034ed81194b2506d81abc 100644
|
| --- a/ios/chrome/browser/reading_list/reading_list_model_impl.cc
|
| +++ b/ios/chrome/browser/reading_list/reading_list_model_impl.cc
|
| @@ -54,17 +54,35 @@ void ReadingListModelImpl::ResetUnseenEntries() {
|
| storageLayer_->SavePersistentHasUnseen(false);
|
| }
|
|
|
| -// Returns a specific entry.
|
| -const ReadingListEntry& ReadingListModelImpl::GetUnreadEntryAtIndex(
|
| +const ReadingListEntry* ReadingListModelImpl::GetUnreadEntryAtIndex(
|
| size_t index) const {
|
| DCHECK(loaded());
|
| - return unread_[index];
|
| + if (index >= unread_.size())
|
| + return nullptr;
|
| + return &unread_[index];
|
| }
|
|
|
| -const ReadingListEntry& ReadingListModelImpl::GetReadEntryAtIndex(
|
| +const ReadingListEntry* ReadingListModelImpl::GetReadEntryAtIndex(
|
| size_t index) const {
|
| DCHECK(loaded());
|
| - return read_[index];
|
| + if (index >= read_.size())
|
| + return nullptr;
|
| + return &read_[index];
|
| +}
|
| +
|
| +const ReadingListEntry* ReadingListModelImpl::GetEntryFromURL(
|
| + const GURL& gurl) const {
|
| + auto it = std::find_if(
|
| + read_.begin(), read_.end(),
|
| + [&gurl](const ReadingListEntry& entry) { return gurl == entry.URL(); });
|
| + if (it == read_.end()) {
|
| + it = std::find_if(
|
| + unread_.begin(), unread_.end(),
|
| + [&gurl](const ReadingListEntry& entry) { return gurl == entry.URL(); });
|
| + if (it == unread_.end())
|
| + return nullptr;
|
| + }
|
| + return &(*it);
|
| }
|
|
|
| bool ReadingListModelImpl::CallbackEntryURL(
|
|
|