Chromium Code Reviews| Index: chrome/browser/google/google_url_tracker_navigation_helper_impl.cc |
| diff --git a/chrome/browser/google/google_url_tracker_navigation_helper_impl.cc b/chrome/browser/google/google_url_tracker_navigation_helper_impl.cc |
| index 64e4c5cb1adbfb69f00aaf928d729ddf6ba26597..32d78b2a1f1c309f03b80a24dd652770d208d4cf 100644 |
| --- a/chrome/browser/google/google_url_tracker_navigation_helper_impl.cc |
| +++ b/chrome/browser/google/google_url_tracker_navigation_helper_impl.cc |
| @@ -12,25 +12,21 @@ |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/web_contents.h" |
| -GoogleURLTrackerNavigationHelperImpl:: |
| - GoogleURLTrackerNavigationHelperImpl() : tracker_(NULL) { |
| +GoogleURLTrackerNavigationHelperImpl::GoogleURLTrackerNavigationHelperImpl( |
| + content::WebContents* web_contents, |
| + GoogleURLTracker* tracker) |
| + : GoogleURLTrackerNavigationHelper(tracker), |
| + web_contents_(web_contents) { |
| } |
| -GoogleURLTrackerNavigationHelperImpl:: |
| - ~GoogleURLTrackerNavigationHelperImpl() { |
| -} |
| - |
| -void GoogleURLTrackerNavigationHelperImpl::SetGoogleURLTracker( |
| - GoogleURLTracker* tracker) { |
| - DCHECK(tracker); |
| - tracker_ = tracker; |
| +GoogleURLTrackerNavigationHelperImpl::~GoogleURLTrackerNavigationHelperImpl() { |
| } |
| void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit( |
| - const content::NavigationController* nav_controller, |
| bool listen) { |
| content::NotificationSource navigation_controller_source = |
| - content::Source<content::NavigationController>(nav_controller); |
| + content::Source<content::NavigationController>( |
| + &web_contents_->GetController()); |
| if (listen) { |
| registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| navigation_controller_source); |
| @@ -40,47 +36,35 @@ void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit( |
| } |
| } |
| -bool GoogleURLTrackerNavigationHelperImpl::IsListeningForNavigationCommit( |
| - const content::NavigationController* nav_controller) { |
| +bool GoogleURLTrackerNavigationHelperImpl::IsListeningForNavigationCommit() { |
| content::NotificationSource navigation_controller_source = |
| - content::Source<content::NavigationController>(nav_controller); |
| + content::Source<content::NavigationController>( |
| + &web_contents_->GetController()); |
| return registrar_.IsRegistered( |
| this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| navigation_controller_source); |
| } |
| void GoogleURLTrackerNavigationHelperImpl::SetListeningForTabDestruction( |
| - const content::NavigationController* nav_controller, |
| bool listen) { |
| - content::NotificationSource navigation_controller_source = |
| - content::Source<content::NavigationController>(nav_controller); |
| + content::NotificationSource web_contents_source = |
| + content::Source<content::WebContents>(web_contents_); |
| if (listen) { |
| - registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| - GetWebContentsSource(navigation_controller_source)); |
| + registrar_.Add(this, |
| + content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| + web_contents_source); |
| } else { |
| - registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| - GetWebContentsSource(navigation_controller_source)); |
| + registrar_.Remove(this, |
| + content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| + web_contents_source); |
| } |
| } |
| -bool GoogleURLTrackerNavigationHelperImpl::IsListeningForTabDestruction( |
| - const content::NavigationController* nav_controller) { |
| - content::NotificationSource navigation_controller_source = |
| - content::Source<content::NavigationController>(nav_controller); |
| +bool GoogleURLTrackerNavigationHelperImpl::IsListeningForTabDestruction() { |
| return registrar_.IsRegistered( |
| this, |
| content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| - GetWebContentsSource(navigation_controller_source)); |
| -} |
| - |
| -content::NotificationSource |
| - GoogleURLTrackerNavigationHelperImpl::GetWebContentsSource( |
| - const content::NotificationSource& nav_controller_source) { |
| - content::NavigationController* controller = |
| - content::Source<content::NavigationController>( |
| - nav_controller_source).ptr(); |
| - content::WebContents* web_contents = controller->GetWebContents(); |
| - return content::Source<content::WebContents>(web_contents); |
| + content::Source<content::WebContents>(web_contents_)); |
| } |
| void GoogleURLTrackerNavigationHelperImpl::Observe( |
| @@ -91,23 +75,24 @@ void GoogleURLTrackerNavigationHelperImpl::Observe( |
| case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { |
| content::NavigationController* controller = |
| content::Source<content::NavigationController>(source).ptr(); |
| + DCHECK_EQ(controller->GetWebContents(), web_contents_); |
|
Peter Kasting
2014/05/16 23:38:13
Nit: (expected, actual) (2 places)
blundell
2014/05/17 19:23:54
Done.
|
| + |
| // Here we're only listening to notifications where we already know |
| // there's an associated InfoBarService. |
| - content::WebContents* web_contents = controller->GetWebContents(); |
| InfoBarService* infobar_service = |
| - InfoBarService::FromWebContents(web_contents); |
| + InfoBarService::FromWebContents(web_contents_); |
| DCHECK(infobar_service); |
| const GURL& search_url = controller->GetActiveEntry()->GetURL(); |
| if (!search_url.is_valid()) // Not clear if this can happen. |
| - tracker_->OnTabClosed(controller); |
| - tracker_->OnNavigationCommitted(infobar_service, search_url); |
| + google_url_tracker()->OnTabClosed(this); |
| + google_url_tracker()->OnNavigationCommitted(infobar_service, search_url); |
| break; |
| } |
| case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: { |
| - content::WebContents* web_contents = |
| - content::Source<content::WebContents>(source).ptr(); |
| - tracker_->OnTabClosed(&web_contents->GetController()); |
| + DCHECK_EQ(content::Source<content::WebContents>(source).ptr(), |
| + web_contents_); |
| + google_url_tracker()->OnTabClosed(this); |
| break; |
| } |