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

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

Issue 293503003: Eliminate dependence of GoogleURLTracker et al. on InfoBarService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ownership problem 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_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"
10 #include "components/infobars/core/infobar.h" 9 #include "components/infobars/core/infobar.h"
11 #include "content/public/browser/notification_details.h" 10 #include "content/public/browser/notification_details.h"
12 #include "content/public/browser/notification_source.h" 11 #include "content/public/browser/notification_source.h"
13 12
14
15 GoogleURLTrackerMapEntry::GoogleURLTrackerMapEntry( 13 GoogleURLTrackerMapEntry::GoogleURLTrackerMapEntry(
16 GoogleURLTracker* google_url_tracker, 14 GoogleURLTracker* google_url_tracker,
17 InfoBarService* infobar_service, 15 infobars::InfoBarManager* infobar_manager,
18 scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper) 16 scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper)
19 : google_url_tracker_(google_url_tracker), 17 : google_url_tracker_(google_url_tracker),
20 infobar_service_(infobar_service), 18 infobar_manager_(infobar_manager),
21 infobar_delegate_(NULL), 19 infobar_delegate_(NULL),
22 navigation_helper_(navigation_helper.Pass()) { 20 navigation_helper_(navigation_helper.Pass()) {
23 } 21 }
24 22
25 GoogleURLTrackerMapEntry::~GoogleURLTrackerMapEntry() { 23 GoogleURLTrackerMapEntry::~GoogleURLTrackerMapEntry() {
26 } 24 }
27 25
28 void GoogleURLTrackerMapEntry::Observe( 26 void GoogleURLTrackerMapEntry::Observe(
29 int type, 27 int type,
30 const content::NotificationSource& source, 28 const content::NotificationSource& source,
31 const content::NotificationDetails& details) { 29 const content::NotificationDetails& details) {
32 DCHECK(infobar_delegate_); 30 DCHECK(infobar_delegate_);
33 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); 31 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type);
34 DCHECK_EQ(infobar_service_, content::Source<InfoBarService>(source).ptr()); 32 DCHECK_EQ(infobar_manager_,
33 content::Source<infobars::InfoBarManager>(source).ptr());
35 if (content::Details<infobars::InfoBar::RemovedDetails>( 34 if (content::Details<infobars::InfoBar::RemovedDetails>(
36 details)->first->delegate() == infobar_delegate_) { 35 details)->first->delegate() == infobar_delegate_) {
37 google_url_tracker_->DeleteMapEntryForService(infobar_service_); 36 google_url_tracker_->DeleteMapEntryForManager(infobar_manager_);
38 // WARNING: At this point |this| has been deleted! 37 // WARNING: At this point |this| has been deleted!
39 } 38 }
40 } 39 }
41 40
42 void GoogleURLTrackerMapEntry::SetInfoBarDelegate( 41 void GoogleURLTrackerMapEntry::SetInfoBarDelegate(
43 GoogleURLTrackerInfoBarDelegate* infobar_delegate) { 42 GoogleURLTrackerInfoBarDelegate* infobar_delegate) {
44 DCHECK(!infobar_delegate_); 43 DCHECK(!infobar_delegate_);
44
45 // Transfer ownership of |navigation_helper_| to the infobar delegate as the
46 // infobar delegate has need of it after this object has been destroyed in
47 // certain cases.
Peter Kasting 2014/05/28 22:19:04 Nit: Perhaps say what those cases are
blundell 2014/05/30 09:39:18 Done.
48 infobar_delegate->set_navigation_helper(navigation_helper_.Pass());
45 infobar_delegate_ = infobar_delegate; 49 infobar_delegate_ = infobar_delegate;
46 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, 50 registrar_.Add(this,
47 content::Source<InfoBarService>(infobar_service_)); 51 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
52 content::Source<infobars::InfoBarManager>(infobar_manager_));
48 } 53 }
49 54
50 void GoogleURLTrackerMapEntry::Close(bool redo_search) { 55 void GoogleURLTrackerMapEntry::Close(bool redo_search) {
51 if (infobar_delegate_) { 56 if (infobar_delegate_) {
52 infobar_delegate_->Close(redo_search); 57 infobar_delegate_->Close(redo_search);
53 } else { 58 } else {
54 // WARNING: |infobar_service_| may point to a deleted object. Do not 59 // WARNING: |infobar_manager_| may point to a deleted object. Do not
55 // dereference it! See GoogleURLTracker::OnTabClosed(). 60 // dereference it! See GoogleURLTracker::OnTabClosed().
56 google_url_tracker_->DeleteMapEntryForService(infobar_service_); 61 google_url_tracker_->DeleteMapEntryForManager(infobar_manager_);
57 } 62 }
58 // WARNING: At this point |this| has been deleted! 63 // WARNING: At this point |this| has been deleted!
59 } 64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698