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

Unified Diff: third_party/WebKit/Source/modules/background_sync/SyncManager.cpp

Issue 2515353002: [background-sync] Merge SyncManager and BackgroundSyncProvider (Closed)
Patch Set: Reorder methods 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/background_sync/SyncManager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/background_sync/SyncManager.cpp
diff --git a/third_party/WebKit/Source/modules/background_sync/SyncManager.cpp b/third_party/WebKit/Source/modules/background_sync/SyncManager.cpp
index 5215bc3f595f2216503fba38dbc36e5024f63cdf..506a04321a0a4611957fb22ff3f74942393a3ed7 100644
--- a/third_party/WebKit/Source/modules/background_sync/SyncManager.cpp
+++ b/third_party/WebKit/Source/modules/background_sync/SyncManager.cpp
@@ -11,22 +11,15 @@
#include "core/dom/DOMException.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/ExecutionContext.h"
-#include "modules/background_sync/BackgroundSyncProvider.h"
#include "modules/serviceworkers/ServiceWorkerRegistration.h"
+#include "platform/heap/Persistent.h"
+#include "public/platform/InterfaceProvider.h"
#include "public/platform/Platform.h"
+#include "wtf/Functional.h"
#include "wtf/PtrUtil.h"
-#include "wtf/ThreadSpecific.h"
namespace blink {
-// static
-BackgroundSyncProvider* SyncManager::backgroundSyncProvider() {
- DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<BackgroundSyncProvider>,
- syncProvider,
- new ThreadSpecific<BackgroundSyncProvider>);
- return syncProvider;
-}
-
SyncManager::SyncManager(ServiceWorkerRegistration* registration)
: m_registration(registration) {
DCHECK(registration);
@@ -52,8 +45,11 @@ ScriptPromise SyncManager::registerFunction(ScriptState* scriptState,
syncRegistration->network_state =
blink::mojom::BackgroundSyncNetworkState::ONLINE;
- backgroundSyncProvider()->registerBackgroundSync(
- std::move(syncRegistration), m_registration->webRegistration(), resolver);
+ getBackgroundSyncServicePtr()->Register(
+ std::move(syncRegistration),
+ m_registration->webRegistration()->registrationId(),
+ convertToBaseCallback(
+ WTF::bind(SyncManager::registerCallback, wrapPersistent(resolver))));
return promise;
}
@@ -62,12 +58,93 @@ ScriptPromise SyncManager::getTags(ScriptState* scriptState) {
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
- backgroundSyncProvider()->getRegistrations(m_registration->webRegistration(),
- resolver);
+ getBackgroundSyncServicePtr()->GetRegistrations(
+ m_registration->webRegistration()->registrationId(),
+ convertToBaseCallback(WTF::bind(&SyncManager::getRegistrationsCallback,
+ wrapPersistent(resolver))));
return promise;
}
+const mojom::blink::BackgroundSyncServicePtr&
+SyncManager::getBackgroundSyncServicePtr() {
+ if (!m_backgroundSyncService.get()) {
+ Platform::current()->interfaceProvider()->getInterface(
+ mojo::GetProxy(&m_backgroundSyncService));
+ }
+ return m_backgroundSyncService;
+}
+
+// static
+void SyncManager::registerCallback(ScriptPromiseResolver* resolver,
+ mojom::blink::BackgroundSyncError error,
+ mojom::blink::SyncRegistrationPtr options) {
+ // TODO(iclelland): Determine the correct error message to return in each case
+ switch (error) {
+ case mojom::blink::BackgroundSyncError::NONE:
+ if (!options) {
+ resolver->resolve(v8::Null(resolver->getScriptState()->isolate()));
+ return;
+ }
+ resolver->resolve();
+ break;
+ case mojom::blink::BackgroundSyncError::NOT_FOUND:
+ NOTREACHED();
+ break;
+ case mojom::blink::BackgroundSyncError::STORAGE:
+ resolver->reject(
+ DOMException::create(UnknownError, "Background Sync is disabled."));
+ break;
+ case mojom::blink::BackgroundSyncError::NOT_ALLOWED:
+ resolver->reject(
+ DOMException::create(InvalidAccessError,
+ "Attempted to register a sync event without a "
+ "window or registration tag too long."));
+ break;
+ case mojom::blink::BackgroundSyncError::PERMISSION_DENIED:
+ resolver->reject(
+ DOMException::create(PermissionDeniedError, "Permission denied."));
+ break;
+ case mojom::blink::BackgroundSyncError::NO_SERVICE_WORKER:
+ resolver->reject(
+ DOMException::create(UnknownError, "No service worker is active."));
+ break;
+ }
+}
+
+// static
+void SyncManager::getRegistrationsCallback(
+ ScriptPromiseResolver* resolver,
+ mojom::blink::BackgroundSyncError error,
+ mojo::WTFArray<mojom::blink::SyncRegistrationPtr> registrations) {
+ // TODO(iclelland): Determine the correct error message to return in each case
+ switch (error) {
+ case mojom::blink::BackgroundSyncError::NONE: {
+ Vector<String> tags;
+ for (const auto& r : registrations.storage()) {
+ tags.append(r->tag);
+ }
+ resolver->resolve(tags);
+ break;
+ }
+ case mojom::blink::BackgroundSyncError::NOT_FOUND:
+ case mojom::blink::BackgroundSyncError::NOT_ALLOWED:
+ case mojom::blink::BackgroundSyncError::PERMISSION_DENIED:
+ // These errors should never be returned from
+ // BackgroundSyncManager::GetRegistrations
+ NOTREACHED();
+ break;
+ case mojom::blink::BackgroundSyncError::STORAGE:
+ resolver->reject(
+ DOMException::create(UnknownError, "Background Sync is disabled."));
+ break;
+ case mojom::blink::BackgroundSyncError::NO_SERVICE_WORKER:
+ resolver->reject(
+ DOMException::create(UnknownError, "No service worker is active."));
+ break;
+ }
+}
+
DEFINE_TRACE(SyncManager) {
visitor->trace(m_registration);
}
« no previous file with comments | « third_party/WebKit/Source/modules/background_sync/SyncManager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698