| 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..193a197599e66f02e04bd71f20c5c54eda2dcb7c 100644
|
| --- a/chrome/browser/ntp_snippets/bookmark_last_visit_updater.cc
|
| +++ b/chrome/browser/ntp_snippets/bookmark_last_visit_updater.cc
|
| @@ -4,13 +4,13 @@
|
|
|
| #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() {}
|
| -
|
| // static
|
| void BookmarkLastVisitUpdater::CreateForWebContentsWithBookmarkModel(
|
| content::WebContents* web_contents,
|
| @@ -19,16 +19,36 @@ void BookmarkLastVisitUpdater::CreateForWebContentsWithBookmarkModel(
|
| web_contents, bookmark_model));
|
| }
|
|
|
| +BookmarkLastVisitUpdater::~BookmarkLastVisitUpdater() {
|
| + bookmark_model_->RemoveObserver(this);
|
| +}
|
| +
|
| 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) {
|
| 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()) {
|
| + ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame(
|
| + bookmark_model_, new_bookmark_url);
|
| + }
|
| +}
|
|
|