| 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 cba876e73b60c1363a9ab60d1ce6c3ba3c8effbf..60c8ed299c0e77e450d66c7d4ca31b1f0931e1f4 100644
|
| --- a/components/ntp_snippets/bookmarks/bookmark_last_visit_utils.cc
|
| +++ b/components/ntp_snippets/bookmarks/bookmark_last_visit_utils.cc
|
| @@ -36,8 +36,10 @@ std::string FormatLastVisitDate(const base::Time& date) {
|
| }
|
|
|
| bool CompareBookmarksByLastVisitDate(const BookmarkNode* a,
|
| - const BookmarkNode* b) {
|
| - return GetLastVisitDateForBookmark(a) > GetLastVisitDateForBookmark(b);
|
| + const BookmarkNode* b,
|
| + bool use_creation_date) {
|
| + return GetLastVisitDateForBookmark(a, use_creation_date) >
|
| + GetLastVisitDateForBookmark(b, use_creation_date);
|
| }
|
|
|
| } // namespace
|
| @@ -59,20 +61,25 @@ void UpdateBookmarkOnURLVisitedInMainFrame(BookmarkModel* bookmark_model,
|
| }
|
| }
|
|
|
| -base::Time GetLastVisitDateForBookmark(const BookmarkNode* node) {
|
| +base::Time GetLastVisitDateForBookmark(const BookmarkNode* node,
|
| + bool use_creation_date) {
|
| if (!node)
|
| return base::Time::UnixEpoch();
|
|
|
| + if (use_creation_date)
|
| + return node->date_added();
|
| +
|
| std::string last_visit_date_string;
|
| node->GetMetaInfo(kBookmarkLastVisitDateKey, &last_visit_date_string);
|
| return ParseLastVisitDate(last_visit_date_string);
|
| }
|
|
|
| -base::Time GetLastVisitDateForBookmarkIfNotDismissed(const BookmarkNode* node) {
|
| +base::Time GetLastVisitDateForBookmarkIfNotDismissed(const BookmarkNode* node,
|
| + bool use_creation_date) {
|
| if (IsDismissedFromNTPForBookmark(node))
|
| return base::Time::UnixEpoch();
|
|
|
| - return GetLastVisitDateForBookmark(node);
|
| + return GetLastVisitDateForBookmark(node, use_creation_date);
|
| }
|
|
|
| void MarkBookmarksDismissed(BookmarkModel* bookmark_model, const GURL& url) {
|
| @@ -107,8 +114,28 @@ void MarkAllBookmarksUndismissed(BookmarkModel* bookmark_model) {
|
| }
|
| }
|
|
|
| +bool IsLastVisitDataAvailable(BookmarkModel* bookmark_model) {
|
| + // Get all the bookmark URLs.
|
| + std::vector<BookmarkModel::URLAndTitle> bookmarks;
|
| + bookmark_model->GetBookmarks(&bookmarks);
|
| +
|
| + std::string unused;
|
| + for (const BookmarkModel::URLAndTitle& bookmark : bookmarks) {
|
| + // Get all bookmarks for the given URL.
|
| + std::vector<const BookmarkNode*> bookmarks_for_url;
|
| + bookmark_model->GetNodesByURL(bookmark.url, &bookmarks_for_url);
|
| + for (const BookmarkNode* node : bookmarks_for_url) {
|
| + if (node->GetMetaInfo(kBookmarkLastVisitDateKey, &unused))
|
| + return true;
|
| + }
|
| + }
|
| +
|
| + return false;
|
| +}
|
| +
|
| std::vector<const BookmarkNode*> GetRecentlyVisitedBookmarks(
|
| BookmarkModel* bookmark_model,
|
| + bool use_creation_date,
|
| int max_count,
|
| const base::Time& min_visit_time) {
|
| // Get all the bookmark URLs.
|
| @@ -119,7 +146,7 @@ std::vector<const BookmarkNode*> GetRecentlyVisitedBookmarks(
|
| // |min_visit_time|). Recent visits to dismissed bookmarks are not considered.
|
| bookmarks.erase(
|
| std::remove_if(bookmarks.begin(), bookmarks.end(),
|
| - [&bookmark_model, &min_visit_time](
|
| + [&bookmark_model, &min_visit_time, use_creation_date](
|
| const BookmarkModel::URLAndTitle& bookmark) {
|
| // Get all bookmarks for the given URL.
|
| std::vector<const BookmarkNode*> bookmarks_for_url;
|
| @@ -129,8 +156,8 @@ std::vector<const BookmarkNode*> GetRecentlyVisitedBookmarks(
|
| // Keep if at least one (non-dismissed) bookmark has been
|
| // recently visited.
|
| for (const BookmarkNode* node : bookmarks_for_url) {
|
| - if (GetLastVisitDateForBookmarkIfNotDismissed(node) >
|
| - min_visit_time)
|
| + if (GetLastVisitDateForBookmarkIfNotDismissed(
|
| + node, use_creation_date) > min_visit_time)
|
| return false;
|
| }
|
| // Otherwise erase this URL.
|
| @@ -140,11 +167,13 @@ std::vector<const BookmarkNode*> GetRecentlyVisitedBookmarks(
|
|
|
| // Sort the remaining bookmarks by date.
|
| std::sort(bookmarks.begin(), bookmarks.end(),
|
| - [&bookmark_model](const BookmarkModel::URLAndTitle& a,
|
| - const BookmarkModel::URLAndTitle& b) {
|
| + [&bookmark_model, use_creation_date](
|
| + const BookmarkModel::URLAndTitle& a,
|
| + const BookmarkModel::URLAndTitle& b) {
|
| return CompareBookmarksByLastVisitDate(
|
| bookmark_model->GetMostRecentlyAddedUserNodeForURL(a.url),
|
| - bookmark_model->GetMostRecentlyAddedUserNodeForURL(b.url));
|
| + bookmark_model->GetMostRecentlyAddedUserNodeForURL(b.url),
|
| + use_creation_date);
|
| });
|
|
|
| // Insert the first |max_count| items from |bookmarks| into |result|.
|
|
|