Index: Source/modules/background_sync/SyncManager.cpp |
diff --git a/Source/modules/push_messaging/PushManager.cpp b/Source/modules/background_sync/SyncManager.cpp |
similarity index 34% |
copy from Source/modules/push_messaging/PushManager.cpp |
copy to Source/modules/background_sync/SyncManager.cpp |
index 53e46b5424efcadcb879d8a2040dfdc934df471d..58bc0d925cbec75cf6d0aa0073d5beb200e7595c 100644 |
--- a/Source/modules/push_messaging/PushManager.cpp |
+++ b/Source/modules/background_sync/SyncManager.cpp |
@@ -1,9 +1,9 @@ |
-// Copyright 2014 The Chromium Authors. All rights reserved. |
+// 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/push_messaging/PushManager.h" |
+#include "modules/background_sync/SyncManager.h" |
#include "bindings/core/v8/CallbackPromiseAdapter.h" |
#include "bindings/core/v8/ScriptPromise.h" |
@@ -13,84 +13,92 @@ |
#include "core/dom/Document.h" |
#include "core/dom/ExceptionCode.h" |
#include "core/dom/ExecutionContext.h" |
-#include "modules/push_messaging/PushController.h" |
-#include "modules/push_messaging/PushError.h" |
-#include "modules/push_messaging/PushPermissionStatusCallbacks.h" |
-#include "modules/push_messaging/PushSubscription.h" |
-#include "modules/push_messaging/PushSubscriptionCallbacks.h" |
+#include "modules/background_sync/SyncCallbacks.h" |
+#include "modules/background_sync/SyncRegistrationOptions.h" |
#include "modules/serviceworkers/ServiceWorkerRegistration.h" |
#include "public/platform/Platform.h" |
-#include "public/platform/modules/push_messaging/WebPushClient.h" |
-#include "public/platform/modules/push_messaging/WebPushProvider.h" |
+#include "public/platform/modules/background_sync/WebSyncProvider.h" |
+#include "public/platform/modules/background_sync/WebSyncRegistration.h" |
#include "wtf/RefPtr.h" |
+ |
namespace blink { |
namespace { |
-WebPushProvider* pushProvider() |
-{ |
- WebPushProvider* webPushProvider = Platform::current()->pushProvider(); |
- ASSERT(webPushProvider); |
- return webPushProvider; |
-} |
+ unsigned long kMinAllowablePeriod = 60000; |
jochen (gone - plz use gerrit)
2015/03/13 14:39:03
don't indent in a namespace
what's the unit of ti
jkarlin
2015/03/13 18:51:39
Oddly enough the Blink style guide says that neste
jkarlin
2015/03/15 12:43:10
Ah, I'm wrong. "The contents of other nested name
iclelland
2015/03/16 13:09:40
I'll comment in the code, but all times are in mil
iclelland
2015/03/16 13:09:40
Done.
|
+ |
+ WebSyncProvider* backgroundSyncProvider() |
+ { |
+ WebSyncProvider* webSyncProvider = Platform::current()->backgroundSyncProvider(); |
+ ASSERT(webSyncProvider); |
+ return webSyncProvider; |
+ } |
-} // namespace |
+} |
-PushManager::PushManager(ServiceWorkerRegistration* registration) |
+SyncManager::SyncManager(ServiceWorkerRegistration* registration) |
: m_registration(registration) |
{ |
ASSERT(registration); |
} |
-ScriptPromise PushManager::subscribe(ScriptState* scriptState) |
+unsigned long SyncManager::minAllowablePeriod() |
+{ |
+ return kMinAllowablePeriod; |
+} |
+ |
+ScriptPromise SyncManager::registerFunction(blink::ScriptState* scriptState, const SyncRegistrationOptions& options) |
{ |
if (!m_registration->active()) |
- return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(AbortError, "Subscription failed - no active Service Worker")); |
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(AbortError, "Registration failed - no active Service Worker")); |
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); |
ScriptPromise promise = resolver->promise(); |
- // The document context is the only reasonable context from which to ask the user for permission |
- // to use the Push API. The embedder should persist the permission so that later calls in |
- // different contexts can succeed. |
- if (scriptState->executionContext()->isDocument()) { |
- Document* document = toDocument(scriptState->executionContext()); |
- // FIXME: add test coverage for this condition - https://crbug.com/440431 |
- if (!document->domWindow() || !document->frame()) |
- return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "Document is detached from window.")); |
- PushController::clientFrom(document->frame()).registerPushMessaging(m_registration->webRegistration(), new PushSubscriptionCallbacks(resolver, m_registration)); |
+ WebSyncRegistration::NetworkType networkType; |
+ String minRequiredNetwork = options.minRequiredNetwork(); |
+ if (minRequiredNetwork == "network-any") { |
+ networkType = WebSyncRegistration::NetworkType::NetworkTypeAny; |
+ } else if (minRequiredNetwork == "network-non-mobile") { |
+ networkType = WebSyncRegistration::NetworkType::NetworkTypeNonMobile; |
+ } else if (minRequiredNetwork == "network-offline") { |
+ networkType = WebSyncRegistration::NetworkType::NetworkTypeOffline; |
} else { |
- pushProvider()->registerPushMessaging(m_registration->webRegistration(), new PushSubscriptionCallbacks(resolver, m_registration)); |
+ networkType = WebSyncRegistration::NetworkType::NetworkTypeOnline; |
} |
+ WebSyncRegistration webSyncRegistration = WebSyncRegistration(options.id(), options.minDelay(), options.maxDelay(), options.minPeriod(), networkType, options.allowOnBattery(), options.idleRequired()); |
+ backgroundSyncProvider()->registerBackgroundSync(&webSyncRegistration, new SyncRegistrationCallbacks(resolver, m_registration)); |
return promise; |
} |
-ScriptPromise PushManager::getSubscription(ScriptState* scriptState) |
+ScriptPromise SyncManager::getRegistration(blink::ScriptState* scriptState, const String& syncRegistrationId) |
{ |
+ if (!m_registration->active()) |
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(AbortError, "Operation failed - no active Service Worker")); |
+ |
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); |
ScriptPromise promise = resolver->promise(); |
- pushProvider()->getRegistration(m_registration->webRegistration(), new PushSubscriptionCallbacks(resolver, m_registration)); |
+ backgroundSyncProvider()->getRegistration(syncRegistrationId, new SyncRegistrationCallbacks(resolver, m_registration)); |
+ |
return promise; |
} |
-ScriptPromise PushManager::hasPermission(ScriptState* scriptState) |
+ScriptPromise SyncManager::getRegistrations(blink::ScriptState* scriptState) |
{ |
- if (scriptState->executionContext()->isDocument()) { |
- Document* document = toDocument(scriptState->executionContext()); |
- // FIXME: add test coverage for this condition - https://crbug.com/440431 |
- if (!document->domWindow() || !document->frame()) |
- return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "Document is detached from window.")); |
- } |
+ if (!m_registration->active()) |
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(AbortError, "Operation failed - no active Service Worker")); |
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); |
ScriptPromise promise = resolver->promise(); |
- pushProvider()->getPermissionStatus(m_registration->webRegistration(), new PushPermissionStatusCallbacks(resolver)); |
+ |
+ backgroundSyncProvider()->getRegistrations(new SyncGetRegistrationsCallbacks(resolver, m_registration)); |
+ |
return promise; |
} |
-DEFINE_TRACE(PushManager) |
+DEFINE_TRACE(SyncManager) |
{ |
visitor->trace(m_registration); |
} |