diff options
Diffstat (limited to 'chrome/browser/notifications/notification_ui_manager.cc')
-rw-r--r-- | chrome/browser/notifications/notification_ui_manager.cc | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/chrome/browser/notifications/notification_ui_manager.cc b/chrome/browser/notifications/notification_ui_manager.cc index adc44cf..6e2ff02 100644 --- a/chrome/browser/notifications/notification_ui_manager.cc +++ b/chrome/browser/notifications/notification_ui_manager.cc @@ -10,6 +10,8 @@ #include "chrome/browser/notifications/balloon_collection.h" #include "chrome/browser/notifications/notification.h" #include "chrome/browser/renderer_host/site_instance.h" +#include "chrome/common/notification_service.h" +#include "chrome/common/notification_type.h" // A class which represents a notification waiting to be shown. class QueuedNotification { @@ -38,6 +40,8 @@ class QueuedNotification { NotificationUIManager::NotificationUIManager() : balloon_collection_(NULL) { + registrar_.Add(this, NotificationType::APP_TERMINATING, + NotificationService::AllSources()); } NotificationUIManager::~NotificationUIManager() { @@ -66,17 +70,39 @@ void NotificationUIManager::Add(const Notification& notification, CheckAndShowNotifications(); } -bool NotificationUIManager::Cancel(const Notification& notification) { - // First look through the notifications that haven't been shown. If not - // found there, call to the active balloon collection to tear it down. +bool NotificationUIManager::CancelById(const std::string& id) { + // See if this ID hasn't been shown yet. NotificationDeque::iterator iter; for (iter = show_queue_.begin(); iter != show_queue_.end(); ++iter) { - if (notification.IsSame((*iter)->notification())) { + if ((*iter)->notification().notification_id() == id) { show_queue_.erase(iter); return true; } } - return balloon_collection_->Remove(notification); + // If it has been shown, remove it from the balloon collections. + return balloon_collection_->RemoveById(id); +} + +bool NotificationUIManager::CancelAllBySourceOrigin(const GURL& source) { + // Same pattern as CancelById, but more complicated than the above + // because there may be multiple notifications from the same source. + bool removed = false; + NotificationDeque::iterator iter; + for (iter = show_queue_.begin(); iter != show_queue_.end();) { + if ((*iter)->notification().origin_url() == source) { + iter = show_queue_.erase(iter); + removed = true; + } else { + ++iter; + } + } + + return balloon_collection_->RemoveBySourceOrigin(source) || removed; +} + +void NotificationUIManager::CancelAll() { + STLDeleteElements(&show_queue_); + balloon_collection_->RemoveAll(); } void NotificationUIManager::CheckAndShowNotifications() { @@ -130,3 +156,12 @@ bool NotificationUIManager::TryReplacement(const Notification& notification) { return false; } + +void NotificationUIManager::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + if (type == NotificationType::APP_TERMINATING) + CancelAll(); + else + NOTREACHED(); +} |