| 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_map_entry.h" | 5 #include "chrome/browser/google/google_url_tracker_map_entry.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/google/google_url_tracker_infobar_delegate.h" | 9 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h" |
| 10 #include "chrome/browser/infobars/infobar.h" | 10 #include "components/infobars/core/infobar.h" |
| 11 #include "content/public/browser/notification_details.h" | 11 #include "content/public/browser/notification_details.h" |
| 12 #include "content/public/browser/notification_source.h" | 12 #include "content/public/browser/notification_source.h" |
| 13 | 13 |
| 14 | 14 |
| 15 GoogleURLTrackerMapEntry::GoogleURLTrackerMapEntry( | 15 GoogleURLTrackerMapEntry::GoogleURLTrackerMapEntry( |
| 16 GoogleURLTracker* google_url_tracker, | 16 GoogleURLTracker* google_url_tracker, |
| 17 InfoBarService* infobar_service, | 17 InfoBarService* infobar_service, |
| 18 const content::NavigationController* navigation_controller) | 18 const content::NavigationController* navigation_controller) |
| 19 : google_url_tracker_(google_url_tracker), | 19 : google_url_tracker_(google_url_tracker), |
| 20 infobar_service_(infobar_service), | 20 infobar_service_(infobar_service), |
| 21 infobar_delegate_(NULL), | 21 infobar_delegate_(NULL), |
| 22 navigation_controller_(navigation_controller) { | 22 navigation_controller_(navigation_controller) { |
| 23 } | 23 } |
| 24 | 24 |
| 25 GoogleURLTrackerMapEntry::~GoogleURLTrackerMapEntry() { | 25 GoogleURLTrackerMapEntry::~GoogleURLTrackerMapEntry() { |
| 26 } | 26 } |
| 27 | 27 |
| 28 void GoogleURLTrackerMapEntry::Observe( | 28 void GoogleURLTrackerMapEntry::Observe( |
| 29 int type, | 29 int type, |
| 30 const content::NotificationSource& source, | 30 const content::NotificationSource& source, |
| 31 const content::NotificationDetails& details) { | 31 const content::NotificationDetails& details) { |
| 32 DCHECK(infobar_delegate_); | 32 DCHECK(infobar_delegate_); |
| 33 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); | 33 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); |
| 34 DCHECK_EQ(infobar_service_, content::Source<InfoBarService>(source).ptr()); | 34 DCHECK_EQ(infobar_service_, content::Source<InfoBarService>(source).ptr()); |
| 35 if (content::Details<InfoBar::RemovedDetails>(details)->first->delegate() == | 35 if (content::Details<infobars::InfoBar::RemovedDetails>( |
| 36 infobar_delegate_) { | 36 details)->first->delegate() == infobar_delegate_) { |
| 37 google_url_tracker_->DeleteMapEntryForService(infobar_service_); | 37 google_url_tracker_->DeleteMapEntryForService(infobar_service_); |
| 38 // WARNING: At this point |this| has been deleted! | 38 // WARNING: At this point |this| has been deleted! |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 void GoogleURLTrackerMapEntry::SetInfoBarDelegate( | 42 void GoogleURLTrackerMapEntry::SetInfoBarDelegate( |
| 43 GoogleURLTrackerInfoBarDelegate* infobar_delegate) { | 43 GoogleURLTrackerInfoBarDelegate* infobar_delegate) { |
| 44 DCHECK(!infobar_delegate_); | 44 DCHECK(!infobar_delegate_); |
| 45 infobar_delegate_ = infobar_delegate; | 45 infobar_delegate_ = infobar_delegate; |
| 46 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 46 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 47 content::Source<InfoBarService>(infobar_service_)); | 47 content::Source<InfoBarService>(infobar_service_)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void GoogleURLTrackerMapEntry::Close(bool redo_search) { | 50 void GoogleURLTrackerMapEntry::Close(bool redo_search) { |
| 51 if (infobar_delegate_) { | 51 if (infobar_delegate_) { |
| 52 infobar_delegate_->Close(redo_search); | 52 infobar_delegate_->Close(redo_search); |
| 53 } else { | 53 } else { |
| 54 // WARNING: |infobar_service_| may point to a deleted object. Do not | 54 // WARNING: |infobar_service_| may point to a deleted object. Do not |
| 55 // dereference it! See GoogleURLTracker::OnTabClosed(). | 55 // dereference it! See GoogleURLTracker::OnTabClosed(). |
| 56 google_url_tracker_->DeleteMapEntryForService(infobar_service_); | 56 google_url_tracker_->DeleteMapEntryForService(infobar_service_); |
| 57 } | 57 } |
| 58 // WARNING: At this point |this| has been deleted! | 58 // WARNING: At this point |this| has been deleted! |
| 59 } | 59 } |
| OLD | NEW |