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

Unified Diff: chrome/browser/ntp_snippets/bookmark_last_visit_updater.cc

Issue 2234393002: Marking last_visited date for bookmarks created from an open tab (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Marc's comments Created 4 years, 4 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: chrome/browser/ntp_snippets/bookmark_last_visit_updater.cc
diff --git a/chrome/browser/ntp_snippets/bookmark_last_visit_updater.cc b/chrome/browser/ntp_snippets/bookmark_last_visit_updater.cc
index 001e8e2073d47641aff0adf86872a0bf2f2085f2..6b9b6f01cef5b209b56fcc49394ba82ff8aef7a4 100644
--- a/chrome/browser/ntp_snippets/bookmark_last_visit_updater.cc
+++ b/chrome/browser/ntp_snippets/bookmark_last_visit_updater.cc
@@ -4,12 +4,16 @@
#include "chrome/browser/ntp_snippets/bookmark_last_visit_updater.h"
+#include "components/bookmarks/browser/bookmark_model.h"
+#include "components/bookmarks/browser/bookmark_node.h"
#include "components/ntp_snippets/bookmarks/bookmark_last_visit_utils.h"
#include "content/public/browser/navigation_handle.h"
DEFINE_WEB_CONTENTS_USER_DATA_KEY(BookmarkLastVisitUpdater);
-BookmarkLastVisitUpdater::~BookmarkLastVisitUpdater() {}
+BookmarkLastVisitUpdater::~BookmarkLastVisitUpdater() {
+ bookmark_model_->RemoveObserver(this);
+}
// static
void BookmarkLastVisitUpdater::CreateForWebContentsWithBookmarkModel(
@@ -23,12 +27,43 @@ BookmarkLastVisitUpdater::BookmarkLastVisitUpdater(
content::WebContents* web_contents,
bookmarks::BookmarkModel* bookmark_model)
: content::WebContentsObserver(web_contents),
- bookmark_model_(bookmark_model) {}
+ bookmark_model_(bookmark_model),
+ web_contents_(web_contents) {
+ bookmark_model->AddObserver(this);
+}
void BookmarkLastVisitUpdater::DidStartNavigation(
content::NavigationHandle* navigation_handle) {
+ // Mark visited bookmark when the navigation starts (may end somewhere else
+ // due to server-side redirects).
+ NewURLVisited(navigation_handle);
+}
+
+void BookmarkLastVisitUpdater::DidRedirectNavigation(
+ content::NavigationHandle* navigation_handle) {
+ // Mark visited bookmark also after each redirect.
+ NewURLVisited(navigation_handle);
+}
+
+void BookmarkLastVisitUpdater::NewURLVisited(
+ content::NavigationHandle* navigation_handle) {
if (!navigation_handle->IsInMainFrame() || navigation_handle->IsErrorPage())
return;
+
ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame(
bookmark_model_, navigation_handle->GetURL());
}
+
+void BookmarkLastVisitUpdater::BookmarkNodeAdded(
+ bookmarks::BookmarkModel* model,
+ const bookmarks::BookmarkNode* parent,
+ int index) {
+ const GURL& new_bookmark_url = parent->GetChild(index)->url();
+
+ if (new_bookmark_url == web_contents_->GetLastCommittedURL()) {
+ // Consider in this TabHelper only bookmarks created from this tab (and not
+ // the ones created from other tabs or created through bookmark sync).
+ ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame(
+ bookmark_model_, new_bookmark_url);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698