summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-22 18:41:32 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-22 18:41:32 +0000
commit5be94dffc6b19e0ed8397879ad60fe06e498cb3a (patch)
tree0deaf3ff22bb9d56cab3fcaf8e0a51dea050bd3d /chrome/browser
parent0b5f1163a0060e848d90684a2b1c2c8269df292b (diff)
downloadchromium_src-5be94dffc6b19e0ed8397879ad60fe06e498cb3a.zip
chromium_src-5be94dffc6b19e0ed8397879ad60fe06e498cb3a.tar.gz
chromium_src-5be94dffc6b19e0ed8397879ad60fe06e498cb3a.tar.bz2
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
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/modal_html_dialog_delegate.cc20
-rw-r--r--chrome/browser/modal_html_dialog_delegate.h7
-rw-r--r--chrome/browser/tab_contents/site_instance.cc9
-rw-r--r--chrome/browser/tab_contents/site_instance.h4
4 files changed, 11 insertions, 29 deletions
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<TabContents>(contents_));
+ registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED,
+ Source<TabContents>(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<TabContents>(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<TabContents>(contents_));
- contents_ = NULL; // No longer safe to access.
-}
diff --git a/chrome/browser/modal_html_dialog_delegate.h b/chrome/browser/modal_html_dialog_delegate.h
index f2822e3..1865a36 100644
--- a/chrome/browser/modal_html_dialog_delegate.h
+++ b/chrome/browser/modal_html_dialog_delegate.h
@@ -10,7 +10,7 @@
#include "base/gfx/size.h"
#include "chrome/browser/dom_ui/html_dialog_ui.h"
#include "chrome/common/ipc_message.h"
-#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
// This class can only be used on the UI thread.
class ModalHtmlDialogDelegate
@@ -38,10 +38,7 @@ class ModalHtmlDialogDelegate
virtual void OnDialogClosed(const std::string& json_retval);
private:
- // Invoked from the destructor or when we receive notification the web
- // contents has been disconnnected. Removes the observer from the TabContents
- // and NULLs out contents_.
- void RemoveObserver();
+ NotificationRegistrar registrar_;
// The TabContents that opened the dialog.
TabContents* contents_;
diff --git a/chrome/browser/tab_contents/site_instance.cc b/chrome/browser/tab_contents/site_instance.cc
index 346283f..0dbe744 100644
--- a/chrome/browser/tab_contents/site_instance.cc
+++ b/chrome/browser/tab_contents/site_instance.cc
@@ -17,9 +17,8 @@ SiteInstance::SiteInstance(BrowsingInstance* browsing_instance)
has_site_(false) {
DCHECK(browsing_instance);
- NotificationService::current()->AddObserver(this,
- NotificationType::RENDERER_PROCESS_TERMINATED,
- NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED,
+ NotificationService::AllSources());
}
SiteInstance::~SiteInstance() {
@@ -28,10 +27,6 @@ SiteInstance::~SiteInstance() {
// (within the same BrowsingInstance) can safely create a new SiteInstance.
if (has_site_)
browsing_instance_->UnregisterSiteInstance(this);
-
- NotificationService::current()->RemoveObserver(this,
- NotificationType::RENDERER_PROCESS_TERMINATED,
- NotificationService::AllSources());
}
RenderProcessHost* SiteInstance::GetProcess() {
diff --git a/chrome/browser/tab_contents/site_instance.h b/chrome/browser/tab_contents/site_instance.h
index 8cf238b..5c14dcc 100644
--- a/chrome/browser/tab_contents/site_instance.h
+++ b/chrome/browser/tab_contents/site_instance.h
@@ -7,7 +7,7 @@
#include "chrome/browser/browsing_instance.h"
#include "chrome/browser/renderer_host/render_process_host.h"
-#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
#include "googleurl/src/gurl.h"
///////////////////////////////////////////////////////////////////////////////
@@ -144,6 +144,8 @@ class SiteInstance : public base::RefCounted<SiteInstance>,
const NotificationSource& source,
const NotificationDetails& details);
+ NotificationRegistrar registrar_;
+
// BrowsingInstance to which this SiteInstance belongs.
scoped_refptr<BrowsingInstance> browsing_instance_;