Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: chrome/browser/notifications/platform_notification_service_impl.cc

Issue 1619703002: Implement notificationclose event (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Recovered a lost piece of logging. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 using content::BrowserThread; 62 using content::BrowserThread;
63 using content::PlatformNotificationContext; 63 using content::PlatformNotificationContext;
64 using message_center::NotifierId; 64 using message_center::NotifierId;
65 65
66 namespace { 66 namespace {
67 67
68 // Invalid id for a renderer process. Used in cases where we need to check for 68 // Invalid id for a renderer process. Used in cases where we need to check for
69 // permission without having an associated renderer process yet. 69 // permission without having an associated renderer process yet.
70 const int kInvalidRenderProcessId = -1; 70 const int kInvalidRenderProcessId = -1;
71 71
72 // Callback to provide when deleting the data associated with persistent Web
73 // Notifications from the notification database.
74 void OnPersistentNotificationDataDeleted(bool success) {
75 UMA_HISTOGRAM_BOOLEAN("Notifications.PersistentNotificationDataDeleted",
76 success);
77 }
78
79 // Persistent notifications fired through the delegate do not care about the 72 // Persistent notifications fired through the delegate do not care about the
80 // lifetime of the Service Worker responsible for executing the event. 73 // lifetime of the Service Worker responsible for executing the event.
81 void OnEventDispatchComplete(content::PersistentNotificationStatus status) { 74 void OnClickEventDispatchComplete(
75 content::PersistentNotificationStatus status) {
82 UMA_HISTOGRAM_ENUMERATION( 76 UMA_HISTOGRAM_ENUMERATION(
83 "Notifications.PersistentWebNotificationClickResult", status, 77 "Notifications.PersistentWebNotificationClickResult", status,
84 content::PersistentNotificationStatus:: 78 content::PersistentNotificationStatus::
85 PERSISTENT_NOTIFICATION_STATUS_MAX); 79 PERSISTENT_NOTIFICATION_STATUS_MAX);
86 } 80 }
87 81
82 void OnCloseEventDispatchComplete(
83 content::PersistentNotificationStatus status) {
84 // TODO(nsatragno): add Notifications.PersistentWebNotificationCloseResult
85 // metric.
Peter Beverloo 2016/01/27 19:03:57 We'll probably want these to be included in the fi
Nina 2016/01/28 11:59:01 Done.
86 }
87
88 void CancelNotification(const std::string& id, ProfileID profile_id) { 88 void CancelNotification(const std::string& id, ProfileID profile_id) {
89 PlatformNotificationServiceImpl::GetInstance() 89 PlatformNotificationServiceImpl::GetInstance()
90 ->GetNotificationUIManager()->CancelById(id, profile_id); 90 ->GetNotificationUIManager()->CancelById(id, profile_id);
91 } 91 }
92 92
93 // Callback to run once the profile has been loaded in order to perform a 93 // Callback to run once the profile has been loaded in order to perform a
94 // given |operation| in a notification. 94 // given |operation| in a notification.
95 void ProfileLoadedCallback( 95 void ProfileLoadedCallback(
96 PlatformNotificationServiceImpl::NotificationOperation operation, 96 PlatformNotificationServiceImpl::NotificationOperation operation,
97 const GURL& origin, 97 const GURL& origin,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 if (action_index == -1) { 198 if (action_index == -1) {
199 content::RecordAction(base::UserMetricsAction( 199 content::RecordAction(base::UserMetricsAction(
200 "Notifications.Persistent.Clicked")); 200 "Notifications.Persistent.Clicked"));
201 } else { 201 } else {
202 content::RecordAction(base::UserMetricsAction( 202 content::RecordAction(base::UserMetricsAction(
203 "Notifications.Persistent.ClickedActionButton")); 203 "Notifications.Persistent.ClickedActionButton"));
204 } 204 }
205 205
206 content::NotificationEventDispatcher::GetInstance() 206 content::NotificationEventDispatcher::GetInstance()
207 ->DispatchNotificationClickEvent( 207 ->DispatchNotificationClickEvent(
208 browser_context, 208 browser_context, persistent_notification_id, origin, action_index,
209 persistent_notification_id, 209 base::Bind(&OnClickEventDispatchComplete));
210 origin,
211 action_index,
212 base::Bind(&OnEventDispatchComplete));
213 } 210 }
214 211
215 void PlatformNotificationServiceImpl::OnPersistentNotificationClose( 212 void PlatformNotificationServiceImpl::OnPersistentNotificationClose(
216 BrowserContext* browser_context, 213 BrowserContext* browser_context,
217 int64_t persistent_notification_id, 214 int64_t persistent_notification_id,
218 const GURL& origin, 215 const GURL& origin,
219 bool by_user) const { 216 bool by_user) const {
220 DCHECK_CURRENTLY_ON(BrowserThread::UI); 217 DCHECK_CURRENTLY_ON(BrowserThread::UI);
221 if (by_user) { 218 if (by_user) {
222 content::RecordAction(base::UserMetricsAction( 219 content::RecordAction(base::UserMetricsAction(
223 "Notifications.Persistent.ClosedByUser")); 220 "Notifications.Persistent.ClosedByUser"));
224 } else { 221 } else {
225 content::RecordAction(base::UserMetricsAction( 222 content::RecordAction(base::UserMetricsAction(
226 "Notifications.Persistent.ClosedProgrammatically")); 223 "Notifications.Persistent.ClosedProgrammatically"));
227 } 224 }
228 225 content::NotificationEventDispatcher::GetInstance()
229 PlatformNotificationContext* context = 226 ->DispatchNotificationCloseEvent(
230 BrowserContext::GetStoragePartitionForSite(browser_context, origin) 227 browser_context, persistent_notification_id, origin, by_user,
231 ->GetPlatformNotificationContext(); 228 base::Bind(&OnCloseEventDispatchComplete));
232
233 BrowserThread::PostTask(
234 BrowserThread::IO,
235 FROM_HERE,
236 base::Bind(&PlatformNotificationContext::DeleteNotificationData,
237 context,
238 persistent_notification_id,
239 origin,
240 base::Bind(&OnPersistentNotificationDataDeleted)));
241 } 229 }
242 230
243 blink::WebNotificationPermission 231 blink::WebNotificationPermission
244 PlatformNotificationServiceImpl::CheckPermissionOnUIThread( 232 PlatformNotificationServiceImpl::CheckPermissionOnUIThread(
245 BrowserContext* browser_context, 233 BrowserContext* browser_context,
246 const GURL& origin, 234 const GURL& origin,
247 int render_process_id) { 235 int render_process_id) {
248 DCHECK_CURRENTLY_ON(BrowserThread::UI); 236 DCHECK_CURRENTLY_ON(BrowserThread::UI);
249 237
250 Profile* profile = Profile::FromBrowserContext(browser_context); 238 Profile* profile = Profile::FromBrowserContext(browser_context);
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( 537 extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
550 origin.host(), extensions::ExtensionRegistry::EVERYTHING); 538 origin.host(), extensions::ExtensionRegistry::EVERYTHING);
551 DCHECK(extension); 539 DCHECK(extension);
552 540
553 return base::UTF8ToUTF16(extension->name()); 541 return base::UTF8ToUTF16(extension->name());
554 } 542 }
555 #endif 543 #endif
556 544
557 return base::string16(); 545 return base::string16();
558 } 546 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698