Chromium Code Reviews| Index: ash/system/web_notification/message_center.cc |
| diff --git a/ash/system/web_notification/message_center.cc b/ash/system/web_notification/message_center.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6c3c165ee3ea4382026423f6afca4f63651f5a79 |
| --- /dev/null |
| +++ b/ash/system/web_notification/message_center.cc |
| @@ -0,0 +1,134 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ash/system/web_notification/message_center.h" |
| +#include "base/logging.h" |
| + |
| +namespace message_center { |
| + |
| +//------------------------------------------------------------------------------ |
| + |
| +MessageCenter::MessageCenter(Host* host) |
| + : host_(host), |
| + delegate_(NULL) { |
| + notification_list_.reset(new WebNotificationList(this)); |
| +} |
| + |
| +MessageCenter::~MessageCenter() { |
| + notification_list_.reset(); |
| +} |
| + |
| +void MessageCenter::SetDelegate(Delegate* delegate) { |
| + DCHECK(!delegate_); |
| + delegate_ = delegate; |
| +} |
| + |
| +void MessageCenter::SetMessageCenterVisible(bool visible) { |
| + notification_list_->SetMessageCenterVisible(visible); |
| +} |
| + |
| +size_t MessageCenter::NotificationCount() const { |
| + return notification_list_->notifications().size(); |
| +} |
| + |
| +size_t MessageCenter::UnreadNotificationCount() const { |
| + return notification_list_->unread_count(); |
| +} |
| + |
| +bool MessageCenter::HasPopupNotifications() const { |
| + return notification_list_->HasPopupNotifications(); |
| +} |
| + |
| +//------------------------------------------------------------------------------ |
| +// Client code interface. |
| + |
| +void MessageCenter::AddNotification(const std::string& id, |
| + const string16& title, |
| + const string16& message, |
|
miket_OOO
2012/10/19 20:45:26
fix ze indent
stevenjb
2012/10/19 21:47:54
Done.
|
| + const string16& display_source, |
| + const std::string& extension_id) { |
| + notification_list_->AddNotification( |
| + id, title, message, display_source, extension_id); |
| + if (host_) |
| + host_->MessageCenterChanged(true); |
| +} |
| + |
| +void MessageCenter::UpdateNotification(const std::string& old_id, |
| + const std::string& new_id, |
| + const string16& title, |
| + const string16& message) { |
| + notification_list_->UpdateNotificationMessage( |
| + old_id, new_id, title, message); |
| + if (host_) |
| + host_->MessageCenterChanged(true); |
| +} |
| + |
| +void MessageCenter::RemoveNotification(const std::string& id) { |
| + if (!notification_list_->RemoveNotification(id)) |
| + return; |
| + if (host_) |
| + host_->MessageCenterChanged(false); |
| +} |
| + |
| +void MessageCenter::SetNotificationImage(const std::string& id, |
| + const gfx::ImageSkia& image) { |
| + if (!notification_list_->SetNotificationImage(id, image)) |
| + return; |
| + if (host_) |
| + host_->MessageCenterChanged(true); |
| +} |
| + |
| +//------------------------------------------------------------------------------ |
| +// Overridden from WebNotificationList::Delegate. |
| + |
| +void MessageCenter::SendRemoveNotification(const std::string& id) { |
| + if (delegate_) |
| + delegate_->NotificationRemoved(id); |
| +} |
| + |
| +void MessageCenter::SendRemoveAllNotifications() { |
| + if (delegate_) { |
| + const WebNotificationList::Notifications& notifications = |
| + notification_list_->notifications(); |
| + for (WebNotificationList::Notifications::const_iterator loopiter = |
| + notifications.begin(); |
| + loopiter != notifications.end(); ) { |
| + WebNotificationList::Notifications::const_iterator curiter = loopiter++; |
| + std::string notification_id = curiter->id; |
| + // May call RemoveNotification and erase curiter. |
| + delegate_->NotificationRemoved(notification_id); |
| + } |
| + } |
| +} |
| + |
| +void MessageCenter::DisableNotificationByExtension( |
| + const std::string& id) { |
| + if (delegate_) |
| + delegate_->DisableExtension(id); |
| + // When we disable notifications, we remove any existing matching |
| + // notifications to avoid adding complicated UI to re-enable the source. |
| + notification_list_->SendRemoveNotificationsByExtension(id); |
| +} |
| + |
| +void MessageCenter::DisableNotificationByUrl(const std::string& id) { |
| + if (delegate_) |
| + delegate_->DisableNotificationsFromSource(id); |
| + notification_list_->SendRemoveNotificationsBySource(id); |
| +} |
| + |
| +void MessageCenter::ShowNotificationSettings(const std::string& id) { |
| + if (delegate_) |
| + delegate_->ShowSettings(id); |
| +} |
| + |
| +void MessageCenter::OnNotificationClicked(const std::string& id) { |
| + if (delegate_) |
| + delegate_->OnClicked(id); |
| +} |
| + |
| +WebNotificationList* MessageCenter::GetNotificationList() { |
| + return notification_list_.get(); |
| +} |
| + |
| +} // namespace message_center |