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 |
| index 868f2a027484bb7cddcde3beffd50cabbcd62698..9f404ca391d8903c910719a5ee74b3f2d67922cd 100644 |
| --- a/chrome/browser/ntp_snippets/bookmark_last_visit_updater.cc |
| +++ b/chrome/browser/ntp_snippets/bookmark_last_visit_updater.cc |
| @@ -8,6 +8,7 @@ |
| #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/browser_context.h" |
| #include "content/public/browser/navigation_handle.h" |
| namespace { |
| @@ -25,10 +26,6 @@ bool IsMobilePlatform() { |
| DEFINE_WEB_CONTENTS_USER_DATA_KEY(BookmarkLastVisitUpdater); |
| BookmarkLastVisitUpdater::~BookmarkLastVisitUpdater() { |
| - // In unit-tests on desktop, the bookmark_model is null. |
| - if (!bookmark_model_) { |
| - return; |
| - } |
| bookmark_model_->RemoveObserver(this); |
| } |
| @@ -36,6 +33,12 @@ BookmarkLastVisitUpdater::~BookmarkLastVisitUpdater() { |
| void BookmarkLastVisitUpdater::CreateForWebContentsWithBookmarkModel( |
|
Bernhard Bauer
2016/12/14 15:58:45
Name this method Maybe... now?
jkrcal
2016/12/14 16:40:16
Done.
|
| content::WebContents* web_contents, |
| bookmarks::BookmarkModel* bookmark_model) { |
| + // Do not create the helper for missing |bookmark_model| (in some unit-tests) |
| + // or for incognito profiles where tracking bookmark visits is not desired. |
| + content::BrowserContext* browser_context = web_contents->GetBrowserContext(); |
| + if (!bookmark_model || browser_context->IsOffTheRecord()) { |
| + return; |
| + } |
| web_contents->SetUserData(UserDataKey(), new BookmarkLastVisitUpdater( |
| web_contents, bookmark_model)); |
| } |
| @@ -46,11 +49,8 @@ BookmarkLastVisitUpdater::BookmarkLastVisitUpdater( |
| : content::WebContentsObserver(web_contents), |
| bookmark_model_(bookmark_model), |
| web_contents_(web_contents) { |
| - // In unit-tests on desktop, the bookmark_model is null. |
| - if (!bookmark_model_) { |
| - return; |
| - } |
| - bookmark_model->AddObserver(this); |
| + DCHECK(bookmark_model_); |
| + bookmark_model_->AddObserver(this); |
| } |
| void BookmarkLastVisitUpdater::DidStartNavigation( |
| @@ -68,9 +68,7 @@ void BookmarkLastVisitUpdater::DidRedirectNavigation( |
| void BookmarkLastVisitUpdater::NewURLVisited( |
| content::NavigationHandle* navigation_handle) { |
| - // In unit-tests on desktop, the bookmark_model is null. |
| - if (!navigation_handle->IsInMainFrame() || navigation_handle->IsErrorPage() || |
| - !bookmark_model_) { |
| + if (!navigation_handle->IsInMainFrame() || navigation_handle->IsErrorPage()) { |
| return; |
| } |