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

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: Fixed nits 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 72 // Persistent notifications fired through the delegate do not care about the
73 // Notifications from the notification database. 73 // lifetime of the Service Worker responsible for executing the event.
74 void OnPersistentNotificationDataDeleted(bool success) { 74 void OnClickEventDispatchComplete(
75 UMA_HISTOGRAM_BOOLEAN("Notifications.PersistentNotificationDataDeleted", 75 content::PersistentNotificationStatus status) {
76 success); 76 UMA_HISTOGRAM_ENUMERATION(
77 "Notifications.PersistentWebNotificationClickResult", status,
78 content::PersistentNotificationStatus::
79 PERSISTENT_NOTIFICATION_STATUS_MAX);
77 } 80 }
78 81
79 // Persistent notifications fired through the delegate do not care about the 82 void OnCloseEventDispatchComplete(
80 // lifetime of the Service Worker responsible for executing the event. 83 content::PersistentNotificationStatus status) {
81 void OnEventDispatchComplete(content::PersistentNotificationStatus status) {
82 UMA_HISTOGRAM_ENUMERATION( 84 UMA_HISTOGRAM_ENUMERATION(
83 "Notifications.PersistentWebNotificationClickResult", status, 85 "Notifications.PersistentWebNotificationCloseResult", status,
84 content::PersistentNotificationStatus:: 86 content::PersistentNotificationStatus::
85 PERSISTENT_NOTIFICATION_STATUS_MAX); 87 PERSISTENT_NOTIFICATION_STATUS_MAX);
86 } 88 }
87 89
88 void CancelNotification(const std::string& id, ProfileID profile_id) { 90 void CancelNotification(const std::string& id, ProfileID profile_id) {
89 PlatformNotificationServiceImpl::GetInstance() 91 PlatformNotificationServiceImpl::GetInstance()
90 ->GetNotificationUIManager()->CancelById(id, profile_id); 92 ->GetNotificationUIManager()->CancelById(id, profile_id);
91 } 93 }
92 94
93 // Callback to run once the profile has been loaded in order to perform a 95 // Callback to run once the profile has been loaded in order to perform a
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 if (action_index == -1) { 200 if (action_index == -1) {
199 content::RecordAction(base::UserMetricsAction( 201 content::RecordAction(base::UserMetricsAction(
200 "Notifications.Persistent.Clicked")); 202 "Notifications.Persistent.Clicked"));
201 } else { 203 } else {
202 content::RecordAction(base::UserMetricsAction( 204 content::RecordAction(base::UserMetricsAction(
203 "Notifications.Persistent.ClickedActionButton")); 205 "Notifications.Persistent.ClickedActionButton"));
204 } 206 }
205 207
206 content::NotificationEventDispatcher::GetInstance() 208 content::NotificationEventDispatcher::GetInstance()
207 ->DispatchNotificationClickEvent( 209 ->DispatchNotificationClickEvent(
208 browser_context, 210 browser_context, persistent_notification_id, origin, action_index,
209 persistent_notification_id, 211 base::Bind(&OnClickEventDispatchComplete));
210 origin,
211 action_index,
212 base::Bind(&OnEventDispatchComplete));
213 } 212 }
214 213
215 void PlatformNotificationServiceImpl::OnPersistentNotificationClose( 214 void PlatformNotificationServiceImpl::OnPersistentNotificationClose(
216 BrowserContext* browser_context, 215 BrowserContext* browser_context,
217 int64_t persistent_notification_id, 216 int64_t persistent_notification_id,
218 const GURL& origin, 217 const GURL& origin,
219 bool by_user) const { 218 bool by_user) const {
220 DCHECK_CURRENTLY_ON(BrowserThread::UI); 219 DCHECK_CURRENTLY_ON(BrowserThread::UI);
221 if (by_user) { 220 if (by_user) {
222 content::RecordAction(base::UserMetricsAction( 221 content::RecordAction(base::UserMetricsAction(
223 "Notifications.Persistent.ClosedByUser")); 222 "Notifications.Persistent.ClosedByUser"));
224 } else { 223 } else {
225 content::RecordAction(base::UserMetricsAction( 224 content::RecordAction(base::UserMetricsAction(
226 "Notifications.Persistent.ClosedProgrammatically")); 225 "Notifications.Persistent.ClosedProgrammatically"));
227 } 226 }
228 227 content::NotificationEventDispatcher::GetInstance()
229 PlatformNotificationContext* context = 228 ->DispatchNotificationCloseEvent(
230 BrowserContext::GetStoragePartitionForSite(browser_context, origin) 229 browser_context, persistent_notification_id, origin, by_user,
231 ->GetPlatformNotificationContext(); 230 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 } 231 }
242 232
243 blink::WebNotificationPermission 233 blink::WebNotificationPermission
244 PlatformNotificationServiceImpl::CheckPermissionOnUIThread( 234 PlatformNotificationServiceImpl::CheckPermissionOnUIThread(
245 BrowserContext* browser_context, 235 BrowserContext* browser_context,
246 const GURL& origin, 236 const GURL& origin,
247 int render_process_id) { 237 int render_process_id) {
248 DCHECK_CURRENTLY_ON(BrowserThread::UI); 238 DCHECK_CURRENTLY_ON(BrowserThread::UI);
249 239
250 Profile* profile = Profile::FromBrowserContext(browser_context); 240 Profile* profile = Profile::FromBrowserContext(browser_context);
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( 540 extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
551 origin.host(), extensions::ExtensionRegistry::EVERYTHING); 541 origin.host(), extensions::ExtensionRegistry::EVERYTHING);
552 DCHECK(extension); 542 DCHECK(extension);
553 543
554 return base::UTF8ToUTF16(extension->name()); 544 return base::UTF8ToUTF16(extension->name());
555 } 545 }
556 #endif 546 #endif
557 547
558 return base::string16(); 548 return base::string16();
559 } 549 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698