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

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

Issue 293503003: Eliminate dependence of GoogleURLTracker et al. on InfoBarService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Style nits 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.h" 5 #include "chrome/browser/google/google_url_tracker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/google/google_url_tracker_factory.h" 12 #include "chrome/browser/google/google_url_tracker_factory.h"
13 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h" 13 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h"
14 #include "chrome/browser/google/google_url_tracker_navigation_helper.h" 14 #include "chrome/browser/google/google_url_tracker_navigation_helper.h"
15 #include "chrome/browser/google/google_util.h" 15 #include "chrome/browser/google/google_util.h"
16 #include "chrome/browser/infobars/infobar_service.h"
17 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
20 #include "components/google/core/browser/google_url_tracker_client.h" 19 #include "components/google/core/browser/google_url_tracker_client.h"
21 #include "components/infobars/core/infobar.h" 20 #include "components/infobars/core/infobar.h"
22 #include "content/public/browser/navigation_controller.h" 21 #include "components/infobars/core/infobar_manager.h"
23 #include "content/public/browser/navigation_entry.h"
24 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
25 #include "net/base/load_flags.h" 23 #include "net/base/load_flags.h"
26 #include "net/base/net_util.h" 24 #include "net/base/net_util.h"
27 #include "net/url_request/url_fetcher.h" 25 #include "net/url_request/url_fetcher.h"
28 #include "net/url_request/url_request_status.h" 26 #include "net/url_request/url_request_status.h"
29 27
30 28
31 const char GoogleURLTracker::kDefaultGoogleHomepage[] = 29 const char GoogleURLTracker::kDefaultGoogleHomepage[] =
32 "http://www.google.com/"; 30 "http://www.google.com/";
33 const char GoogleURLTracker::kSearchDomainCheckURL[] = 31 const char GoogleURLTracker::kSearchDomainCheckURL[] =
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 StartFetchIfDesirable(); 199 StartFetchIfDesirable();
202 } 200 }
203 201
204 void GoogleURLTracker::Shutdown() { 202 void GoogleURLTracker::Shutdown() {
205 client_.reset(); 203 client_.reset();
206 fetcher_.reset(); 204 fetcher_.reset();
207 weak_ptr_factory_.InvalidateWeakPtrs(); 205 weak_ptr_factory_.InvalidateWeakPtrs();
208 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 206 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
209 } 207 }
210 208
211 void GoogleURLTracker::DeleteMapEntryForService( 209 void GoogleURLTracker::DeleteMapEntryForManager(
212 const InfoBarService* infobar_service) { 210 const infobars::InfoBarManager* infobar_manager) {
213 // WARNING: |infobar_service| may point to a deleted object. Do not 211 // WARNING: |infobar_manager| may point to a deleted object. Do not
214 // dereference it! See OnTabClosed(). 212 // dereference it! See OnTabClosed().
215 EntryMap::iterator i(entry_map_.find(infobar_service)); 213 EntryMap::iterator i(entry_map_.find(infobar_manager));
216 DCHECK(i != entry_map_.end()); 214 DCHECK(i != entry_map_.end());
217 GoogleURLTrackerMapEntry* map_entry = i->second; 215 GoogleURLTrackerMapEntry* map_entry = i->second;
218 216
219 UnregisterForEntrySpecificNotifications(map_entry, false); 217 UnregisterForEntrySpecificNotifications(map_entry, false);
220 entry_map_.erase(i); 218 entry_map_.erase(i);
221 delete map_entry; 219 delete map_entry;
222 } 220 }
223 221
224 void GoogleURLTracker::SetNeedToFetch() { 222 void GoogleURLTracker::SetNeedToFetch() {
225 need_to_fetch_ = true; 223 need_to_fetch_ = true;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 search_committed_ = true; 270 search_committed_ = true;
273 // These notifications will fire a bit later in the same call chain we're 271 // These notifications will fire a bit later in the same call chain we're
274 // currently in. 272 // currently in.
275 if (!client_->IsListeningForNavigationStart()) 273 if (!client_->IsListeningForNavigationStart())
276 client_->SetListeningForNavigationStart(true); 274 client_->SetListeningForNavigationStart(true);
277 } 275 }
278 } 276 }
279 277
280 void GoogleURLTracker::OnNavigationPending( 278 void GoogleURLTracker::OnNavigationPending(
281 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper, 279 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper,
282 InfoBarService* infobar_service, 280 infobars::InfoBarManager* infobar_manager,
283 int pending_id) { 281 int pending_id) {
284 GoogleURLTrackerMapEntry* map_entry = NULL; 282 GoogleURLTrackerMapEntry* map_entry = NULL;
285 283
286 EntryMap::iterator i(entry_map_.find(infobar_service)); 284 EntryMap::iterator i(entry_map_.find(infobar_manager));
287 if (i != entry_map_.end()) 285 if (i != entry_map_.end())
288 map_entry = i->second; 286 map_entry = i->second;
289 287
290 if (search_committed_) { 288 if (search_committed_) {
291 search_committed_ = false; 289 search_committed_ = false;
292 if (!map_entry) { 290 if (!map_entry) {
293 // This is a search on a tab that doesn't have one of our infobars, so 291 // This is a search on a tab that doesn't have one of our infobars, so
294 // prepare to add one. Note that we only listen for the tab's destruction 292 // prepare to add one. Note that we only listen for the tab's destruction
295 // on this path; if there was already a map entry, then either it doesn't 293 // on this path; if there was already a map entry, then either it doesn't
296 // yet have an infobar and we're already registered for this, or it has an 294 // yet have an infobar and we're already registered for this, or it has an
297 // infobar and the infobar's owner will handle tearing it down when the 295 // infobar and the infobar's owner will handle tearing it down when the
298 // tab is destroyed. 296 // tab is destroyed.
299 map_entry = new GoogleURLTrackerMapEntry( 297 map_entry = new GoogleURLTrackerMapEntry(
300 this, infobar_service, nav_helper.Pass()); 298 this, infobar_manager, nav_helper.Pass());
301 map_entry->navigation_helper()->SetListeningForTabDestruction(true); 299 map_entry->navigation_helper()->SetListeningForTabDestruction(true);
302 entry_map_.insert(std::make_pair(infobar_service, map_entry)); 300 entry_map_.insert(std::make_pair(infobar_manager, map_entry));
303 } else if (map_entry->infobar_delegate()) { 301 } else if (map_entry->infobar_delegate()) {
304 // This is a new search on a tab where we already have an infobar. 302 // This is a new search on a tab where we already have an infobar.
305 map_entry->infobar_delegate()->set_pending_id(pending_id); 303 map_entry->infobar_delegate()->set_pending_id(pending_id);
306 } 304 }
307 305
308 // Whether there's an existing infobar or not, we need to listen for the 306 // Whether there's an existing infobar or not, we need to listen for the
309 // load to commit, so we can show and/or update the infobar when it does. 307 // load to commit, so we can show and/or update the infobar when it does.
310 // (We may already be registered for this if there is an existing infobar 308 // (We may already be registered for this if there is an existing infobar
311 // that had a previous pending search that hasn't yet committed.) 309 // that had a previous pending search that hasn't yet committed.)
312 if (!map_entry->navigation_helper()->IsListeningForNavigationCommit()) 310 if (!map_entry->navigation_helper()->IsListeningForNavigationCommit())
(...skipping 16 matching lines...) Expand all
329 // an infobar. This means the original search won't commit, so delete the 327 // an infobar. This means the original search won't commit, so delete the
330 // entry. 328 // entry.
331 map_entry->Close(false); 329 map_entry->Close(false);
332 } 330 }
333 } else { 331 } else {
334 // Non-search navigation on a tab without an infobars. This is irrelevant 332 // Non-search navigation on a tab without an infobars. This is irrelevant
335 // to us. 333 // to us.
336 } 334 }
337 } 335 }
338 336
339 void GoogleURLTracker::OnNavigationCommitted(InfoBarService* infobar_service, 337 void GoogleURLTracker::OnNavigationCommitted(
340 const GURL& search_url) { 338 infobars::InfoBarManager* infobar_manager,
341 EntryMap::iterator i(entry_map_.find(infobar_service)); 339 const GURL& search_url) {
340 EntryMap::iterator i(entry_map_.find(infobar_manager));
342 DCHECK(i != entry_map_.end()); 341 DCHECK(i != entry_map_.end());
343 GoogleURLTrackerMapEntry* map_entry = i->second; 342 GoogleURLTrackerMapEntry* map_entry = i->second;
344 DCHECK(search_url.is_valid()); 343 DCHECK(search_url.is_valid());
345 344
346 UnregisterForEntrySpecificNotifications(map_entry, true); 345 UnregisterForEntrySpecificNotifications(map_entry, true);
347 if (map_entry->has_infobar_delegate()) { 346 if (map_entry->has_infobar_delegate()) {
348 map_entry->infobar_delegate()->Update(search_url); 347 map_entry->infobar_delegate()->Update(search_url);
349 } else { 348 } else {
350 infobars::InfoBar* infobar = 349 infobars::InfoBar* infobar = infobar_creator_.Run(
351 infobar_creator_.Run(infobar_service, this, search_url); 350 infobar_manager, this, map_entry->navigation_helper(), search_url);
352 if (infobar) { 351 if (infobar) {
353 map_entry->SetInfoBarDelegate( 352 map_entry->SetInfoBarDelegate(
354 static_cast<GoogleURLTrackerInfoBarDelegate*>(infobar->delegate())); 353 static_cast<GoogleURLTrackerInfoBarDelegate*>(infobar->delegate()));
355 } else { 354 } else {
356 map_entry->Close(false); 355 map_entry->Close(false);
357 } 356 }
358 } 357 }
359 } 358 }
360 359
361 void GoogleURLTracker::OnTabClosed( 360 void GoogleURLTracker::OnTabClosed(
362 GoogleURLTrackerNavigationHelper* nav_helper) { 361 GoogleURLTrackerNavigationHelper* nav_helper) {
363 // Because InfoBarService tears itself down on tab destruction, it's possible 362 // Because InfoBarManager tears itself down on tab destruction, it's possible
364 // to get a non-NULL InfoBarService pointer here, depending on which order 363 // to get a non-NULL InfoBarManager pointer here, depending on which order
365 // notifications fired in. Likewise, the pointer in |entry_map_| (and in its 364 // notifications fired in. Likewise, the pointer in |entry_map_| (and in its
366 // associated MapEntry) may point to deleted memory. Therefore, if we were to 365 // associated MapEntry) may point to deleted memory. Therefore, if we were
367 // access the InfoBarService* we have for this tab, we'd need to ensure we 366 // to access the InfoBarManager* we have for this tab, we'd need to ensure we
368 // just looked at the raw pointer value, and never dereferenced it. This 367 // just looked at the raw pointer value, and never dereferenced it. This
369 // function doesn't need to do even that, but others in the call chain from 368 // function doesn't need to do even that, but others in the call chain from
370 // here might (and have comments pointing back here). 369 // here might (and have comments pointing back here).
371 for (EntryMap::iterator i(entry_map_.begin()); i != entry_map_.end(); ++i) { 370 for (EntryMap::iterator i(entry_map_.begin()); i != entry_map_.end(); ++i) {
372 if (i->second->navigation_helper() == nav_helper) { 371 if (i->second->navigation_helper() == nav_helper) {
373 i->second->Close(false); 372 i->second->Close(false);
374 return; 373 return;
375 } 374 }
376 } 375 }
377 NOTREACHED(); 376 NOTREACHED();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 if (i->second->navigation_helper()->IsListeningForNavigationCommit()) { 411 if (i->second->navigation_helper()->IsListeningForNavigationCommit()) {
413 DCHECK(client_->IsListeningForNavigationStart()); 412 DCHECK(client_->IsListeningForNavigationStart());
414 return; 413 return;
415 } 414 }
416 } 415 }
417 if (client_->IsListeningForNavigationStart()) { 416 if (client_->IsListeningForNavigationStart()) {
418 DCHECK(!search_committed_); 417 DCHECK(!search_committed_);
419 client_->SetListeningForNavigationStart(false); 418 client_->SetListeningForNavigationStart(false);
420 } 419 }
421 } 420 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698