| 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);
|
| + }
|
| +}
|
|
|