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

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: Removed redundant TODO Created 4 years, 11 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 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 70 // Callback to provide when deleting the data associated with persistent Web
71 // Notifications from the notification database. 71 // Notifications from the notification database.
72 void OnPersistentNotificationDataDeleted(bool success) { 72 void OnPersistentNotificationDataDeleted(bool success) {
Peter Beverloo 2016/01/21 14:17:37 nit: This is unused now. If we will deprecate the
Nina 2016/01/25 14:54:55 Removed and deprecated histogram.
73 UMA_HISTOGRAM_BOOLEAN("Notifications.PersistentNotificationDataDeleted", 73 UMA_HISTOGRAM_BOOLEAN("Notifications.PersistentNotificationDataDeleted",
74 success); 74 success);
75 } 75 }
76 76
77 // Callback called when the persistent notification close event has been handled
78 // to remove the notification from the database.
79 void OnDidSendPersistentNotificationCloseEvent(
80 BrowserContext* browser_context,
81 int64_t persistent_notification_id,
82 const GURL& origin,
83 content::PersistentNotificationStatus status) {
84
85 PlatformNotificationContext* context =
86 BrowserContext::GetStoragePartitionForSite(browser_context, origin)
87 ->GetPlatformNotificationContext();
88
89 // TODO(nsatragno): add Notifications.PersistentWebNotificationCloseResult
90 // metric.
91 BrowserThread::PostTask(
Peter Beverloo 2016/01/21 14:17:37 Since we're already calling into content per Dispa
Nina 2016/01/25 14:54:55 Refactored code to avoid this ping - pong between
Peter Beverloo 2016/01/26 16:13:45 Note that it's between //chrome and //content - bo
Nina 2016/01/27 18:48:57 Acknowledged.
92 BrowserThread::IO,
93 FROM_HERE,
94 base::Bind(&PlatformNotificationContext::DeleteNotificationData,
95 context,
96 persistent_notification_id,
97 origin,
98 base::Bind(&OnPersistentNotificationDataDeleted)));
99 }
100
77 // Persistent notifications fired through the delegate do not care about the 101 // Persistent notifications fired through the delegate do not care about the
78 // lifetime of the Service Worker responsible for executing the event. 102 // lifetime of the Service Worker responsible for executing the event.
79 void OnEventDispatchComplete(content::PersistentNotificationStatus status) { 103 void OnEventDispatchComplete(content::PersistentNotificationStatus status) {
80 UMA_HISTOGRAM_ENUMERATION( 104 UMA_HISTOGRAM_ENUMERATION(
81 "Notifications.PersistentWebNotificationClickResult", status, 105 "Notifications.PersistentWebNotificationClickResult", status,
82 content::PersistentNotificationStatus:: 106 content::PersistentNotificationStatus::
83 PERSISTENT_NOTIFICATION_STATUS_MAX); 107 PERSISTENT_NOTIFICATION_STATUS_MAX);
84 } 108 }
85 109
86 void CancelNotification(const std::string& id, ProfileID profile_id) { 110 void CancelNotification(const std::string& id, ProfileID profile_id) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 236
213 void PlatformNotificationServiceImpl::OnPersistentNotificationClose( 237 void PlatformNotificationServiceImpl::OnPersistentNotificationClose(
214 BrowserContext* browser_context, 238 BrowserContext* browser_context,
215 int64_t persistent_notification_id, 239 int64_t persistent_notification_id,
216 const GURL& origin, 240 const GURL& origin,
217 bool by_user) const { 241 bool by_user) const {
218 DCHECK_CURRENTLY_ON(BrowserThread::UI); 242 DCHECK_CURRENTLY_ON(BrowserThread::UI);
219 if (by_user) { 243 if (by_user) {
220 content::RecordAction(base::UserMetricsAction( 244 content::RecordAction(base::UserMetricsAction(
221 "Notifications.Persistent.ClosedByUser")); 245 "Notifications.Persistent.ClosedByUser"));
246
247 content::NotificationEventDispatcher::GetInstance()
248 ->DispatchNotificationCloseEvent(
249 browser_context,
250 persistent_notification_id,
251 origin,
252 base::Bind(&OnDidSendPersistentNotificationCloseEvent,
253 browser_context,
254 persistent_notification_id,
255 origin));
222 } else { 256 } else {
223 content::RecordAction(base::UserMetricsAction( 257 content::RecordAction(base::UserMetricsAction(
224 "Notifications.Persistent.ClosedProgrammatically")); 258 "Notifications.Persistent.ClosedProgrammatically"));
225 } 259 }
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 } 260 }
240 261
241 blink::WebNotificationPermission 262 blink::WebNotificationPermission
242 PlatformNotificationServiceImpl::CheckPermissionOnUIThread( 263 PlatformNotificationServiceImpl::CheckPermissionOnUIThread(
243 BrowserContext* browser_context, 264 BrowserContext* browser_context,
244 const GURL& origin, 265 const GURL& origin,
245 int render_process_id) { 266 int render_process_id) {
246 DCHECK_CURRENTLY_ON(BrowserThread::UI); 267 DCHECK_CURRENTLY_ON(BrowserThread::UI);
247 268
248 Profile* profile = Profile::FromBrowserContext(browser_context); 269 Profile* profile = Profile::FromBrowserContext(browser_context);
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( 567 extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
547 origin.host(), extensions::ExtensionRegistry::EVERYTHING); 568 origin.host(), extensions::ExtensionRegistry::EVERYTHING);
548 DCHECK(extension); 569 DCHECK(extension);
549 570
550 return base::UTF8ToUTF16(extension->name()); 571 return base::UTF8ToUTF16(extension->name());
551 } 572 }
552 #endif 573 #endif
553 574
554 return base::string16(); 575 return base::string16();
555 } 576 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698