OLD | NEW |
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 "modules/background_sync/SyncCallbacks.h" | 5 #include "modules/background_sync/SyncCallbacks.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
8 #include "modules/background_sync/SyncError.h" | 8 #include "modules/background_sync/SyncError.h" |
9 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 9 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
10 #include "wtf/OwnPtr.h" | 10 #include "wtf/OwnPtr.h" |
11 #include "wtf/PassOwnPtr.h" | 11 #include "wtf/PassOwnPtr.h" |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
15 SyncRegistrationCallbacks::SyncRegistrationCallbacks(ScriptPromiseResolver* reso
lver, ServiceWorkerRegistration* serviceWorkerRegistration) | 15 SyncRegistrationCallbacks::SyncRegistrationCallbacks(ScriptPromiseResolver* reso
lver, ServiceWorkerRegistration* serviceWorkerRegistration) |
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 SyncRegistrationCallbacks::~SyncRegistrationCallbacks() | 23 SyncRegistrationCallbacks::~SyncRegistrationCallbacks() |
24 { | 24 { |
25 } | 25 } |
26 | 26 |
27 void SyncRegistrationCallbacks::onSuccess(WebPassOwnPtr<WebSyncRegistration> web
SyncRegistration) | 27 void SyncRegistrationCallbacks::onSuccess(WebPassOwnPtr<WebSyncRegistration> web
SyncRegistration) |
28 { | 28 { |
29 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ
eDOMObjectsAreStopped()) { | 29 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContext()-
>activeDOMObjectsAreStopped()) { |
30 return; | 30 return; |
31 } | 31 } |
32 | 32 |
33 OwnPtr<WebSyncRegistration> registration = webSyncRegistration.release(); | 33 OwnPtr<WebSyncRegistration> registration = webSyncRegistration.release(); |
34 if (!registration) { | 34 if (!registration) { |
35 m_resolver->resolve(v8::Null(m_resolver->scriptState()->isolate())); | 35 m_resolver->resolve(v8::Null(m_resolver->getScriptState()->isolate())); |
36 return; | 36 return; |
37 } | 37 } |
38 m_resolver->resolve(); | 38 m_resolver->resolve(); |
39 } | 39 } |
40 | 40 |
41 void SyncRegistrationCallbacks::onError(const WebSyncError& error) | 41 void SyncRegistrationCallbacks::onError(const WebSyncError& error) |
42 { | 42 { |
43 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ
eDOMObjectsAreStopped()) { | 43 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContext()-
>activeDOMObjectsAreStopped()) { |
44 return; | 44 return; |
45 } | 45 } |
46 m_resolver->reject(SyncError::take(m_resolver.get(), error)); | 46 m_resolver->reject(SyncError::take(m_resolver.get(), error)); |
47 } | 47 } |
48 | 48 |
49 SyncGetRegistrationsCallbacks::SyncGetRegistrationsCallbacks(ScriptPromiseResolv
er* resolver, ServiceWorkerRegistration* serviceWorkerRegistration) | 49 SyncGetRegistrationsCallbacks::SyncGetRegistrationsCallbacks(ScriptPromiseResolv
er* resolver, ServiceWorkerRegistration* serviceWorkerRegistration) |
50 : m_resolver(resolver) | 50 : m_resolver(resolver) |
51 , m_serviceWorkerRegistration(serviceWorkerRegistration) | 51 , m_serviceWorkerRegistration(serviceWorkerRegistration) |
52 { | 52 { |
53 ASSERT(m_resolver); | 53 ASSERT(m_resolver); |
54 ASSERT(m_serviceWorkerRegistration); | 54 ASSERT(m_serviceWorkerRegistration); |
55 } | 55 } |
56 | 56 |
57 SyncGetRegistrationsCallbacks::~SyncGetRegistrationsCallbacks() | 57 SyncGetRegistrationsCallbacks::~SyncGetRegistrationsCallbacks() |
58 { | 58 { |
59 } | 59 } |
60 | 60 |
61 void SyncGetRegistrationsCallbacks::onSuccess(const WebVector<WebSyncRegistratio
n*>& webSyncRegistrations) | 61 void SyncGetRegistrationsCallbacks::onSuccess(const WebVector<WebSyncRegistratio
n*>& webSyncRegistrations) |
62 { | 62 { |
63 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ
eDOMObjectsAreStopped()) { | 63 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContext()-
>activeDOMObjectsAreStopped()) { |
64 return; | 64 return; |
65 } | 65 } |
66 Vector<String> tags; | 66 Vector<String> tags; |
67 for (const WebSyncRegistration* r : webSyncRegistrations) { | 67 for (const WebSyncRegistration* r : webSyncRegistrations) { |
68 tags.append(r->tag); | 68 tags.append(r->tag); |
69 } | 69 } |
70 m_resolver->resolve(tags); | 70 m_resolver->resolve(tags); |
71 } | 71 } |
72 | 72 |
73 void SyncGetRegistrationsCallbacks::onError(const WebSyncError& error) | 73 void SyncGetRegistrationsCallbacks::onError(const WebSyncError& error) |
74 { | 74 { |
75 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ
eDOMObjectsAreStopped()) { | 75 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContext()-
>activeDOMObjectsAreStopped()) { |
76 return; | 76 return; |
77 } | 77 } |
78 m_resolver->reject(SyncError::take(m_resolver.get(), error)); | 78 m_resolver->reject(SyncError::take(m_resolver.get(), error)); |
79 } | 79 } |
80 | 80 |
81 } // namespace blink | 81 } // namespace blink |
OLD | NEW |