| 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/BackgroundFetchRegistration.h" | 5 #include "modules/background_fetch/BackgroundFetchRegistration.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptState.h" |
| 7 #include "modules/background_fetch/BackgroundFetchBridge.h" | 8 #include "modules/background_fetch/BackgroundFetchBridge.h" |
| 8 #include "modules/background_fetch/IconDefinition.h" | 9 #include "modules/background_fetch/IconDefinition.h" |
| 9 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 10 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
| 10 | 11 |
| 11 namespace blink { | 12 namespace blink { |
| 12 | 13 |
| 13 BackgroundFetchRegistration::BackgroundFetchRegistration( | 14 BackgroundFetchRegistration::BackgroundFetchRegistration( |
| 14 ServiceWorkerRegistration* registration, | 15 ServiceWorkerRegistration* registration, |
| 15 String tag, | 16 String tag, |
| 16 HeapVector<IconDefinition> icons, | 17 HeapVector<IconDefinition> icons, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 33 } | 34 } |
| 34 | 35 |
| 35 long long BackgroundFetchRegistration::totalDownloadSize() const { | 36 long long BackgroundFetchRegistration::totalDownloadSize() const { |
| 36 return m_totalDownloadSize; | 37 return m_totalDownloadSize; |
| 37 } | 38 } |
| 38 | 39 |
| 39 String BackgroundFetchRegistration::title() const { | 40 String BackgroundFetchRegistration::title() const { |
| 40 return m_title; | 41 return m_title; |
| 41 } | 42 } |
| 42 | 43 |
| 43 void BackgroundFetchRegistration::abort() { | 44 ScriptPromise BackgroundFetchRegistration::abort(ScriptState* scriptState) { |
| 44 BackgroundFetchBridge::from(m_registration)->abort(m_tag); | 45 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 46 ScriptPromise promise = resolver->promise(); |
| 47 |
| 48 BackgroundFetchBridge::from(m_registration) |
| 49 ->abort(m_tag, WTF::bind(&BackgroundFetchRegistration::didAbort, |
| 50 wrapPersistent(this), wrapPersistent(resolver))); |
| 51 |
| 52 return promise; |
| 53 } |
| 54 |
| 55 void BackgroundFetchRegistration::didAbort( |
| 56 ScriptPromiseResolver* resolver, |
| 57 mojom::blink::BackgroundFetchError error) { |
| 58 switch (error) { |
| 59 case mojom::blink::BackgroundFetchError::NONE: |
| 60 resolver->resolve(true /* success */); |
| 61 return; |
| 62 case mojom::blink::BackgroundFetchError::INVALID_TAG: |
| 63 resolver->resolve(false /* success */); |
| 64 return; |
| 65 case mojom::blink::BackgroundFetchError::DUPLICATED_TAG: |
| 66 // Not applicable for this callback. |
| 67 break; |
| 68 } |
| 69 |
| 70 NOTREACHED(); |
| 45 } | 71 } |
| 46 | 72 |
| 47 DEFINE_TRACE(BackgroundFetchRegistration) { | 73 DEFINE_TRACE(BackgroundFetchRegistration) { |
| 48 visitor->trace(m_registration); | 74 visitor->trace(m_registration); |
| 49 visitor->trace(m_icons); | 75 visitor->trace(m_icons); |
| 50 } | 76 } |
| 51 | 77 |
| 52 } // namespace blink | 78 } // namespace blink |
| OLD | NEW |