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

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

Issue 283413002: Turn GoogleURLTrackerNavigationHelper(Impl) into a per-tab object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit 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:: 15 DEFINE_WEB_CONTENTS_USER_DATA_KEY(GoogleURLTrackerNavigationHelperImpl);
16 GoogleURLTrackerNavigationHelperImpl() : tracker_(NULL) { 16
17 // static
18 void GoogleURLTrackerNavigationHelperImpl::CreateForWebContentsAndTracker(
Peter Kasting 2014/05/15 21:29:52 Function definition order should match .h declarat
blundell 2014/05/16 11:54:18 Function removed. On 2014/05/15 21:29:52, Peter K
19 content::WebContents* contents,
20 GoogleURLTracker* tracker) {
21 if (FromWebContents(contents))
22 return;
Peter Kasting 2014/05/15 21:29:52 Is this conditional actually needed?
blundell 2014/05/16 11:54:18 Function removed. On 2014/05/15 21:29:52, Peter K
23
24 contents->SetUserData(
25 UserDataKey(),
26 new GoogleURLTrackerNavigationHelperImpl(contents, tracker));
17 } 27 }
18 28
19 GoogleURLTrackerNavigationHelperImpl:: 29 GoogleURLTrackerNavigationHelperImpl::GoogleURLTrackerNavigationHelperImpl(
20 ~GoogleURLTrackerNavigationHelperImpl() { 30 content::WebContents* web_contents,
31 GoogleURLTracker* tracker)
32 : GoogleURLTrackerNavigationHelper(tracker), web_contents_(web_contents) {
Peter Kasting 2014/05/15 21:29:52 Nit: One line per initializer
blundell 2014/05/16 11:54:18 Done.
21 } 33 }
22 34
23 void GoogleURLTrackerNavigationHelperImpl::SetGoogleURLTracker( 35 GoogleURLTrackerNavigationHelperImpl::~GoogleURLTrackerNavigationHelperImpl() {
24 GoogleURLTracker* tracker) {
25 DCHECK(tracker);
26 tracker_ = tracker;
27 } 36 }
28 37
29 void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit( 38 void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit(
30 const content::NavigationController* nav_controller,
31 bool listen) { 39 bool listen) {
32 content::NotificationSource navigation_controller_source = 40 content::NotificationSource navigation_controller_source =
33 content::Source<content::NavigationController>(nav_controller); 41 content::Source<content::NavigationController>(
42 &web_contents_->GetController());
34 if (listen) { 43 if (listen) {
35 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 44 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
36 navigation_controller_source); 45 navigation_controller_source);
37 } else { 46 } else {
38 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 47 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
39 navigation_controller_source); 48 navigation_controller_source);
40 } 49 }
41 } 50 }
42 51
43 bool GoogleURLTrackerNavigationHelperImpl::IsListeningForNavigationCommit( 52 bool GoogleURLTrackerNavigationHelperImpl::IsListeningForNavigationCommit() {
44 const content::NavigationController* nav_controller) {
45 content::NotificationSource navigation_controller_source = 53 content::NotificationSource navigation_controller_source =
46 content::Source<content::NavigationController>(nav_controller); 54 content::Source<content::NavigationController>(
55 &web_contents_->GetController());
47 return registrar_.IsRegistered( 56 return registrar_.IsRegistered(
48 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 57 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
49 navigation_controller_source); 58 navigation_controller_source);
50 } 59 }
51 60
52 void GoogleURLTrackerNavigationHelperImpl::SetListeningForTabDestruction( 61 void GoogleURLTrackerNavigationHelperImpl::SetListeningForTabDestruction(
53 const content::NavigationController* nav_controller,
54 bool listen) { 62 bool listen) {
55 content::NotificationSource navigation_controller_source = 63 content::NotificationSource web_contents_source =
56 content::Source<content::NavigationController>(nav_controller); 64 content::Source<content::WebContents>(web_contents_);
57 if (listen) { 65 if (listen) {
58 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 66 registrar_.Add(this,
59 GetWebContentsSource(navigation_controller_source)); 67 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
68 web_contents_source);
60 } else { 69 } else {
61 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 70 registrar_.Remove(this,
62 GetWebContentsSource(navigation_controller_source)); 71 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
72 web_contents_source);
63 } 73 }
64 } 74 }
65 75
66 bool GoogleURLTrackerNavigationHelperImpl::IsListeningForTabDestruction( 76 bool GoogleURLTrackerNavigationHelperImpl::IsListeningForTabDestruction() {
67 const content::NavigationController* nav_controller) {
68 content::NotificationSource navigation_controller_source =
69 content::Source<content::NavigationController>(nav_controller);
70 return registrar_.IsRegistered( 77 return registrar_.IsRegistered(
71 this, 78 this,
72 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 79 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
73 GetWebContentsSource(navigation_controller_source)); 80 content::Source<content::WebContents>(web_contents_));
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);
84 } 81 }
85 82
86 void GoogleURLTrackerNavigationHelperImpl::Observe( 83 void GoogleURLTrackerNavigationHelperImpl::Observe(
87 int type, 84 int type,
88 const content::NotificationSource& source, 85 const content::NotificationSource& source,
89 const content::NotificationDetails& details) { 86 const content::NotificationDetails& details) {
90 switch (type) { 87 switch (type) {
91 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { 88 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
92 content::NavigationController* controller = 89 content::NavigationController* controller =
93 content::Source<content::NavigationController>(source).ptr(); 90 content::Source<content::NavigationController>(source).ptr();
91 DCHECK(controller->GetWebContents() == web_contents_);
Peter Kasting 2014/05/15 21:29:52 Nit: I think this can be DCHECK_EQ()
blundell 2014/05/16 11:54:18 Done.
92
94 // Here we're only listening to notifications where we already know 93 // Here we're only listening to notifications where we already know
95 // there's an associated InfoBarService. 94 // there's an associated InfoBarService.
96 content::WebContents* web_contents = controller->GetWebContents();
97 InfoBarService* infobar_service = 95 InfoBarService* infobar_service =
98 InfoBarService::FromWebContents(web_contents); 96 InfoBarService::FromWebContents(web_contents_);
99 DCHECK(infobar_service); 97 DCHECK(infobar_service);
100 const GURL& search_url = controller->GetActiveEntry()->GetURL(); 98 const GURL& search_url = controller->GetActiveEntry()->GetURL();
101 if (!search_url.is_valid()) // Not clear if this can happen. 99 if (!search_url.is_valid()) // Not clear if this can happen.
102 tracker_->OnTabClosed(controller); 100 google_url_tracker()->OnTabClosed(this);
103 tracker_->OnNavigationCommitted(infobar_service, search_url); 101 google_url_tracker()->OnNavigationCommitted(infobar_service, search_url);
104 break; 102 break;
105 } 103 }
106 104
107 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: { 105 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: {
108 content::WebContents* web_contents = 106 DCHECK(content::Source<content::WebContents>(source).ptr() ==
109 content::Source<content::WebContents>(source).ptr(); 107 web_contents_);
110 tracker_->OnTabClosed(&web_contents->GetController()); 108 google_url_tracker()->OnTabClosed(this);
111 break; 109 break;
112 } 110 }
113 111
114 default: 112 default:
115 NOTREACHED() << "Unknown notification received:" << type; 113 NOTREACHED() << "Unknown notification received:" << type;
116 } 114 }
117 } 115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698