Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ntp_snippets/bookmark_last_visit_updater.h" | 5 #include "chrome/browser/ntp_snippets/bookmark_last_visit_updater.h" |
| 6 | 6 |
| 7 #include "components/bookmarks/browser/bookmark_model.h" | |
| 8 #include "components/bookmarks/browser/bookmark_node.h" | |
| 7 #include "components/ntp_snippets/bookmarks/bookmark_last_visit_utils.h" | 9 #include "components/ntp_snippets/bookmarks/bookmark_last_visit_utils.h" |
| 8 #include "content/public/browser/navigation_handle.h" | 10 #include "content/public/browser/navigation_handle.h" |
| 9 | 11 |
| 10 DEFINE_WEB_CONTENTS_USER_DATA_KEY(BookmarkLastVisitUpdater); | 12 DEFINE_WEB_CONTENTS_USER_DATA_KEY(BookmarkLastVisitUpdater); |
| 11 | 13 |
| 12 BookmarkLastVisitUpdater::~BookmarkLastVisitUpdater() {} | |
| 13 | |
| 14 // static | 14 // static |
| 15 void BookmarkLastVisitUpdater::CreateForWebContentsWithBookmarkModel( | 15 void BookmarkLastVisitUpdater::CreateForWebContentsWithBookmarkModel( |
| 16 content::WebContents* web_contents, | 16 content::WebContents* web_contents, |
| 17 bookmarks::BookmarkModel* bookmark_model) { | 17 bookmarks::BookmarkModel* bookmark_model) { |
| 18 web_contents->SetUserData(UserDataKey(), new BookmarkLastVisitUpdater( | 18 web_contents->SetUserData(UserDataKey(), new BookmarkLastVisitUpdater( |
| 19 web_contents, bookmark_model)); | 19 web_contents, bookmark_model)); |
| 20 } | 20 } |
| 21 | 21 |
| 22 BookmarkLastVisitUpdater::~BookmarkLastVisitUpdater() { | |
|
Marc Treib
2016/08/11 13:03:43
Why move this? (The ordering is kinda weird anyway
jkrcal
2016/08/11 13:59:26
Done. I've forgotten about the header. Looking at
| |
| 23 bookmark_model_->RemoveObserver(this); | |
| 24 } | |
| 25 | |
| 22 BookmarkLastVisitUpdater::BookmarkLastVisitUpdater( | 26 BookmarkLastVisitUpdater::BookmarkLastVisitUpdater( |
| 23 content::WebContents* web_contents, | 27 content::WebContents* web_contents, |
| 24 bookmarks::BookmarkModel* bookmark_model) | 28 bookmarks::BookmarkModel* bookmark_model) |
| 25 : content::WebContentsObserver(web_contents), | 29 : content::WebContentsObserver(web_contents), |
| 26 bookmark_model_(bookmark_model) {} | 30 bookmark_model_(bookmark_model), |
| 31 web_contents_(web_contents) { | |
| 32 bookmark_model->AddObserver(this); | |
| 33 } | |
| 27 | 34 |
| 28 void BookmarkLastVisitUpdater::DidStartNavigation( | 35 void BookmarkLastVisitUpdater::DidStartNavigation( |
| 29 content::NavigationHandle* navigation_handle) { | 36 content::NavigationHandle* navigation_handle) { |
| 37 // Mark visited bookmark when the navigation starts (may end somewhere else | |
| 38 // due to server-side redirects). | |
| 39 NewURLVisited(navigation_handle); | |
| 40 } | |
| 41 | |
| 42 void BookmarkLastVisitUpdater::DidRedirectNavigation( | |
| 43 content::NavigationHandle* navigation_handle) { | |
| 44 // Mark visited bookmark also after each redirect. | |
| 45 NewURLVisited(navigation_handle); | |
| 46 } | |
| 47 | |
| 48 void BookmarkLastVisitUpdater::NewURLVisited( | |
| 49 content::NavigationHandle* navigation_handle) { | |
| 30 if (!navigation_handle->IsInMainFrame() || navigation_handle->IsErrorPage()) | 50 if (!navigation_handle->IsInMainFrame() || navigation_handle->IsErrorPage()) |
| 31 return; | 51 return; |
| 52 | |
| 32 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame( | 53 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame( |
| 33 bookmark_model_, navigation_handle->GetURL()); | 54 bookmark_model_, navigation_handle->GetURL()); |
| 34 } | 55 } |
| 56 | |
| 57 void BookmarkLastVisitUpdater::BookmarkNodeAdded( | |
| 58 bookmarks::BookmarkModel* model, | |
| 59 const bookmarks::BookmarkNode* parent, | |
| 60 int index) { | |
| 61 const GURL& new_bookmark_url = parent->GetChild(index)->url(); | |
| 62 | |
| 63 if (new_bookmark_url == web_contents_->GetLastCommittedURL()) { | |
|
Marc Treib
2016/08/11 13:03:43
What's this check for?
jkrcal
2016/08/11 13:59:26
Added a comment. Is it clearer now?
(the check is
Marc Treib
2016/08/11 14:06:23
Yup, better, thanks!
| |
| 64 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame( | |
| 65 bookmark_model_, new_bookmark_url); | |
| 66 } | |
| 67 } | |
| OLD | NEW |