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

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

Issue 2473483012: Move content/child/background_sync to Blink. (Closed)
Patch Set: Fix nits Created 4 years, 1 month 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 "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/PtrUtil.h" 10 #include "wtf/PtrUtil.h"
11 #include <memory> 11 #include <memory>
12 12
13 namespace blink { 13 namespace blink {
14 14
15 SyncRegistrationCallbacks::SyncRegistrationCallbacks( 15 SyncRegistrationCallbacks::SyncRegistrationCallbacks(
16 ScriptPromiseResolver* resolver, 16 ScriptPromiseResolver* resolver,
17 ServiceWorkerRegistration* serviceWorkerRegistration) 17 ServiceWorkerRegistration* serviceWorkerRegistration)
18 : m_resolver(resolver), 18 : m_resolver(resolver),
19 m_serviceWorkerRegistration(serviceWorkerRegistration) { 19 m_serviceWorkerRegistration(serviceWorkerRegistration) {
20 ASSERT(m_resolver); 20 ASSERT(m_resolver);
21 ASSERT(m_serviceWorkerRegistration); 21 ASSERT(m_serviceWorkerRegistration);
22 } 22 }
23 23
24 SyncRegistrationCallbacks::~SyncRegistrationCallbacks() {} 24 SyncRegistrationCallbacks::~SyncRegistrationCallbacks() {}
25 25
26 void SyncRegistrationCallbacks::onSuccess( 26 void SyncRegistrationCallbacks::onSuccess(
27 std::unique_ptr<WebSyncRegistration> webSyncRegistration) { 27 mojom::blink::SyncRegistrationPtr syncRegistration) {
28 if (!m_resolver->getExecutionContext() || 28 if (!m_resolver->getExecutionContext() ||
29 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) { 29 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) {
30 return; 30 return;
31 } 31 }
32 32
33 std::unique_ptr<WebSyncRegistration> registration = 33 if (!syncRegistration) {
34 wrapUnique(webSyncRegistration.release());
35 if (!registration) {
36 m_resolver->resolve(v8::Null(m_resolver->getScriptState()->isolate())); 34 m_resolver->resolve(v8::Null(m_resolver->getScriptState()->isolate()));
37 return; 35 return;
38 } 36 }
39 m_resolver->resolve(); 37 m_resolver->resolve();
40 } 38 }
41 39
42 void SyncRegistrationCallbacks::onError(const WebSyncError& error) { 40 void SyncRegistrationCallbacks::onError(const WebSyncError& error) {
43 if (!m_resolver->getExecutionContext() || 41 if (!m_resolver->getExecutionContext() ||
44 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) { 42 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) {
45 return; 43 return;
46 } 44 }
47 m_resolver->reject(SyncError::take(m_resolver.get(), error)); 45 m_resolver->reject(SyncError::take(m_resolver.get(), error));
48 } 46 }
49 47
50 SyncGetRegistrationsCallbacks::SyncGetRegistrationsCallbacks( 48 SyncGetRegistrationsCallbacks::SyncGetRegistrationsCallbacks(
51 ScriptPromiseResolver* resolver, 49 ScriptPromiseResolver* resolver,
52 ServiceWorkerRegistration* serviceWorkerRegistration) 50 ServiceWorkerRegistration* serviceWorkerRegistration)
53 : m_resolver(resolver), 51 : m_resolver(resolver),
54 m_serviceWorkerRegistration(serviceWorkerRegistration) { 52 m_serviceWorkerRegistration(serviceWorkerRegistration) {
55 ASSERT(m_resolver); 53 ASSERT(m_resolver);
56 ASSERT(m_serviceWorkerRegistration); 54 ASSERT(m_serviceWorkerRegistration);
57 } 55 }
58 56
59 SyncGetRegistrationsCallbacks::~SyncGetRegistrationsCallbacks() {} 57 SyncGetRegistrationsCallbacks::~SyncGetRegistrationsCallbacks() {}
60 58
61 void SyncGetRegistrationsCallbacks::onSuccess( 59 void SyncGetRegistrationsCallbacks::onSuccess(
62 const WebVector<WebSyncRegistration*>& webSyncRegistrations) { 60 const WebVector<mojom::blink::SyncRegistration*>& syncRegistrations) {
63 if (!m_resolver->getExecutionContext() || 61 if (!m_resolver->getExecutionContext() ||
64 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) { 62 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) {
65 return; 63 return;
66 } 64 }
67 Vector<String> tags; 65 Vector<String> tags;
68 for (const WebSyncRegistration* r : webSyncRegistrations) { 66 for (const mojom::blink::SyncRegistration* r : syncRegistrations) {
69 tags.append(r->tag); 67 tags.append(r->tag);
70 } 68 }
71 m_resolver->resolve(tags); 69 m_resolver->resolve(tags);
72 } 70 }
73 71
74 void SyncGetRegistrationsCallbacks::onError(const WebSyncError& error) { 72 void SyncGetRegistrationsCallbacks::onError(const WebSyncError& error) {
75 if (!m_resolver->getExecutionContext() || 73 if (!m_resolver->getExecutionContext() ||
76 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) { 74 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) {
77 return; 75 return;
78 } 76 }
79 m_resolver->reject(SyncError::take(m_resolver.get(), error)); 77 m_resolver->reject(SyncError::take(m_resolver.get(), error));
80 } 78 }
81 79
82 } // namespace blink 80 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698