| 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 #ifndef BackgroundFetchBridge_h | 5 #ifndef BackgroundFetchBridge_h |
| 6 #define BackgroundFetchBridge_h | 6 #define BackgroundFetchBridge_h |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 9 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
| 10 #include "platform/Supplementable.h" | 10 #include "platform/Supplementable.h" |
| 11 #include "platform/heap/Handle.h" | 11 #include "platform/heap/Handle.h" |
| 12 #include "public/platform/modules/background_fetch/background_fetch.mojom-blink.
h" | 12 #include "public/platform/modules/background_fetch/background_fetch.mojom-blink.
h" |
| 13 #include "wtf/Functional.h" | 13 #include "wtf/Functional.h" |
| 14 #include "wtf/Vector.h" | 14 #include "wtf/Vector.h" |
| 15 #include "wtf/text/WTFString.h" | 15 #include "wtf/text/WTFString.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 class BackgroundFetchOptions; |
| 19 class BackgroundFetchRegistration; | 20 class BackgroundFetchRegistration; |
| 20 | 21 |
| 21 // The bridge is responsible for establishing and maintaining the Mojo | 22 // The bridge is responsible for establishing and maintaining the Mojo |
| 22 // connection to the BackgroundFetchService. It's keyed on an active Service | 23 // connection to the BackgroundFetchService. It's keyed on an active Service |
| 23 // Worker Registration. | 24 // Worker Registration. |
| 24 class BackgroundFetchBridge final | 25 class BackgroundFetchBridge final |
| 25 : public GarbageCollectedFinalized<BackgroundFetchBridge>, | 26 : public GarbageCollectedFinalized<BackgroundFetchBridge>, |
| 26 public Supplement<ServiceWorkerRegistration> { | 27 public Supplement<ServiceWorkerRegistration> { |
| 27 USING_GARBAGE_COLLECTED_MIXIN(BackgroundFetchBridge); | 28 USING_GARBAGE_COLLECTED_MIXIN(BackgroundFetchBridge); |
| 28 WTF_MAKE_NONCOPYABLE(BackgroundFetchBridge); | 29 WTF_MAKE_NONCOPYABLE(BackgroundFetchBridge); |
| 29 | 30 |
| 30 public: | 31 public: |
| 31 using UpdateUICallback = Function<void(mojom::blink::BackgroundFetchError)>; | 32 using UpdateUICallback = Function<void(mojom::blink::BackgroundFetchError)>; |
| 32 using GetRegistrationCallback = | 33 using RegistrationCallback = Function<void(mojom::blink::BackgroundFetchError, |
| 33 Function<void(mojom::blink::BackgroundFetchError, | 34 BackgroundFetchRegistration*)>; |
| 34 BackgroundFetchRegistration*)>; | |
| 35 using GetTagsCallback = | 35 using GetTagsCallback = |
| 36 Function<void(mojom::blink::BackgroundFetchError, const Vector<String>&)>; | 36 Function<void(mojom::blink::BackgroundFetchError, const Vector<String>&)>; |
| 37 | 37 |
| 38 static BackgroundFetchBridge* from(ServiceWorkerRegistration*); | 38 static BackgroundFetchBridge* from(ServiceWorkerRegistration*); |
| 39 static const char* supplementName(); | 39 static const char* supplementName(); |
| 40 | 40 |
| 41 virtual ~BackgroundFetchBridge(); | 41 virtual ~BackgroundFetchBridge(); |
| 42 | 42 |
| 43 // TODO(peter): Implement support for the `fetch()` function in the bridge. | 43 // Creates a new Background Fetch registration identified by |tag| with the |
| 44 // given |options| for the sequence of |requests|. The |callback| will be |
| 45 // invoked when the registration has been created. |
| 46 void fetch(const String& tag, |
| 47 const BackgroundFetchOptions&, |
| 48 std::unique_ptr<RegistrationCallback>); |
| 44 | 49 |
| 45 // Updates the user interface for the Background Fetch identified by |tag| | 50 // Updates the user interface for the Background Fetch identified by |tag| |
| 46 // with the updated |title|. Will invoke the |callback| when the interface | 51 // with the updated |title|. Will invoke the |callback| when the interface |
| 47 // has been requested to update. | 52 // has been requested to update. |
| 48 void updateUI(const String& tag, | 53 void updateUI(const String& tag, |
| 49 const String& title, | 54 const String& title, |
| 50 std::unique_ptr<UpdateUICallback>); | 55 std::unique_ptr<UpdateUICallback>); |
| 51 | 56 |
| 52 // Aborts the active Background Fetch for |tag|. Does not respond. | 57 // Aborts the active Background Fetch for |tag|. Does not respond. |
| 53 void abort(const String& tag); | 58 void abort(const String& tag); |
| 54 | 59 |
| 55 // Gets the Background Fetch registration for the given |tag|. Will invoke the | 60 // Gets the Background Fetch registration for the given |tag|. Will invoke the |
| 56 // |callback| with the Background Fetch registration, which may be a nullptr | 61 // |callback| with the Background Fetch registration, which may be a nullptr |
| 57 // if the |tag| does not exist, when the Mojo call has completed. | 62 // if the |tag| does not exist, when the Mojo call has completed. |
| 58 void getRegistration(const String& tag, | 63 void getRegistration(const String& tag, |
| 59 std::unique_ptr<GetRegistrationCallback>); | 64 std::unique_ptr<RegistrationCallback>); |
| 60 | 65 |
| 61 // Gets the sequence of tags for active Background Fetch registrations. Will | 66 // Gets the sequence of tags for active Background Fetch registrations. Will |
| 62 // invoke the |callback| with the tags when the Mojo call has completed. | 67 // invoke the |callback| with the tags when the Mojo call has completed. |
| 63 void getTags(std::unique_ptr<GetTagsCallback>); | 68 void getTags(std::unique_ptr<GetTagsCallback>); |
| 64 | 69 |
| 65 private: | 70 private: |
| 66 explicit BackgroundFetchBridge(ServiceWorkerRegistration&); | 71 explicit BackgroundFetchBridge(ServiceWorkerRegistration&); |
| 67 | 72 |
| 68 // Returns an initialized BackgroundFetchServicePtr. A connection will be | 73 // Returns an initialized BackgroundFetchServicePtr. A connection will be |
| 69 // established after the first call to this method. | 74 // established after the first call to this method. |
| 70 mojom::blink::BackgroundFetchServicePtr& getService(); | 75 mojom::blink::BackgroundFetchServicePtr& getService(); |
| 71 | 76 |
| 72 void didGetRegistration(std::unique_ptr<GetRegistrationCallback>, | 77 void didGetRegistration(std::unique_ptr<RegistrationCallback>, |
| 73 mojom::blink::BackgroundFetchError, | 78 mojom::blink::BackgroundFetchError, |
| 74 mojom::blink::BackgroundFetchRegistrationPtr); | 79 mojom::blink::BackgroundFetchRegistrationPtr); |
| 75 | 80 |
| 76 mojom::blink::BackgroundFetchServicePtr m_backgroundFetchService; | 81 mojom::blink::BackgroundFetchServicePtr m_backgroundFetchService; |
| 77 }; | 82 }; |
| 78 | 83 |
| 79 } // namespace blink | 84 } // namespace blink |
| 80 | 85 |
| 81 #endif // BackgroundFetchBridge_h | 86 #endif // BackgroundFetchBridge_h |
| OLD | NEW |