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

Side by Side Diff: ui/message_center/message_center_impl.cc

Issue 15582004: Move NotificationDelegate into message_center. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix the ever-changing Mac unit tests. Created 7 years, 7 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 unified diff | Download patch
OLDNEW
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
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 NotificationDelegate* delegate =
68 notification_list_->GetNotificationDelegate(id);
69 return delegate && delegate->HasClickedListener();
68 } 70 }
69 71
70 const NotificationList::Notifications& MessageCenterImpl::GetNotifications() { 72 const NotificationList::Notifications& MessageCenterImpl::GetNotifications() {
71 return notification_list_->GetNotifications(); 73 return notification_list_->GetNotifications();
72 } 74 }
73 75
74 NotificationList::PopupNotifications 76 NotificationList::PopupNotifications
75 MessageCenterImpl::GetPopupNotifications() { 77 MessageCenterImpl::GetPopupNotifications() {
76 return notification_list_->GetPopupNotifications(); 78 return notification_list_->GetPopupNotifications();
77 } 79 }
78 80
79 //------------------------------------------------------------------------------ 81 //------------------------------------------------------------------------------
80 // Client code interface. 82 // Client code interface.
81 83
82 void MessageCenterImpl::AddNotification( 84 void MessageCenterImpl::AddNotification(
83 NotificationType type, 85 NotificationType type,
84 const std::string& id, 86 const std::string& id,
85 const string16& title, 87 const string16& title,
86 const string16& message, 88 const string16& message,
87 const string16& display_source, 89 const string16& display_source,
88 const std::string& extension_id, 90 const std::string& extension_id,
89 const base::DictionaryValue* optional_fields) { 91 const base::DictionaryValue* optional_fields,
92 NotificationDelegate* delegate) {
90 // Sometimes the notification can be added with the same id and the 93 // Sometimes the notification can be added with the same id and the
91 // |notification_list| will replace the notification instead of adding new. 94 // |notification_list| will replace the notification instead of adding new.
92 // This is essentially an update rather than addition. 95 // This is essentially an update rather than addition.
93 bool already_exists = notification_list_->HasNotification(id); 96 bool already_exists = notification_list_->HasNotification(id);
94 notification_list_->AddNotification(type, id, title, message, display_source, 97 notification_list_->AddNotification(type,
95 extension_id, optional_fields); 98 id,
99 title,
100 message,
101 display_source,
102 extension_id,
103 optional_fields,
104 delegate);
96 if (already_exists) { 105 if (already_exists) {
97 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 106 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
98 OnNotificationUpdated(id)); 107 OnNotificationUpdated(id));
99 } else { 108 } else {
100 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 109 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
101 OnNotificationAdded(id)); 110 OnNotificationAdded(id));
102 } 111 }
103 } 112 }
104 113
105 void MessageCenterImpl::UpdateNotification( 114 void MessageCenterImpl::UpdateNotification(
106 const std::string& old_id, 115 const std::string& old_id,
107 const std::string& new_id, 116 const std::string& new_id,
108 const string16& title, 117 const string16& title,
109 const string16& message, 118 const string16& message,
110 const base::DictionaryValue* optional_fields) { 119 const base::DictionaryValue* optional_fields,
120 NotificationDelegate* delegate) {
111 notification_list_->UpdateNotificationMessage( 121 notification_list_->UpdateNotificationMessage(
112 old_id, new_id, title, message, optional_fields); 122 old_id, new_id, title, message, optional_fields, delegate);
113 if (old_id == new_id) { 123 if (old_id == new_id) {
114 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 124 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
115 OnNotificationUpdated(new_id)); 125 OnNotificationUpdated(new_id));
116 } else { 126 } else {
117 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 127 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
118 OnNotificationRemoved(old_id, false)); 128 OnNotificationRemoved(old_id, false));
119 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 129 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
120 OnNotificationAdded(new_id)); 130 OnNotificationAdded(new_id));
121 } 131 }
122 } 132 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 notification_list_->MarkNotificationAsExpanded(id); 236 notification_list_->MarkNotificationAsExpanded(id);
227 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 237 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
228 OnNotificationUpdated(id)); 238 OnNotificationUpdated(id));
229 } 239 }
230 240
231 void MessageCenterImpl::ClickOnNotification(const std::string& id) { 241 void MessageCenterImpl::ClickOnNotification(const std::string& id) {
232 if (!HasNotification(id)) 242 if (!HasNotification(id))
233 return; 243 return;
234 if (HasPopupNotifications()) 244 if (HasPopupNotifications())
235 MarkSinglePopupAsShown(id, true); 245 MarkSinglePopupAsShown(id, true);
236 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 246 NotificationDelegate* delegate =
237 OnNotificationClicked(id)); 247 notification_list_->GetNotificationDelegate(id);
248 if (delegate)
249 delegate->Click();
250 FOR_EACH_OBSERVER(
251 MessageCenterObserver, observer_list_, OnNotificationClicked(id));
238 } 252 }
239 253
240 void MessageCenterImpl::ClickOnNotificationButton(const std::string& id, 254 void MessageCenterImpl::ClickOnNotificationButton(const std::string& id,
241 int button_index) { 255 int button_index) {
242 if (!HasNotification(id)) 256 if (!HasNotification(id))
243 return; 257 return;
244 if (HasPopupNotifications()) 258 if (HasPopupNotifications())
245 MarkSinglePopupAsShown(id, true); 259 MarkSinglePopupAsShown(id, true);
246 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 260 NotificationDelegate* delegate =
247 OnNotificationButtonClicked(id, button_index)); 261 notification_list_->GetNotificationDelegate(id);
262 if (delegate)
263 delegate->ButtonClick(button_index);
264 FOR_EACH_OBSERVER(
265 MessageCenterObserver, observer_list_, OnNotificationButtonClicked(
266 id, button_index));
248 } 267 }
249 268
250 void MessageCenterImpl::MarkSinglePopupAsShown(const std::string& id, 269 void MessageCenterImpl::MarkSinglePopupAsShown(const std::string& id,
251 bool mark_notification_as_read) { 270 bool mark_notification_as_read) {
252 if (!HasNotification(id)) 271 if (!HasNotification(id))
253 return; 272 return;
254 notification_list_->MarkSinglePopupAsShown(id, mark_notification_as_read); 273 notification_list_->MarkSinglePopupAsShown(id, mark_notification_as_read);
255 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 274 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
256 OnNotificationUpdated(id)); 275 OnNotificationUpdated(id));
257 } 276 }
258 277
259 void MessageCenterImpl::DisplayedNotification(const std::string& id) { 278 void MessageCenterImpl::DisplayedNotification(const std::string& id) {
260 if (!HasNotification(id)) 279 if (!HasNotification(id))
261 return; 280 return;
262 281
263 if (HasPopupNotifications()) 282 if (HasPopupNotifications())
264 notification_list_->MarkSinglePopupAsDisplayed(id); 283 notification_list_->MarkSinglePopupAsDisplayed(id);
265 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 284 NotificationDelegate* delegate =
266 OnNotificationDisplayed(id)); 285 notification_list_->GetNotificationDelegate(id);
286 if (delegate)
287 delegate->Display();
288 FOR_EACH_OBSERVER(
289 MessageCenterObserver, observer_list_, OnNotificationDisplayed(id));
267 } 290 }
268 291
269 void MessageCenterImpl::SetQuietMode(bool in_quiet_mode) { 292 void MessageCenterImpl::SetQuietMode(bool in_quiet_mode) {
270 notification_list_->SetQuietMode(in_quiet_mode); 293 notification_list_->SetQuietMode(in_quiet_mode);
271 } 294 }
272 295
273 void MessageCenterImpl::EnterQuietModeWithExpire( 296 void MessageCenterImpl::EnterQuietModeWithExpire(
274 const base::TimeDelta& expires_in) { 297 const base::TimeDelta& expires_in) {
275 notification_list_->EnterQuietModeWithExpire(expires_in); 298 notification_list_->EnterQuietModeWithExpire(expires_in);
276 } 299 }
277 300
278 } // namespace message_center 301 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/message_center_impl.h ('k') | ui/message_center/message_center_tray_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698