From bfd04a62ce610d7bb61dbb78811dccbed23589b7 Mon Sep 17 00:00:00 2001 From: "brettw@chromium.org" Date: Sun, 1 Feb 2009 18:16:56 +0000 Subject: Remove most header file dependencies on the notification type list. It is really painful to add more types, since lots of headers include the notification service to derive from the notification observer. This splits that out, so much less of the project should end up including notification_types.h ---Paths modified but not in any changelist: Review URL: http://codereview.chromium.org/19744 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9020 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/common/notification_service.cc | 59 ++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 25 deletions(-) (limited to 'chrome/common/notification_service.cc') diff --git a/chrome/common/notification_service.cc b/chrome/common/notification_service.cc index dccadbe..5b732df 100644 --- a/chrome/common/notification_service.cc +++ b/chrome/common/notification_service.cc @@ -33,33 +33,34 @@ NotificationService::NotificationService() { void NotificationService::AddObserver(NotificationObserver* observer, NotificationType type, const NotificationSource& source) { - DCHECK(type < NOTIFICATION_TYPE_COUNT); + DCHECK(type.value < NotificationType::NOTIFICATION_TYPE_COUNT); NotificationObserverList* observer_list; - if (HasKey(observers_[type], source)) { - observer_list = observers_[type][source.map_key()]; + if (HasKey(observers_[type.value], source)) { + observer_list = observers_[type.value][source.map_key()]; } else { observer_list = new NotificationObserverList; - observers_[type][source.map_key()] = observer_list; + observers_[type.value][source.map_key()] = observer_list; } observer_list->AddObserver(observer); #ifndef NDEBUG - ++observer_counts_[type]; + ++observer_counts_[type.value]; #endif } void NotificationService::RemoveObserver(NotificationObserver* observer, NotificationType type, const NotificationSource& source) { - DCHECK(type < NOTIFICATION_TYPE_COUNT); - DCHECK(HasKey(observers_[type], source)); + DCHECK(type.value < NotificationType::NOTIFICATION_TYPE_COUNT); + DCHECK(HasKey(observers_[type.value], source)); - NotificationObserverList* observer_list = observers_[type][source.map_key()]; + NotificationObserverList* observer_list = + observers_[type.value][source.map_key()]; if (observer_list) { observer_list->RemoveObserver(observer); #ifndef NDEBUG - --observer_counts_[type]; + --observer_counts_[type.value]; #endif } @@ -69,34 +70,42 @@ void NotificationService::RemoveObserver(NotificationObserver* observer, void NotificationService::Notify(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { - DCHECK(type > NOTIFY_ALL); // Allowed for subscription, but not posting. - DCHECK(type < NOTIFICATION_TYPE_COUNT); + DCHECK(type.value > NotificationType::ALL) << + "Allowed for observing, but not posting."; + DCHECK(type.value < NotificationType::NOTIFICATION_TYPE_COUNT); // There's no particular reason for the order in which the different // classes of observers get notified here. // Notify observers of all types and all sources - if (HasKey(observers_[NOTIFY_ALL], AllSources()) && - source != AllSources()) + if (HasKey(observers_[NotificationType::ALL], AllSources()) && + source != AllSources()) { FOR_EACH_OBSERVER(NotificationObserver, - *observers_[NOTIFY_ALL][AllSources().map_key()], - Observe(type, source, details)); + *observers_[NotificationType::ALL][AllSources().map_key()], + Observe(type, source, details)); + } + // Notify observers of all types and the given source - if (HasKey(observers_[NOTIFY_ALL], source)) + if (HasKey(observers_[NotificationType::ALL], source)) { FOR_EACH_OBSERVER(NotificationObserver, - *observers_[NOTIFY_ALL][source.map_key()], - Observe(type, source, details)); + *observers_[NotificationType::ALL][source.map_key()], + Observe(type, source, details)); + } + // Notify observers of the given type and all sources - if (HasKey(observers_[type], AllSources()) && - source != AllSources()) + if (HasKey(observers_[type.value], AllSources()) && + source != AllSources()) { FOR_EACH_OBSERVER(NotificationObserver, - *observers_[type][AllSources().map_key()], + *observers_[type.value][AllSources().map_key()], Observe(type, source, details)); + } + // Notify observers of the given type and the given source - if (HasKey(observers_[type], source)) + if (HasKey(observers_[type.value], source)) { FOR_EACH_OBSERVER(NotificationObserver, - *observers_[type][source.map_key()], + *observers_[type.value][source.map_key()], Observe(type, source, details)); + } } @@ -104,7 +113,7 @@ NotificationService::~NotificationService() { lazy_tls_ptr.Pointer()->Set(NULL); #ifndef NDEBUG - for (int i = 0; i < NOTIFICATION_TYPE_COUNT; i++) { + for (int i = 0; i < NotificationType::NOTIFICATION_TYPE_COUNT; i++) { if (observer_counts_[i] > 0) { LOG(WARNING) << observer_counts_[i] << " notification observer(s) leaked" << " of notification type " << i; @@ -112,7 +121,7 @@ NotificationService::~NotificationService() { } #endif - for (int i = 0; i < NOTIFICATION_TYPE_COUNT; i++) { + for (int i = 0; i < NotificationType::NOTIFICATION_TYPE_COUNT; i++) { NotificationSourceMap omap = observers_[i]; for (NotificationSourceMap::iterator it = omap.begin(); it != omap.end(); ++it) { -- cgit v1.1