| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/notification_system_observer.h" | 5 #include "chrome/browser/notifications/notification_system_observer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/notifications/notification_ui_manager.h" | 9 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
| 12 #include "extensions/common/extension.h" | 12 #include "extensions/common/extension.h" |
| 13 | 13 |
| 14 NotificationSystemObserver::NotificationSystemObserver( | 14 NotificationSystemObserver::NotificationSystemObserver( |
| 15 NotificationUIManager* ui_manager) | 15 NotificationUIManager* ui_manager) |
| 16 : ui_manager_(ui_manager) { | 16 : ui_manager_(ui_manager) { |
| 17 DCHECK(ui_manager_); | 17 DCHECK(ui_manager_); |
| 18 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, | 18 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
| 19 content::NotificationService::AllSources()); | 19 content::NotificationService::AllSources()); |
| 20 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 20 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
| 21 content::NotificationService::AllSources()); | 21 content::NotificationService::AllSources()); |
| 22 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 22 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 23 content::NotificationService::AllSources()); | 23 content::NotificationService::AllSources()); |
| 24 } | 24 } |
| 25 | 25 |
| 26 NotificationSystemObserver::~NotificationSystemObserver() { | 26 NotificationSystemObserver::~NotificationSystemObserver() { |
| 27 } | 27 } |
| 28 | 28 |
| 29 void NotificationSystemObserver::Observe( | 29 void NotificationSystemObserver::Observe( |
| 30 int type, | 30 int type, |
| 31 const content::NotificationSource& source, | 31 const content::NotificationSource& source, |
| 32 const content::NotificationDetails& details) { | 32 const content::NotificationDetails& details) { |
| 33 if (type == chrome::NOTIFICATION_APP_TERMINATING) { | 33 if (type == chrome::NOTIFICATION_APP_TERMINATING) { |
| 34 ui_manager_->CancelAll(); | 34 ui_manager_->CancelAll(); |
| 35 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { | 35 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { |
| 36 if (!content::Source<Profile>(source)->IsOffTheRecord()) { | 36 if (!content::Source<Profile>(source)->IsOffTheRecord()) { |
| 37 extensions::UnloadedExtensionInfo* extension_info = | 37 extensions::UnloadedExtensionInfo* extension_info = |
| 38 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); | 38 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); |
| 39 const extensions::Extension* extension = extension_info->extension; | 39 const extensions::Extension* extension = extension_info->extension; |
| 40 ui_manager_->CancelAllBySourceOrigin(extension->url()); | 40 ui_manager_->CancelAllBySourceOrigin(extension->url()); |
| 41 } | 41 } |
| 42 } else if (type == chrome::NOTIFICATION_PROFILE_DESTROYED) { | 42 } else if (type == chrome::NOTIFICATION_PROFILE_DESTROYED) { |
| 43 // We only want to remove the incognito notifications. | 43 // We only want to remove the incognito notifications. |
| 44 if (content::Source<Profile>(source)->IsOffTheRecord()) | 44 if (content::Source<Profile>(source)->IsOffTheRecord()) |
| 45 ui_manager_->CancelAllByProfile(content::Source<Profile>(source).ptr()); | 45 ui_manager_->CancelAllByProfile(content::Source<Profile>(source).ptr()); |
| 46 } else { | 46 } else { |
| 47 NOTREACHED(); | 47 NOTREACHED(); |
| 48 } | 48 } |
| 49 } | 49 } |
| OLD | NEW |