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 "chrome/browser/notifications/message_center_notification_manager.h" | 5 #include "chrome/browser/notifications/message_center_notification_manager.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "chrome/browser/extensions/extension_info_map.h" | 10 #include "chrome/browser/extensions/extension_info_map.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 old_notification->notification().Close(false); // Not by user. | 144 old_notification->notification().Close(false); // Not by user. |
145 delete old_notification; | 145 delete old_notification; |
146 profile_notifications_.erase(old_id); | 146 profile_notifications_.erase(old_id); |
147 ProfileNotification* new_notification = | 147 ProfileNotification* new_notification = |
148 new ProfileNotification(profile, notification, message_center_); | 148 new ProfileNotification(profile, notification, message_center_); |
149 profile_notifications_[notification.notification_id()] = new_notification; | 149 profile_notifications_[notification.notification_id()] = new_notification; |
150 message_center_->UpdateNotification(old_id, | 150 message_center_->UpdateNotification(old_id, |
151 notification.notification_id(), | 151 notification.notification_id(), |
152 notification.title(), | 152 notification.title(), |
153 notification.body(), | 153 notification.body(), |
154 notification.optional_fields()); | 154 notification.optional_fields(), |
| 155 notification.delegate()); |
155 new_notification->StartDownloads(); | 156 new_notification->StartDownloads(); |
156 return true; | 157 return true; |
157 } | 158 } |
158 } | 159 } |
159 return false; | 160 return false; |
160 } | 161 } |
161 | 162 |
162 //////////////////////////////////////////////////////////////////////////////// | 163 //////////////////////////////////////////////////////////////////////////////// |
163 // MessageCenter::Delegate | 164 // MessageCenter::Delegate |
164 | 165 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 222 chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
222 else | 223 else |
223 chrome::ShowExtensions(browser, std::string()); | 224 chrome::ShowExtensions(browser, std::string()); |
224 } | 225 } |
225 | 226 |
226 void MessageCenterNotificationManager::ShowSettingsDialog( | 227 void MessageCenterNotificationManager::ShowSettingsDialog( |
227 gfx::NativeView context) { | 228 gfx::NativeView context) { |
228 settings_controller_->ShowSettingsDialog(context); | 229 settings_controller_->ShowSettingsDialog(context); |
229 } | 230 } |
230 | 231 |
231 bool MessageCenterNotificationManager::HasClickedListener( | |
232 const std::string& notification_id) { | |
233 ProfileNotification* profile_notification = | |
234 FindProfileNotification(notification_id); | |
235 return profile_notification && | |
236 profile_notification->notification().HasClickedListener(); | |
237 } | |
238 | |
239 //////////////////////////////////////////////////////////////////////////////// | 232 //////////////////////////////////////////////////////////////////////////////// |
240 // MessageCenter::Observer | 233 // MessageCenter::Observer |
241 void MessageCenterNotificationManager::OnNotificationRemoved( | 234 void MessageCenterNotificationManager::OnNotificationRemoved( |
242 const std::string& notification_id, | 235 const std::string& notification_id, |
243 bool by_user) { | 236 bool by_user) { |
244 // Do not call FindProfileNotification(). Some tests create notifications | 237 // Do not call FindProfileNotification(). Some tests create notifications |
245 // directly to MessageCenter, but this method will be called for the removals | 238 // directly to MessageCenter, but this method will be called for the removals |
246 // of such notifications. | 239 // of such notifications. |
247 NotificationMap::const_iterator iter = | 240 NotificationMap::const_iterator iter = |
248 profile_notifications_.find(notification_id); | 241 profile_notifications_.find(notification_id); |
249 if (iter != profile_notifications_.end()) | 242 if (iter != profile_notifications_.end()) |
250 RemoveProfileNotification(iter->second, by_user); | 243 RemoveProfileNotification(iter->second, by_user); |
251 } | 244 } |
252 | 245 |
253 void MessageCenterNotificationManager::OnNotificationClicked( | |
254 const std::string& notification_id) { | |
255 ProfileNotification* profile_notification = | |
256 FindProfileNotification(notification_id); | |
257 if (!profile_notification) | |
258 return; | |
259 profile_notification->notification().Click(); | |
260 } | |
261 | |
262 void MessageCenterNotificationManager::OnNotificationButtonClicked( | |
263 const std::string& notification_id, | |
264 int button_index) { | |
265 ProfileNotification* profile_notification = | |
266 FindProfileNotification(notification_id); | |
267 if (!profile_notification) | |
268 return; | |
269 profile_notification->notification().ButtonClick(button_index); | |
270 } | |
271 | |
272 void MessageCenterNotificationManager::OnNotificationDisplayed( | |
273 const std::string& notification_id) { | |
274 FindProfileNotification(notification_id)->notification().Display(); | |
275 } | |
276 | |
277 //////////////////////////////////////////////////////////////////////////////// | 246 //////////////////////////////////////////////////////////////////////////////// |
278 // ImageDownloads | 247 // ImageDownloads |
279 | 248 |
280 MessageCenterNotificationManager::ImageDownloads::ImageDownloads( | 249 MessageCenterNotificationManager::ImageDownloads::ImageDownloads( |
281 message_center::MessageCenter* message_center, | 250 message_center::MessageCenter* message_center, |
282 ImageDownloadsObserver* observer) | 251 ImageDownloadsObserver* observer) |
283 : message_center_(message_center), | 252 : message_center_(message_center), |
284 pending_downloads_(0), | 253 pending_downloads_(0), |
285 observer_(observer) { | 254 observer_(observer) { |
286 } | 255 } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 // Notification ids should be unique. | 435 // Notification ids should be unique. |
467 DCHECK(profile_notifications_.find(id) == profile_notifications_.end()); | 436 DCHECK(profile_notifications_.find(id) == profile_notifications_.end()); |
468 profile_notifications_[id] = profile_notification; | 437 profile_notifications_[id] = profile_notification; |
469 | 438 |
470 message_center_->AddNotification(notification.type(), | 439 message_center_->AddNotification(notification.type(), |
471 notification.notification_id(), | 440 notification.notification_id(), |
472 notification.title(), | 441 notification.title(), |
473 notification.body(), | 442 notification.body(), |
474 notification.display_source(), | 443 notification.display_source(), |
475 profile_notification->GetExtensionId(), | 444 profile_notification->GetExtensionId(), |
476 notification.optional_fields()); | 445 notification.optional_fields(), |
| 446 notification.delegate()); |
477 profile_notification->StartDownloads(); | 447 profile_notification->StartDownloads(); |
478 } | 448 } |
479 | 449 |
480 void MessageCenterNotificationManager::RemoveProfileNotification( | 450 void MessageCenterNotificationManager::RemoveProfileNotification( |
481 ProfileNotification* profile_notification, | 451 ProfileNotification* profile_notification, |
482 bool by_user) { | 452 bool by_user) { |
483 profile_notification->notification().Close(by_user); | 453 profile_notification->notification().Close(by_user); |
484 std::string id = profile_notification->notification().notification_id(); | 454 std::string id = profile_notification->notification().notification_id(); |
485 profile_notifications_.erase(id); | 455 profile_notifications_.erase(id); |
486 delete profile_notification; | 456 delete profile_notification; |
487 } | 457 } |
488 | 458 |
489 MessageCenterNotificationManager::ProfileNotification* | 459 MessageCenterNotificationManager::ProfileNotification* |
490 MessageCenterNotificationManager::FindProfileNotification( | 460 MessageCenterNotificationManager::FindProfileNotification( |
491 const std::string& id) const { | 461 const std::string& id) const { |
492 NotificationMap::const_iterator iter = profile_notifications_.find(id); | 462 NotificationMap::const_iterator iter = profile_notifications_.find(id); |
493 if (iter == profile_notifications_.end()) | 463 if (iter == profile_notifications_.end()) |
494 return NULL; | 464 return NULL; |
495 | 465 |
496 return (*iter).second; | 466 return (*iter).second; |
497 } | 467 } |
OLD | NEW |