Index: Source/modules/background_sync/PeriodicSyncManager.cpp |
diff --git a/Source/modules/background_sync/SyncManager.cpp b/Source/modules/background_sync/PeriodicSyncManager.cpp |
similarity index 51% |
copy from Source/modules/background_sync/SyncManager.cpp |
copy to Source/modules/background_sync/PeriodicSyncManager.cpp |
index 4298bd72e84a6f2e8cff23e7e4fee6ef03cc9e51..9ab36de9a0976b246d624b9a0d6f23ae00c8e3cc 100644 |
--- a/Source/modules/background_sync/SyncManager.cpp |
+++ b/Source/modules/background_sync/PeriodicSyncManager.cpp |
@@ -3,7 +3,7 @@ |
// found in the LICENSE file. |
#include "config.h" |
-#include "modules/background_sync/SyncManager.h" |
+#include "modules/background_sync/PeriodicSyncManager.h" |
#include "bindings/core/v8/CallbackPromiseAdapter.h" |
#include "bindings/core/v8/ScriptPromise.h" |
@@ -13,8 +13,8 @@ |
#include "core/dom/Document.h" |
#include "core/dom/ExceptionCode.h" |
#include "core/dom/ExecutionContext.h" |
+#include "modules/background_sync/PeriodicSyncRegistrationOptions.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/background_sync/WebSyncProvider.h" |
@@ -30,7 +30,7 @@ namespace { |
* respond to syncManager.minAllowablePeriod. |
* The time is expressed in milliseconds, |
*/ |
-unsigned long kMinAllowablePeriod = 12 * 60 * 60 * 1000; |
+unsigned long kMinPossiblePeriod = 12 * 60 * 60 * 1000; |
WebSyncProvider* backgroundSyncProvider() |
{ |
@@ -41,18 +41,18 @@ WebSyncProvider* backgroundSyncProvider() |
} |
-SyncManager::SyncManager(ServiceWorkerRegistration* registration) |
+PeriodicSyncManager::PeriodicSyncManager(ServiceWorkerRegistration* registration) |
: m_registration(registration) |
{ |
ASSERT(registration); |
} |
-unsigned long SyncManager::minAllowablePeriod() |
+unsigned long PeriodicSyncManager::minPossiblePeriod() |
{ |
- return kMinAllowablePeriod; |
+ return kMinPossiblePeriod; |
jkarlin
2015/04/17 19:04:49
Please create a bug to push this value up to the b
iclelland
2015/04/22 14:05:10
Done. crbug.com/479707
|
} |
-ScriptPromise SyncManager::registerFunction(blink::ScriptState* scriptState, const SyncRegistrationOptions& options) |
+ScriptPromise PeriodicSyncManager::registerFunction(blink::ScriptState* scriptState, const PeriodicSyncRegistrationOptions& options) |
{ |
if (!m_registration->active()) |
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(AbortError, "Registration failed - no active Service Worker")); |
@@ -60,24 +60,29 @@ ScriptPromise SyncManager::registerFunction(blink::ScriptState* scriptState, con |
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); |
ScriptPromise promise = resolver->promise(); |
- 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; |
+ WebSyncRegistration::NetworkState networkState; |
+ String networkStateString = options.networkState(); |
+ if (networkStateString == "any") { |
+ networkState = WebSyncRegistration::NetworkState::NetworkStateAny; |
+ } else if (networkStateString == "avoid-cellular") { |
+ networkState = WebSyncRegistration::NetworkState::NetworkStateAvoidCellular; |
} else { |
- networkType = WebSyncRegistration::NetworkType::NetworkTypeOnline; |
+ networkState = WebSyncRegistration::NetworkState::NetworkStateOnline; |
} |
- WebSyncRegistration webSyncRegistration(options.id(), options.minDelay(), options.maxDelay(), options.minPeriod(), networkType, options.allowOnBattery(), options.idleRequired()); |
+ WebSyncRegistration::PowerState powerState; |
+ String powerStateString = options.powerState(); |
+ if (powerStateString == "avoid-draining") { |
+ powerState = WebSyncRegistration::PowerState::PowerStateAvoidDraining; |
+ } else { |
+ powerState = WebSyncRegistration::PowerState::PowerStateAuto; |
+ } |
+ WebSyncRegistration webSyncRegistration(WebSyncRegistration::UNREGISTERED_SYNC_ID, WebSyncRegistration::PeriodicityPeriodic, options.tag(), options.minPeriod(), networkState, powerState); |
backgroundSyncProvider()->registerBackgroundSync(&webSyncRegistration, m_registration->webRegistration(), new SyncRegistrationCallbacks(resolver, m_registration)); |
return promise; |
} |
-ScriptPromise SyncManager::getRegistration(blink::ScriptState* scriptState, const String& syncRegistrationId) |
+ScriptPromise PeriodicSyncManager::getRegistration(blink::ScriptState* scriptState, const String& syncRegistrationTag) |
{ |
if (!m_registration->active()) |
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(AbortError, "Operation failed - no active Service Worker")); |
@@ -85,12 +90,12 @@ ScriptPromise SyncManager::getRegistration(blink::ScriptState* scriptState, cons |
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); |
ScriptPromise promise = resolver->promise(); |
- backgroundSyncProvider()->getRegistration(syncRegistrationId, m_registration->webRegistration(), new SyncRegistrationCallbacks(resolver, m_registration)); |
+ backgroundSyncProvider()->getRegistration(blink::WebSyncRegistration::PeriodicityPeriodic, syncRegistrationTag, m_registration->webRegistration(), new SyncRegistrationCallbacks(resolver, m_registration)); |
return promise; |
} |
-ScriptPromise SyncManager::getRegistrations(blink::ScriptState* scriptState) |
+ScriptPromise PeriodicSyncManager::getRegistrations(blink::ScriptState* scriptState) |
{ |
if (!m_registration->active()) |
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(AbortError, "Operation failed - no active Service Worker")); |
@@ -98,12 +103,23 @@ ScriptPromise SyncManager::getRegistrations(blink::ScriptState* scriptState) |
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); |
ScriptPromise promise = resolver->promise(); |
- backgroundSyncProvider()->getRegistrations(m_registration->webRegistration(), new SyncGetRegistrationsCallbacks(resolver, m_registration)); |
+ backgroundSyncProvider()->getRegistrations(blink::WebSyncRegistration::PeriodicityPeriodic, m_registration->webRegistration(), new SyncGetRegistrationsCallbacks(resolver, m_registration)); |
+ |
+ return promise; |
+} |
+ScriptPromise PeriodicSyncManager::permissionState(blink::ScriptState* scriptState) |
+{ |
+ 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(); |
+ resolver->resolve(String::fromUTF8("granted")); |
jkarlin
2015/04/17 19:04:49
This needs to call up to the browser process. Plea
iclelland
2015/04/22 14:05:10
Done. crbug.com/479708 (Also for SyncManager.cpp)
|
return promise; |
} |
-DEFINE_TRACE(SyncManager) |
+DEFINE_TRACE(PeriodicSyncManager) |
{ |
visitor->trace(m_registration); |
} |