| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/background_sync/SyncManager.h" | 6 #include "modules/background_sync/SyncManager.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
| 10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 } | 33 } |
| 34 | 34 |
| 35 } | 35 } |
| 36 | 36 |
| 37 SyncManager::SyncManager(ServiceWorkerRegistration* registration) | 37 SyncManager::SyncManager(ServiceWorkerRegistration* registration) |
| 38 : m_registration(registration) | 38 : m_registration(registration) |
| 39 { | 39 { |
| 40 ASSERT(registration); | 40 ASSERT(registration); |
| 41 } | 41 } |
| 42 | 42 |
| 43 ScriptPromise SyncManager::registerFunction(ScriptState* scriptState, const Sync
RegistrationOptions& options) | 43 ScriptPromise SyncManager::registerFunction(ScriptState* scriptState, ExecutionC
ontext* context, const SyncRegistrationOptions& options) |
| 44 { | 44 { |
| 45 if (!m_registration->active()) | |
| 46 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Registration failed - no active Service Worker")); | |
| 47 | |
| 48 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 45 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 49 ScriptPromise promise = resolver->promise(); | 46 ScriptPromise promise = resolver->promise(); |
| 50 | 47 |
| 51 WebSyncRegistration* webSyncRegistration = new WebSyncRegistration( | 48 WebSyncRegistration* webSyncRegistration = new WebSyncRegistration( |
| 52 WebSyncRegistration::UNREGISTERED_SYNC_ID /* id */, | 49 WebSyncRegistration::UNREGISTERED_SYNC_ID /* id */, |
| 53 WebSyncRegistration::PeriodicityOneShot, | 50 WebSyncRegistration::PeriodicityOneShot, |
| 54 options.tag(), | 51 options.tag(), |
| 55 0 /* minPeriod */, | 52 0 /* minPeriod */, |
| 56 WebSyncRegistration::NetworkStateOnline /* networkState */, | 53 WebSyncRegistration::NetworkStateOnline /* networkState */, |
| 57 WebSyncRegistration::PowerStateAuto /* powerState */ | 54 WebSyncRegistration::PowerStateAuto /* powerState */ |
| 58 ); | 55 ); |
| 59 backgroundSyncProvider()->registerBackgroundSync(webSyncRegistration, m_regi
stration->webRegistration(), new SyncRegistrationCallbacks(resolver, m_registrat
ion)); | 56 backgroundSyncProvider()->registerBackgroundSync(webSyncRegistration, m_regi
stration->webRegistration(), context->isServiceWorkerGlobalScope(), new SyncRegi
strationCallbacks(resolver, m_registration)); |
| 60 | 57 |
| 61 return promise; | 58 return promise; |
| 62 } | 59 } |
| 63 | 60 |
| 64 ScriptPromise SyncManager::getRegistration(ScriptState* scriptState, const Strin
g& syncRegistrationId) | 61 ScriptPromise SyncManager::getRegistration(ScriptState* scriptState, const Strin
g& syncRegistrationId) |
| 65 { | 62 { |
| 66 if (!m_registration->active()) | |
| 67 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Operation failed - no active Service Worker")); | |
| 68 | |
| 69 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 63 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 70 ScriptPromise promise = resolver->promise(); | 64 ScriptPromise promise = resolver->promise(); |
| 71 | 65 |
| 72 backgroundSyncProvider()->getRegistration(WebSyncRegistration::PeriodicityOn
eShot, syncRegistrationId, m_registration->webRegistration(), new SyncRegistrati
onCallbacks(resolver, m_registration)); | 66 backgroundSyncProvider()->getRegistration(WebSyncRegistration::PeriodicityOn
eShot, syncRegistrationId, m_registration->webRegistration(), new SyncRegistrati
onCallbacks(resolver, m_registration)); |
| 73 | 67 |
| 74 return promise; | 68 return promise; |
| 75 } | 69 } |
| 76 | 70 |
| 77 ScriptPromise SyncManager::getRegistrations(ScriptState* scriptState) | 71 ScriptPromise SyncManager::getRegistrations(ScriptState* scriptState) |
| 78 { | 72 { |
| 79 if (!m_registration->active()) | |
| 80 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Operation failed - no active Service Worker")); | |
| 81 | |
| 82 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 73 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 83 ScriptPromise promise = resolver->promise(); | 74 ScriptPromise promise = resolver->promise(); |
| 84 | 75 |
| 85 backgroundSyncProvider()->getRegistrations(WebSyncRegistration::PeriodicityO
neShot, m_registration->webRegistration(), new SyncGetRegistrationsCallbacks(res
olver, m_registration)); | 76 backgroundSyncProvider()->getRegistrations(WebSyncRegistration::PeriodicityO
neShot, m_registration->webRegistration(), new SyncGetRegistrationsCallbacks(res
olver, m_registration)); |
| 86 | 77 |
| 87 return promise; | 78 return promise; |
| 88 } | 79 } |
| 89 | 80 |
| 90 ScriptPromise SyncManager::permissionState(ScriptState* scriptState) | 81 ScriptPromise SyncManager::permissionState(ScriptState* scriptState) |
| 91 { | 82 { |
| 92 if (!m_registration->active()) | |
| 93 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Operation failed - no active Service Worker")); | |
| 94 | |
| 95 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 83 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 96 ScriptPromise promise = resolver->promise(); | 84 ScriptPromise promise = resolver->promise(); |
| 97 | 85 |
| 98 backgroundSyncProvider()->getPermissionStatus(WebSyncRegistration::Periodici
tyOneShot, m_registration->webRegistration(), new SyncGetPermissionStatusCallbac
ks(resolver, m_registration)); | 86 backgroundSyncProvider()->getPermissionStatus(WebSyncRegistration::Periodici
tyOneShot, m_registration->webRegistration(), new SyncGetPermissionStatusCallbac
ks(resolver, m_registration)); |
| 99 | 87 |
| 100 return promise; | 88 return promise; |
| 101 } | 89 } |
| 102 | 90 |
| 103 DEFINE_TRACE(SyncManager) | 91 DEFINE_TRACE(SyncManager) |
| 104 { | 92 { |
| 105 visitor->trace(m_registration); | 93 visitor->trace(m_registration); |
| 106 } | 94 } |
| 107 | 95 |
| 108 } // namespace blink | 96 } // namespace blink |
| OLD | NEW |