OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/message_center/message_center.h" | 5 #include "ui/message_center/message_center.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
| 10 #include "ui/message_center/notification.h" |
| 11 #include "ui/message_center/notification_list.h" |
10 | 12 |
11 namespace message_center { | 13 namespace message_center { |
12 | 14 |
13 //------------------------------------------------------------------------------ | 15 //------------------------------------------------------------------------------ |
14 MessageCenter::MessageCenter() | 16 MessageCenter::MessageCenter() |
15 : delegate_(NULL) { | 17 : delegate_(NULL) { |
16 notification_list_.reset(new NotificationList(this)); | 18 notification_list_.reset(new NotificationList(this)); |
17 } | 19 } |
18 | 20 |
19 MessageCenter::~MessageCenter() { | 21 MessageCenter::~MessageCenter() { |
(...skipping 25 matching lines...) Expand all Loading... |
45 } | 47 } |
46 | 48 |
47 bool MessageCenter::HasPopupNotifications() const { | 49 bool MessageCenter::HasPopupNotifications() const { |
48 return notification_list_->HasPopupNotifications(); | 50 return notification_list_->HasPopupNotifications(); |
49 } | 51 } |
50 | 52 |
51 //------------------------------------------------------------------------------ | 53 //------------------------------------------------------------------------------ |
52 // Client code interface. | 54 // Client code interface. |
53 | 55 |
54 void MessageCenter::AddNotification( | 56 void MessageCenter::AddNotification( |
55 ui::notifications::NotificationType type, | 57 NotificationType type, |
56 const std::string& id, | 58 const std::string& id, |
57 const string16& title, | 59 const string16& title, |
58 const string16& message, | 60 const string16& message, |
59 const string16& display_source, | 61 const string16& display_source, |
60 const std::string& extension_id, | 62 const std::string& extension_id, |
61 const base::DictionaryValue* optional_fields) { | 63 const base::DictionaryValue* optional_fields) { |
62 notification_list_->AddNotification(type, id, title, message, display_source, | 64 notification_list_->AddNotification(type, id, title, message, display_source, |
63 extension_id, optional_fields); | 65 extension_id, optional_fields); |
64 NotifyMessageCenterChanged(true); | 66 NotifyMessageCenterChanged(true); |
65 } | 67 } |
66 | 68 |
67 void MessageCenter::UpdateNotification( | 69 void MessageCenter::UpdateNotification( |
68 const std::string& old_id, | 70 const std::string& old_id, |
69 const std::string& new_id, | 71 const std::string& new_id, |
70 const string16& title, | 72 const string16& title, |
71 const string16& message, | 73 const string16& message, |
72 const base::DictionaryValue* optional_fields) { | 74 const base::DictionaryValue* optional_fields) { |
73 notification_list_->UpdateNotificationMessage( | 75 notification_list_->UpdateNotificationMessage( |
74 old_id, new_id, title, message, optional_fields); | 76 old_id, new_id, title, message, optional_fields); |
75 NotifyMessageCenterChanged(true); | 77 NotifyMessageCenterChanged(true); |
76 } | 78 } |
77 | 79 |
78 void MessageCenter::RemoveNotification(const std::string& id) { | 80 void MessageCenter::RemoveNotification(const std::string& id) { |
79 if (!notification_list_->RemoveNotification(id)) | 81 notification_list_->RemoveNotification(id); |
80 return; | |
81 NotifyMessageCenterChanged(false); | 82 NotifyMessageCenterChanged(false); |
82 } | 83 } |
83 | 84 |
84 void MessageCenter::SetNotificationIcon(const std::string& notification_id, | 85 void MessageCenter::SetNotificationIcon(const std::string& notification_id, |
85 const gfx::ImageSkia& image) { | 86 const gfx::ImageSkia& image) { |
86 if (notification_list_->SetNotificationIcon(notification_id, image)) | 87 if (notification_list_->SetNotificationIcon(notification_id, image)) |
87 NotifyMessageCenterChanged(true); | 88 NotifyMessageCenterChanged(true); |
88 } | 89 } |
89 | 90 |
90 void MessageCenter::SetNotificationImage(const std::string& notification_id, | 91 void MessageCenter::SetNotificationImage(const std::string& notification_id, |
(...skipping 13 matching lines...) Expand all Loading... |
104 //------------------------------------------------------------------------------ | 105 //------------------------------------------------------------------------------ |
105 // Overridden from NotificationList::Delegate. | 106 // Overridden from NotificationList::Delegate. |
106 | 107 |
107 void MessageCenter::SendRemoveNotification(const std::string& id) { | 108 void MessageCenter::SendRemoveNotification(const std::string& id) { |
108 if (delegate_) | 109 if (delegate_) |
109 delegate_->NotificationRemoved(id); | 110 delegate_->NotificationRemoved(id); |
110 } | 111 } |
111 | 112 |
112 void MessageCenter::SendRemoveAllNotifications() { | 113 void MessageCenter::SendRemoveAllNotifications() { |
113 if (delegate_) { | 114 if (delegate_) { |
114 NotificationList::Notifications notifications; | 115 const NotificationList::Notifications& notifications = |
115 notification_list_->GetNotifications(¬ifications); | 116 notification_list_->GetNotifications(); |
116 for (NotificationList::Notifications::const_iterator loopiter = | 117 for (NotificationList::Notifications::const_iterator loopiter = |
117 notifications.begin(); | 118 notifications.begin(); |
118 loopiter != notifications.end(); ) { | 119 loopiter != notifications.end(); ) { |
119 NotificationList::Notifications::const_iterator curiter = loopiter++; | 120 NotificationList::Notifications::const_iterator curiter = loopiter++; |
120 std::string notification_id = curiter->id; | 121 std::string notification_id = (*curiter)->id(); |
121 // May call RemoveNotification and erase curiter. | 122 // May call RemoveNotification and erase curiter. |
122 delegate_->NotificationRemoved(notification_id); | 123 delegate_->NotificationRemoved(notification_id); |
123 } | 124 } |
124 } | 125 } |
125 } | 126 } |
126 | 127 |
127 void MessageCenter::DisableNotificationByExtension( | 128 void MessageCenter::DisableNotificationByExtension( |
128 const std::string& id) { | 129 const std::string& id) { |
129 if (delegate_) | 130 if (delegate_) |
130 delegate_->DisableExtension(id); | 131 delegate_->DisableExtension(id); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // Private. | 184 // Private. |
184 | 185 |
185 void MessageCenter::NotifyMessageCenterChanged(bool new_notification) { | 186 void MessageCenter::NotifyMessageCenterChanged(bool new_notification) { |
186 FOR_EACH_OBSERVER(Observer, | 187 FOR_EACH_OBSERVER(Observer, |
187 observer_list_, | 188 observer_list_, |
188 OnMessageCenterChanged(new_notification)); | 189 OnMessageCenterChanged(new_notification)); |
189 } | 190 } |
190 | 191 |
191 | 192 |
192 } // namespace message_center | 193 } // namespace message_center |
OLD | NEW |