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

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

Issue 2436743002: Add GetEntryFromURL method to the ReadingListModel. (Closed)
Patch Set: 2 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..dba2c4cec65b2f8e6af297a4cdaf633b10d58d5b 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,28 @@ const ReadingListEntry& ReadingListModelImpl::GetReadEntryAtIndex(
return read_[index];
}
+const ReadingListEntry* ReadingListModelImpl::GetEntryFromURL(
+ const GURL& gurl) const {
+ auto it = std::find_if(
Olivier 2016/10/25 13:10:09 DCHECK(loaded())
jif 2016/10/25 13:18:45 Done.
+ read_.begin(), read_.end(),
+ [&gurl](const ReadingListEntry& entry) { return gurl == entry.URL(); });
Olivier 2016/10/25 13:10:09 This should not be needed as there is already a te
gambard 2016/10/25 13:18:34 I don't mind lambda but we already have a == opera
jif 2016/10/25 13:18:44 CallbackEntryURL requires creating a fake ReadingL
Olivier 2016/10/25 13:21:59 I don't think creating one ReadingListEntry is mor
jif-google 2016/10/25 13:51:28 The lambda would be compiled as a struct containin
Olivier 2016/10/25 15:21:09 IMO, find_if should be used if you want to find an
+ 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(
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