Chromium Code Reviews| Index: components/ntp_snippets/bookmarks/bookmark_last_visit_utils.cc |
| diff --git a/components/ntp_snippets/bookmarks/bookmark_last_visit_utils.cc b/components/ntp_snippets/bookmarks/bookmark_last_visit_utils.cc |
| index bd1b3888a16364d4daa727474a3f5443a09841b7..afb2860973b5569e56124a4b8a57cbfeef794283 100644 |
| --- a/components/ntp_snippets/bookmarks/bookmark_last_visit_utils.cc |
| +++ b/components/ntp_snippets/bookmarks/bookmark_last_visit_utils.cc |
| @@ -22,11 +22,6 @@ namespace ntp_snippets { |
| namespace { |
| -struct RecentBookmark { |
| - const bookmarks::BookmarkNode* node; |
| - bool visited_recently; |
| -}; |
| - |
| const char kBookmarkLastVisitDateKey[] = "last_visited"; |
| const char kBookmarkDismissedFromNTP[] = "dismissed_from_ntp"; |
| @@ -131,8 +126,7 @@ std::vector<const BookmarkNode*> GetRecentlyVisitedBookmarks( |
| std::vector<BookmarkModel::URLAndTitle> bookmark_urls; |
| bookmark_model->GetBookmarks(&bookmark_urls); |
| - std::vector<RecentBookmark> bookmarks; |
| - int recently_visited_count = 0; |
| + std::vector<const BookmarkNode*> recent_not_dismissed_bookmarks; |
| // Find for each bookmark the most recently visited BookmarkNode and find out |
| // whether it is visited since |min_visit_time|. |
| for (const BookmarkModel::URLAndTitle& url_and_title : bookmark_urls) { |
| @@ -149,49 +143,36 @@ std::vector<const BookmarkNode*> GetRecentlyVisitedBookmarks( |
| return CompareBookmarksByLastVisitDate(a, b, creation_date_fallback); |
| }); |
| - // Find out if it has been _visited_ recently enough. |
| - bool visited_recently = |
| - min_visit_time < GetLastVisitDateForBookmark( |
| - most_recent, /*creation_date_fallback=*/false); |
| - if (visited_recently) |
| - recently_visited_count++; |
| - if (!IsDismissedFromNTPForBookmark(most_recent)) |
| - bookmarks.push_back({most_recent, visited_recently}); |
|
Marc Treib
2016/09/01 09:46:01
We want to keep this, so that the creation_date_fa
vitaliii
2016/09/01 10:15:41
Done.
|
| + if (min_visit_time < GetLastVisitDateForBookmark( |
| + most_recent, /* creation_date_fallback */ false) && |
| + !IsDismissedFromNTPForBookmark(most_recent)) { |
| + recent_not_dismissed_bookmarks.push_back(most_recent); |
| + } |
| } |
| - if (recently_visited_count < min_count) { |
| - // There aren't enough recently-visited bookmarks. Fill the list up to |
| - // |min_count| with older bookmarks (in particular those with only a |
| - // creation date, if creation_date_fallback is true). |
| - max_count = min_count; |
| + if (recent_not_dismissed_bookmarks.size() < static_cast<size_t>(min_count)) { |
| + // There aren't enough recently-visited bookmarks, do not show any. |
|
Marc Treib
2016/09/01 09:46:01
This is not the behavior we want (sorry, I must ha
vitaliii
2016/09/01 10:15:41
Done.
|
| + return std::vector<const BookmarkNode*>(); |
| } else { |
| - // Remove the bookmarks that are not recently visited; we do not need them. |
| - // (We might end up with fewer than |min_count| bookmarks if all the recent |
| - // ones are dismissed.) |
| - bookmarks.erase( |
| - std::remove_if(bookmarks.begin(), bookmarks.end(), |
| - [](const RecentBookmark& bookmark) { |
| - return !bookmark.visited_recently; |
| - }), |
| - bookmarks.end()); |
| - } |
| - |
| - // Sort the remaining entries by date. |
| - std::sort(bookmarks.begin(), bookmarks.end(), |
| - [creation_date_fallback](const RecentBookmark& a, |
| - const RecentBookmark& b) { |
| - return CompareBookmarksByLastVisitDate(a.node, b.node, |
| - creation_date_fallback); |
| - }); |
| - |
| - // Insert the first |max_count| items from |bookmarks| into |result|. |
|
Marc Treib
2016/09/01 09:46:01
I think the problem is here: We're missing a check
vitaliii
2016/09/01 10:15:41
Done.
|
| - std::vector<const BookmarkNode*> result; |
| - for (const RecentBookmark& bookmark : bookmarks) { |
| - result.push_back(bookmark.node); |
| - if (result.size() >= static_cast<size_t>(max_count)) |
| - break; |
| + // Sort the bookmarks we can show by date. |
| + std::sort(recent_not_dismissed_bookmarks.begin(), |
| + recent_not_dismissed_bookmarks.end(), |
| + [creation_date_fallback](const BookmarkNode* first, |
| + const BookmarkNode* second) { |
| + return CompareBookmarksByLastVisitDate(first, second, |
| + creation_date_fallback); |
| + }); |
| + |
| + // Return the first |max_count| items from |recent_not_dismissed_bookmarks|. |
| + if (recent_not_dismissed_bookmarks.size() <= |
| + static_cast<size_t>(max_count)) { |
| + return recent_not_dismissed_bookmarks; |
| + } else { |
| + return std::vector<const BookmarkNode*>( |
| + recent_not_dismissed_bookmarks.begin(), |
| + recent_not_dismissed_bookmarks.begin() + max_count); |
| + } |
| } |
| - return result; |
| } |
| std::vector<const BookmarkNode*> GetDismissedBookmarksForDebugging( |