OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_impl.h" | 5 #include "ui/message_center/message_center_impl.h" |
6 | 6 |
7 #include "base/observer_list.h" | 7 #include "base/observer_list.h" |
8 #include "ui/message_center/message_center_observer.h" | 8 #include "ui/message_center/message_center_observer.h" |
9 #include "ui/message_center/notification.h" | 9 #include "ui/message_center/notification.h" |
10 #include "ui/message_center/notification_list.h" | 10 #include "ui/message_center/notification_list.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 | 57 |
58 bool MessageCenterImpl::HasNotification(const std::string& id) { | 58 bool MessageCenterImpl::HasNotification(const std::string& id) { |
59 return notification_list_->HasNotification(id); | 59 return notification_list_->HasNotification(id); |
60 } | 60 } |
61 | 61 |
62 bool MessageCenterImpl::IsQuietMode() const { | 62 bool MessageCenterImpl::IsQuietMode() const { |
63 return notification_list_->quiet_mode(); | 63 return notification_list_->quiet_mode(); |
64 } | 64 } |
65 | 65 |
66 bool MessageCenterImpl::HasClickedListener(const std::string& id) { | 66 bool MessageCenterImpl::HasClickedListener(const std::string& id) { |
67 return delegate_ && delegate_->HasClickedListener(id); | 67 return delegate_ && delegate_->HasClickedListener(id); |
Jun Mukai
2013/05/24 01:29:19
can you edit here to use GetDelegate?
dewittj
2013/05/24 18:01:00
Done.
| |
68 } | 68 } |
69 | 69 |
70 const NotificationList::Notifications& MessageCenterImpl::GetNotifications() { | 70 const NotificationList::Notifications& MessageCenterImpl::GetNotifications() { |
71 return notification_list_->GetNotifications(); | 71 return notification_list_->GetNotifications(); |
72 } | 72 } |
73 | 73 |
74 NotificationList::PopupNotifications | 74 NotificationList::PopupNotifications |
75 MessageCenterImpl::GetPopupNotifications() { | 75 MessageCenterImpl::GetPopupNotifications() { |
76 return notification_list_->GetPopupNotifications(); | 76 return notification_list_->GetPopupNotifications(); |
77 } | 77 } |
78 | 78 |
79 //------------------------------------------------------------------------------ | 79 //------------------------------------------------------------------------------ |
80 // Client code interface. | 80 // Client code interface. |
81 | 81 |
82 void MessageCenterImpl::AddNotification( | 82 void MessageCenterImpl::AddNotification( |
83 NotificationType type, | 83 NotificationType type, |
84 const std::string& id, | 84 const std::string& id, |
85 const string16& title, | 85 const string16& title, |
86 const string16& message, | 86 const string16& message, |
87 const string16& display_source, | 87 const string16& display_source, |
88 const std::string& extension_id, | 88 const std::string& extension_id, |
89 const base::DictionaryValue* optional_fields) { | 89 const base::DictionaryValue* optional_fields, |
90 NotificationDelegate* delegate) { | |
90 // Sometimes the notification can be added with the same id and the | 91 // Sometimes the notification can be added with the same id and the |
91 // |notification_list| will replace the notification instead of adding new. | 92 // |notification_list| will replace the notification instead of adding new. |
92 // This is essentially an update rather than addition. | 93 // This is essentially an update rather than addition. |
93 bool already_exists = notification_list_->HasNotification(id); | 94 bool already_exists = notification_list_->HasNotification(id); |
94 notification_list_->AddNotification(type, id, title, message, display_source, | 95 notification_list_->AddNotification(type, |
95 extension_id, optional_fields); | 96 id, |
97 title, | |
98 message, | |
99 display_source, | |
100 extension_id, | |
101 optional_fields, | |
102 delegate); | |
96 if (already_exists) { | 103 if (already_exists) { |
97 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, | 104 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, |
98 OnNotificationUpdated(id)); | 105 OnNotificationUpdated(id)); |
99 } else { | 106 } else { |
100 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, | 107 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, |
101 OnNotificationAdded(id)); | 108 OnNotificationAdded(id)); |
102 } | 109 } |
103 } | 110 } |
104 | 111 |
105 void MessageCenterImpl::UpdateNotification( | 112 void MessageCenterImpl::UpdateNotification( |
106 const std::string& old_id, | 113 const std::string& old_id, |
107 const std::string& new_id, | 114 const std::string& new_id, |
108 const string16& title, | 115 const string16& title, |
109 const string16& message, | 116 const string16& message, |
110 const base::DictionaryValue* optional_fields) { | 117 const base::DictionaryValue* optional_fields, |
118 NotificationDelegate* delegate) { | |
111 notification_list_->UpdateNotificationMessage( | 119 notification_list_->UpdateNotificationMessage( |
112 old_id, new_id, title, message, optional_fields); | 120 old_id, new_id, title, message, optional_fields, delegate); |
113 if (old_id == new_id) { | 121 if (old_id == new_id) { |
114 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, | 122 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, |
115 OnNotificationUpdated(new_id)); | 123 OnNotificationUpdated(new_id)); |
116 } else { | 124 } else { |
117 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, | 125 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, |
118 OnNotificationRemoved(old_id, false)); | 126 OnNotificationRemoved(old_id, false)); |
119 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, | 127 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, |
120 OnNotificationAdded(new_id)); | 128 OnNotificationAdded(new_id)); |
121 } | 129 } |
122 } | 130 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 notification_list_->MarkNotificationAsExpanded(id); | 234 notification_list_->MarkNotificationAsExpanded(id); |
227 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, | 235 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, |
228 OnNotificationUpdated(id)); | 236 OnNotificationUpdated(id)); |
229 } | 237 } |
230 | 238 |
231 void MessageCenterImpl::ClickOnNotification(const std::string& id) { | 239 void MessageCenterImpl::ClickOnNotification(const std::string& id) { |
232 if (!HasNotification(id)) | 240 if (!HasNotification(id)) |
233 return; | 241 return; |
234 if (HasPopupNotifications()) | 242 if (HasPopupNotifications()) |
235 MarkSinglePopupAsShown(id, true); | 243 MarkSinglePopupAsShown(id, true); |
236 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, | 244 NotificationDelegate* delegate = |
237 OnNotificationClicked(id)); | 245 notification_list_->GetNotificationDelegate(id); |
246 if (delegate) | |
247 delegate->Click(); | |
248 FOR_EACH_OBSERVER( | |
249 MessageCenterObserver, observer_list_, OnNotificationClicked(id)); | |
238 } | 250 } |
239 | 251 |
240 void MessageCenterImpl::ClickOnNotificationButton(const std::string& id, | 252 void MessageCenterImpl::ClickOnNotificationButton(const std::string& id, |
241 int button_index) { | 253 int button_index) { |
242 if (!HasNotification(id)) | 254 if (!HasNotification(id)) |
243 return; | 255 return; |
244 if (HasPopupNotifications()) | 256 if (HasPopupNotifications()) |
245 MarkSinglePopupAsShown(id, true); | 257 MarkSinglePopupAsShown(id, true); |
246 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, | 258 NotificationDelegate* delegate = |
259 notification_list_->GetNotificationDelegate(id); | |
260 if (delegate) | |
261 delegate->ButtonClick(button_index); | |
262 FOR_EACH_OBSERVER(MessageCenterObserver, | |
263 observer_list_, | |
247 OnNotificationButtonClicked(id, button_index)); | 264 OnNotificationButtonClicked(id, button_index)); |
248 } | 265 } |
249 | 266 |
250 void MessageCenterImpl::MarkSinglePopupAsShown(const std::string& id, | 267 void MessageCenterImpl::MarkSinglePopupAsShown(const std::string& id, |
251 bool mark_notification_as_read) { | 268 bool mark_notification_as_read) { |
252 if (!HasNotification(id)) | 269 if (!HasNotification(id)) |
253 return; | 270 return; |
254 notification_list_->MarkSinglePopupAsShown(id, mark_notification_as_read); | 271 notification_list_->MarkSinglePopupAsShown(id, mark_notification_as_read); |
255 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, | 272 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, |
256 OnNotificationUpdated(id)); | 273 OnNotificationUpdated(id)); |
257 } | 274 } |
258 | 275 |
259 void MessageCenterImpl::DisplayedNotification(const std::string& id) { | 276 void MessageCenterImpl::DisplayedNotification(const std::string& id) { |
260 if (!HasNotification(id)) | 277 if (!HasNotification(id)) |
261 return; | 278 return; |
262 | 279 |
263 if (HasPopupNotifications()) | 280 if (HasPopupNotifications()) |
264 notification_list_->MarkSinglePopupAsDisplayed(id); | 281 notification_list_->MarkSinglePopupAsDisplayed(id); |
265 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, | 282 NotificationDelegate* delegate = |
266 OnNotificationDisplayed(id)); | 283 notification_list_->GetNotificationDelegate(id); |
284 if (delegate) | |
285 delegate->Display(); | |
286 FOR_EACH_OBSERVER( | |
287 MessageCenterObserver, observer_list_, OnNotificationDisplayed(id)); | |
267 } | 288 } |
268 | 289 |
269 void MessageCenterImpl::SetQuietMode(bool in_quiet_mode) { | 290 void MessageCenterImpl::SetQuietMode(bool in_quiet_mode) { |
270 notification_list_->SetQuietMode(in_quiet_mode); | 291 notification_list_->SetQuietMode(in_quiet_mode); |
271 } | 292 } |
272 | 293 |
273 void MessageCenterImpl::EnterQuietModeWithExpire( | 294 void MessageCenterImpl::EnterQuietModeWithExpire( |
274 const base::TimeDelta& expires_in) { | 295 const base::TimeDelta& expires_in) { |
275 notification_list_->EnterQuietModeWithExpire(expires_in); | 296 notification_list_->EnterQuietModeWithExpire(expires_in); |
276 } | 297 } |
277 | 298 |
278 } // namespace message_center | 299 } // namespace message_center |
OLD | NEW |