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

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

Issue 2606283003: Revert of Disable tracking of visits to bookmarks in incognito (Closed)
Patch Set: Created 3 years, 12 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 6f657cdc9f332e6dec2559acc140b7ec31bb6396..6a08043b29ba516d8a5acf4f1733ef5bb79527cc 100644
--- a/chrome/browser/ntp_snippets/bookmark_last_visit_updater.cc
+++ b/chrome/browser/ntp_snippets/bookmark_last_visit_updater.cc
@@ -8,7 +8,6 @@
#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 {
@@ -26,19 +25,16 @@
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);
}
// static
-void BookmarkLastVisitUpdater::MaybeCreateForWebContentsWithBookmarkModel(
+void BookmarkLastVisitUpdater::CreateForWebContentsWithBookmarkModel(
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));
}
@@ -49,8 +45,10 @@
: content::WebContentsObserver(web_contents),
bookmark_model_(bookmark_model),
web_contents_(web_contents) {
- DCHECK(bookmark_model_);
- bookmark_model_->AddObserver(this);
+ // In unit-tests on desktop, the bookmark_model is null.
+ if (!bookmark_model_)
+ return;
+ bookmark_model->AddObserver(this);
}
void BookmarkLastVisitUpdater::DidStartNavigation(
@@ -68,7 +66,9 @@
void BookmarkLastVisitUpdater::NewURLVisited(
content::NavigationHandle* navigation_handle) {
- if (!navigation_handle->IsInMainFrame() || navigation_handle->IsErrorPage()) {
+ // In unit-tests on desktop, the bookmark_model is null.
+ if (!navigation_handle->IsInMainFrame() || navigation_handle->IsErrorPage() ||
+ !bookmark_model_) {
return;
}

Powered by Google App Engine
This is Rietveld 408576698