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/notification_ui_manager_impl.h" | 5 #include "chrome/browser/notifications/notification_ui_manager_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/fullscreen.h" | 12 #include "chrome/browser/fullscreen.h" |
13 #include "chrome/browser/idle.h" | 13 #include "chrome/browser/idle.h" |
14 #include "chrome/browser/notifications/balloon_collection.h" | 14 #include "chrome/browser/notifications/balloon_collection.h" |
15 #include "chrome/browser/notifications/notification.h" | 15 #include "chrome/browser/notifications/notification.h" |
| 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/extensions/extension.h" |
17 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
18 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
19 | 21 |
20 namespace { | 22 namespace { |
21 const int kUserStatePollingIntervalSeconds = 1; | 23 const int kUserStatePollingIntervalSeconds = 1; |
22 } | 24 } |
23 | 25 |
24 // A class which represents a notification waiting to be shown. | 26 // A class which represents a notification waiting to be shown. |
25 class QueuedNotification { | 27 class QueuedNotification { |
26 public: | 28 public: |
(...skipping 16 matching lines...) Expand all Loading... |
43 // Non owned pointer to the user's profile. | 45 // Non owned pointer to the user's profile. |
44 Profile* profile_; | 46 Profile* profile_; |
45 | 47 |
46 DISALLOW_COPY_AND_ASSIGN(QueuedNotification); | 48 DISALLOW_COPY_AND_ASSIGN(QueuedNotification); |
47 }; | 49 }; |
48 | 50 |
49 NotificationUIManagerImpl::NotificationUIManagerImpl() | 51 NotificationUIManagerImpl::NotificationUIManagerImpl() |
50 : is_user_active_(true) { | 52 : is_user_active_(true) { |
51 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, | 53 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
52 content::NotificationService::AllSources()); | 54 content::NotificationService::AllSources()); |
| 55 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 56 content::NotificationService::AllSources()); |
| 57 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 58 content::NotificationService::AllSources()); |
53 } | 59 } |
54 | 60 |
55 NotificationUIManagerImpl::~NotificationUIManagerImpl() { | 61 NotificationUIManagerImpl::~NotificationUIManagerImpl() { |
56 } | 62 } |
57 | 63 |
58 void NotificationUIManagerImpl::Add(const Notification& notification, | 64 void NotificationUIManagerImpl::Add(const Notification& notification, |
59 Profile* profile) { | 65 Profile* profile) { |
60 if (TryReplacement(notification, profile)) { | 66 if (TryReplacement(notification, profile)) { |
61 return; | 67 return; |
62 } | 68 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 notifications->push_back(&(*iter)->notification()); | 199 notifications->push_back(&(*iter)->notification()); |
194 } | 200 } |
195 } | 201 } |
196 | 202 |
197 void NotificationUIManagerImpl::Observe( | 203 void NotificationUIManagerImpl::Observe( |
198 int type, | 204 int type, |
199 const content::NotificationSource& source, | 205 const content::NotificationSource& source, |
200 const content::NotificationDetails& details) { | 206 const content::NotificationDetails& details) { |
201 if (type == chrome::NOTIFICATION_APP_TERMINATING) { | 207 if (type == chrome::NOTIFICATION_APP_TERMINATING) { |
202 CancelAll(); | 208 CancelAll(); |
| 209 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { |
| 210 if (!content::Source<Profile>(source)->IsOffTheRecord()) { |
| 211 extensions::UnloadedExtensionInfo* extension_info = |
| 212 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); |
| 213 const extensions::Extension* extension = extension_info->extension; |
| 214 CancelAllBySourceOrigin(extension->url()); |
| 215 } |
| 216 } else if (type == chrome::NOTIFICATION_PROFILE_DESTROYED) { |
| 217 // We only want to remove the incognito notifications. |
| 218 if (content::Source<Profile>(source)->IsOffTheRecord()) |
| 219 CancelAllByProfile(content::Source<Profile>(source).ptr()); |
203 } else { | 220 } else { |
204 NOTREACHED(); | 221 NOTREACHED(); |
205 } | 222 } |
206 } | 223 } |
OLD | NEW |