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

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

Issue 1096503002: [Background Sync] Converting Blink code to the MVP API (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Unregister method requires the sync registration tag Created 5 years, 8 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/SyncManager.h ('k') | Source/modules/background_sync/SyncManager.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/background_sync/SyncManager.cpp
diff --git a/Source/modules/background_sync/SyncManager.cpp b/Source/modules/background_sync/SyncManager.cpp
index 4298bd72e84a6f2e8cff23e7e4fee6ef03cc9e51..6485b61ad15235e16a2becd0d538e826a6ec7749 100644
--- a/Source/modules/background_sync/SyncManager.cpp
+++ b/Source/modules/background_sync/SyncManager.cpp
@@ -25,13 +25,6 @@
namespace blink {
namespace {
-/* This is the minimum period which will be allowed by the Background
- * Sync manager process. It is recorded here in order to be able to
- * respond to syncManager.minAllowablePeriod.
- * The time is expressed in milliseconds,
- */
-unsigned long kMinAllowablePeriod = 12 * 60 * 60 * 1000;
-
WebSyncProvider* backgroundSyncProvider()
{
WebSyncProvider* webSyncProvider = Platform::current()->backgroundSyncProvider();
@@ -47,11 +40,6 @@ SyncManager::SyncManager(ServiceWorkerRegistration* registration)
ASSERT(registration);
}
-unsigned long SyncManager::minAllowablePeriod()
-{
- return kMinAllowablePeriod;
-}
-
ScriptPromise SyncManager::registerFunction(blink::ScriptState* scriptState, const SyncRegistrationOptions& options)
{
if (!m_registration->active())
@@ -60,19 +48,15 @@ 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;
- } else {
- networkType = WebSyncRegistration::NetworkType::NetworkTypeOnline;
- }
- WebSyncRegistration webSyncRegistration(options.id(), options.minDelay(), options.maxDelay(), options.minPeriod(), networkType, options.allowOnBattery(), options.idleRequired());
- backgroundSyncProvider()->registerBackgroundSync(&webSyncRegistration, m_registration->webRegistration(), new SyncRegistrationCallbacks(resolver, m_registration));
+ WebSyncRegistration* webSyncRegistration = new WebSyncRegistration(
+ WebSyncRegistration::UNREGISTERED_SYNC_ID /* id */,
+ WebSyncRegistration::PeriodicityOneShot,
+ options.tag(),
+ 0 /* minPeriod */,
+ WebSyncRegistration::NetworkStateAny /* networkState */,
+ WebSyncRegistration::PowerStateAuto /* powerState */
+ );
+ backgroundSyncProvider()->registerBackgroundSync(webSyncRegistration, m_registration->webRegistration(), new SyncRegistrationCallbacks(resolver, m_registration));
return promise;
}
@@ -85,7 +69,7 @@ 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::PeriodicityOneShot, syncRegistrationId, m_registration->webRegistration(), new SyncRegistrationCallbacks(resolver, m_registration));
return promise;
}
@@ -98,8 +82,19 @@ 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::PeriodicityOneShot, m_registration->webRegistration(), new SyncGetRegistrationsCallbacks(resolver, m_registration));
+
+ return promise;
+}
+ScriptPromise SyncManager::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"));
return promise;
}
« no previous file with comments | « Source/modules/background_sync/SyncManager.h ('k') | Source/modules/background_sync/SyncManager.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698