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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 : m_registration(registration) | 45 : m_registration(registration) |
46 { | 46 { |
47 ASSERT(registration); | 47 ASSERT(registration); |
48 } | 48 } |
49 | 49 |
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(blink::ScriptState* scriptSt
ate, const 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 RefPtrWillBeRawPtr<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") { |
(...skipping 16 matching lines...) Expand all Loading... |
82 options.tag(), | 82 options.tag(), |
83 options.minPeriod(), | 83 options.minPeriod(), |
84 networkState, | 84 networkState, |
85 powerState | 85 powerState |
86 ); | 86 ); |
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(blink::ScriptState* scriptSta
te, const 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 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
98 ScriptPromise promise = resolver->promise(); | 98 ScriptPromise promise = resolver->promise(); |
99 | 99 |
100 backgroundSyncProvider()->getRegistration(blink::WebSyncRegistration::Period
icityPeriodic, syncRegistrationTag, m_registration->webRegistration(), new SyncR
egistrationCallbacks(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(blink::ScriptState* scriptSt
ate) | 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 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
111 ScriptPromise promise = resolver->promise(); | 111 ScriptPromise promise = resolver->promise(); |
112 | 112 |
113 backgroundSyncProvider()->getRegistrations(blink::WebSyncRegistration::Perio
dicityPeriodic, m_registration->webRegistration(), new SyncGetRegistrationsCallb
acks(resolver, 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(blink::ScriptState* scriptSta
te) | 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 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
124 ScriptPromise promise = resolver->promise(); | 124 ScriptPromise promise = resolver->promise(); |
125 resolver->resolve(String::fromUTF8("granted")); | 125 resolver->resolve(String::fromUTF8("granted")); |
126 return promise; | 126 return promise; |
127 } | 127 } |
128 | 128 |
129 DEFINE_TRACE(PeriodicSyncManager) | 129 DEFINE_TRACE(PeriodicSyncManager) |
130 { | 130 { |
131 visitor->trace(m_registration); | 131 visitor->trace(m_registration); |
132 } | 132 } |
133 | 133 |
134 } // namespace blink | 134 } // namespace blink |
OLD | NEW |