Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c29e4b8ce91e785e82335db1d3594cc90ebf09e8 |
| --- /dev/null |
| +++ b/chrome/browser/ntp_snippets/bookmark_last_visit_updater.cc |
| @@ -0,0 +1,36 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ntp_snippets/bookmark_last_visit_updater.h" |
| + |
| +#include "components/bookmarks/browser/bookmark_model.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); |
| + |
| +// static |
| +void BookmarkLastVisitUpdater::CreateForWebContentsWithBookmarkModel( |
|
sky
2016/08/01 15:15:47
nit: make order match header.
Philipp Keck
2016/08/02 13:05:33
Done.
|
| + content::WebContents* web_contents, |
| + bookmarks::BookmarkModel* bookmark_model) { |
| + DCHECK(web_contents); |
| + web_contents->SetUserData(UserDataKey(), new BookmarkLastVisitUpdater( |
| + web_contents, bookmark_model)); |
| +} |
| + |
| +BookmarkLastVisitUpdater::~BookmarkLastVisitUpdater() {} |
| + |
| +BookmarkLastVisitUpdater::BookmarkLastVisitUpdater( |
| + content::WebContents* web_contents, |
| + bookmarks::BookmarkModel* bookmark_model) |
| + : content::WebContentsObserver(web_contents), |
| + bookmark_model_(bookmark_model) {} |
| + |
| +void BookmarkLastVisitUpdater::DidStartNavigation( |
| + content::NavigationHandle* navigation_handle) { |
| + if (!navigation_handle->IsInMainFrame() || navigation_handle->IsErrorPage()) |
| + return; |
| + ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame( |
| + bookmark_model_, navigation_handle->GetURL()); |
| +} |