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

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

Issue 290453005: Remove Infobars notifications from GoogleURLTrackerMapEntry (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments 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 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_service.h"
10 #include "components/infobars/core/infobar.h" 11 #include "components/infobars/core/infobar.h"
11 #include "content/public/browser/notification_details.h"
12 #include "content/public/browser/notification_source.h"
13
14 12
15 GoogleURLTrackerMapEntry::GoogleURLTrackerMapEntry( 13 GoogleURLTrackerMapEntry::GoogleURLTrackerMapEntry(
16 GoogleURLTracker* google_url_tracker, 14 GoogleURLTracker* google_url_tracker,
17 InfoBarService* infobar_service, 15 InfoBarService* infobar_service,
18 const content::NavigationController* navigation_controller) 16 const content::NavigationController* navigation_controller)
19 : google_url_tracker_(google_url_tracker), 17 : google_url_tracker_(google_url_tracker),
20 infobar_service_(infobar_service), 18 infobar_service_(infobar_service),
21 infobar_delegate_(NULL), 19 infobar_delegate_(NULL),
22 navigation_controller_(navigation_controller) { 20 navigation_controller_(navigation_controller),
21 observing_(false) {
22 DCHECK(infobar_service_);
23 } 23 }
24 24
25 GoogleURLTrackerMapEntry::~GoogleURLTrackerMapEntry() { 25 GoogleURLTrackerMapEntry::~GoogleURLTrackerMapEntry() {
26 } 26 if (observing_)
27 27 infobar_service_->RemoveObserver(this);
28 void GoogleURLTrackerMapEntry::Observe(
29 int type,
30 const content::NotificationSource& source,
31 const content::NotificationDetails& details) {
32 DCHECK(infobar_delegate_);
33 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type);
34 DCHECK_EQ(infobar_service_, content::Source<InfoBarService>(source).ptr());
35 if (content::Details<infobars::InfoBar::RemovedDetails>(
36 details)->first->delegate() == infobar_delegate_) {
37 google_url_tracker_->DeleteMapEntryForService(infobar_service_);
38 // WARNING: At this point |this| has been deleted!
39 }
40 } 28 }
41 29
42 void GoogleURLTrackerMapEntry::SetInfoBarDelegate( 30 void GoogleURLTrackerMapEntry::SetInfoBarDelegate(
43 GoogleURLTrackerInfoBarDelegate* infobar_delegate) { 31 GoogleURLTrackerInfoBarDelegate* infobar_delegate) {
44 DCHECK(!infobar_delegate_); 32 DCHECK(!infobar_delegate_);
45 infobar_delegate_ = infobar_delegate; 33 infobar_delegate_ = infobar_delegate;
46 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, 34 infobar_service_->AddObserver(this);
47 content::Source<InfoBarService>(infobar_service_)); 35 observing_ = true;
48 } 36 }
49 37
50 void GoogleURLTrackerMapEntry::Close(bool redo_search) { 38 void GoogleURLTrackerMapEntry::Close(bool redo_search) {
51 if (infobar_delegate_) { 39 if (infobar_delegate_) {
52 infobar_delegate_->Close(redo_search); 40 infobar_delegate_->Close(redo_search);
53 } else { 41 } else {
54 // WARNING: |infobar_service_| may point to a deleted object. Do not 42 // WARNING: |infobar_service_| may point to a deleted object. Do not
55 // dereference it! See GoogleURLTracker::OnTabClosed(). 43 // dereference it! See GoogleURLTracker::OnTabClosed().
56 google_url_tracker_->DeleteMapEntryForService(infobar_service_); 44 google_url_tracker_->DeleteMapEntryForService(infobar_service_);
57 } 45 }
58 // WARNING: At this point |this| has been deleted! 46 // WARNING: At this point |this| has been deleted!
59 } 47 }
48
49 // infobars::InfoBarManager::Observer implementation.
Peter Kasting 2014/05/28 22:27:19 Nit: Don't add this comment.
50
51 void GoogleURLTrackerMapEntry::OnInfoBarRemoved(infobars::InfoBar* infobar,
52 bool animate) {
53 DCHECK(infobar_delegate_);
54 if (infobar->delegate() == infobar_delegate_) {
55 google_url_tracker_->DeleteMapEntryForService(infobar_service_);
56 // WARNING: At this point |this| has been deleted!
57 }
58 }
59
60 void GoogleURLTrackerMapEntry::OnManagerShuttingDown(
61 infobars::InfoBarManager* manager) {
62 DCHECK(observing_);
63 DCHECK_EQ(infobar_service_, manager);
64 manager->RemoveObserver(this);
65 observing_ = false;
66 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698