Chromium Code Reviews| 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 loopiter = profile_notifications_.begin(); | |
| 83 loopiter != profile_notifications_.end();) { | |
| 84 NotificationMap::iterator curiter = loopiter++; | |
|
Dmitry Titov
2013/05/17 00:14:41
This loop does not need curiter/loopiter treatment
| |
| 85 if ((*curiter).second->notification().origin_url() == source && | |
| 86 profile->IsSameProfile((*curiter).second->profile())) { | |
| 87 notification_ids.insert(curiter->first); | |
| 88 } | |
| 89 } | |
| 90 return notification_ids; | |
| 91 } | |
| 92 | |
| 73 bool MessageCenterNotificationManager::CancelAllBySourceOrigin( | 93 bool MessageCenterNotificationManager::CancelAllBySourceOrigin( |
| 74 const GURL& source) { | 94 const GURL& source) { |
| 75 // Same pattern as CancelById, but more complicated than the above | 95 // Same pattern as CancelById, but more complicated than the above |
| 76 // because there may be multiple notifications from the same source. | 96 // because there may be multiple notifications from the same source. |
| 77 bool removed = NotificationUIManagerImpl::CancelAllBySourceOrigin(source); | 97 bool removed = NotificationUIManagerImpl::CancelAllBySourceOrigin(source); |
| 78 | 98 |
| 79 for (NotificationMap::iterator loopiter = profile_notifications_.begin(); | 99 for (NotificationMap::iterator loopiter = profile_notifications_.begin(); |
| 80 loopiter != profile_notifications_.end(); ) { | 100 loopiter != profile_notifications_.end(); ) { |
| 81 NotificationMap::iterator curiter = loopiter++; | 101 NotificationMap::iterator curiter = loopiter++; |
| 82 if ((*curiter).second->notification().origin_url() == source) { | 102 if ((*curiter).second->notification().origin_url() == source) { |
| 83 message_center_->RemoveNotification(curiter->first, /* by_user */ false); | 103 message_center_->RemoveNotification(curiter->first, /* by_user */ false); |
| 84 removed = true; | 104 removed = true; |
| 85 } | 105 } |
| 86 } | 106 } |
| 87 return removed; | 107 return removed; |
| 88 } | 108 } |
| 89 | 109 |
| 90 bool MessageCenterNotificationManager::CancelAllByProfile(Profile* profile) { | 110 bool MessageCenterNotificationManager::CancelAllByProfile(Profile* profile) { |
| 91 // Same pattern as CancelAllBySourceOrigin. | 111 // Same pattern as CancelAllBySourceOrigin. |
| 92 bool removed = NotificationUIManagerImpl::CancelAllByProfile(profile); | 112 bool removed = NotificationUIManagerImpl::CancelAllByProfile(profile); |
| 93 | 113 |
| 94 for (NotificationMap::iterator loopiter = profile_notifications_.begin(); | 114 for (NotificationMap::iterator loopiter = profile_notifications_.begin(); |
| 95 loopiter != profile_notifications_.end(); ) { | 115 loopiter != profile_notifications_.end(); ) { |
| 96 NotificationMap::iterator curiter = loopiter++; | 116 NotificationMap::iterator curiter = loopiter++; |
| 97 if ((*curiter).second->profile() == profile) { | 117 if (profile->IsSameProfile((*curiter).second->profile())) { |
| 98 message_center_->RemoveNotification(curiter->first, /* by_user */ false); | 118 message_center_->RemoveNotification(curiter->first, /* by_user */ false); |
| 99 removed = true; | 119 removed = true; |
| 100 } | 120 } |
| 101 } | 121 } |
| 102 return removed; | 122 return removed; |
| 103 } | 123 } |
| 104 | 124 |
| 105 void MessageCenterNotificationManager::CancelAll() { | 125 void MessageCenterNotificationManager::CancelAll() { |
| 106 NotificationUIManagerImpl::CancelAll(); | 126 NotificationUIManagerImpl::CancelAll(); |
| 107 | 127 |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 480 | 500 |
| 481 MessageCenterNotificationManager::ProfileNotification* | 501 MessageCenterNotificationManager::ProfileNotification* |
| 482 MessageCenterNotificationManager::FindProfileNotification( | 502 MessageCenterNotificationManager::FindProfileNotification( |
| 483 const std::string& id) const { | 503 const std::string& id) const { |
| 484 NotificationMap::const_iterator iter = profile_notifications_.find(id); | 504 NotificationMap::const_iterator iter = profile_notifications_.find(id); |
| 485 if (iter == profile_notifications_.end()) | 505 if (iter == profile_notifications_.end()) |
| 486 return NULL; | 506 return NULL; |
| 487 | 507 |
| 488 return (*iter).second; | 508 return (*iter).second; |
| 489 } | 509 } |
| OLD | NEW |