| 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, ExecutionC
ontext* context, const SyncRegistrationOptions& options) | 43 ScriptPromise SyncManager::registerFunction(ScriptState* scriptState, ExecutionC
ontext* context, const String& tag) |
| 44 { | 44 { |
| 45 // TODO(jkarlin): Wait for the registration to become active instead of reje
cting. See crbug.com/542437. | 45 // TODO(jkarlin): Wait for the registration to become active instead of reje
cting. See crbug.com/542437. |
| 46 if (!m_registration->active()) | 46 if (!m_registration->active()) |
| 47 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Registration failed - no active Service Worker")); | 47 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Registration failed - no active Service Worker")); |
| 48 | 48 |
| 49 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 49 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 50 ScriptPromise promise = resolver->promise(); | 50 ScriptPromise promise = resolver->promise(); |
| 51 | 51 |
| 52 WebSyncRegistration* webSyncRegistration = new WebSyncRegistration( | 52 WebSyncRegistration* webSyncRegistration = new WebSyncRegistration( |
| 53 WebSyncRegistration::UNREGISTERED_SYNC_ID /* id */, | 53 WebSyncRegistration::UNREGISTERED_SYNC_ID /* id */, |
| 54 WebSyncRegistration::PeriodicityOneShot, | 54 WebSyncRegistration::PeriodicityOneShot, |
| 55 options.tag(), | 55 tag, |
| 56 0 /* minPeriod */, | 56 0 /* minPeriod */, |
| 57 WebSyncRegistration::NetworkStateOnline /* networkState */, | 57 WebSyncRegistration::NetworkStateOnline /* networkState */, |
| 58 WebSyncRegistration::PowerStateAuto /* powerState */ | 58 WebSyncRegistration::PowerStateAuto /* powerState */ |
| 59 ); | 59 ); |
| 60 backgroundSyncProvider()->registerBackgroundSync(webSyncRegistration, m_regi
stration->webRegistration(), context->isServiceWorkerGlobalScope(), new SyncRegi
strationCallbacks(resolver, m_registration)); | 60 backgroundSyncProvider()->registerBackgroundSync(webSyncRegistration, m_regi
stration->webRegistration(), context->isServiceWorkerGlobalScope(), new SyncRegi
strationCallbacks(resolver, m_registration)); |
| 61 | 61 |
| 62 return promise; | 62 return promise; |
| 63 } | 63 } |
| 64 | 64 |
| 65 ScriptPromise SyncManager::getRegistration(ScriptState* scriptState, const Strin
g& syncRegistrationId) | 65 ScriptPromise SyncManager::getTags(ScriptState* scriptState) |
| 66 { | 66 { |
| 67 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 67 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 68 ScriptPromise promise = resolver->promise(); | 68 ScriptPromise promise = resolver->promise(); |
| 69 | |
| 70 backgroundSyncProvider()->getRegistration(WebSyncRegistration::PeriodicityOn
eShot, syncRegistrationId, m_registration->webRegistration(), new SyncRegistrati
onCallbacks(resolver, m_registration)); | |
| 71 | |
| 72 return promise; | |
| 73 } | |
| 74 | |
| 75 ScriptPromise SyncManager::getRegistrations(ScriptState* scriptState) | |
| 76 { | |
| 77 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | |
| 78 ScriptPromise promise = resolver->promise(); | |
| 79 | 69 |
| 80 backgroundSyncProvider()->getRegistrations(WebSyncRegistration::PeriodicityO
neShot, m_registration->webRegistration(), new SyncGetRegistrationsCallbacks(res
olver, m_registration)); | 70 backgroundSyncProvider()->getRegistrations(WebSyncRegistration::PeriodicityO
neShot, m_registration->webRegistration(), new SyncGetRegistrationsCallbacks(res
olver, m_registration)); |
| 81 | 71 |
| 82 return promise; | 72 return promise; |
| 83 } | 73 } |
| 84 | 74 |
| 85 ScriptPromise SyncManager::permissionState(ScriptState* scriptState) | |
| 86 { | |
| 87 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | |
| 88 ScriptPromise promise = resolver->promise(); | |
| 89 | |
| 90 backgroundSyncProvider()->getPermissionStatus(WebSyncRegistration::Periodici
tyOneShot, m_registration->webRegistration(), new SyncGetPermissionStatusCallbac
ks(resolver, m_registration)); | |
| 91 | |
| 92 return promise; | |
| 93 } | |
| 94 | |
| 95 DEFINE_TRACE(SyncManager) | 75 DEFINE_TRACE(SyncManager) |
| 96 { | 76 { |
| 97 visitor->trace(m_registration); | 77 visitor->trace(m_registration); |
| 98 } | 78 } |
| 99 | 79 |
| 100 } // namespace blink | 80 } // namespace blink |
| OLD | NEW |