Chromium Code Reviews| Index: third_party/WebKit/Source/modules/background_fetch/BackgroundFetchBridge.h |
| diff --git a/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchBridge.h b/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchBridge.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1b8ff5d10c666ca41ffaebac647322e360569fd8 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchBridge.h |
| @@ -0,0 +1,81 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BackgroundFetchBridge_h |
| +#define BackgroundFetchBridge_h |
| + |
| +#include <memory> |
| +#include "modules/serviceworkers/ServiceWorkerRegistration.h" |
| +#include "platform/Supplementable.h" |
| +#include "platform/heap/Handle.h" |
| +#include "public/platform/modules/background_fetch/background_fetch.mojom-blink.h" |
| +#include "wtf/Functional.h" |
| +#include "wtf/Vector.h" |
| +#include "wtf/text/WTFString.h" |
| + |
| +namespace blink { |
| + |
| +class BackgroundFetchRegistration; |
| + |
| +// The bridge is responsible for establishing and maintaining the Mojo |
| +// connection to the BackgroundFetchService. It's keyed on an active Service |
| +// Worker Registration. |
| +class BackgroundFetchBridge final |
| + : public GarbageCollectedFinalized<BackgroundFetchBridge>, |
| + public Supplement<ServiceWorkerRegistration> { |
| + USING_GARBAGE_COLLECTED_MIXIN(BackgroundFetchBridge); |
| + WTF_MAKE_NONCOPYABLE(BackgroundFetchBridge); |
| + |
| + public: |
| + using UpdateUICallback = Function<void(mojom::blink::BackgroundFetchError)>; |
| + using GetRegistrationCallback = |
| + Function<void(mojom::blink::BackgroundFetchError, |
| + BackgroundFetchRegistration*)>; |
| + using GetTagsCallback = |
| + Function<void(mojom::blink::BackgroundFetchError, const Vector<String>&)>; |
| + |
| + static BackgroundFetchBridge* from(ServiceWorkerRegistration*); |
| + static const char* supplementName(); |
| + |
| + virtual ~BackgroundFetchBridge(); |
| + |
| + // TODO(peter): Implement suppor for the `fetch()` function in the bridge. |
|
haraken
2017/03/14 09:13:14
support
Peter Beverloo
2017/03/14 15:17:21
Done.
|
| + |
| + // Updates the user interface for the Background Fetch identified by |tag| |
| + // with the updated |title|. Will invoke the |callback| when the interface |
| + // has been updated. |
|
harkness
2017/03/14 11:55:47
Can we give a weaker time guarantee for this? Inst
Peter Beverloo
2017/03/14 15:17:21
Done.
|
| + void updateUI(const String& tag, |
| + const String& title, |
| + std::unique_ptr<UpdateUICallback>); |
| + |
| + // Aborts the active Background Fetch for |tag|. Does not respond. |
| + void abort(const String& tag); |
| + |
| + // Gets the Background Fetch registration for the given |tag|. Will invoke the |
| + // |callback| with the Background Fetch registration, which may be a nullptr |
| + // if the |tag| does not exist, when the Mojo call has completed. |
| + void getRegistration(const String& tag, |
| + std::unique_ptr<GetRegistrationCallback>); |
| + |
| + // Gets the sequence of tags for active Background Fetch registrations. Will |
| + // invoke the |callback| with the tags when the Mojo call has completed. |
| + void getTags(std::unique_ptr<GetTagsCallback>); |
| + |
| + private: |
| + explicit BackgroundFetchBridge(ServiceWorkerRegistration&); |
| + |
| + // Returns an initialized BackgroundFetchServicePtr. A connection will be |
| + // established after the first call to this method. |
| + const mojom::blink::BackgroundFetchServicePtr& GetService(); |
| + |
| + void didGetRegistration(std::unique_ptr<GetRegistrationCallback>, |
| + mojom::blink::BackgroundFetchError, |
| + mojom::blink::BackgroundFetchRegistrationPtr); |
| + |
| + mojom::blink::BackgroundFetchServicePtr m_backgroundFetchService; |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // BackgroundFetchBridge_h |