Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/system/web_notification/message_center.h" | |
| 6 #include "base/logging.h" | |
| 7 | |
| 8 namespace message_center { | |
| 9 | |
| 10 //------------------------------------------------------------------------------ | |
| 11 | |
| 12 MessageCenter::MessageCenter(Host* host) | |
| 13 : host_(host), | |
| 14 delegate_(NULL) { | |
| 15 notification_list_.reset(new WebNotificationList(this)); | |
| 16 } | |
| 17 | |
| 18 MessageCenter::~MessageCenter() { | |
| 19 notification_list_.reset(); | |
| 20 } | |
| 21 | |
| 22 void MessageCenter::SetDelegate(Delegate* delegate) { | |
| 23 DCHECK(!delegate_); | |
| 24 delegate_ = delegate; | |
| 25 } | |
| 26 | |
| 27 void MessageCenter::SetMessageCenterVisible(bool visible) { | |
| 28 notification_list_->SetMessageCenterVisible(visible); | |
| 29 } | |
| 30 | |
| 31 size_t MessageCenter::NotificationCount() const { | |
| 32 return notification_list_->notifications().size(); | |
| 33 } | |
| 34 | |
| 35 size_t MessageCenter::UnreadNotificationCount() const { | |
| 36 return notification_list_->unread_count(); | |
| 37 } | |
| 38 | |
| 39 bool MessageCenter::HasPopupNotifications() const { | |
| 40 return notification_list_->HasPopupNotifications(); | |
| 41 } | |
| 42 | |
| 43 //------------------------------------------------------------------------------ | |
| 44 // Client code interface. | |
| 45 | |
| 46 void MessageCenter::AddNotification(const std::string& id, | |
| 47 const string16& title, | |
| 48 const string16& message, | |
|
miket_OOO
2012/10/19 20:45:26
fix ze indent
stevenjb
2012/10/19 21:47:54
Done.
| |
| 49 const string16& display_source, | |
| 50 const std::string& extension_id) { | |
| 51 notification_list_->AddNotification( | |
| 52 id, title, message, display_source, extension_id); | |
| 53 if (host_) | |
| 54 host_->MessageCenterChanged(true); | |
| 55 } | |
| 56 | |
| 57 void MessageCenter::UpdateNotification(const std::string& old_id, | |
| 58 const std::string& new_id, | |
| 59 const string16& title, | |
| 60 const string16& message) { | |
| 61 notification_list_->UpdateNotificationMessage( | |
| 62 old_id, new_id, title, message); | |
| 63 if (host_) | |
| 64 host_->MessageCenterChanged(true); | |
| 65 } | |
| 66 | |
| 67 void MessageCenter::RemoveNotification(const std::string& id) { | |
| 68 if (!notification_list_->RemoveNotification(id)) | |
| 69 return; | |
| 70 if (host_) | |
| 71 host_->MessageCenterChanged(false); | |
| 72 } | |
| 73 | |
| 74 void MessageCenter::SetNotificationImage(const std::string& id, | |
| 75 const gfx::ImageSkia& image) { | |
| 76 if (!notification_list_->SetNotificationImage(id, image)) | |
| 77 return; | |
| 78 if (host_) | |
| 79 host_->MessageCenterChanged(true); | |
| 80 } | |
| 81 | |
| 82 //------------------------------------------------------------------------------ | |
| 83 // Overridden from WebNotificationList::Delegate. | |
| 84 | |
| 85 void MessageCenter::SendRemoveNotification(const std::string& id) { | |
| 86 if (delegate_) | |
| 87 delegate_->NotificationRemoved(id); | |
| 88 } | |
| 89 | |
| 90 void MessageCenter::SendRemoveAllNotifications() { | |
| 91 if (delegate_) { | |
| 92 const WebNotificationList::Notifications& notifications = | |
| 93 notification_list_->notifications(); | |
| 94 for (WebNotificationList::Notifications::const_iterator loopiter = | |
| 95 notifications.begin(); | |
| 96 loopiter != notifications.end(); ) { | |
| 97 WebNotificationList::Notifications::const_iterator curiter = loopiter++; | |
| 98 std::string notification_id = curiter->id; | |
| 99 // May call RemoveNotification and erase curiter. | |
| 100 delegate_->NotificationRemoved(notification_id); | |
| 101 } | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 void MessageCenter::DisableNotificationByExtension( | |
| 106 const std::string& id) { | |
| 107 if (delegate_) | |
| 108 delegate_->DisableExtension(id); | |
| 109 // When we disable notifications, we remove any existing matching | |
| 110 // notifications to avoid adding complicated UI to re-enable the source. | |
| 111 notification_list_->SendRemoveNotificationsByExtension(id); | |
| 112 } | |
| 113 | |
| 114 void MessageCenter::DisableNotificationByUrl(const std::string& id) { | |
| 115 if (delegate_) | |
| 116 delegate_->DisableNotificationsFromSource(id); | |
| 117 notification_list_->SendRemoveNotificationsBySource(id); | |
| 118 } | |
| 119 | |
| 120 void MessageCenter::ShowNotificationSettings(const std::string& id) { | |
| 121 if (delegate_) | |
| 122 delegate_->ShowSettings(id); | |
| 123 } | |
| 124 | |
| 125 void MessageCenter::OnNotificationClicked(const std::string& id) { | |
| 126 if (delegate_) | |
| 127 delegate_->OnClicked(id); | |
| 128 } | |
| 129 | |
| 130 WebNotificationList* MessageCenter::GetNotificationList() { | |
| 131 return notification_list_.get(); | |
| 132 } | |
| 133 | |
| 134 } // namespace message_center | |
| OLD | NEW |