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