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

Side by Side Diff: chrome/browser/google/google_url_tracker.h

Issue 11114009: Split the existing GoogleURLTrackerInfoBarDelegate into two classes (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 2 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 #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ 5 #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_
6 #define CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ 6 #define CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // NAV_ENTRY_PENDING notification to get the appropriate NavigationController. 86 // NAV_ENTRY_PENDING notification to get the appropriate NavigationController.
87 // When the load commits, we'll show the infobar. 87 // When the load commits, we'll show the infobar.
88 // 88 //
89 // When |profile| is NULL or a testing profile, this function does nothing. 89 // When |profile| is NULL or a testing profile, this function does nothing.
90 static void GoogleURLSearchCommitted(Profile* profile); 90 static void GoogleURLSearchCommitted(Profile* profile);
91 91
92 static const char kDefaultGoogleHomepage[]; 92 static const char kDefaultGoogleHomepage[];
93 static const char kSearchDomainCheckURL[]; 93 static const char kSearchDomainCheckURL[];
94 94
95 private: 95 private:
96 friend class GoogleURLTrackerInfoBarDelegate; 96 friend class GoogleURLTrackerInfoBarDelegate;
Ilya Sherman 2012/10/16 20:16:24 Whoa, I just noticed this. How 'bout we expose pu
Peter Kasting 2012/10/16 23:29:35 OK. I hadn't done this so far because the current
97 friend class GoogleURLTrackerTest; 97 friend class GoogleURLTrackerTest;
98 98
99 struct MapEntry { 99 class MapEntry;
Ilya Sherman 2012/10/16 20:16:24 How about defining this in a separate header file?
Peter Kasting 2012/10/16 23:29:35 :/ I'm less convinced of the benefits of this, but
100 MapEntry(); // Required by STL.
101 MapEntry(GoogleURLTrackerInfoBarDelegate* infobar,
102 const content::NotificationSource& navigation_controller_source,
103 const content::NotificationSource& web_contents_source);
104 ~MapEntry();
105 100
106 GoogleURLTrackerInfoBarDelegate* infobar; 101 typedef std::map<const InfoBarTabHelper*, MapEntry*> InfoBarMap;
107 content::NotificationSource navigation_controller_source;
108 content::NotificationSource web_contents_source;
109 };
110 102
111 typedef std::map<const InfoBarTabHelper*, MapEntry> InfoBarMap; 103 // Creates an infobar delegate and adds it to |infobar_helper|. Returns the
104 // delegate pointer on success or NULL on failure. The caller does not own
105 // the returned object, the InfoBarTabHelper does.
112 typedef GoogleURLTrackerInfoBarDelegate* (*InfoBarCreator)( 106 typedef GoogleURLTrackerInfoBarDelegate* (*InfoBarCreator)(
113 InfoBarTabHelper* infobar_helper, 107 InfoBarTabHelper* infobar_helper,
114 GoogleURLTracker* google_url_tracker, 108 GoogleURLTracker* google_url_tracker,
115 const GURL& new_google_url); 109 const GURL& new_google_url);
116 110
117 // net::URLFetcherDelegate: 111 // net::URLFetcherDelegate:
118 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 112 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
119 113
120 // content::NotificationObserver: 114 // content::NotificationObserver:
121 virtual void Observe(int type, 115 virtual void Observe(int type,
122 const content::NotificationSource& source, 116 const content::NotificationSource& source,
123 const content::NotificationDetails& details) OVERRIDE; 117 const content::NotificationDetails& details) OVERRIDE;
124 118
125 // NetworkChangeNotifier::IPAddressObserver: 119 // NetworkChangeNotifier::IPAddressObserver:
126 virtual void OnIPAddressChanged() OVERRIDE; 120 virtual void OnIPAddressChanged() OVERRIDE;
127 121
128 // ProfileKeyedService: 122 // ProfileKeyedService:
129 virtual void Shutdown() OVERRIDE; 123 virtual void Shutdown() OVERRIDE;
130 124
131 // Callbacks from GoogleURLTrackerInfoBarDelegate: 125 // Callbacks from GoogleURLTrackerInfoBarDelegate:
132 void AcceptGoogleURL(const GURL& google_url, bool redo_searches); 126 void AcceptGoogleURL(bool redo_searches);
133 void CancelGoogleURL(const GURL& google_url); 127 void CancelGoogleURL();
134 void InfoBarClosed(const InfoBarTabHelper* infobar_helper); 128
129 // Callback from MapEntry:
130 void DeleteMapEntryForHelper(const InfoBarTabHelper* infobar_helper);
135 131
136 // Registers consumer interest in getting an updated URL from the server. 132 // Registers consumer interest in getting an updated URL from the server.
137 // Observe chrome::NOTIFICATION_GOOGLE_URL_UPDATED to be notified when the URL 133 // Observe chrome::NOTIFICATION_GOOGLE_URL_UPDATED to be notified when the URL
138 // changes. 134 // changes.
139 void SetNeedToFetch(); 135 void SetNeedToFetch();
140 136
141 // Called when the five second startup sleep has finished. Runs any pending 137 // Called when the five second startup sleep has finished. Runs any pending
142 // fetch. 138 // fetch.
143 void FinishSleep(); 139 void FinishSleep();
144 140
(...skipping 20 matching lines...) Expand all
165 const content::NotificationSource& navigation_controller_source, 161 const content::NotificationSource& navigation_controller_source,
166 const content::NotificationSource& web_contents_source, 162 const content::NotificationSource& web_contents_source,
167 InfoBarTabHelper* infobar_helper, 163 InfoBarTabHelper* infobar_helper,
168 int pending_id); 164 int pending_id);
169 165
170 // Called by Observe() once a load we're watching commits, or the associated 166 // Called by Observe() once a load we're watching commits, or the associated
171 // tab is closed. |infobar_helper| is the same as for OnNavigationPending(); 167 // tab is closed. |infobar_helper| is the same as for OnNavigationPending();
172 // |search_url| is valid when this call is due to a successful navigation 168 // |search_url| is valid when this call is due to a successful navigation
173 // (indicating that we should show or update the relevant infobar) as opposed 169 // (indicating that we should show or update the relevant infobar) as opposed
174 // to tab closure (which means we should delete the infobar). 170 // to tab closure (which means we should delete the infobar).
175 void OnNavigationCommittedOrTabClosed(const InfoBarTabHelper* infobar_helper, 171 void OnNavigationCommittedOrTabClosed(InfoBarTabHelper* infobar_helper,
176 const GURL& search_url); 172 const GURL& search_url);
177 173
178 // Called by Observe() when an instant navigation occurs. This will call 174 // Called by Observe() when an instant navigation occurs. This will call
179 // OnNavigationPending(), and, depending on whether this is a search we were 175 // OnNavigationPending(), and, depending on whether this is a search we were
180 // listening for, may then also call OnNavigationCommittedOrTabClosed(). 176 // listening for, may then also call OnNavigationCommittedOrTabClosed().
181 void OnInstantCommitted( 177 void OnInstantCommitted(
182 const content::NotificationSource& navigation_controller_source, 178 const content::NotificationSource& navigation_controller_source,
183 const content::NotificationSource& web_contents_source, 179 const content::NotificationSource& web_contents_source,
184 InfoBarTabHelper* infobar_helper, 180 InfoBarTabHelper* infobar_helper,
185 const GURL& search_url); 181 const GURL& search_url);
186 182
187 // Closes all open infobars. If |redo_searches| is true, this also triggers 183 // Closes all open infobars. If |redo_searches| is true, this also triggers
188 // each tab to re-perform the user's search, but on the new Google TLD. 184 // each tab to re-perform the user's search, but on the new Google TLD.
189 void CloseAllInfoBars(bool redo_searches); 185 void CloseAllInfoBars(bool redo_searches);
190 186
191 // Unregisters any listeners for the notification sources in |map_entry|. 187 // Unregisters any listeners for the notification sources in |map_entry|.
192 // This sanity-DCHECKs that these are registered (or not) in the specific 188 // This sanity-DCHECKs that these are registered (or not) in the specific
193 // cases we expect. (|must_be_listening_for_commit| is used purely for this 189 // cases we expect. (|must_be_listening_for_commit| is used purely for this
194 // sanity-checking.) This also unregisters our global NAV_ENTRY_PENDING/ 190 // sanity-checking.) This also unregisters our global NAV_ENTRY_PENDING/
195 // INSTANT_COMMITTED listeners if there are no remaining listeners for 191 // INSTANT_COMMITTED listeners if there are no remaining listeners for
196 // NAV_ENTRY_COMMITTED, as we no longer need them until another search is 192 // NAV_ENTRY_COMMITTED, as we no longer need them until another search is
197 // committed. 193 // committed.
198 void UnregisterForEntrySpecificNotifications( 194 void UnregisterForEntrySpecificNotifications(
199 const MapEntry& map_entry, 195 const MapEntry& map_entry,
200 bool must_be_listening_for_commit); 196 bool must_be_listening_for_commit);
201 197
202 Profile* profile_; 198 Profile* profile_;
203 content::NotificationRegistrar registrar_; 199 content::NotificationRegistrar registrar_;
204 InfoBarCreator infobar_creator_; 200 InfoBarCreator infobar_creator_;
205 // TODO(ukai): GoogleURLTracker should track google domain (e.g. google.co.uk)
206 // rather than URL (e.g. http://www.google.co.uk/), so that user could
207 // configure to use https in search engine templates.
Ilya Sherman 2012/10/16 20:16:24 Is this being removed because it's no longer appro
Peter Kasting 2012/10/16 23:29:35 We solved this problem in a different way by suppo
208 GURL google_url_; 201 GURL google_url_;
209 GURL fetched_google_url_; 202 GURL fetched_google_url_;
210 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; 203 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_;
211 scoped_ptr<net::URLFetcher> fetcher_; 204 scoped_ptr<net::URLFetcher> fetcher_;
212 int fetcher_id_; 205 int fetcher_id_;
213 bool in_startup_sleep_; // True if we're in the five-second "no fetching" 206 bool in_startup_sleep_; // True if we're in the five-second "no fetching"
214 // period that begins at browser start. 207 // period that begins at browser start.
215 bool already_fetched_; // True if we've already fetched a URL once this run; 208 bool already_fetched_; // True if we've already fetched a URL once this run;
216 // we won't fetch again until after a restart. 209 // we won't fetch again until after a restart.
217 bool need_to_fetch_; // True if a consumer actually wants us to fetch an 210 bool need_to_fetch_; // True if a consumer actually wants us to fetch an
218 // updated URL. If this is never set, we won't 211 // updated URL. If this is never set, we won't
219 // bother to fetch anything. 212 // bother to fetch anything.
220 // Consumers should observe 213 // Consumers should observe
221 // chrome::NOTIFICATION_GOOGLE_URL_UPDATED. 214 // chrome::NOTIFICATION_GOOGLE_URL_UPDATED.
222 bool need_to_prompt_; // True if the last fetched Google URL is not 215 bool need_to_prompt_; // True if the last fetched Google URL is not
223 // matched with current user's default Google URL 216 // matched with current user's default Google URL
224 // nor the last prompted Google URL. 217 // nor the last prompted Google URL.
225 bool search_committed_; // True when we're expecting a notification of a new 218 bool search_committed_; // True when we're expecting a notification of a new
226 // pending search navigation. 219 // pending search navigation.
227 InfoBarMap infobar_map_; 220 InfoBarMap infobar_map_;
228 221
229 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); 222 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker);
230 }; 223 };
231 224
225 class GoogleURLTracker::MapEntry : public content::NotificationObserver {
226 public:
227 MapEntry(GoogleURLTracker* google_url_tracker,
228 InfoBarTabHelper* infobar_helper,
229 const content::NotificationSource& navigation_controller_source,
230 const content::NotificationSource& web_contents_source);
231 virtual ~MapEntry();
232
233 bool has_infobar() const { return !!infobar_; }
234 GoogleURLTrackerInfoBarDelegate* infobar() { return infobar_; }
235 void SetInfoBar(GoogleURLTrackerInfoBarDelegate* infobar);
236
237 const content::NotificationSource& navigation_controller_source() const {
238 return navigation_controller_source_;
239 }
240 const content::NotificationSource& web_contents_source() const {
241 return web_contents_source_;
242 }
243
244 void Close(bool redo_search);
245
246 private:
247 friend class GoogleURLTrackerTest;
248
249 // content::NotificationObserver:
250 virtual void Observe(int type,
251 const content::NotificationSource& source,
252 const content::NotificationDetails& details) OVERRIDE;
253
254 content::NotificationRegistrar registrar_;
255 GoogleURLTracker* google_url_tracker_;
256 InfoBarTabHelper* infobar_helper_;
Ilya Sherman 2012/10/16 20:16:24 nit: Can these be const members?
Peter Kasting 2012/10/16 23:29:35 Added as much const as possible.
257 GoogleURLTrackerInfoBarDelegate* infobar_;
258 content::NotificationSource navigation_controller_source_;
259 content::NotificationSource web_contents_source_;
Ilya Sherman 2012/10/16 20:16:24 nit: Can these be const members?
Peter Kasting 2012/10/16 23:29:35 Yes.
260
261 DISALLOW_COPY_AND_ASSIGN(MapEntry);
262 };
263
232 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ 264 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/google/google_url_tracker.cc » ('j') | chrome/browser/google/google_url_tracker.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698