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 <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 std::unique_ptr<ProfileNotification> profile_notification) { | 345 std::unique_ptr<ProfileNotification> profile_notification) { |
346 const Notification& notification = profile_notification->notification(); | 346 const Notification& notification = profile_notification->notification(); |
347 std::string id = notification.id(); | 347 std::string id = notification.id(); |
348 // Notification ids should be unique. | 348 // Notification ids should be unique. |
349 DCHECK(profile_notifications_.find(id) == profile_notifications_.end()); | 349 DCHECK(profile_notifications_.find(id) == profile_notifications_.end()); |
350 profile_notifications_[id] = std::move(profile_notification); | 350 profile_notifications_[id] = std::move(profile_notification); |
351 } | 351 } |
352 | 352 |
353 void MessageCenterNotificationManager::RemoveProfileNotification( | 353 void MessageCenterNotificationManager::RemoveProfileNotification( |
354 const std::string& notification_id) { | 354 const std::string& notification_id) { |
355 profile_notifications_.erase(notification_id); | 355 auto it = profile_notifications_.find(notification_id); |
| 356 if (it == profile_notifications_.end()) |
| 357 return; |
| 358 |
| 359 // Delay destruction of the ProfileNotification until after all the work |
| 360 // removing it from |profile_notifications_| is complete. This must be done |
| 361 // because this ProfileNotification might have the one ScopedKeepAlive object |
| 362 // that was keeping the browser alive, and destroying it would result in a re- |
| 363 // entrant call to this class. Because every method in this class touches |
| 364 // |profile_notifications_|, |profile_notifications_| must always be in a |
| 365 // self-consistent state in moments where re-entrance might happen. |
| 366 // https://crbug.com/649971 |
| 367 std::unique_ptr<ProfileNotification> notification = std::move(it->second); |
| 368 profile_notifications_.erase(it); |
| 369 // Now that the map modifications are complete, going out of scope will |
| 370 // destroy the notification. |
356 } | 371 } |
357 | 372 |
358 ProfileNotification* MessageCenterNotificationManager::FindProfileNotification( | 373 ProfileNotification* MessageCenterNotificationManager::FindProfileNotification( |
359 const std::string& id) const { | 374 const std::string& id) const { |
360 auto iter = profile_notifications_.find(id); | 375 auto iter = profile_notifications_.find(id); |
361 if (iter == profile_notifications_.end()) | 376 if (iter == profile_notifications_.end()) |
362 return nullptr; | 377 return nullptr; |
363 | 378 |
364 return (*iter).second.get(); | 379 return (*iter).second.get(); |
365 } | 380 } |
(...skipping 12 matching lines...) Expand all Loading... |
378 it != registry->enabled_extensions().end(); | 393 it != registry->enabled_extensions().end(); |
379 ++it) { | 394 ++it) { |
380 if ((*it->get()).permissions_data()->HasAPIPermission( | 395 if ((*it->get()).permissions_data()->HasAPIPermission( |
381 extensions::APIPermission::ID::kNotificationProvider)) { | 396 extensions::APIPermission::ID::kNotificationProvider)) { |
382 extension_id = (*it->get()).id(); | 397 extension_id = (*it->get()).id(); |
383 return extension_id; | 398 return extension_id; |
384 } | 399 } |
385 } | 400 } |
386 return extension_id; | 401 return extension_id; |
387 } | 402 } |
OLD | NEW |