OLD | NEW |
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.h" |
16 #include "chrome/browser/infobars/infobar_service.h" | 17 #include "chrome/browser/infobars/infobar_service.h" |
17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
20 #include "content/public/browser/navigation_controller.h" | 21 #include "content/public/browser/navigation_controller.h" |
21 #include "content/public/browser/navigation_entry.h" | 22 #include "content/public/browser/navigation_entry.h" |
22 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
23 #include "net/base/load_flags.h" | 24 #include "net/base/load_flags.h" |
24 #include "net/base/net_util.h" | 25 #include "net/base/net_util.h" |
25 #include "net/url_request/url_fetcher.h" | 26 #include "net/url_request/url_fetcher.h" |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 const GURL& search_url) { | 342 const GURL& search_url) { |
342 EntryMap::iterator i(entry_map_.find(infobar_service)); | 343 EntryMap::iterator i(entry_map_.find(infobar_service)); |
343 DCHECK(i != entry_map_.end()); | 344 DCHECK(i != entry_map_.end()); |
344 GoogleURLTrackerMapEntry* map_entry = i->second; | 345 GoogleURLTrackerMapEntry* map_entry = i->second; |
345 DCHECK(search_url.is_valid()); | 346 DCHECK(search_url.is_valid()); |
346 | 347 |
347 UnregisterForEntrySpecificNotifications(*map_entry, true); | 348 UnregisterForEntrySpecificNotifications(*map_entry, true); |
348 if (map_entry->has_infobar_delegate()) { | 349 if (map_entry->has_infobar_delegate()) { |
349 map_entry->infobar_delegate()->Update(search_url); | 350 map_entry->infobar_delegate()->Update(search_url); |
350 } else { | 351 } else { |
351 GoogleURLTrackerInfoBarDelegate* infobar = | 352 InfoBar* infobar = infobar_creator_.Run(infobar_service, this, search_url); |
352 infobar_creator_.Run(infobar_service, this, search_url); | 353 if (infobar) { |
353 if (infobar) | 354 map_entry->SetInfoBarDelegate( |
354 map_entry->SetInfoBarDelegate(infobar); | 355 static_cast<GoogleURLTrackerInfoBarDelegate*>(infobar->delegate())); |
355 else | 356 } else { |
356 map_entry->Close(false); | 357 map_entry->Close(false); |
| 358 } |
357 } | 359 } |
358 } | 360 } |
359 | 361 |
360 void GoogleURLTracker::OnTabClosed( | 362 void GoogleURLTracker::OnTabClosed( |
361 content::NavigationController* navigation_controller) { | 363 content::NavigationController* navigation_controller) { |
362 // Because InfoBarService tears itself down on tab destruction, it's possible | 364 // Because InfoBarService tears itself down on tab destruction, it's possible |
363 // to get a non-NULL InfoBarService pointer here, depending on which order | 365 // to get a non-NULL InfoBarService pointer here, depending on which order |
364 // notifications fired in. Likewise, the pointer in |entry_map_| (and in its | 366 // notifications fired in. Likewise, the pointer in |entry_map_| (and in its |
365 // associated MapEntry) may point to deleted memory. Therefore, if we were to | 367 // associated MapEntry) may point to deleted memory. Therefore, if we were to |
366 // access the InfoBarService* we have for this tab, we'd need to ensure we | 368 // access the InfoBarService* we have for this tab, we'd need to ensure we |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 i->second->navigation_controller())) { | 418 i->second->navigation_controller())) { |
417 DCHECK(nav_helper_->IsListeningForNavigationStart()); | 419 DCHECK(nav_helper_->IsListeningForNavigationStart()); |
418 return; | 420 return; |
419 } | 421 } |
420 } | 422 } |
421 if (nav_helper_->IsListeningForNavigationStart()) { | 423 if (nav_helper_->IsListeningForNavigationStart()) { |
422 DCHECK(!search_committed_); | 424 DCHECK(!search_committed_); |
423 nav_helper_->SetListeningForNavigationStart(false); | 425 nav_helper_->SetListeningForNavigationStart(false); |
424 } | 426 } |
425 } | 427 } |
OLD | NEW |