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

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

Issue 2050123002: Remove OwnPtr from Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First attempt to land. Created 4 years, 6 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/NotificationManager.h" 14 #include "modules/notifications/NotificationManager.h"
15 #include "modules/notifications/NotificationOptions.h" 15 #include "modules/notifications/NotificationOptions.h"
16 #include "modules/notifications/NotificationResourcesLoader.h" 16 #include "modules/notifications/NotificationResourcesLoader.h"
17 #include "modules/serviceworkers/ServiceWorkerRegistration.h" 17 #include "modules/serviceworkers/ServiceWorkerRegistration.h"
18 #include "platform/Histogram.h" 18 #include "platform/Histogram.h"
19 #include "platform/heap/Handle.h" 19 #include "platform/heap/Handle.h"
20 #include "public/platform/Platform.h" 20 #include "public/platform/Platform.h"
21 #include "public/platform/WebSecurityOrigin.h" 21 #include "public/platform/WebSecurityOrigin.h"
22 #include "public/platform/modules/notifications/WebNotificationData.h" 22 #include "public/platform/modules/notifications/WebNotificationData.h"
23 #include "wtf/Assertions.h" 23 #include "wtf/Assertions.h"
24 #include "wtf/PtrUtil.h"
24 #include "wtf/RefPtr.h" 25 #include "wtf/RefPtr.h"
26 #include <memory>
25 27
26 namespace blink { 28 namespace blink {
27 namespace { 29 namespace {
28 30
29 // Allows using a CallbackPromiseAdapter with a WebVector to resolve the 31 // Allows using a CallbackPromiseAdapter with a WebVector to resolve the
30 // getNotifications() promise with a HeapVector owning Notifications. 32 // getNotifications() promise with a HeapVector owning Notifications.
31 class NotificationArray { 33 class NotificationArray {
32 public: 34 public:
33 using WebType = const WebVector<WebPersistentNotificationInfo>&; 35 using WebType = const WebVector<WebPersistentNotificationInfo>&;
34 36
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 if (exceptionState.hadException()) 71 if (exceptionState.hadException())
70 return exceptionState.reject(scriptState); 72 return exceptionState.reject(scriptState);
71 73
72 // Log number of actions developer provided in linear histogram: 0 -> underf low bucket, 1-16 -> distinct buckets, 17+ -> overflow bucket. 74 // Log number of actions developer provided in linear histogram: 0 -> underf low bucket, 1-16 -> distinct buckets, 17+ -> overflow bucket.
73 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, notificationCountHisto gram, new EnumerationHistogram("Notifications.PersistentNotificationActionCount" , 17)); 75 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, notificationCountHisto gram, new EnumerationHistogram("Notifications.PersistentNotificationActionCount" , 17));
74 notificationCountHistogram.count(options.actions().size()); 76 notificationCountHistogram.count(options.actions().size());
75 77
76 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 78 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
77 ScriptPromise promise = resolver->promise(); 79 ScriptPromise promise = resolver->promise();
78 80
79 OwnPtr<WebNotificationShowCallbacks> callbacks = adoptPtr(new CallbackPromis eAdapter<void, void>(resolver)); 81 std::unique_ptr<WebNotificationShowCallbacks> callbacks = wrapUnique(new Cal lbackPromiseAdapter<void, void>(resolver));
80 ServiceWorkerRegistrationNotifications::from(executionContext, registration) .prepareShow(data, std::move(callbacks)); 82 ServiceWorkerRegistrationNotifications::from(executionContext, registration) .prepareShow(data, std::move(callbacks));
81 83
82 return promise; 84 return promise;
83 } 85 }
84 86
85 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta te* scriptState, ServiceWorkerRegistration& registration, const GetNotificationO ptions& options) 87 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta te* scriptState, ServiceWorkerRegistration& registration, const GetNotificationO ptions& options)
86 { 88 {
87 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 89 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
88 ScriptPromise promise = resolver->promise(); 90 ScriptPromise promise = resolver->promise();
89 91
(...skipping 28 matching lines...) Expand all
118 ServiceWorkerRegistrationNotifications& ServiceWorkerRegistrationNotifications:: from(ExecutionContext* executionContext, ServiceWorkerRegistration& registration ) 120 ServiceWorkerRegistrationNotifications& ServiceWorkerRegistrationNotifications:: from(ExecutionContext* executionContext, ServiceWorkerRegistration& registration )
119 { 121 {
120 ServiceWorkerRegistrationNotifications* supplement = static_cast<ServiceWork erRegistrationNotifications*>(Supplement<ServiceWorkerRegistration>::from(regist ration, supplementName())); 122 ServiceWorkerRegistrationNotifications* supplement = static_cast<ServiceWork erRegistrationNotifications*>(Supplement<ServiceWorkerRegistration>::from(regist ration, supplementName()));
121 if (!supplement) { 123 if (!supplement) {
122 supplement = new ServiceWorkerRegistrationNotifications(executionContext , &registration); 124 supplement = new ServiceWorkerRegistrationNotifications(executionContext , &registration);
123 provideTo(registration, supplementName(), supplement); 125 provideTo(registration, supplementName(), supplement);
124 } 126 }
125 return *supplement; 127 return *supplement;
126 } 128 }
127 129
128 void ServiceWorkerRegistrationNotifications::prepareShow(const WebNotificationDa ta& data, PassOwnPtr<WebNotificationShowCallbacks> callbacks) 130 void ServiceWorkerRegistrationNotifications::prepareShow(const WebNotificationDa ta& data, std::unique_ptr<WebNotificationShowCallbacks> callbacks)
129 { 131 {
130 RefPtr<SecurityOrigin> origin = getExecutionContext()->getSecurityOrigin(); 132 RefPtr<SecurityOrigin> origin = getExecutionContext()->getSecurityOrigin();
131 NotificationResourcesLoader* loader = new NotificationResourcesLoader(bind<N otificationResourcesLoader*>(&ServiceWorkerRegistrationNotifications::didLoadRes ources, WeakPersistentThisPointer<ServiceWorkerRegistrationNotifications>(this), origin.release(), data, passed(std::move(callbacks)))); 133 NotificationResourcesLoader* loader = new NotificationResourcesLoader(WTF::b ind<NotificationResourcesLoader*>(&ServiceWorkerRegistrationNotifications::didLo adResources, WeakPersistentThisPointer<ServiceWorkerRegistrationNotifications>(t his), origin.release(), data, passed(std::move(callbacks))));
132 m_loaders.add(loader); 134 m_loaders.add(loader);
133 loader->start(getExecutionContext(), data); 135 loader->start(getExecutionContext(), data);
134 } 136 }
135 137
136 void ServiceWorkerRegistrationNotifications::didLoadResources(PassRefPtr<Securit yOrigin> origin, const WebNotificationData& data, PassOwnPtr<WebNotificationShow Callbacks> callbacks, NotificationResourcesLoader* loader) 138 void ServiceWorkerRegistrationNotifications::didLoadResources(PassRefPtr<Securit yOrigin> origin, const WebNotificationData& data, std::unique_ptr<WebNotificatio nShowCallbacks> callbacks, NotificationResourcesLoader* loader)
137 { 139 {
138 DCHECK(m_loaders.contains(loader)); 140 DCHECK(m_loaders.contains(loader));
139 141
140 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); 142 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager();
141 DCHECK(notificationManager); 143 DCHECK(notificationManager);
142 144
143 notificationManager->showPersistent(WebSecurityOrigin(origin.get()), data, l oader->getResources(), m_registration->webRegistration(), callbacks.leakPtr()); 145 notificationManager->showPersistent(WebSecurityOrigin(origin.get()), data, l oader->getResources(), m_registration->webRegistration(), callbacks.release());
144 m_loaders.remove(loader); 146 m_loaders.remove(loader);
145 } 147 }
146 148
147 } // namespace blink 149 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698