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

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

Issue 1096503002: [Background Sync] Converting Blink code to the MVP API (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Unregister method requires the sync registration tag Created 5 years, 8 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 2015 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/background_sync/SyncCallbacks.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/background_sync/PeriodicSyncRegistration.h"
9 #include "modules/background_sync/SyncError.h" 10 #include "modules/background_sync/SyncError.h"
10 #include "modules/background_sync/SyncRegistration.h" 11 #include "modules/background_sync/SyncRegistration.h"
11 #include "modules/serviceworkers/ServiceWorkerRegistration.h" 12 #include "modules/serviceworkers/ServiceWorkerRegistration.h"
12 13
13 namespace blink { 14 namespace blink {
14 15
15 SyncRegistrationCallbacks::SyncRegistrationCallbacks(PassRefPtrWillBeRawPtr<Scri ptPromiseResolver> resolver, ServiceWorkerRegistration* serviceWorkerRegistratio n) 16 SyncRegistrationCallbacks::SyncRegistrationCallbacks(PassRefPtrWillBeRawPtr<Scri ptPromiseResolver> resolver, ServiceWorkerRegistration* serviceWorkerRegistratio n)
16 : m_resolver(resolver) 17 : m_resolver(resolver)
17 , m_serviceWorkerRegistration(serviceWorkerRegistration) 18 , m_serviceWorkerRegistration(serviceWorkerRegistration)
18 { 19 {
19 ASSERT(m_resolver); 20 ASSERT(m_resolver);
20 ASSERT(m_serviceWorkerRegistration); 21 ASSERT(m_serviceWorkerRegistration);
21 } 22 }
22 23
23 SyncRegistrationCallbacks::~SyncRegistrationCallbacks() 24 SyncRegistrationCallbacks::~SyncRegistrationCallbacks()
24 { 25 {
25 } 26 }
26 27
27 void SyncRegistrationCallbacks::onSuccess(WebSyncRegistration* webSyncRegistrati on) 28 void SyncRegistrationCallbacks::onSuccess(WebSyncRegistration* webSyncRegistrati on)
28 { 29 {
29 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped()) { 30 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped()) {
30 SyncRegistration::dispose(webSyncRegistration); 31 SyncRegistration::dispose(webSyncRegistration);
31 return; 32 return;
32 } 33 }
33 34
34 if (!webSyncRegistration) { 35 if (!webSyncRegistration) {
35 m_resolver->resolve(v8::Null(m_resolver->scriptState()->isolate())); 36 m_resolver->resolve(v8::Null(m_resolver->scriptState()->isolate()));
36 return; 37 return;
37 } 38 }
38 m_resolver->resolve(SyncRegistration::take(m_resolver.get(), webSyncRegistra tion, m_serviceWorkerRegistration)); 39 switch (webSyncRegistration->periodicity) {
40 case WebSyncRegistration::PeriodicityPeriodic:
41 m_resolver->resolve(PeriodicSyncRegistration::take(m_resolver.get(), web SyncRegistration, m_serviceWorkerRegistration));
42 break;
43 case WebSyncRegistration::PeriodicityOneShot:
44 m_resolver->resolve(SyncRegistration::take(m_resolver.get(), webSyncRegi stration, m_serviceWorkerRegistration));
45 break;
46 }
39 } 47 }
40 48
41 void SyncRegistrationCallbacks::onError(WebSyncError* error) 49 void SyncRegistrationCallbacks::onError(WebSyncError* error)
42 { 50 {
43 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped()) { 51 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped()) {
44 SyncError::dispose(error); 52 SyncError::dispose(error);
45 return; 53 return;
46 } 54 }
47 m_resolver->reject(SyncError::take(m_resolver.get(), error)); 55 m_resolver->reject(SyncError::take(m_resolver.get(), error));
48 } 56 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 delete(webSyncRegistrations); 106 delete(webSyncRegistrations);
99 } 107 }
100 return; 108 return;
101 } 109 }
102 110
103 if (!webSyncRegistrations) { 111 if (!webSyncRegistrations) {
104 m_resolver->resolve(v8::Null(m_resolver->scriptState()->isolate())); 112 m_resolver->resolve(v8::Null(m_resolver->scriptState()->isolate()));
105 return; 113 return;
106 } 114 }
107 115
108 Vector<SyncRegistration*> syncRegistrations; 116 if (webSyncRegistrations->size() && (*webSyncRegistrations)[0]->periodicity == blink::WebSyncRegistration::PeriodicityOneShot) {
109 for (size_t i = 0; i < webSyncRegistrations->size(); ++i) { 117 Vector<SyncRegistration*> syncRegistrations;
110 WebSyncRegistration* webSyncRegistration = (*webSyncRegistrations)[i]; 118 for (size_t i = 0; i < webSyncRegistrations->size(); ++i) {
111 SyncRegistration* reg = SyncRegistration::take(m_resolver.get(), webSync Registration, m_serviceWorkerRegistration); 119 WebSyncRegistration* webSyncRegistration = (*webSyncRegistrations)[i ];
112 syncRegistrations.append(reg); 120 SyncRegistration* reg = SyncRegistration::take(m_resolver.get(), web SyncRegistration, m_serviceWorkerRegistration);
121 syncRegistrations.append(reg);
122 }
123 delete(webSyncRegistrations);
124 m_resolver->resolve(syncRegistrations);
125 } else {
126 Vector<PeriodicSyncRegistration*> syncRegistrations;
127 for (size_t i = 0; i < webSyncRegistrations->size(); ++i) {
128 WebSyncRegistration* webSyncRegistration = (*webSyncRegistrations)[i ];
129 PeriodicSyncRegistration* reg = PeriodicSyncRegistration::take(m_res olver.get(), webSyncRegistration, m_serviceWorkerRegistration);
130 syncRegistrations.append(reg);
131 }
132 delete(webSyncRegistrations);
133 m_resolver->resolve(syncRegistrations);
113 } 134 }
114 delete(webSyncRegistrations);
115 m_resolver->resolve(syncRegistrations);
116 } 135 }
117 136
118 void SyncGetRegistrationsCallbacks::onError(WebSyncError* error) 137 void SyncGetRegistrationsCallbacks::onError(WebSyncError* error)
119 { 138 {
120 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped()) { 139 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped()) {
121 SyncError::dispose(error); 140 SyncError::dispose(error);
122 return; 141 return;
123 } 142 }
124 m_resolver->reject(SyncError::take(m_resolver.get(), error)); 143 m_resolver->reject(SyncError::take(m_resolver.get(), error));
125 } 144 }
126 145
127 } // namespace blink 146 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/background_sync/ServiceWorkerRegistrationSync.idl ('k') | Source/modules/background_sync/SyncEventInit.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698