| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 bool by_user) { | 244 bool by_user) { |
| 244 // Do not call FindProfileNotification(). Some tests create notifications | 245 // Do not call FindProfileNotification(). Some tests create notifications |
| 245 // directly to MessageCenter, but this method will be called for the removals | 246 // directly to MessageCenter, but this method will be called for the removals |
| 246 // of such notifications. | 247 // of such notifications. |
| 247 NotificationMap::const_iterator iter = | 248 NotificationMap::const_iterator iter = |
| 248 profile_notifications_.find(notification_id); | 249 profile_notifications_.find(notification_id); |
| 249 if (iter != profile_notifications_.end()) | 250 if (iter != profile_notifications_.end()) |
| 250 RemoveProfileNotification(iter->second, by_user); | 251 RemoveProfileNotification(iter->second, by_user); |
| 251 } | 252 } |
| 252 | 253 |
| 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 //////////////////////////////////////////////////////////////////////////////// | 254 //////////////////////////////////////////////////////////////////////////////// |
| 278 // ImageDownloads | 255 // ImageDownloads |
| 279 | 256 |
| 280 MessageCenterNotificationManager::ImageDownloads::ImageDownloads( | 257 MessageCenterNotificationManager::ImageDownloads::ImageDownloads( |
| 281 message_center::MessageCenter* message_center, | 258 message_center::MessageCenter* message_center, |
| 282 ImageDownloadsObserver* observer) | 259 ImageDownloadsObserver* observer) |
| 283 : message_center_(message_center), | 260 : message_center_(message_center), |
| 284 pending_downloads_(0), | 261 pending_downloads_(0), |
| 285 observer_(observer) { | 262 observer_(observer) { |
| 286 } | 263 } |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 // Notification ids should be unique. | 443 // Notification ids should be unique. |
| 467 DCHECK(profile_notifications_.find(id) == profile_notifications_.end()); | 444 DCHECK(profile_notifications_.find(id) == profile_notifications_.end()); |
| 468 profile_notifications_[id] = profile_notification; | 445 profile_notifications_[id] = profile_notification; |
| 469 | 446 |
| 470 message_center_->AddNotification(notification.type(), | 447 message_center_->AddNotification(notification.type(), |
| 471 notification.notification_id(), | 448 notification.notification_id(), |
| 472 notification.title(), | 449 notification.title(), |
| 473 notification.body(), | 450 notification.body(), |
| 474 notification.display_source(), | 451 notification.display_source(), |
| 475 profile_notification->GetExtensionId(), | 452 profile_notification->GetExtensionId(), |
| 476 notification.optional_fields()); | 453 notification.optional_fields(), |
| 454 notification.delegate()); |
| 477 profile_notification->StartDownloads(); | 455 profile_notification->StartDownloads(); |
| 478 } | 456 } |
| 479 | 457 |
| 480 void MessageCenterNotificationManager::RemoveProfileNotification( | 458 void MessageCenterNotificationManager::RemoveProfileNotification( |
| 481 ProfileNotification* profile_notification, | 459 ProfileNotification* profile_notification, |
| 482 bool by_user) { | 460 bool by_user) { |
| 483 profile_notification->notification().Close(by_user); | 461 profile_notification->notification().Close(by_user); |
| 484 std::string id = profile_notification->notification().notification_id(); | 462 std::string id = profile_notification->notification().notification_id(); |
| 485 profile_notifications_.erase(id); | 463 profile_notifications_.erase(id); |
| 486 delete profile_notification; | 464 delete profile_notification; |
| 487 } | 465 } |
| 488 | 466 |
| 489 MessageCenterNotificationManager::ProfileNotification* | 467 MessageCenterNotificationManager::ProfileNotification* |
| 490 MessageCenterNotificationManager::FindProfileNotification( | 468 MessageCenterNotificationManager::FindProfileNotification( |
| 491 const std::string& id) const { | 469 const std::string& id) const { |
| 492 NotificationMap::const_iterator iter = profile_notifications_.find(id); | 470 NotificationMap::const_iterator iter = profile_notifications_.find(id); |
| 493 if (iter == profile_notifications_.end()) | 471 if (iter == profile_notifications_.end()) |
| 494 return NULL; | 472 return NULL; |
| 495 | 473 |
| 496 return (*iter).second; | 474 return (*iter).second; |
| 497 } | 475 } |
| OLD | NEW |