From 5be94dffc6b19e0ed8397879ad60fe06e498cb3a Mon Sep 17 00:00:00 2001 From: "pkasting@chromium.org" Date: Fri, 22 May 2009 18:41:32 +0000 Subject: Use a NotificationRegistrar to listen for notifications.BUG=2381 Review URL: http://codereview.chromium.org/113743 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16767 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/modal_html_dialog_delegate.cc | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'chrome/browser/modal_html_dialog_delegate.cc') diff --git a/chrome/browser/modal_html_dialog_delegate.cc b/chrome/browser/modal_html_dialog_delegate.cc index 12cc713..d566b86 100644 --- a/chrome/browser/modal_html_dialog_delegate.cc +++ b/chrome/browser/modal_html_dialog_delegate.cc @@ -15,9 +15,8 @@ ModalHtmlDialogDelegate::ModalHtmlDialogDelegate( : contents_(contents), sync_response_(sync_result) { // Listen for when the TabContents or its renderer dies. - NotificationService::current()-> - AddObserver(this, NotificationType::TAB_CONTENTS_DISCONNECTED, - Source(contents_)); + registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED, + Source(contents_)); // This information is needed to show the dialog HTML content. params_.url = url; @@ -27,7 +26,6 @@ ModalHtmlDialogDelegate::ModalHtmlDialogDelegate( } ModalHtmlDialogDelegate::~ModalHtmlDialogDelegate() { - RemoveObserver(); } void ModalHtmlDialogDelegate::Observe(NotificationType type, @@ -35,7 +33,8 @@ void ModalHtmlDialogDelegate::Observe(NotificationType type, const NotificationDetails& details) { DCHECK(type == NotificationType::TAB_CONTENTS_DISCONNECTED); DCHECK(Source(source).ptr() == contents_); - RemoveObserver(); + registrar_.RemoveAll(); + contents_ = NULL; } bool ModalHtmlDialogDelegate::IsDialogModal() const { @@ -65,14 +64,3 @@ void ModalHtmlDialogDelegate::OnDialogClosed(const std::string& json_retval) { // We are done with this request, so delete us. delete this; } - -void ModalHtmlDialogDelegate::RemoveObserver() { - if (!contents_) - return; - - NotificationService::current()->RemoveObserver( - this, - NotificationType::TAB_CONTENTS_DISCONNECTED, - Source(contents_)); - contents_ = NULL; // No longer safe to access. -} -- cgit v1.1