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

Side by Side Diff: Source/modules/background_sync/SyncCallbacks.cpp

Issue 963683002: Add IDL and initial Blink API for Background Sync (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressing first round style issues Created 5 years, 9 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 2015 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 "config.h" 5 #include "config.h"
6 #include "modules/push_messaging/PushSubscriptionCallbacks.h" 6 #include "modules/background_sync/SyncCallbacks.h"
7 7
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "modules/push_messaging/PushError.h" 9 #include "modules/background_sync/SyncError.h"
10 #include "modules/push_messaging/PushSubscription.h" 10 #include "modules/background_sync/SyncRegistration.h"
11 #include "modules/serviceworkers/ServiceWorkerRegistration.h" 11 #include "modules/serviceworkers/ServiceWorkerRegistration.h"
12 12
13 namespace blink { 13 namespace blink {
14 14
15 PushSubscriptionCallbacks::PushSubscriptionCallbacks(PassRefPtrWillBeRawPtr<Scri ptPromiseResolver> resolver, ServiceWorkerRegistration* serviceWorkerRegistratio n) 15 SyncRegistrationCallbacks::SyncRegistrationCallbacks(PassRefPtrWillBeRawPtr<Scri ptPromiseResolver> resolver, ServiceWorkerRegistration* serviceWorkerRegistratio n)
16 : m_resolver(resolver) 16 : m_resolver(resolver)
17 , m_serviceWorkerRegistration(serviceWorkerRegistration) 17 , m_serviceWorkerRegistration(serviceWorkerRegistration)
18 { 18 {
19 ASSERT(m_resolver); 19 ASSERT(m_resolver);
20 ASSERT(m_serviceWorkerRegistration); 20 ASSERT(m_serviceWorkerRegistration);
21 } 21 }
22 22
23 PushSubscriptionCallbacks::~PushSubscriptionCallbacks() 23 SyncRegistrationCallbacks::~SyncRegistrationCallbacks()
24 { 24 {
25 } 25 }
26 26
27 void PushSubscriptionCallbacks::onSuccess(WebPushSubscription* webPushSubscripti on) 27 void SyncRegistrationCallbacks::onSuccess(WebSyncRegistration* webSyncRegistrati on)
28 { 28 {
29 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped()) { 29 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped()) {
30 PushSubscription::dispose(webPushSubscription); 30 SyncRegistration::dispose(webSyncRegistration);
31 return; 31 return;
32 } 32 }
33 33
34 if (!webPushSubscription) { 34 if (!webSyncRegistration) {
35 m_resolver->resolve(v8::Null(m_resolver->scriptState()->isolate())); 35 m_resolver->resolve(v8::Null(m_resolver->scriptState()->isolate()));
36 return; 36 return;
37 } 37 }
38 m_resolver->resolve(PushSubscription::take(m_resolver.get(), webPushSubscrip tion, m_serviceWorkerRegistration)); 38 m_resolver->resolve(SyncRegistration::take(m_resolver.get(), webSyncRegistra tion, m_serviceWorkerRegistration));
39 } 39 }
40 40
41 void PushSubscriptionCallbacks::onError(WebPushError* error) 41 void SyncRegistrationCallbacks::onError(WebSyncError* error)
42 { 42 {
43 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped()) { 43 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped()) {
44 PushError::dispose(error); 44 SyncError::dispose(error);
45 return; 45 return;
46 } 46 }
47 m_resolver->reject(PushError::take(m_resolver.get(), error)); 47 m_resolver->reject(SyncError::take(m_resolver.get(), error));
48 }
49
50 SyncUnregistrationCallbacks::SyncUnregistrationCallbacks(PassRefPtrWillBeRawPtr< ScriptPromiseResolver> resolver, ServiceWorkerRegistration* serviceWorkerRegistr ation)
51 : m_resolver(resolver)
52 , m_serviceWorkerRegistration(serviceWorkerRegistration)
53 {
54 ASSERT(m_resolver);
55 ASSERT(m_serviceWorkerRegistration);
56 }
57
58 SyncUnregistrationCallbacks::~SyncUnregistrationCallbacks()
59 {
60 }
61
62 void SyncUnregistrationCallbacks::onSuccess(bool* status)
63 {
64 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped()) {
65 return;
66 }
67
68 m_resolver->resolve(*status);
69 }
70
71 void SyncUnregistrationCallbacks::onError(WebSyncError* error)
72 {
73 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped()) {
74 SyncError::dispose(error);
75 return;
76 }
77 m_resolver->reject(SyncError::take(m_resolver.get(), error));
48 } 78 }
49 79
50 } // namespace blink 80 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698