summaryrefslogtreecommitdiffstats
path: root/chrome/common/notification_registrar.cc
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-23 00:47:32 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-23 00:47:32 +0000
commit9fd40f97918896053bf68332d209036602cc8483 (patch)
tree661b55d1eef19cc04c1a2fea4defeafb06d55fed /chrome/common/notification_registrar.cc
parent3e787b367fb03d59203d69b625a6f65793feecd1 (diff)
downloadchromium_src-9fd40f97918896053bf68332d209036602cc8483.zip
chromium_src-9fd40f97918896053bf68332d209036602cc8483.tar.gz
chromium_src-9fd40f97918896053bf68332d209036602cc8483.tar.bz2
Avoid calling NotificationService::current() unless we have to, to prevent problems during shutdown in atypical cases.We can now be more stringent with the Remove() check that was already in place, since now users _must_ go through NotificationRegistrar to register an observer.
BUG=12560 Review URL: http://codereview.chromium.org/115733 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16821 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/notification_registrar.cc')
-rw-r--r--chrome/common/notification_registrar.cc19
1 files changed, 12 insertions, 7 deletions
diff --git a/chrome/common/notification_registrar.cc b/chrome/common/notification_registrar.cc
index 73635b5..ac76202 100644
--- a/chrome/common/notification_registrar.cc
+++ b/chrome/common/notification_registrar.cc
@@ -47,15 +47,11 @@ void NotificationRegistrar::Remove(NotificationObserver* observer,
Record record = { observer, type, source };
RecordVector::iterator found = std::find(
registered_.begin(), registered_.end(), record);
- if (found != registered_.end()) {
- registered_.erase(found);
- } else {
- // Fall through to passing the removal through to the notification service.
- // If it really isn't registered, it will also assert and do nothing, but
- // we might as well catch the case where the class is trying to unregister
- // for something they registered without going through us.
+ if (found == registered_.end()) {
NOTREACHED();
+ return;
}
+ registered_.erase(found);
// This can be NULL if our owner outlives the NotificationService, e.g. if our
// owner is a Singleton.
@@ -65,6 +61,15 @@ void NotificationRegistrar::Remove(NotificationObserver* observer,
}
void NotificationRegistrar::RemoveAll() {
+ // Early-exit if no registrations, to avoid calling
+ // NotificationService::current. If we've constructed an object with a
+ // NotificationRegistrar member, but haven't actually used the notification
+ // service, and we reach prgram exit, then calling current() below could try
+ // to initialize the service's lazy TLS pointer during exit, which throws
+ // wrenches at things.
+ if (registered_.empty())
+ return;
+
// This can be NULL if our owner outlives the NotificationService, e.g. if our
// owner is a Singleton.
NotificationService* service = NotificationService::current();