| 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" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/browser/notifications/extension_welcome_notification.h" | 13 #include "chrome/browser/notifications/extension_welcome_notification.h" |
| 14 #include "chrome/browser/notifications/extension_welcome_notification_factory.h" | 14 #include "chrome/browser/notifications/extension_welcome_notification_factory.h" |
| 15 #include "chrome/browser/notifications/fullscreen_notification_blocker.h" | 15 #include "chrome/browser/notifications/fullscreen_notification_blocker.h" |
| 16 #include "chrome/browser/notifications/message_center_settings_controller.h" | 16 #include "chrome/browser/notifications/message_center_settings_controller.h" |
| 17 #include "chrome/browser/notifications/notification.h" | 17 #include "chrome/browser/notifications/notification.h" |
| 18 #include "chrome/browser/notifications/profile_notification.h" | 18 #include "chrome/browser/notifications/profile_notification.h" |
| 19 #include "chrome/browser/notifications/screen_lock_notification_blocker.h" | 19 #include "chrome/browser/notifications/screen_lock_notification_blocker.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
| 23 #include "extensions/browser/extension_registry.h" | 24 #include "extensions/browser/extension_registry.h" |
| 24 #include "extensions/common/extension_set.h" | 25 #include "extensions/common/extension_set.h" |
| 25 #include "extensions/common/permissions/permissions_data.h" | 26 #include "extensions/common/permissions/permissions_data.h" |
| 26 #include "ui/gfx/image/image_skia.h" | 27 #include "ui/gfx/image/image_skia.h" |
| 27 #include "ui/message_center/message_center_style.h" | 28 #include "ui/message_center/message_center_style.h" |
| 28 #include "ui/message_center/message_center_tray.h" | 29 #include "ui/message_center/message_center_tray.h" |
| 29 #include "ui/message_center/message_center_types.h" | 30 #include "ui/message_center/message_center_types.h" |
| 30 #include "ui/message_center/notifier_settings.h" | 31 #include "ui/message_center/notifier_settings.h" |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 DCHECK(profile_notifications_.find(id) == profile_notifications_.end()); | 323 DCHECK(profile_notifications_.find(id) == profile_notifications_.end()); |
| 323 profile_notifications_[id] = std::move(profile_notification); | 324 profile_notifications_[id] = std::move(profile_notification); |
| 324 } | 325 } |
| 325 | 326 |
| 326 void MessageCenterNotificationManager::RemoveProfileNotification( | 327 void MessageCenterNotificationManager::RemoveProfileNotification( |
| 327 const std::string& notification_id) { | 328 const std::string& notification_id) { |
| 328 auto it = profile_notifications_.find(notification_id); | 329 auto it = profile_notifications_.find(notification_id); |
| 329 if (it == profile_notifications_.end()) | 330 if (it == profile_notifications_.end()) |
| 330 return; | 331 return; |
| 331 | 332 |
| 332 // Delay destruction of the ProfileNotification until after all the work | 333 // Delay destruction of the ProfileNotification until current task is |
| 333 // removing it from |profile_notifications_| is complete. This must be done | 334 // completed. This must be done because this ProfileNotification might have |
| 334 // because this ProfileNotification might have the one ScopedKeepAlive object | 335 // the one ScopedKeepAlive object that was keeping the browser alive, and |
| 335 // that was keeping the browser alive, and destroying it would result in a re- | 336 // destroying it would result in: |
| 336 // entrant call to this class. Because every method in this class touches | 337 // a) A reentrant call to this class. Because every method in this class |
| 337 // |profile_notifications_|, |profile_notifications_| must always be in a | 338 // touches |profile_notifications_|, |profile_notifications_| must always |
| 338 // self-consistent state in moments where re-entrance might happen. | 339 // be in a self-consistent state in moments where re-entrance might happen. |
| 339 // https://crbug.com/649971 | 340 // b) A crash like https://crbug.com/649971 because it can trigger |
| 340 std::unique_ptr<ProfileNotification> notification = std::move(it->second); | 341 // shutdown process while we're still inside the call stack from UI |
| 342 // framework. |
| 343 content::BrowserThread::DeleteSoon(content::BrowserThread::UI, FROM_HERE, |
| 344 it->second.release()); |
| 341 profile_notifications_.erase(it); | 345 profile_notifications_.erase(it); |
| 342 // Now that the map modifications are complete, going out of scope will | |
| 343 // destroy the notification. | |
| 344 } | 346 } |
| 345 | 347 |
| 346 ProfileNotification* MessageCenterNotificationManager::FindProfileNotification( | 348 ProfileNotification* MessageCenterNotificationManager::FindProfileNotification( |
| 347 const std::string& id) const { | 349 const std::string& id) const { |
| 348 auto iter = profile_notifications_.find(id); | 350 auto iter = profile_notifications_.find(id); |
| 349 if (iter == profile_notifications_.end()) | 351 if (iter == profile_notifications_.end()) |
| 350 return nullptr; | 352 return nullptr; |
| 351 | 353 |
| 352 return (*iter).second.get(); | 354 return (*iter).second.get(); |
| 353 } | 355 } |
| OLD | NEW |