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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 } | 230 } |
231 | 231 |
232 std::set<std::string> | 232 std::set<std::string> |
233 MessageCenterNotificationManager::GetAllIdsByProfileAndSourceOrigin( | 233 MessageCenterNotificationManager::GetAllIdsByProfileAndSourceOrigin( |
234 Profile* profile, | 234 Profile* profile, |
235 const GURL& source) { | 235 const GURL& source) { |
236 // The profile pointer can be weak, the instance may have been destroyed, so | 236 // The profile pointer can be weak, the instance may have been destroyed, so |
237 // no profile method should be called inside this function. | 237 // no profile method should be called inside this function. |
238 | 238 |
239 std::set<std::string> delegate_ids; | 239 std::set<std::string> delegate_ids; |
240 for (NotificationMap::iterator iter = profile_notifications_.begin(); | 240 for (const auto& pair : profile_notifications_) { |
241 iter != profile_notifications_.end(); iter++) { | 241 const Notification& notification = pair.second->notification(); |
242 if ((*iter).second->notification().origin_url() == source && | 242 if (pair.second->profile() == profile && |
243 profile == (*iter).second->profile()) { | 243 notification.origin_url() == source) { |
244 delegate_ids.insert(iter->second->notification().delegate_id()); | 244 delegate_ids.insert(notification.delegate_id()); |
245 } | 245 } |
246 } | 246 } |
| 247 |
247 return delegate_ids; | 248 return delegate_ids; |
248 } | 249 } |
249 | 250 |
| 251 std::set<std::string> MessageCenterNotificationManager::GetAllIdsByProfile( |
| 252 Profile* profile) { |
| 253 // The profile pointer can be weak, the instance may have been destroyed, so |
| 254 // no profile method should be called inside this function. |
| 255 |
| 256 std::set<std::string> delegate_ids; |
| 257 for (const auto& pair : profile_notifications_) { |
| 258 if (pair.second->profile() == profile) |
| 259 delegate_ids.insert(pair.second->notification().delegate_id()); |
| 260 } |
| 261 |
| 262 return delegate_ids; |
| 263 } |
| 264 |
250 bool MessageCenterNotificationManager::CancelAllBySourceOrigin( | 265 bool MessageCenterNotificationManager::CancelAllBySourceOrigin( |
251 const GURL& source) { | 266 const GURL& source) { |
252 // Same pattern as CancelById, but more complicated than the above | 267 // Same pattern as CancelById, but more complicated than the above |
253 // because there may be multiple notifications from the same source. | 268 // because there may be multiple notifications from the same source. |
254 bool removed = false; | 269 bool removed = false; |
255 | 270 |
256 for (NotificationMap::iterator loopiter = profile_notifications_.begin(); | 271 for (NotificationMap::iterator loopiter = profile_notifications_.begin(); |
257 loopiter != profile_notifications_.end(); ) { | 272 loopiter != profile_notifications_.end(); ) { |
258 NotificationMap::iterator curiter = loopiter++; | 273 NotificationMap::iterator curiter = loopiter++; |
259 if ((*curiter).second->notification().origin_url() == source) { | 274 if ((*curiter).second->notification().origin_url() == source) { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 it != registry->enabled_extensions().end(); | 421 it != registry->enabled_extensions().end(); |
407 ++it) { | 422 ++it) { |
408 if ((*it->get()).permissions_data()->HasAPIPermission( | 423 if ((*it->get()).permissions_data()->HasAPIPermission( |
409 extensions::APIPermission::ID::kNotificationProvider)) { | 424 extensions::APIPermission::ID::kNotificationProvider)) { |
410 extension_id = (*it->get()).id(); | 425 extension_id = (*it->get()).id(); |
411 return extension_id; | 426 return extension_id; |
412 } | 427 } |
413 } | 428 } |
414 return extension_id; | 429 return extension_id; |
415 } | 430 } |
OLD | NEW |