| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "modules/background_fetch/BackgroundFetchManager.h" | 5 #include "modules/background_fetch/BackgroundFetchManager.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "bindings/core/v8/V8ThrowException.h" | 9 #include "bindings/core/v8/V8ThrowException.h" |
| 10 #include "bindings/modules/v8/RequestOrUSVStringOrRequestOrUSVStringSequence.h" |
| 10 #include "modules/background_fetch/BackgroundFetchOptions.h" | 11 #include "modules/background_fetch/BackgroundFetchOptions.h" |
| 11 #include "modules/background_fetch/BackgroundFetchRegistration.h" | 12 #include "modules/background_fetch/BackgroundFetchRegistration.h" |
| 12 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 13 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 | 16 |
| 16 BackgroundFetchManager::BackgroundFetchManager( | 17 BackgroundFetchManager::BackgroundFetchManager( |
| 17 ServiceWorkerRegistration* registration) | 18 ServiceWorkerRegistration* registration) |
| 18 : m_registration(registration) { | 19 : m_registration(registration) { |
| 19 DCHECK(registration); | 20 DCHECK(registration); |
| 20 } | 21 } |
| 21 | 22 |
| 22 ScriptPromise BackgroundFetchManager::fetch( | 23 ScriptPromise BackgroundFetchManager::fetch( |
| 23 ScriptState* scriptState, | 24 ScriptState* scriptState, |
| 24 String tag, | 25 String tag, |
| 25 HeapVector<RequestOrUSVString> requests, | 26 const RequestOrUSVStringOrRequestOrUSVStringSequence& requests, |
| 26 const BackgroundFetchOptions& options) { | 27 const BackgroundFetchOptions& options) { |
| 28 if (requests.isRequest()) { |
| 29 LOG(INFO) << "We were passed a Request IDL object."; |
| 30 } else if (requests.isUSVString()) { |
| 31 LOG(INFO) << "We were passed an USVString."; |
| 32 } else if (requests.isRequestOrUSVStringSequence()) { |
| 33 LOG(INFO) << "We were passed a sequence<(Request or USVString)>."; |
| 34 } else /* requests.isNull() */ { |
| 35 NOTREACHED(); |
| 36 } |
| 37 |
| 27 if (!m_registration->active()) { | 38 if (!m_registration->active()) { |
| 28 return ScriptPromise::reject( | 39 return ScriptPromise::reject( |
| 29 scriptState, | 40 scriptState, |
| 30 V8ThrowException::createTypeError(scriptState->isolate(), | 41 V8ThrowException::createTypeError(scriptState->isolate(), |
| 31 "No active registration available on " | 42 "No active registration available on " |
| 32 "the ServiceWorkerRegistration.")); | 43 "the ServiceWorkerRegistration.")); |
| 33 } | 44 } |
| 34 | 45 |
| 35 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 46 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 36 ScriptPromise promise = resolver->promise(); | 47 ScriptPromise promise = resolver->promise(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 resolver->resolve(Vector<String>()); | 94 resolver->resolve(Vector<String>()); |
| 84 | 95 |
| 85 return promise; | 96 return promise; |
| 86 } | 97 } |
| 87 | 98 |
| 88 DEFINE_TRACE(BackgroundFetchManager) { | 99 DEFINE_TRACE(BackgroundFetchManager) { |
| 89 visitor->trace(m_registration); | 100 visitor->trace(m_registration); |
| 90 } | 101 } |
| 91 | 102 |
| 92 } // namespace blink | 103 } // namespace blink |
| OLD | NEW |