| 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/BackgroundFetchBridge.h" | 5 #include "modules/background_fetch/BackgroundFetchBridge.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include "modules/background_fetch/BackgroundFetchOptions.h" | 8 #include "modules/background_fetch/BackgroundFetchOptions.h" |
| 9 #include "modules/background_fetch/BackgroundFetchRegistration.h" | 9 #include "modules/background_fetch/BackgroundFetchRegistration.h" |
| 10 #include "modules/background_fetch/BackgroundFetchTypeConverters.h" | 10 #include "modules/background_fetch/BackgroundFetchTypeConverters.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 BackgroundFetchBridge::~BackgroundFetchBridge() = default; | 46 BackgroundFetchBridge::~BackgroundFetchBridge() = default; |
| 47 | 47 |
| 48 void BackgroundFetchBridge::fetch( | 48 void BackgroundFetchBridge::fetch( |
| 49 const String& tag, | 49 const String& tag, |
| 50 Vector<WebServiceWorkerRequest> requests, | 50 Vector<WebServiceWorkerRequest> requests, |
| 51 const BackgroundFetchOptions& options, | 51 const BackgroundFetchOptions& options, |
| 52 std::unique_ptr<RegistrationCallback> callback) { | 52 std::unique_ptr<RegistrationCallback> callback) { |
| 53 // TODO(peter): Include |requests| in the Mojo call. | 53 // TODO(peter): Include |requests| in the Mojo call. |
| 54 getService()->Fetch( | 54 getService()->Fetch( |
| 55 supplementable()->webRegistration()->registrationId(), tag, | 55 supplementable()->webRegistration()->registrationId(), |
| 56 getSecurityOrigin(), tag, |
| 56 mojom::blink::BackgroundFetchOptions::From(options), | 57 mojom::blink::BackgroundFetchOptions::From(options), |
| 57 convertToBaseCallback( | 58 convertToBaseCallback( |
| 58 WTF::bind(&BackgroundFetchBridge::didGetRegistration, | 59 WTF::bind(&BackgroundFetchBridge::didGetRegistration, |
| 59 wrapPersistent(this), WTF::passed(std::move(callback))))); | 60 wrapPersistent(this), WTF::passed(std::move(callback))))); |
| 60 } | 61 } |
| 61 | 62 |
| 62 void BackgroundFetchBridge::abort(const String& tag, | 63 void BackgroundFetchBridge::abort(const String& tag, |
| 63 std::unique_ptr<AbortCallback> callback) { | 64 std::unique_ptr<AbortCallback> callback) { |
| 64 getService()->Abort(supplementable()->webRegistration()->registrationId(), | 65 getService()->Abort(supplementable()->webRegistration()->registrationId(), |
| 65 tag, convertToBaseCallback(std::move(callback))); | 66 getSecurityOrigin(), tag, |
| 67 convertToBaseCallback(std::move(callback))); |
| 66 } | 68 } |
| 67 | 69 |
| 68 void BackgroundFetchBridge::updateUI( | 70 void BackgroundFetchBridge::updateUI( |
| 69 const String& tag, | 71 const String& tag, |
| 70 const String& title, | 72 const String& title, |
| 71 std::unique_ptr<UpdateUICallback> callback) { | 73 std::unique_ptr<UpdateUICallback> callback) { |
| 72 getService()->UpdateUI(supplementable()->webRegistration()->registrationId(), | 74 getService()->UpdateUI(supplementable()->webRegistration()->registrationId(), |
| 73 tag, title, | 75 getSecurityOrigin(), tag, title, |
| 74 convertToBaseCallback(std::move(callback))); | 76 convertToBaseCallback(std::move(callback))); |
| 75 } | 77 } |
| 76 | 78 |
| 77 void BackgroundFetchBridge::getRegistration( | 79 void BackgroundFetchBridge::getRegistration( |
| 78 const String& tag, | 80 const String& tag, |
| 79 std::unique_ptr<RegistrationCallback> callback) { | 81 std::unique_ptr<RegistrationCallback> callback) { |
| 80 getService()->GetRegistration( | 82 getService()->GetRegistration( |
| 81 supplementable()->webRegistration()->registrationId(), tag, | 83 supplementable()->webRegistration()->registrationId(), |
| 84 getSecurityOrigin(), tag, |
| 82 convertToBaseCallback( | 85 convertToBaseCallback( |
| 83 WTF::bind(&BackgroundFetchBridge::didGetRegistration, | 86 WTF::bind(&BackgroundFetchBridge::didGetRegistration, |
| 84 wrapPersistent(this), WTF::passed(std::move(callback))))); | 87 wrapPersistent(this), WTF::passed(std::move(callback))))); |
| 85 } | 88 } |
| 86 | 89 |
| 87 void BackgroundFetchBridge::didGetRegistration( | 90 void BackgroundFetchBridge::didGetRegistration( |
| 88 std::unique_ptr<RegistrationCallback> callback, | 91 std::unique_ptr<RegistrationCallback> callback, |
| 89 mojom::blink::BackgroundFetchError error, | 92 mojom::blink::BackgroundFetchError error, |
| 90 mojom::blink::BackgroundFetchRegistrationPtr registrationPtr) { | 93 mojom::blink::BackgroundFetchRegistrationPtr registrationPtr) { |
| 91 BackgroundFetchRegistration* registration = | 94 BackgroundFetchRegistration* registration = |
| 92 registrationPtr.To<BackgroundFetchRegistration*>(); | 95 registrationPtr.To<BackgroundFetchRegistration*>(); |
| 93 | 96 |
| 94 if (registration) { | 97 if (registration) { |
| 95 DCHECK_EQ(error, mojom::blink::BackgroundFetchError::NONE); | 98 DCHECK_EQ(error, mojom::blink::BackgroundFetchError::NONE); |
| 96 registration->setServiceWorkerRegistration(supplementable()); | 99 registration->setServiceWorkerRegistration(supplementable()); |
| 97 } | 100 } |
| 98 | 101 |
| 99 (*callback)(error, registration); | 102 (*callback)(error, registration); |
| 100 } | 103 } |
| 101 | 104 |
| 102 void BackgroundFetchBridge::getTags(std::unique_ptr<GetTagsCallback> callback) { | 105 void BackgroundFetchBridge::getTags(std::unique_ptr<GetTagsCallback> callback) { |
| 103 getService()->GetTags(supplementable()->webRegistration()->registrationId(), | 106 getService()->GetTags(supplementable()->webRegistration()->registrationId(), |
| 107 getSecurityOrigin(), |
| 104 convertToBaseCallback(std::move(callback))); | 108 convertToBaseCallback(std::move(callback))); |
| 105 } | 109 } |
| 106 | 110 |
| 111 SecurityOrigin* BackgroundFetchBridge::getSecurityOrigin() { |
| 112 return supplementable()->getExecutionContext()->getSecurityOrigin(); |
| 113 } |
| 114 |
| 107 mojom::blink::BackgroundFetchServicePtr& BackgroundFetchBridge::getService() { | 115 mojom::blink::BackgroundFetchServicePtr& BackgroundFetchBridge::getService() { |
| 108 if (!m_backgroundFetchService) { | 116 if (!m_backgroundFetchService) { |
| 109 Platform::current()->interfaceProvider()->getInterface( | 117 Platform::current()->interfaceProvider()->getInterface( |
| 110 mojo::MakeRequest(&m_backgroundFetchService)); | 118 mojo::MakeRequest(&m_backgroundFetchService)); |
| 111 } | 119 } |
| 112 return m_backgroundFetchService; | 120 return m_backgroundFetchService; |
| 113 } | 121 } |
| 114 | 122 |
| 115 } // namespace blink | 123 } // namespace blink |
| OLD | NEW |