Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: third_party/WebKit/Source/modules/background_fetch/BackgroundFetchBridge.h

Issue 2762573003: Implement BackgroundFetchManager.fetch() and struct traits (Closed)
Patch Set: First round of comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 AbortCallback = Function<void(mojom::blink::BackgroundFetchError)>; 32 using AbortCallback = Function<void(mojom::blink::BackgroundFetchError)>;
32 using GetRegistrationCallback =
33 Function<void(mojom::blink::BackgroundFetchError,
34 BackgroundFetchRegistration*)>;
35 using GetTagsCallback = 33 using GetTagsCallback =
36 Function<void(mojom::blink::BackgroundFetchError, const Vector<String>&)>; 34 Function<void(mojom::blink::BackgroundFetchError, const Vector<String>&)>;
35 using RegistrationCallback = Function<void(mojom::blink::BackgroundFetchError,
36 BackgroundFetchRegistration*)>;
37 using UpdateUICallback = Function<void(mojom::blink::BackgroundFetchError)>; 37 using UpdateUICallback = Function<void(mojom::blink::BackgroundFetchError)>;
38 38
39 static BackgroundFetchBridge* from(ServiceWorkerRegistration*); 39 static BackgroundFetchBridge* from(ServiceWorkerRegistration*);
40 static const char* supplementName(); 40 static const char* supplementName();
41 41
42 virtual ~BackgroundFetchBridge(); 42 virtual ~BackgroundFetchBridge();
43 43
44 // TODO(peter): Implement support for the `fetch()` function in the bridge. 44 // Creates a new Background Fetch registration identified by |tag| with the
45 // given |options| for the sequence of |requests|. The |callback| will be
46 // invoked when the registration has been created.
47 void fetch(const String& tag,
48 const BackgroundFetchOptions&,
49 std::unique_ptr<RegistrationCallback>);
45 50
46 // Updates the user interface for the Background Fetch identified by |tag| 51 // Updates the user interface for the Background Fetch identified by |tag|
47 // with the updated |title|. Will invoke the |callback| when the interface 52 // with the updated |title|. Will invoke the |callback| when the interface
48 // has been requested to update. 53 // has been requested to update.
49 void updateUI(const String& tag, 54 void updateUI(const String& tag,
50 const String& title, 55 const String& title,
51 std::unique_ptr<UpdateUICallback>); 56 std::unique_ptr<UpdateUICallback>);
52 57
53 // Aborts the active Background Fetch for |tag|. Will invoke the |callback| 58 // Aborts the active Background Fetch for |tag|. Will invoke the |callback|
54 // when the Background Fetch identified by |tag| has been aborted, or could 59 // when the Background Fetch identified by |tag| has been aborted, or could
55 // not be aborted for operational reasons. 60 // not be aborted for operational reasons.
56 void abort(const String& tag, std::unique_ptr<AbortCallback>); 61 void abort(const String& tag, std::unique_ptr<AbortCallback>);
57 62
58 // Gets the Background Fetch registration for the given |tag|. Will invoke the 63 // Gets the Background Fetch registration for the given |tag|. Will invoke the
59 // |callback| with the Background Fetch registration, which may be a nullptr 64 // |callback| with the Background Fetch registration, which may be a nullptr
60 // if the |tag| does not exist, when the Mojo call has completed. 65 // if the |tag| does not exist, when the Mojo call has completed.
61 void getRegistration(const String& tag, 66 void getRegistration(const String& tag,
62 std::unique_ptr<GetRegistrationCallback>); 67 std::unique_ptr<RegistrationCallback>);
63 68
64 // Gets the sequence of tags for active Background Fetch registrations. Will 69 // Gets the sequence of tags for active Background Fetch registrations. Will
65 // invoke the |callback| with the tags when the Mojo call has completed. 70 // invoke the |callback| with the tags when the Mojo call has completed.
66 void getTags(std::unique_ptr<GetTagsCallback>); 71 void getTags(std::unique_ptr<GetTagsCallback>);
67 72
68 private: 73 private:
69 explicit BackgroundFetchBridge(ServiceWorkerRegistration&); 74 explicit BackgroundFetchBridge(ServiceWorkerRegistration&);
70 75
71 // Returns an initialized BackgroundFetchServicePtr. A connection will be 76 // Returns an initialized BackgroundFetchServicePtr. A connection will be
72 // established after the first call to this method. 77 // established after the first call to this method.
73 mojom::blink::BackgroundFetchServicePtr& getService(); 78 mojom::blink::BackgroundFetchServicePtr& getService();
74 79
75 void didGetRegistration(std::unique_ptr<GetRegistrationCallback>, 80 void didGetRegistration(std::unique_ptr<RegistrationCallback>,
76 mojom::blink::BackgroundFetchError, 81 mojom::blink::BackgroundFetchError,
77 mojom::blink::BackgroundFetchRegistrationPtr); 82 mojom::blink::BackgroundFetchRegistrationPtr);
78 83
79 mojom::blink::BackgroundFetchServicePtr m_backgroundFetchService; 84 mojom::blink::BackgroundFetchServicePtr m_backgroundFetchService;
80 }; 85 };
81 86
82 } // namespace blink 87 } // namespace blink
83 88
84 #endif // BackgroundFetchBridge_h 89 #endif // BackgroundFetchBridge_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698