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

Side by Side Diff: chrome/browser/google/google_url_tracker_navigation_helper_impl.cc

Issue 294193005: Revert of Turn GoogleURLTrackerNavigationHelper(Impl) into a per-tab object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/google/google_url_tracker_navigation_helper_impl.h" 5 #include "chrome/browser/google/google_url_tracker_navigation_helper_impl.h"
6 6
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/google/google_url_tracker.h" 8 #include "chrome/browser/google/google_url_tracker.h"
9 #include "chrome/browser/infobars/infobar_service.h" 9 #include "chrome/browser/infobars/infobar_service.h"
10 #include "content/public/browser/navigation_controller.h" 10 #include "content/public/browser/navigation_controller.h"
11 #include "content/public/browser/navigation_entry.h" 11 #include "content/public/browser/navigation_entry.h"
12 #include "content/public/browser/notification_service.h" 12 #include "content/public/browser/notification_service.h"
13 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
14 14
15 GoogleURLTrackerNavigationHelperImpl::GoogleURLTrackerNavigationHelperImpl( 15 GoogleURLTrackerNavigationHelperImpl::
16 content::WebContents* web_contents, 16 GoogleURLTrackerNavigationHelperImpl() : tracker_(NULL) {
17 GoogleURLTracker* tracker)
18 : GoogleURLTrackerNavigationHelper(tracker),
19 web_contents_(web_contents) {
20 } 17 }
21 18
22 GoogleURLTrackerNavigationHelperImpl::~GoogleURLTrackerNavigationHelperImpl() { 19 GoogleURLTrackerNavigationHelperImpl::
20 ~GoogleURLTrackerNavigationHelperImpl() {
21 }
22
23 void GoogleURLTrackerNavigationHelperImpl::SetGoogleURLTracker(
24 GoogleURLTracker* tracker) {
25 DCHECK(tracker);
26 tracker_ = tracker;
23 } 27 }
24 28
25 void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit( 29 void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit(
30 const content::NavigationController* nav_controller,
26 bool listen) { 31 bool listen) {
27 content::NotificationSource navigation_controller_source = 32 content::NotificationSource navigation_controller_source =
28 content::Source<content::NavigationController>( 33 content::Source<content::NavigationController>(nav_controller);
29 &web_contents_->GetController());
30 if (listen) { 34 if (listen) {
31 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 35 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
32 navigation_controller_source); 36 navigation_controller_source);
33 } else { 37 } else {
34 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 38 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
35 navigation_controller_source); 39 navigation_controller_source);
36 } 40 }
37 } 41 }
38 42
39 bool GoogleURLTrackerNavigationHelperImpl::IsListeningForNavigationCommit() { 43 bool GoogleURLTrackerNavigationHelperImpl::IsListeningForNavigationCommit(
44 const content::NavigationController* nav_controller) {
40 content::NotificationSource navigation_controller_source = 45 content::NotificationSource navigation_controller_source =
41 content::Source<content::NavigationController>( 46 content::Source<content::NavigationController>(nav_controller);
42 &web_contents_->GetController());
43 return registrar_.IsRegistered( 47 return registrar_.IsRegistered(
44 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 48 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
45 navigation_controller_source); 49 navigation_controller_source);
46 } 50 }
47 51
48 void GoogleURLTrackerNavigationHelperImpl::SetListeningForTabDestruction( 52 void GoogleURLTrackerNavigationHelperImpl::SetListeningForTabDestruction(
53 const content::NavigationController* nav_controller,
49 bool listen) { 54 bool listen) {
50 content::NotificationSource web_contents_source = 55 content::NotificationSource navigation_controller_source =
51 content::Source<content::WebContents>(web_contents_); 56 content::Source<content::NavigationController>(nav_controller);
52 if (listen) { 57 if (listen) {
53 registrar_.Add(this, 58 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
54 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 59 GetWebContentsSource(navigation_controller_source));
55 web_contents_source);
56 } else { 60 } else {
57 registrar_.Remove(this, 61 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
58 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 62 GetWebContentsSource(navigation_controller_source));
59 web_contents_source);
60 } 63 }
61 } 64 }
62 65
63 bool GoogleURLTrackerNavigationHelperImpl::IsListeningForTabDestruction() { 66 bool GoogleURLTrackerNavigationHelperImpl::IsListeningForTabDestruction(
67 const content::NavigationController* nav_controller) {
68 content::NotificationSource navigation_controller_source =
69 content::Source<content::NavigationController>(nav_controller);
64 return registrar_.IsRegistered( 70 return registrar_.IsRegistered(
65 this, 71 this,
66 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 72 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
67 content::Source<content::WebContents>(web_contents_)); 73 GetWebContentsSource(navigation_controller_source));
74 }
75
76 content::NotificationSource
77 GoogleURLTrackerNavigationHelperImpl::GetWebContentsSource(
78 const content::NotificationSource& nav_controller_source) {
79 content::NavigationController* controller =
80 content::Source<content::NavigationController>(
81 nav_controller_source).ptr();
82 content::WebContents* web_contents = controller->GetWebContents();
83 return content::Source<content::WebContents>(web_contents);
68 } 84 }
69 85
70 void GoogleURLTrackerNavigationHelperImpl::Observe( 86 void GoogleURLTrackerNavigationHelperImpl::Observe(
71 int type, 87 int type,
72 const content::NotificationSource& source, 88 const content::NotificationSource& source,
73 const content::NotificationDetails& details) { 89 const content::NotificationDetails& details) {
74 switch (type) { 90 switch (type) {
75 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { 91 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
76 content::NavigationController* controller = 92 content::NavigationController* controller =
77 content::Source<content::NavigationController>(source).ptr(); 93 content::Source<content::NavigationController>(source).ptr();
78 DCHECK_EQ(web_contents_, controller->GetWebContents());
79
80 // Here we're only listening to notifications where we already know 94 // Here we're only listening to notifications where we already know
81 // there's an associated InfoBarService. 95 // there's an associated InfoBarService.
96 content::WebContents* web_contents = controller->GetWebContents();
82 InfoBarService* infobar_service = 97 InfoBarService* infobar_service =
83 InfoBarService::FromWebContents(web_contents_); 98 InfoBarService::FromWebContents(web_contents);
84 DCHECK(infobar_service); 99 DCHECK(infobar_service);
85 const GURL& search_url = controller->GetActiveEntry()->GetURL(); 100 const GURL& search_url = controller->GetActiveEntry()->GetURL();
86 if (!search_url.is_valid()) // Not clear if this can happen. 101 if (!search_url.is_valid()) // Not clear if this can happen.
87 google_url_tracker()->OnTabClosed(this); 102 tracker_->OnTabClosed(controller);
88 google_url_tracker()->OnNavigationCommitted(infobar_service, search_url); 103 tracker_->OnNavigationCommitted(infobar_service, search_url);
89 break; 104 break;
90 } 105 }
91 106
92 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: { 107 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: {
93 DCHECK_EQ(web_contents_, 108 content::WebContents* web_contents =
94 content::Source<content::WebContents>(source).ptr()); 109 content::Source<content::WebContents>(source).ptr();
95 google_url_tracker()->OnTabClosed(this); 110 tracker_->OnTabClosed(&web_contents->GetController());
96 break; 111 break;
97 } 112 }
98 113
99 default: 114 default:
100 NOTREACHED() << "Unknown notification received:" << type; 115 NOTREACHED() << "Unknown notification received:" << type;
101 } 116 }
102 } 117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698