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

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

Issue 285193002: Create GoogleURLTrackerClient interface and //chrome implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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 GoogleURLTrackerNavigationHelperImpl::
16 GoogleURLTrackerNavigationHelperImpl() : tracker_(NULL) { 16 GoogleURLTrackerNavigationHelperImpl() : tracker_(NULL) {
17 } 17 }
18 18
19 GoogleURLTrackerNavigationHelperImpl:: 19 GoogleURLTrackerNavigationHelperImpl::
20 ~GoogleURLTrackerNavigationHelperImpl() { 20 ~GoogleURLTrackerNavigationHelperImpl() {
21 } 21 }
22 22
23 void GoogleURLTrackerNavigationHelperImpl::SetGoogleURLTracker( 23 void GoogleURLTrackerNavigationHelperImpl::SetGoogleURLTracker(
24 GoogleURLTracker* tracker) { 24 GoogleURLTracker* tracker) {
25 DCHECK(tracker); 25 DCHECK(tracker);
26 tracker_ = tracker; 26 tracker_ = tracker;
27 } 27 }
28 28
29 void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationStart(
30 bool listen) {
31 if (listen) {
32 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
33 content::NotificationService::AllBrowserContextsAndSources());
34 } else {
35 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
36 content::NotificationService::AllBrowserContextsAndSources());
37 }
38 }
39
40 bool GoogleURLTrackerNavigationHelperImpl::IsListeningForNavigationStart() {
41 return registrar_.IsRegistered(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
42 content::NotificationService::AllBrowserContextsAndSources());
43 }
44
45 void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit( 29 void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit(
46 const content::NavigationController* nav_controller, 30 const content::NavigationController* nav_controller,
47 bool listen) { 31 bool listen) {
48 content::NotificationSource navigation_controller_source = 32 content::NotificationSource navigation_controller_source =
49 content::Source<content::NavigationController>(nav_controller); 33 content::Source<content::NavigationController>(nav_controller);
50 if (listen) { 34 if (listen) {
51 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 35 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
52 navigation_controller_source); 36 navigation_controller_source);
53 } else { 37 } else {
54 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 38 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 nav_controller_source).ptr(); 81 nav_controller_source).ptr();
98 content::WebContents* web_contents = controller->GetWebContents(); 82 content::WebContents* web_contents = controller->GetWebContents();
99 return content::Source<content::WebContents>(web_contents); 83 return content::Source<content::WebContents>(web_contents);
100 } 84 }
101 85
102 void GoogleURLTrackerNavigationHelperImpl::Observe( 86 void GoogleURLTrackerNavigationHelperImpl::Observe(
103 int type, 87 int type,
104 const content::NotificationSource& source, 88 const content::NotificationSource& source,
105 const content::NotificationDetails& details) { 89 const content::NotificationDetails& details) {
106 switch (type) { 90 switch (type) {
107 case content::NOTIFICATION_NAV_ENTRY_PENDING: {
108 content::NavigationController* controller =
109 content::Source<content::NavigationController>(source).ptr();
110 content::WebContents* web_contents = controller->GetWebContents();
111 InfoBarService* infobar_service =
112 InfoBarService::FromWebContents(web_contents);
113 // Because we're listening to all sources, there may be no
114 // InfoBarService for some notifications, e.g. navigations in
115 // bubbles/balloons etc.
116 if (infobar_service) {
117 tracker_->OnNavigationPending(
118 controller, infobar_service,
119 controller->GetPendingEntry()->GetUniqueID());
120 }
121 break;
122 }
123
124 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { 91 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
125 content::NavigationController* controller = 92 content::NavigationController* controller =
126 content::Source<content::NavigationController>(source).ptr(); 93 content::Source<content::NavigationController>(source).ptr();
127 // Here we're only listening to notifications where we already know 94 // Here we're only listening to notifications where we already know
128 // there's an associated InfoBarService. 95 // there's an associated InfoBarService.
129 content::WebContents* web_contents = controller->GetWebContents(); 96 content::WebContents* web_contents = controller->GetWebContents();
130 InfoBarService* infobar_service = 97 InfoBarService* infobar_service =
131 InfoBarService::FromWebContents(web_contents); 98 InfoBarService::FromWebContents(web_contents);
132 DCHECK(infobar_service); 99 DCHECK(infobar_service);
133 const GURL& search_url = controller->GetActiveEntry()->GetURL(); 100 const GURL& search_url = controller->GetActiveEntry()->GetURL();
134 if (!search_url.is_valid()) // Not clear if this can happen. 101 if (!search_url.is_valid()) // Not clear if this can happen.
135 tracker_->OnTabClosed(controller); 102 tracker_->OnTabClosed(controller);
136 tracker_->OnNavigationCommitted(infobar_service, search_url); 103 tracker_->OnNavigationCommitted(infobar_service, search_url);
137 break; 104 break;
138 } 105 }
139 106
140 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: { 107 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: {
141 content::WebContents* web_contents = 108 content::WebContents* web_contents =
142 content::Source<content::WebContents>(source).ptr(); 109 content::Source<content::WebContents>(source).ptr();
143 tracker_->OnTabClosed(&web_contents->GetController()); 110 tracker_->OnTabClosed(&web_contents->GetController());
144 break; 111 break;
145 } 112 }
146 113
147 default: 114 default:
148 NOTREACHED() << "Unknown notification received:" << type; 115 NOTREACHED() << "Unknown notification received:" << type;
149 } 116 }
150 } 117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698