| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 // If it has been shown, remove it. | 64 // If it has been shown, remove it. |
| 65 NotificationMap::iterator iter = profile_notifications_.find(id); | 65 NotificationMap::iterator iter = profile_notifications_.find(id); |
| 66 if (iter == profile_notifications_.end()) | 66 if (iter == profile_notifications_.end()) |
| 67 return false; | 67 return false; |
| 68 | 68 |
| 69 message_center_->RemoveNotification(id, /* by_user */ false); | 69 message_center_->RemoveNotification(id, /* by_user */ false); |
| 70 return true; | 70 return true; |
| 71 } | 71 } |
| 72 | 72 |
| 73 std::set<std::string> |
| 74 MessageCenterNotificationManager::GetAllIdsByProfileAndSourceOrigin( |
| 75 Profile* profile, |
| 76 const GURL& source) { |
| 77 |
| 78 std::set<std::string> notification_ids = |
| 79 NotificationUIManagerImpl::GetAllIdsByProfileAndSourceOrigin(profile, |
| 80 source); |
| 81 |
| 82 for (NotificationMap::iterator iter = profile_notifications_.begin(); |
| 83 iter != profile_notifications_.end(); iter++) { |
| 84 if ((*iter).second->notification().origin_url() == source && |
| 85 profile->IsSameProfile((*iter).second->profile())) { |
| 86 notification_ids.insert(iter->first); |
| 87 } |
| 88 } |
| 89 return notification_ids; |
| 90 } |
| 91 |
| 73 bool MessageCenterNotificationManager::CancelAllBySourceOrigin( | 92 bool MessageCenterNotificationManager::CancelAllBySourceOrigin( |
| 74 const GURL& source) { | 93 const GURL& source) { |
| 75 // Same pattern as CancelById, but more complicated than the above | 94 // Same pattern as CancelById, but more complicated than the above |
| 76 // because there may be multiple notifications from the same source. | 95 // because there may be multiple notifications from the same source. |
| 77 bool removed = NotificationUIManagerImpl::CancelAllBySourceOrigin(source); | 96 bool removed = NotificationUIManagerImpl::CancelAllBySourceOrigin(source); |
| 78 | 97 |
| 79 for (NotificationMap::iterator loopiter = profile_notifications_.begin(); | 98 for (NotificationMap::iterator loopiter = profile_notifications_.begin(); |
| 80 loopiter != profile_notifications_.end(); ) { | 99 loopiter != profile_notifications_.end(); ) { |
| 81 NotificationMap::iterator curiter = loopiter++; | 100 NotificationMap::iterator curiter = loopiter++; |
| 82 if ((*curiter).second->notification().origin_url() == source) { | 101 if ((*curiter).second->notification().origin_url() == source) { |
| 83 message_center_->RemoveNotification(curiter->first, /* by_user */ false); | 102 message_center_->RemoveNotification(curiter->first, /* by_user */ false); |
| 84 removed = true; | 103 removed = true; |
| 85 } | 104 } |
| 86 } | 105 } |
| 87 return removed; | 106 return removed; |
| 88 } | 107 } |
| 89 | 108 |
| 90 bool MessageCenterNotificationManager::CancelAllByProfile(Profile* profile) { | 109 bool MessageCenterNotificationManager::CancelAllByProfile(Profile* profile) { |
| 91 // Same pattern as CancelAllBySourceOrigin. | 110 // Same pattern as CancelAllBySourceOrigin. |
| 92 bool removed = NotificationUIManagerImpl::CancelAllByProfile(profile); | 111 bool removed = NotificationUIManagerImpl::CancelAllByProfile(profile); |
| 93 | 112 |
| 94 for (NotificationMap::iterator loopiter = profile_notifications_.begin(); | 113 for (NotificationMap::iterator loopiter = profile_notifications_.begin(); |
| 95 loopiter != profile_notifications_.end(); ) { | 114 loopiter != profile_notifications_.end(); ) { |
| 96 NotificationMap::iterator curiter = loopiter++; | 115 NotificationMap::iterator curiter = loopiter++; |
| 97 if ((*curiter).second->profile() == profile) { | 116 if (profile->IsSameProfile((*curiter).second->profile())) { |
| 98 message_center_->RemoveNotification(curiter->first, /* by_user */ false); | 117 message_center_->RemoveNotification(curiter->first, /* by_user */ false); |
| 99 removed = true; | 118 removed = true; |
| 100 } | 119 } |
| 101 } | 120 } |
| 102 return removed; | 121 return removed; |
| 103 } | 122 } |
| 104 | 123 |
| 105 void MessageCenterNotificationManager::CancelAll() { | 124 void MessageCenterNotificationManager::CancelAll() { |
| 106 NotificationUIManagerImpl::CancelAll(); | 125 NotificationUIManagerImpl::CancelAll(); |
| 107 | 126 |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 | 507 |
| 489 MessageCenterNotificationManager::ProfileNotification* | 508 MessageCenterNotificationManager::ProfileNotification* |
| 490 MessageCenterNotificationManager::FindProfileNotification( | 509 MessageCenterNotificationManager::FindProfileNotification( |
| 491 const std::string& id) const { | 510 const std::string& id) const { |
| 492 NotificationMap::const_iterator iter = profile_notifications_.find(id); | 511 NotificationMap::const_iterator iter = profile_notifications_.find(id); |
| 493 if (iter == profile_notifications_.end()) | 512 if (iter == profile_notifications_.end()) |
| 494 return NULL; | 513 return NULL; |
| 495 | 514 |
| 496 return (*iter).second; | 515 return (*iter).second; |
| 497 } | 516 } |
| OLD | NEW |