Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Unified Diff: ash/system/web_notification/message_center.cc

Issue 11189099: Re-factor Ash Message Center code part 4/4 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/system/web_notification/message_center.h ('k') | ash/system/web_notification/web_notification_list.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0032c97c8e9789cf8ecc1cfaa1228eff80050836
--- /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,
+ 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
« no previous file with comments | « ash/system/web_notification/message_center.h ('k') | ash/system/web_notification/web_notification_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698