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

Side by Side Diff: third_party/WebKit/Source/modules/notifications/ServiceWorkerRegistrationNotifications.cpp

Issue 1652983005: Remove Enumeration Histograms from the Blink Platform API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master_blink_histograms_5a
Patch Set: Rebase two new histograms were added today 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 "modules/notifications/ServiceWorkerRegistrationNotifications.h" 5 #include "modules/notifications/ServiceWorkerRegistrationNotifications.h"
6 6
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" 7 #include "bindings/core/v8/CallbackPromiseAdapter.h"
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "core/dom/ExecutionContext.h" 10 #include "core/dom/ExecutionContext.h"
11 #include "modules/notifications/GetNotificationOptions.h" 11 #include "modules/notifications/GetNotificationOptions.h"
12 #include "modules/notifications/Notification.h" 12 #include "modules/notifications/Notification.h"
13 #include "modules/notifications/NotificationData.h" 13 #include "modules/notifications/NotificationData.h"
14 #include "modules/notifications/NotificationOptions.h" 14 #include "modules/notifications/NotificationOptions.h"
15 #include "modules/serviceworkers/ServiceWorkerRegistration.h" 15 #include "modules/serviceworkers/ServiceWorkerRegistration.h"
16 #include "platform/Histogram.h"
16 #include "public/platform/Platform.h" 17 #include "public/platform/Platform.h"
17 #include "public/platform/WebSecurityOrigin.h" 18 #include "public/platform/WebSecurityOrigin.h"
18 #include "public/platform/modules/notifications/WebNotificationData.h" 19 #include "public/platform/modules/notifications/WebNotificationData.h"
19 #include "public/platform/modules/notifications/WebNotificationManager.h" 20 #include "public/platform/modules/notifications/WebNotificationManager.h"
20 21
21 namespace blink { 22 namespace blink {
22 namespace { 23 namespace {
23 24
24 // Allows using a CallbackPromiseAdapter with a WebVector to resolve the 25 // Allows using a CallbackPromiseAdapter with a WebVector to resolve the
25 // getNotifications() promise with a HeapVector owning Notifications. 26 // getNotifications() promise with a HeapVector owning Notifications.
(...skipping 27 matching lines...) Expand all
53 // If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps. 54 // If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps.
54 if (Notification::checkPermission(executionContext) != WebNotificationPermis sionAllowed) 55 if (Notification::checkPermission(executionContext) != WebNotificationPermis sionAllowed)
55 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No notification permission has been granted for thi s origin.")); 56 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No notification permission has been granted for thi s origin."));
56 57
57 // Validate the developer-provided values to get a WebNotificationData objec t. 58 // Validate the developer-provided values to get a WebNotificationData objec t.
58 WebNotificationData data = createWebNotificationData(executionContext, title , options, exceptionState); 59 WebNotificationData data = createWebNotificationData(executionContext, title , options, exceptionState);
59 if (exceptionState.hadException()) 60 if (exceptionState.hadException())
60 return exceptionState.reject(scriptState); 61 return exceptionState.reject(scriptState);
61 62
62 // Log number of actions developer provided in linear histogram: 0 -> underf low bucket, 1-16 -> distinct buckets, 17+ -> overflow bucket. 63 // Log number of actions developer provided in linear histogram: 0 -> underf low bucket, 1-16 -> distinct buckets, 17+ -> overflow bucket.
63 Platform::current()->histogramEnumeration("Notifications.PersistentNotificat ionActionCount", options.actions().size(), 17); 64 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, notificationCountHisto gram, new EnumerationHistogram("Notifications.PersistentNotificationActionCount" , 17));
65 notificationCountHistogram.count(options.actions().size());
64 66
65 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 67 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
66 ScriptPromise promise = resolver->promise(); 68 ScriptPromise promise = resolver->promise();
67 69
68 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver); 70 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver);
69 71
70 SecurityOrigin* origin = executionContext->securityOrigin(); 72 SecurityOrigin* origin = executionContext->securityOrigin();
71 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); 73 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager();
72 ASSERT(notificationManager); 74 ASSERT(notificationManager);
73 75
74 notificationManager->showPersistent(WebSecurityOrigin(origin), data, service WorkerRegistration.webRegistration(), callbacks); 76 notificationManager->showPersistent(WebSecurityOrigin(origin), data, service WorkerRegistration.webRegistration(), callbacks);
75 return promise; 77 return promise;
76 } 78 }
77 79
78 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Get NotificationOptions& options) 80 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Get NotificationOptions& options)
79 { 81 {
80 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 82 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
81 ScriptPromise promise = resolver->promise(); 83 ScriptPromise promise = resolver->promise();
82 84
83 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica tionArray, void>(resolver); 85 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica tionArray, void>(resolver);
84 86
85 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); 87 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager();
86 ASSERT(notificationManager); 88 ASSERT(notificationManager);
87 89
88 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati on.webRegistration(), callbacks); 90 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati on.webRegistration(), callbacks);
89 return promise; 91 return promise;
90 } 92 }
91 93
92 } // namespace blink 94 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698