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
3 // found in the LICENSE file.
5 #include "chrome/browser/notifications/notification_system_observer.h"
7 #include "base/logging.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/notifications/notification_ui_manager.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/browser/notification_service.h"
12 #include "extensions/common/extension.h"
14 NotificationSystemObserver::NotificationSystemObserver(
15 NotificationUIManager
* ui_manager
)
16 : ui_manager_(ui_manager
) {
18 registrar_
.Add(this, chrome::NOTIFICATION_APP_TERMINATING
,
19 content::NotificationService::AllSources());
21 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED
,
22 content::NotificationService::AllSources());
23 registrar_
.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED
,
24 content::NotificationService::AllSources());
27 NotificationSystemObserver::~NotificationSystemObserver() {
30 void NotificationSystemObserver::Observe(
32 const content::NotificationSource
& source
,
33 const content::NotificationDetails
& details
) {
34 if (type
== chrome::NOTIFICATION_APP_TERMINATING
) {
35 ui_manager_
->CancelAll();
36 } else if (type
== extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED
) {
37 if (!content::Source
<Profile
>(source
)->IsOffTheRecord()) {
38 extensions::UnloadedExtensionInfo
* extension_info
=
39 content::Details
<extensions::UnloadedExtensionInfo
>(details
).ptr();
40 const extensions::Extension
* extension
= extension_info
->extension
;
41 ui_manager_
->CancelAllBySourceOrigin(extension
->url());
43 } else if (type
== chrome::NOTIFICATION_PROFILE_DESTROYED
) {
44 // We only want to remove the incognito notifications.
45 if (content::Source
<Profile
>(source
)->IsOffTheRecord())
46 ui_manager_
->CancelAllByProfile(NotificationUIManager::GetProfileID(
47 content::Source
<Profile
>(source
).ptr()));