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

Unified Diff: ios/chrome/browser/reading_list/reading_list_model_impl.cc

Issue 2436743002: Add GetEntryFromURL method to the ReadingListModel. (Closed)
Patch Set: Fixed test. 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 side-by-side diff with in-line comments
Download patch
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 a07f7f2b98851361e0189072cbb15d52b9c7df3f..1066206e65d581c687a5e366dfc55b1008cc2f4d 100644
--- a/ios/chrome/browser/reading_list/reading_list_model_impl.cc
+++ b/ios/chrome/browser/reading_list/reading_list_model_impl.cc
@@ -54,7 +54,6 @@ void ReadingListModelImpl::ResetUnseenEntries() {
storageLayer_->SavePersistentHasUnseen(false);
}
-// Returns a specific entry.
const ReadingListEntry& ReadingListModelImpl::GetUnreadEntryAtIndex(
size_t index) const {
DCHECK(loaded());
@@ -67,20 +66,26 @@ const ReadingListEntry& ReadingListModelImpl::GetReadEntryAtIndex(
return read_[index];
}
+const ReadingListEntry* ReadingListModelImpl::GetEntryFromURL(
+ const GURL& gurl) const {
+ DCHECK(loaded());
+ ReadingListEntry entry(gurl, std::string());
+ auto it = std::find(read_.begin(), read_.end(), entry);
+ if (it == read_.end()) {
+ it = std::find(unread_.begin(), unread_.end(), entry);
+ if (it == unread_.end())
+ return nullptr;
+ }
+ return &(*it);
+}
+
bool ReadingListModelImpl::CallbackEntryURL(
const GURL& url,
base::Callback<void(const ReadingListEntry&)> callback) const {
DCHECK(loaded());
- ReadingListEntry entry(url, std::string());
- auto resultUnread = std::find(unread_.begin(), unread_.end(), entry);
- if (resultUnread != unread_.end()) {
- callback.Run(*resultUnread);
- return true;
- }
-
- auto resultRead = std::find(read_.begin(), read_.end(), entry);
- if (resultRead != read_.end()) {
- callback.Run(*resultRead);
+ const ReadingListEntry* entry = GetEntryFromURL(url);
+ if (entry) {
+ callback.Run(*entry);
return true;
}
return false;

Powered by Google App Engine
This is Rietveld 408576698