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

Unified 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: Add missing serviceWorkerRegistration.syncManager to interface tests 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/background_sync/SyncCallbacks.h ('k') | Source/modules/background_sync/SyncError.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/background_sync/SyncCallbacks.cpp
diff --git a/Source/modules/background_sync/SyncCallbacks.cpp b/Source/modules/background_sync/SyncCallbacks.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..6a5a32ca9f94fe20ec8bdca9183753e66de3c034
--- /dev/null
+++ b/Source/modules/background_sync/SyncCallbacks.cpp
@@ -0,0 +1,125 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "modules/background_sync/SyncCallbacks.h"
+
+#include "bindings/core/v8/ScriptPromiseResolver.h"
+#include "modules/background_sync/SyncError.h"
+#include "modules/background_sync/SyncRegistration.h"
+#include "modules/serviceworkers/ServiceWorkerRegistration.h"
+
+namespace blink {
+
+SyncRegistrationCallbacks::SyncRegistrationCallbacks(PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver, ServiceWorkerRegistration* serviceWorkerRegistration)
+ : m_resolver(resolver)
+ , m_serviceWorkerRegistration(serviceWorkerRegistration)
+{
+ ASSERT(m_resolver);
+ ASSERT(m_serviceWorkerRegistration);
+}
+
+SyncRegistrationCallbacks::~SyncRegistrationCallbacks()
+{
+}
+
+void SyncRegistrationCallbacks::onSuccess(WebSyncRegistration* webSyncRegistration)
+{
+ if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped()) {
+ SyncRegistration::dispose(webSyncRegistration);
+ return;
+ }
+
+ if (!webSyncRegistration) {
+ m_resolver->resolve(v8::Null(m_resolver->scriptState()->isolate()));
+ return;
+ }
+ m_resolver->resolve(SyncRegistration::take(m_resolver.get(), webSyncRegistration, m_serviceWorkerRegistration));
+}
+
+void SyncRegistrationCallbacks::onError(WebSyncError* error)
+{
+ if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped()) {
+ SyncError::dispose(error);
+ return;
+ }
+ m_resolver->reject(SyncError::take(m_resolver.get(), error));
+}
+
+SyncUnregistrationCallbacks::SyncUnregistrationCallbacks(PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver, ServiceWorkerRegistration* serviceWorkerRegistration)
+ : m_resolver(resolver)
+ , m_serviceWorkerRegistration(serviceWorkerRegistration)
+{
+ ASSERT(m_resolver);
+ ASSERT(m_serviceWorkerRegistration);
+}
+
+SyncUnregistrationCallbacks::~SyncUnregistrationCallbacks()
+{
+}
+
+void SyncUnregistrationCallbacks::onSuccess(bool* status)
+{
+ if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped()) {
+ return;
+ }
+
+ m_resolver->resolve(*status);
+}
+
+void SyncUnregistrationCallbacks::onError(WebSyncError* error)
+{
+ if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped()) {
+ SyncError::dispose(error);
+ return;
+ }
+ m_resolver->reject(SyncError::take(m_resolver.get(), error));
+}
+
+SyncGetRegistrationsCallbacks::SyncGetRegistrationsCallbacks(PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver, ServiceWorkerRegistration* serviceWorkerRegistration)
+ : m_resolver(resolver)
+ , m_serviceWorkerRegistration(serviceWorkerRegistration)
+{
+ ASSERT(m_resolver);
+ ASSERT(m_serviceWorkerRegistration);
+}
+
+SyncGetRegistrationsCallbacks::~SyncGetRegistrationsCallbacks()
+{
+}
+
+void SyncGetRegistrationsCallbacks::onSuccess(WebVector<WebSyncRegistration>* webSyncRegistrations)
+{
+ if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped()) {
+ for (size_t i = 0; i < webSyncRegistrations->size(); ++i) {
+ WebSyncRegistration webSyncRegistration = (*webSyncRegistrations)[i];
+ SyncRegistration::dispose(&webSyncRegistration);
+ }
+ return;
+ }
+
+ if (!webSyncRegistrations) {
+ m_resolver->resolve(v8::Null(m_resolver->scriptState()->isolate()));
+ return;
+ }
+
+ Vector<SyncRegistration*> syncRegistrations;
+ for (size_t i = 0; i < webSyncRegistrations->size(); ++i) {
+ WebSyncRegistration webSyncRegistration = (*webSyncRegistrations)[i];
+ SyncRegistration* reg = SyncRegistration::take(m_resolver.get(), &webSyncRegistration, m_serviceWorkerRegistration);
+ syncRegistrations.append(reg);
+ }
+ m_resolver->resolve(syncRegistrations);
+}
+
+void SyncGetRegistrationsCallbacks::onError(WebSyncError* error)
+{
+ if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped()) {
+ SyncError::dispose(error);
+ return;
+ }
+ m_resolver->reject(SyncError::take(m_resolver.get(), error));
+}
+
+} // namespace blink
« no previous file with comments | « Source/modules/background_sync/SyncCallbacks.h ('k') | Source/modules/background_sync/SyncError.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698