diff options
Diffstat (limited to 'chrome/common/notification_registrar.cc')
-rw-r--r-- | chrome/common/notification_registrar.cc | 19 |
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(); |