Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/platform_notification_service_impl.h" | 5 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 using content::BrowserThread; | 60 using content::BrowserThread; |
| 61 using content::PlatformNotificationContext; | 61 using content::PlatformNotificationContext; |
| 62 using message_center::NotifierId; | 62 using message_center::NotifierId; |
| 63 | 63 |
| 64 namespace { | 64 namespace { |
| 65 | 65 |
| 66 // Invalid id for a renderer process. Used in cases where we need to check for | 66 // Invalid id for a renderer process. Used in cases where we need to check for |
| 67 // permission without having an associated renderer process yet. | 67 // permission without having an associated renderer process yet. |
| 68 const int kInvalidRenderProcessId = -1; | 68 const int kInvalidRenderProcessId = -1; |
| 69 | 69 |
| 70 // Callback to provide when deleting the data associated with persistent Web | |
| 71 // Notifications from the notification database. | |
| 72 void OnPersistentNotificationDataDeleted(bool success) { | |
| 73 UMA_HISTOGRAM_BOOLEAN("Notifications.PersistentNotificationDataDeleted", | |
| 74 success); | |
| 75 } | |
| 76 | |
| 77 // Persistent notifications fired through the delegate do not care about the | 70 // Persistent notifications fired through the delegate do not care about the |
| 78 // lifetime of the Service Worker responsible for executing the event. | 71 // lifetime of the Service Worker responsible for executing the event. |
| 79 void OnEventDispatchComplete(content::PersistentNotificationStatus status) { | 72 void OnClickEventDispatchComplete( |
| 73 content::PersistentNotificationStatus status) { | |
| 80 UMA_HISTOGRAM_ENUMERATION( | 74 UMA_HISTOGRAM_ENUMERATION( |
| 81 "Notifications.PersistentWebNotificationClickResult", status, | 75 "Notifications.PersistentWebNotificationClickResult", status, |
| 82 content::PersistentNotificationStatus:: | 76 content::PersistentNotificationStatus:: |
| 83 PERSISTENT_NOTIFICATION_STATUS_MAX); | 77 PERSISTENT_NOTIFICATION_STATUS_MAX); |
| 84 } | 78 } |
| 85 | 79 |
| 80 void OnCloseEventDispatchComplete( | |
| 81 content::PersistentNotificationStatus status) { | |
| 82 // TODO(nsatragno): add Notifications.PersistentWebNotificationCloseResult | |
| 83 // metric. | |
| 84 } | |
| 85 | |
| 86 void CancelNotification(const std::string& id, ProfileID profile_id) { | 86 void CancelNotification(const std::string& id, ProfileID profile_id) { |
| 87 PlatformNotificationServiceImpl::GetInstance() | 87 PlatformNotificationServiceImpl::GetInstance() |
| 88 ->GetNotificationUIManager()->CancelById(id, profile_id); | 88 ->GetNotificationUIManager()->CancelById(id, profile_id); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // Callback to run once the profile has been loaded in order to perform a | 91 // Callback to run once the profile has been loaded in order to perform a |
| 92 // given |operation| in a notification. | 92 // given |operation| in a notification. |
| 93 void ProfileLoadedCallback( | 93 void ProfileLoadedCallback( |
| 94 PlatformNotificationServiceImpl::NotificationOperation operation, | 94 PlatformNotificationServiceImpl::NotificationOperation operation, |
| 95 const GURL& origin, | 95 const GURL& origin, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 if (action_index == -1) { | 196 if (action_index == -1) { |
| 197 content::RecordAction(base::UserMetricsAction( | 197 content::RecordAction(base::UserMetricsAction( |
| 198 "Notifications.Persistent.Clicked")); | 198 "Notifications.Persistent.Clicked")); |
| 199 } else { | 199 } else { |
| 200 content::RecordAction(base::UserMetricsAction( | 200 content::RecordAction(base::UserMetricsAction( |
| 201 "Notifications.Persistent.ClickedActionButton")); | 201 "Notifications.Persistent.ClickedActionButton")); |
| 202 } | 202 } |
| 203 | 203 |
| 204 content::NotificationEventDispatcher::GetInstance() | 204 content::NotificationEventDispatcher::GetInstance() |
| 205 ->DispatchNotificationClickEvent( | 205 ->DispatchNotificationClickEvent( |
| 206 browser_context, | 206 browser_context, persistent_notification_id, origin, action_index, |
| 207 persistent_notification_id, | 207 base::Bind(&OnClickEventDispatchComplete)); |
| 208 origin, | |
| 209 action_index, | |
| 210 base::Bind(&OnEventDispatchComplete)); | |
| 211 } | 208 } |
| 212 | 209 |
| 213 void PlatformNotificationServiceImpl::OnPersistentNotificationClose( | 210 void PlatformNotificationServiceImpl::OnPersistentNotificationClose( |
| 214 BrowserContext* browser_context, | 211 BrowserContext* browser_context, |
| 215 int64_t persistent_notification_id, | 212 int64_t persistent_notification_id, |
| 216 const GURL& origin, | 213 const GURL& origin, |
| 217 bool by_user) const { | 214 bool by_user) const { |
| 218 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 215 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 219 if (by_user) { | 216 if (by_user) { |
| 220 content::RecordAction(base::UserMetricsAction( | 217 content::RecordAction(base::UserMetricsAction( |
| 221 "Notifications.Persistent.ClosedByUser")); | 218 "Notifications.Persistent.ClosedByUser")); |
| 219 | |
| 220 content::NotificationEventDispatcher::GetInstance() | |
| 221 ->DispatchNotificationCloseEvent( | |
| 222 browser_context, persistent_notification_id, origin, | |
| 223 base::Bind(&OnCloseEventDispatchComplete)); | |
| 222 } else { | 224 } else { |
| 223 content::RecordAction(base::UserMetricsAction( | 225 content::RecordAction(base::UserMetricsAction( |
|
Peter Beverloo
2016/01/26 16:13:45
Even when a notification was clicked by the user,
Nina
2016/01/27 18:48:58
Good catch - I think this became an issue when I m
| |
| 224 "Notifications.Persistent.ClosedProgrammatically")); | 226 "Notifications.Persistent.ClosedProgrammatically")); |
| 225 } | 227 } |
| 226 | |
| 227 PlatformNotificationContext* context = | |
| 228 BrowserContext::GetStoragePartitionForSite(browser_context, origin) | |
| 229 ->GetPlatformNotificationContext(); | |
| 230 | |
| 231 BrowserThread::PostTask( | |
| 232 BrowserThread::IO, | |
| 233 FROM_HERE, | |
| 234 base::Bind(&PlatformNotificationContext::DeleteNotificationData, | |
| 235 context, | |
| 236 persistent_notification_id, | |
| 237 origin, | |
| 238 base::Bind(&OnPersistentNotificationDataDeleted))); | |
| 239 } | 228 } |
| 240 | 229 |
| 241 blink::WebNotificationPermission | 230 blink::WebNotificationPermission |
| 242 PlatformNotificationServiceImpl::CheckPermissionOnUIThread( | 231 PlatformNotificationServiceImpl::CheckPermissionOnUIThread( |
| 243 BrowserContext* browser_context, | 232 BrowserContext* browser_context, |
| 244 const GURL& origin, | 233 const GURL& origin, |
| 245 int render_process_id) { | 234 int render_process_id) { |
| 246 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 235 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 247 | 236 |
| 248 Profile* profile = Profile::FromBrowserContext(browser_context); | 237 Profile* profile = Profile::FromBrowserContext(browser_context); |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 535 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
| 547 origin.host(), extensions::ExtensionRegistry::EVERYTHING); | 536 origin.host(), extensions::ExtensionRegistry::EVERYTHING); |
| 548 DCHECK(extension); | 537 DCHECK(extension); |
| 549 | 538 |
| 550 return base::UTF8ToUTF16(extension->name()); | 539 return base::UTF8ToUTF16(extension->name()); |
| 551 } | 540 } |
| 552 #endif | 541 #endif |
| 553 | 542 |
| 554 return base::string16(); | 543 return base::string16(); |
| 555 } | 544 } |
| OLD | NEW |