| 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/PeriodicSyncManager.h" | 6 #include "modules/background_sync/PeriodicSyncManager.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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 unsigned long PeriodicSyncManager::minPossiblePeriod() | 50 unsigned long PeriodicSyncManager::minPossiblePeriod() |
| 51 { | 51 { |
| 52 return kMinPossiblePeriod; | 52 return kMinPossiblePeriod; |
| 53 } | 53 } |
| 54 | 54 |
| 55 ScriptPromise PeriodicSyncManager::registerFunction(ScriptState* scriptState, co
nst PeriodicSyncRegistrationOptions& options) | 55 ScriptPromise PeriodicSyncManager::registerFunction(ScriptState* scriptState, co
nst PeriodicSyncRegistrationOptions& options) |
| 56 { | 56 { |
| 57 if (!m_registration->active()) | 57 if (!m_registration->active()) |
| 58 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Registration failed - no active Service Worker")); | 58 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Registration failed - no active Service Worker")); |
| 59 | 59 |
| 60 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 60 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 61 ScriptPromise promise = resolver->promise(); | 61 ScriptPromise promise = resolver->promise(); |
| 62 | 62 |
| 63 WebSyncRegistration::NetworkState networkState; | 63 WebSyncRegistration::NetworkState networkState; |
| 64 String networkStateString = options.networkState(); | 64 String networkStateString = options.networkState(); |
| 65 if (networkStateString == "any") { | 65 if (networkStateString == "any") { |
| 66 networkState = WebSyncRegistration::NetworkState::NetworkStateAny; | 66 networkState = WebSyncRegistration::NetworkState::NetworkStateAny; |
| 67 } else if (networkStateString == "avoid-cellular") { | 67 } else if (networkStateString == "avoid-cellular") { |
| 68 networkState = WebSyncRegistration::NetworkState::NetworkStateAvoidCellu
lar; | 68 networkState = WebSyncRegistration::NetworkState::NetworkStateAvoidCellu
lar; |
| 69 } else { | 69 } else { |
| 70 networkState = WebSyncRegistration::NetworkState::NetworkStateOnline; | 70 networkState = WebSyncRegistration::NetworkState::NetworkStateOnline; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 87 backgroundSyncProvider()->registerBackgroundSync(webSyncRegistration, m_regi
stration->webRegistration(), new SyncRegistrationCallbacks(resolver, m_registrat
ion)); | 87 backgroundSyncProvider()->registerBackgroundSync(webSyncRegistration, m_regi
stration->webRegistration(), new SyncRegistrationCallbacks(resolver, m_registrat
ion)); |
| 88 | 88 |
| 89 return promise; | 89 return promise; |
| 90 } | 90 } |
| 91 | 91 |
| 92 ScriptPromise PeriodicSyncManager::getRegistration(ScriptState* scriptState, con
st String& syncRegistrationTag) | 92 ScriptPromise PeriodicSyncManager::getRegistration(ScriptState* scriptState, con
st String& syncRegistrationTag) |
| 93 { | 93 { |
| 94 if (!m_registration->active()) | 94 if (!m_registration->active()) |
| 95 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Operation failed - no active Service Worker")); | 95 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Operation failed - no active Service Worker")); |
| 96 | 96 |
| 97 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 97 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 98 ScriptPromise promise = resolver->promise(); | 98 ScriptPromise promise = resolver->promise(); |
| 99 | 99 |
| 100 backgroundSyncProvider()->getRegistration(WebSyncRegistration::PeriodicityPe
riodic, syncRegistrationTag, m_registration->webRegistration(), new SyncRegistra
tionCallbacks(resolver, m_registration)); | 100 backgroundSyncProvider()->getRegistration(WebSyncRegistration::PeriodicityPe
riodic, syncRegistrationTag, m_registration->webRegistration(), new SyncRegistra
tionCallbacks(resolver, m_registration)); |
| 101 | 101 |
| 102 return promise; | 102 return promise; |
| 103 } | 103 } |
| 104 | 104 |
| 105 ScriptPromise PeriodicSyncManager::getRegistrations(ScriptState* scriptState) | 105 ScriptPromise PeriodicSyncManager::getRegistrations(ScriptState* scriptState) |
| 106 { | 106 { |
| 107 if (!m_registration->active()) | 107 if (!m_registration->active()) |
| 108 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Operation failed - no active Service Worker")); | 108 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Operation failed - no active Service Worker")); |
| 109 | 109 |
| 110 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 110 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 111 ScriptPromise promise = resolver->promise(); | 111 ScriptPromise promise = resolver->promise(); |
| 112 | 112 |
| 113 backgroundSyncProvider()->getRegistrations(WebSyncRegistration::PeriodicityP
eriodic, m_registration->webRegistration(), new SyncGetRegistrationsCallbacks(re
solver, m_registration)); | 113 backgroundSyncProvider()->getRegistrations(WebSyncRegistration::PeriodicityP
eriodic, m_registration->webRegistration(), new SyncGetRegistrationsCallbacks(re
solver, m_registration)); |
| 114 | 114 |
| 115 return promise; | 115 return promise; |
| 116 } | 116 } |
| 117 | 117 |
| 118 ScriptPromise PeriodicSyncManager::permissionState(ScriptState* scriptState) | 118 ScriptPromise PeriodicSyncManager::permissionState(ScriptState* scriptState) |
| 119 { | 119 { |
| 120 if (!m_registration->active()) | 120 if (!m_registration->active()) |
| 121 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Operation failed - no active Service Worker")); | 121 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Operation failed - no active Service Worker")); |
| 122 | 122 |
| 123 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 123 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 124 ScriptPromise promise = resolver->promise(); | 124 ScriptPromise promise = resolver->promise(); |
| 125 | 125 |
| 126 backgroundSyncProvider()->getPermissionStatus(WebSyncRegistration::Periodici
tyPeriodic, m_registration->webRegistration(), new SyncGetPermissionStatusCallba
cks(resolver, m_registration)); | 126 backgroundSyncProvider()->getPermissionStatus(WebSyncRegistration::Periodici
tyPeriodic, m_registration->webRegistration(), new SyncGetPermissionStatusCallba
cks(resolver, m_registration)); |
| 127 | 127 |
| 128 return promise; | 128 return promise; |
| 129 } | 129 } |
| 130 | 130 |
| 131 DEFINE_TRACE(PeriodicSyncManager) | 131 DEFINE_TRACE(PeriodicSyncManager) |
| 132 { | 132 { |
| 133 visitor->trace(m_registration); | 133 visitor->trace(m_registration); |
| 134 } | 134 } |
| 135 | 135 |
| 136 } // namespace blink | 136 } // namespace blink |
| OLD | NEW |