diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-05 18:52:03 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-05 18:52:03 +0000 |
commit | fbee5cb8c9797b4fe08afae83ac758a9aec7f7f5 (patch) | |
tree | 74e90131fd87a7ffeca301aec81d29821c2de5c7 /chrome/common | |
parent | a861c9dcaef31d0dad9fbc78a6093f025d564169 (diff) | |
download | chromium_src-fbee5cb8c9797b4fe08afae83ac758a9aec7f7f5.zip chromium_src-fbee5cb8c9797b4fe08afae83ac758a9aec7f7f5.tar.gz chromium_src-fbee5cb8c9797b4fe08afae83ac758a9aec7f7f5.tar.bz2 |
Add the ability for NotificationRegistrar users to check if a particular notification is registered.
BUG=54274
TEST=none
Review URL: http://codereview.chromium.org/4574002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65233 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/notification_registrar.cc | 23 | ||||
-rw-r--r-- | chrome/common/notification_registrar.h | 6 |
2 files changed, 21 insertions, 8 deletions
diff --git a/chrome/common/notification_registrar.cc b/chrome/common/notification_registrar.cc index 7ec5cda..d413585 100644 --- a/chrome/common/notification_registrar.cc +++ b/chrome/common/notification_registrar.cc @@ -47,10 +47,9 @@ NotificationRegistrar::~NotificationRegistrar() { void NotificationRegistrar::Add(NotificationObserver* observer, NotificationType type, const NotificationSource& source) { - Record record = { observer, type, source, PlatformThread::CurrentId() }; + DCHECK(!IsRegistered(observer, type, source)) << "Duplicate registration."; - DCHECK(std::find(registered_.begin(), registered_.end(), record) == - registered_.end()) << "Duplicate registration."; + Record record = { observer, type, source, PlatformThread::CurrentId() }; registered_.push_back(record); NotificationService::current()->AddObserver(observer, type, source); @@ -59,16 +58,16 @@ void NotificationRegistrar::Add(NotificationObserver* observer, void NotificationRegistrar::Remove(NotificationObserver* observer, NotificationType type, const NotificationSource& source) { - Record record = { observer, type, source }; - RecordVector::iterator found = std::find( - registered_.begin(), registered_.end(), record); - if (found == registered_.end()) { + if (!IsRegistered(observer, type, source)) { NOTREACHED() << "Trying to remove unregistered observer of type " << type.value << " from list of size " << registered_.size() << "."; return; } - CheckCalledOnValidThread(found->thread_id); + Record record = { observer, type, source }; + RecordVector::iterator found = std::find( + registered_.begin(), registered_.end(), record); + CheckCalledOnValidThread(found->thread_id); registered_.erase(found); // This can be NULL if our owner outlives the NotificationService, e.g. if our @@ -106,3 +105,11 @@ void NotificationRegistrar::RemoveAll() { bool NotificationRegistrar::IsEmpty() const { return registered_.empty(); } + +bool NotificationRegistrar::IsRegistered(NotificationObserver* observer, + NotificationType type, + const NotificationSource& source) { + Record record = { observer, type, source }; + return std::find(registered_.begin(), registered_.end(), record) != + registered_.end(); +} diff --git a/chrome/common/notification_registrar.h b/chrome/common/notification_registrar.h index 1207d99..9048560 100644 --- a/chrome/common/notification_registrar.h +++ b/chrome/common/notification_registrar.h @@ -42,6 +42,12 @@ class NotificationRegistrar { // Returns true if no notifications are registered. bool IsEmpty() const; + // Returns true if there is already a registered notification with the + // specified details. + bool IsRegistered(NotificationObserver* observer, + NotificationType type, + const NotificationSource& source); + private: struct Record; |