Commit d43cbc46 authored by jkrcal's avatar jkrcal Committed by Commit bot

[Bookmark suggestions] Clean-up in the api: switch const* to const&

This CL cleans up the API in bookmark_last_visit_utils.h to use const&
instead of const* where appropriate.

BUG=652740

Review-Url: https://codereview.chromium.org/2518033002
Cr-Commit-Position: refs/heads/master@{#436297}
parent e84bdf15
......@@ -75,7 +75,7 @@ std::vector<const BookmarkNode*>::const_iterator FindMostRecentBookmark(
for (auto iter = bookmarks.begin(); iter != bookmarks.end(); ++iter) {
base::Time last_visited;
if (GetLastVisitDateForNTPBookmark(*iter, consider_visits_from_desktop,
if (GetLastVisitDateForNTPBookmark(**iter, consider_visits_from_desktop,
&last_visited) &&
most_recent_last_visited <= last_visited) {
most_recent = iter;
......@@ -116,20 +116,20 @@ void UpdateBookmarkOnURLVisitedInMainFrame(BookmarkModel* bookmark_model,
}
}
bool GetLastVisitDateForNTPBookmark(const BookmarkNode* node,
bool GetLastVisitDateForNTPBookmark(const BookmarkNode& node,
bool consider_visits_from_desktop,
base::Time* out) {
if (!node || IsDismissedFromNTPForBookmark(node)) {
if (IsDismissedFromNTPForBookmark(node)) {
return false;
}
bool got_mobile_date =
ExtractLastVisitDate(*node, kBookmarkLastVisitDateOnMobileKey, out);
ExtractLastVisitDate(node, kBookmarkLastVisitDateOnMobileKey, out);
if (consider_visits_from_desktop) {
// Consider the later visit from these two platform groups.
base::Time last_visit_desktop;
if (ExtractLastVisitDate(*node, kBookmarkLastVisitDateOnDesktopKey,
if (ExtractLastVisitDate(node, kBookmarkLastVisitDateOnDesktopKey,
&last_visit_desktop)) {
if (!got_mobile_date) {
*out = last_visit_desktop;
......@@ -151,14 +151,10 @@ void MarkBookmarksDismissed(BookmarkModel* bookmark_model, const GURL& url) {
}
}
bool IsDismissedFromNTPForBookmark(const BookmarkNode* node) {
if (!node) {
return false;
}
bool IsDismissedFromNTPForBookmark(const BookmarkNode& node) {
std::string dismissed_from_ntp;
bool result =
node->GetMetaInfo(kBookmarkDismissedFromNTP, &dismissed_from_ntp);
node.GetMetaInfo(kBookmarkDismissedFromNTP, &dismissed_from_ntp);
DCHECK(!result || dismissed_from_ntp == "1");
return result;
}
......@@ -211,7 +207,7 @@ std::vector<const BookmarkNode*> GetRecentlyVisitedBookmarks(
// Extract the last visit of the node to use later for sorting.
base::Time last_visit_time;
if (!GetLastVisitDateForNTPBookmark(
*most_recent, consider_visits_from_desktop, &last_visit_time) ||
**most_recent, consider_visits_from_desktop, &last_visit_time) ||
last_visit_time <= min_visit_time) {
continue;
}
......@@ -256,7 +252,7 @@ std::vector<const BookmarkNode*> GetDismissedBookmarksForDebugging(
DCHECK(!bookmarks_for_url.empty());
for (const BookmarkNode* node : bookmarks_for_url) {
if (!IsDismissedFromNTPForBookmark(node)) {
if (!IsDismissedFromNTPForBookmark(*node)) {
return true;
}
}
......
......@@ -35,7 +35,7 @@ void UpdateBookmarkOnURLVisitedInMainFrame(
// As visits, we primarily understand visits on Android (the visit when the
// bookmark is created also counts). Visits on desktop platforms are considered
// only if |consider_visits_from_desktop|.
bool GetLastVisitDateForNTPBookmark(const bookmarks::BookmarkNode* node,
bool GetLastVisitDateForNTPBookmark(const bookmarks::BookmarkNode& node,
bool consider_visits_from_desktop,
base::Time* out);
......@@ -44,7 +44,7 @@ void MarkBookmarksDismissed(bookmarks::BookmarkModel* bookmark_model,
const GURL& url);
// Gets the dismissed flag for a given bookmark |node|. Defaults to false.
bool IsDismissedFromNTPForBookmark(const bookmarks::BookmarkNode* node);
bool IsDismissedFromNTPForBookmark(const bookmarks::BookmarkNode& node);
// Removes the dismissed flag from all bookmarks (only for debugging).
void MarkAllBookmarksUndismissed(bookmarks::BookmarkModel* bookmark_model);
......
......@@ -176,7 +176,7 @@ void BookmarkSuggestionsProvider::GetDismissedSuggestionsForDebugging(
std::vector<ContentSuggestion> suggestions;
for (const BookmarkNode* bookmark : bookmarks) {
ConvertBookmark(bookmark, &suggestions);
ConvertBookmark(*bookmark, &suggestions);
}
callback.Run(std::move(suggestions));
}
......@@ -204,7 +204,7 @@ void BookmarkSuggestionsProvider::OnWillChangeBookmarkMetaInfo(
BookmarkModel* model,
const BookmarkNode* node) {
// Store the last visit date of the node that is about to change.
if (!GetLastVisitDateForNTPBookmark(node,
if (!GetLastVisitDateForNTPBookmark(*node,
consider_bookmark_visits_from_desktop_,
&node_to_change_last_visit_date_)) {
node_to_change_last_visit_date_ = base::Time::UnixEpoch();
......@@ -216,7 +216,7 @@ void BookmarkSuggestionsProvider::BookmarkMetaInfoChanged(
const BookmarkNode* node) {
base::Time time;
if (!GetLastVisitDateForNTPBookmark(
node, consider_bookmark_visits_from_desktop_, &time)) {
*node, consider_bookmark_visits_from_desktop_, &time)) {
// Error in loading the last visit date after the change. This happens when
// the bookmark just got dismissed. We must not update the suggestion in
// such a case.
......@@ -241,7 +241,7 @@ void BookmarkSuggestionsProvider::BookmarkNodeRemoved(
const std::set<GURL>& no_longer_bookmarked) {
base::Time time;
if (GetLastVisitDateForNTPBookmark(
node, consider_bookmark_visits_from_desktop_, &time) &&
*node, consider_bookmark_visits_from_desktop_, &time) &&
time < end_of_list_last_visit_date_) {
// We know the node is too old to influence the list.
return;
......@@ -256,7 +256,7 @@ void BookmarkSuggestionsProvider::BookmarkNodeAdded(
const bookmarks::BookmarkNode* parent,
int index) {
base::Time time;
if (!GetLastVisitDateForNTPBookmark(parent->GetChild(index),
if (!GetLastVisitDateForNTPBookmark(*parent->GetChild(index),
consider_bookmark_visits_from_desktop_,
&time) ||
time < end_of_list_last_visit_date_) {
......@@ -269,7 +269,7 @@ void BookmarkSuggestionsProvider::BookmarkNodeAdded(
}
void BookmarkSuggestionsProvider::ConvertBookmark(
const BookmarkNode* bookmark,
const BookmarkNode& bookmark,
std::vector<ContentSuggestion>* suggestions) {
base::Time publish_date;
if (!GetLastVisitDateForNTPBookmark(
......@@ -277,12 +277,12 @@ void BookmarkSuggestionsProvider::ConvertBookmark(
return;
}
ContentSuggestion suggestion(provided_category_, bookmark->url().spec(),
bookmark->url());
suggestion.set_title(bookmark->GetTitle());
ContentSuggestion suggestion(provided_category_, bookmark.url().spec(),
bookmark.url());
suggestion.set_title(bookmark.GetTitle());
suggestion.set_snippet_text(base::string16());
suggestion.set_publish_date(publish_date);
suggestion.set_publisher_name(base::UTF8ToUTF16(bookmark->url().host()));
suggestion.set_publisher_name(base::UTF8ToUTF16(bookmark.url().host()));
suggestions->emplace_back(std::move(suggestion));
}
......@@ -299,7 +299,7 @@ void BookmarkSuggestionsProvider::FetchBookmarksInternal() {
std::vector<ContentSuggestion> suggestions;
for (const BookmarkNode* bookmark : bookmarks) {
ConvertBookmark(bookmark, &suggestions);
ConvertBookmark(*bookmark, &suggestions);
}
if (suggestions.empty()) {
......
......@@ -87,7 +87,7 @@ class BookmarkSuggestionsProvider : public ContentSuggestionsProvider,
bookmarks::BookmarkModel* model,
const std::set<GURL>& removed_urls) override {}
void ConvertBookmark(const bookmarks::BookmarkNode* bookmark,
void ConvertBookmark(const bookmarks::BookmarkNode& bookmark,
std::vector<ContentSuggestion>* suggestions);
// The actual method to fetch bookmarks - follows each call to FetchBookmarks
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment