| 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(blink::ScriptState* scriptState, con
st SyncRegistrationOptions& options) | 43 ScriptPromise SyncManager::registerFunction(ScriptState* scriptState, const Sync
RegistrationOptions& options) |
| 44 { | 44 { |
| 45 if (!m_registration->active()) | 45 if (!m_registration->active()) |
| 46 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Registration failed - no active Service Worker")); | 46 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Registration failed - no active Service Worker")); |
| 47 | 47 |
| 48 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 48 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
| 49 ScriptPromise promise = resolver->promise(); | 49 ScriptPromise promise = resolver->promise(); |
| 50 | 50 |
| 51 WebSyncRegistration* webSyncRegistration = new WebSyncRegistration( | 51 WebSyncRegistration* webSyncRegistration = new WebSyncRegistration( |
| 52 WebSyncRegistration::UNREGISTERED_SYNC_ID /* id */, | 52 WebSyncRegistration::UNREGISTERED_SYNC_ID /* id */, |
| 53 WebSyncRegistration::PeriodicityOneShot, | 53 WebSyncRegistration::PeriodicityOneShot, |
| 54 options.tag(), | 54 options.tag(), |
| 55 0 /* minPeriod */, | 55 0 /* minPeriod */, |
| 56 WebSyncRegistration::NetworkStateAny /* networkState */, | 56 WebSyncRegistration::NetworkStateAny /* networkState */, |
| 57 WebSyncRegistration::PowerStateAuto /* powerState */ | 57 WebSyncRegistration::PowerStateAuto /* powerState */ |
| 58 ); | 58 ); |
| 59 backgroundSyncProvider()->registerBackgroundSync(webSyncRegistration, m_regi
stration->webRegistration(), new SyncRegistrationCallbacks(resolver, m_registrat
ion)); | 59 backgroundSyncProvider()->registerBackgroundSync(webSyncRegistration, m_regi
stration->webRegistration(), new SyncRegistrationCallbacks(resolver, m_registrat
ion)); |
| 60 | 60 |
| 61 return promise; | 61 return promise; |
| 62 } | 62 } |
| 63 | 63 |
| 64 ScriptPromise SyncManager::getRegistration(blink::ScriptState* scriptState, cons
t String& syncRegistrationId) | 64 ScriptPromise SyncManager::getRegistration(ScriptState* scriptState, const Strin
g& syncRegistrationId) |
| 65 { | 65 { |
| 66 if (!m_registration->active()) | 66 if (!m_registration->active()) |
| 67 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Operation failed - no active Service Worker")); | 67 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Operation failed - no active Service Worker")); |
| 68 | 68 |
| 69 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 69 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
| 70 ScriptPromise promise = resolver->promise(); | 70 ScriptPromise promise = resolver->promise(); |
| 71 | 71 |
| 72 backgroundSyncProvider()->getRegistration(blink::WebSyncRegistration::Period
icityOneShot, syncRegistrationId, m_registration->webRegistration(), new SyncReg
istrationCallbacks(resolver, m_registration)); | 72 backgroundSyncProvider()->getRegistration(WebSyncRegistration::PeriodicityOn
eShot, syncRegistrationId, m_registration->webRegistration(), new SyncRegistrati
onCallbacks(resolver, m_registration)); |
| 73 | 73 |
| 74 return promise; | 74 return promise; |
| 75 } | 75 } |
| 76 | 76 |
| 77 ScriptPromise SyncManager::getRegistrations(blink::ScriptState* scriptState) | 77 ScriptPromise SyncManager::getRegistrations(ScriptState* scriptState) |
| 78 { | 78 { |
| 79 if (!m_registration->active()) | 79 if (!m_registration->active()) |
| 80 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Operation failed - no active Service Worker")); | 80 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Operation failed - no active Service Worker")); |
| 81 | 81 |
| 82 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 82 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
| 83 ScriptPromise promise = resolver->promise(); | 83 ScriptPromise promise = resolver->promise(); |
| 84 | 84 |
| 85 backgroundSyncProvider()->getRegistrations(blink::WebSyncRegistration::Perio
dicityOneShot, m_registration->webRegistration(), new SyncGetRegistrationsCallba
cks(resolver, m_registration)); | 85 backgroundSyncProvider()->getRegistrations(WebSyncRegistration::PeriodicityO
neShot, m_registration->webRegistration(), new SyncGetRegistrationsCallbacks(res
olver, m_registration)); |
| 86 | 86 |
| 87 return promise; | 87 return promise; |
| 88 } | 88 } |
| 89 | 89 |
| 90 ScriptPromise SyncManager::permissionState(blink::ScriptState* scriptState) | 90 ScriptPromise SyncManager::permissionState(ScriptState* scriptState) |
| 91 { | 91 { |
| 92 if (!m_registration->active()) | 92 if (!m_registration->active()) |
| 93 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Operation failed - no active Service Worker")); | 93 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Operation failed - no active Service Worker")); |
| 94 | 94 |
| 95 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 95 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
| 96 ScriptPromise promise = resolver->promise(); | 96 ScriptPromise promise = resolver->promise(); |
| 97 resolver->resolve(String::fromUTF8("granted")); | 97 resolver->resolve(String::fromUTF8("granted")); |
| 98 return promise; | 98 return promise; |
| 99 } | 99 } |
| 100 | 100 |
| 101 DEFINE_TRACE(SyncManager) | 101 DEFINE_TRACE(SyncManager) |
| 102 { | 102 { |
| 103 visitor->trace(m_registration); | 103 visitor->trace(m_registration); |
| 104 } | 104 } |
| 105 | 105 |
| 106 } // namespace blink | 106 } // namespace blink |
| OLD | NEW |