| 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_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // in the given profile. | 130 // in the given profile. |
| 131 for (NotificationMap::iterator iter = profile_notifications_.begin(); | 131 for (NotificationMap::iterator iter = profile_notifications_.begin(); |
| 132 iter != profile_notifications_.end(); ++iter) { | 132 iter != profile_notifications_.end(); ++iter) { |
| 133 ProfileNotification* old_notification = (*iter).second; | 133 ProfileNotification* old_notification = (*iter).second; |
| 134 if (old_notification->notification().replace_id() == replace_id && | 134 if (old_notification->notification().replace_id() == replace_id && |
| 135 old_notification->notification().origin_url() == origin_url && | 135 old_notification->notification().origin_url() == origin_url && |
| 136 old_notification->profile() == profile) { | 136 old_notification->profile() == profile) { |
| 137 // Changing the type from non-progress to progress does not count towards | 137 // Changing the type from non-progress to progress does not count towards |
| 138 // the immediate update allowed in the message center. | 138 // the immediate update allowed in the message center. |
| 139 std::string old_id = | 139 std::string old_id = |
| 140 old_notification->notification().notification_id(); | 140 old_notification->notification().delegate_id(); |
| 141 DCHECK(message_center_->FindVisibleNotificationById(old_id)); | 141 DCHECK(message_center_->FindVisibleNotificationById(old_id)); |
| 142 | 142 |
| 143 // Add/remove notification in the local list but just update the same | 143 // Add/remove notification in the local list but just update the same |
| 144 // one in MessageCenter. | 144 // one in MessageCenter. |
| 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.delegate_id()] = new_notification; |
| 150 | 150 |
| 151 // Now pass a copy to message center. | 151 // Now pass a copy to message center. |
| 152 scoped_ptr<message_center::Notification> message_center_notification( | 152 scoped_ptr<message_center::Notification> message_center_notification( |
| 153 make_scoped_ptr(new message_center::Notification(notification))); | 153 make_scoped_ptr(new message_center::Notification(notification))); |
| 154 message_center_->UpdateNotification(old_id, | 154 message_center_->UpdateNotification(old_id, |
| 155 message_center_notification.Pass()); | 155 message_center_notification.Pass()); |
| 156 | 156 |
| 157 new_notification->StartDownloads(); | 157 new_notification->StartDownloads(); |
| 158 return true; | 158 return true; |
| 159 } | 159 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 // In case all downloads are synchronous, assume a pending download. | 316 // In case all downloads are synchronous, assume a pending download. |
| 317 AddPendingDownload(); | 317 AddPendingDownload(); |
| 318 | 318 |
| 319 // Notification primary icon. | 319 // Notification primary icon. |
| 320 StartDownloadWithImage( | 320 StartDownloadWithImage( |
| 321 notification, | 321 notification, |
| 322 ¬ification.icon(), | 322 ¬ification.icon(), |
| 323 notification.icon_url(), | 323 notification.icon_url(), |
| 324 base::Bind(&message_center::MessageCenter::SetNotificationIcon, | 324 base::Bind(&message_center::MessageCenter::SetNotificationIcon, |
| 325 base::Unretained(message_center_), | 325 base::Unretained(message_center_), |
| 326 notification.notification_id())); | 326 notification.delegate_id())); |
| 327 | 327 |
| 328 // Notification image. | 328 // Notification image. |
| 329 StartDownloadWithImage( | 329 StartDownloadWithImage( |
| 330 notification, | 330 notification, |
| 331 NULL, | 331 NULL, |
| 332 notification.image_url(), | 332 notification.image_url(), |
| 333 base::Bind(&message_center::MessageCenter::SetNotificationImage, | 333 base::Bind(&message_center::MessageCenter::SetNotificationImage, |
| 334 base::Unretained(message_center_), | 334 base::Unretained(message_center_), |
| 335 notification.notification_id())); | 335 notification.delegate_id())); |
| 336 | 336 |
| 337 // Notification button icons. | 337 // Notification button icons. |
| 338 StartDownloadWithImage( | 338 StartDownloadWithImage( |
| 339 notification, | 339 notification, |
| 340 NULL, | 340 NULL, |
| 341 notification.button_one_icon_url(), | 341 notification.button_one_icon_url(), |
| 342 base::Bind(&message_center::MessageCenter::SetNotificationButtonIcon, | 342 base::Bind(&message_center::MessageCenter::SetNotificationButtonIcon, |
| 343 base::Unretained(message_center_), | 343 base::Unretained(message_center_), |
| 344 notification.notification_id(), | 344 notification.delegate_id(), |
| 345 0)); | 345 0)); |
| 346 StartDownloadWithImage( | 346 StartDownloadWithImage( |
| 347 notification, | 347 notification, |
| 348 NULL, | 348 NULL, |
| 349 notification.button_two_icon_url(), | 349 notification.button_two_icon_url(), |
| 350 base::Bind(&message_center::MessageCenter::SetNotificationButtonIcon, | 350 base::Bind(&message_center::MessageCenter::SetNotificationButtonIcon, |
| 351 base::Unretained(message_center_), | 351 base::Unretained(message_center_), |
| 352 notification.notification_id(), | 352 notification.delegate_id(), |
| 353 1)); | 353 1)); |
| 354 | 354 |
| 355 // This should tell the observer we're done if everything was synchronous. | 355 // This should tell the observer we're done if everything was synchronous. |
| 356 PendingDownloadCompleted(); | 356 PendingDownloadCompleted(); |
| 357 } | 357 } |
| 358 | 358 |
| 359 void MessageCenterNotificationManager::ImageDownloads::StartDownloadWithImage( | 359 void MessageCenterNotificationManager::ImageDownloads::StartDownloadWithImage( |
| 360 const Notification& notification, | 360 const Notification& notification, |
| 361 const gfx::Image* image, | 361 const gfx::Image* image, |
| 362 const GURL& url, | 362 const GURL& url, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 } | 465 } |
| 466 return std::string(); | 466 return std::string(); |
| 467 } | 467 } |
| 468 | 468 |
| 469 //////////////////////////////////////////////////////////////////////////////// | 469 //////////////////////////////////////////////////////////////////////////////// |
| 470 // private | 470 // private |
| 471 | 471 |
| 472 void MessageCenterNotificationManager::AddProfileNotification( | 472 void MessageCenterNotificationManager::AddProfileNotification( |
| 473 ProfileNotification* profile_notification) { | 473 ProfileNotification* profile_notification) { |
| 474 const Notification& notification = profile_notification->notification(); | 474 const Notification& notification = profile_notification->notification(); |
| 475 std::string id = notification.notification_id(); | 475 std::string id = notification.delegate_id(); |
| 476 // Notification ids should be unique. | 476 // Notification ids should be unique. |
| 477 DCHECK(profile_notifications_.find(id) == profile_notifications_.end()); | 477 DCHECK(profile_notifications_.find(id) == profile_notifications_.end()); |
| 478 profile_notifications_[id] = profile_notification; | 478 profile_notifications_[id] = profile_notification; |
| 479 | 479 |
| 480 // Create the copy for message center, and ensure the extension ID is correct. | 480 // Create the copy for message center, and ensure the extension ID is correct. |
| 481 scoped_ptr<message_center::Notification> message_center_notification( | 481 scoped_ptr<message_center::Notification> message_center_notification( |
| 482 new message_center::Notification(notification)); | 482 new message_center::Notification(notification)); |
| 483 message_center_->AddNotification(message_center_notification.Pass()); | 483 message_center_->AddNotification(message_center_notification.Pass()); |
| 484 | 484 |
| 485 profile_notification->StartDownloads(); | 485 profile_notification->StartDownloads(); |
| 486 } | 486 } |
| 487 | 487 |
| 488 void MessageCenterNotificationManager::RemoveProfileNotification( | 488 void MessageCenterNotificationManager::RemoveProfileNotification( |
| 489 ProfileNotification* profile_notification) { | 489 ProfileNotification* profile_notification) { |
| 490 std::string id = profile_notification->notification().notification_id(); | 490 std::string id = profile_notification->notification().delegate_id(); |
| 491 profile_notifications_.erase(id); | 491 profile_notifications_.erase(id); |
| 492 delete profile_notification; | 492 delete profile_notification; |
| 493 } | 493 } |
| 494 | 494 |
| 495 MessageCenterNotificationManager::ProfileNotification* | 495 MessageCenterNotificationManager::ProfileNotification* |
| 496 MessageCenterNotificationManager::FindProfileNotification( | 496 MessageCenterNotificationManager::FindProfileNotification( |
| 497 const std::string& id) const { | 497 const std::string& id) const { |
| 498 NotificationMap::const_iterator iter = profile_notifications_.find(id); | 498 NotificationMap::const_iterator iter = profile_notifications_.find(id); |
| 499 if (iter == profile_notifications_.end()) | 499 if (iter == profile_notifications_.end()) |
| 500 return NULL; | 500 return NULL; |
| 501 | 501 |
| 502 return (*iter).second; | 502 return (*iter).second; |
| 503 } | 503 } |
| OLD | NEW |