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

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

Issue 2745243002: Implement a Mojo service for Background Fetch (Closed)
Patch Set: Implement a Mojo service for Background Fetch 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "modules/background_fetch/BackgroundFetchBridge.h"
6
7 #include "modules/background_fetch/BackgroundFetchOptions.h"
8 #include "modules/background_fetch/BackgroundFetchRegistration.h"
9 #include "modules/background_fetch/IconDefinition.h"
10 #include "public/platform/InterfaceProvider.h"
11 #include "public/platform/Platform.h"
12 #include "public/platform/modules/serviceworker/WebServiceWorkerRegistration.h"
13
14 namespace blink {
15
16 namespace {
17
18 // Creates a new BackgroundFetchRegistration instance given a Service Worker
19 // Registration and a Mojo BackgroundFetchRegistrationPtr instance.
20 BackgroundFetchRegistration* CreateBackgroundFetchRegistration(
21 ServiceWorkerRegistration* serviceWorkerRegistration,
22 mojom::blink::BackgroundFetchRegistrationPtr registrationPtr) {
23 HeapVector<IconDefinition> icons;
24
25 for (const auto& iconPtr : registrationPtr->icons) {
dcheng 2017/03/16 07:14:08 Is this something that would make sense to typemap
Peter Beverloo 2017/03/16 15:32:55 There's two questions here - (1) Mojo structs t
26 IconDefinition icon;
27 icon.setSrc(iconPtr->src);
28 icon.setSizes(iconPtr->sizes);
29 icon.setType(iconPtr->type);
30
31 icons.push_back(icon);
32 }
33
34 return new BackgroundFetchRegistration(
35 serviceWorkerRegistration, registrationPtr->tag, std::move(icons),
dcheng 2017/03/16 07:14:08 Nit: #include <utility> for std::move
Peter Beverloo 2017/03/16 15:32:56 Done.
36 registrationPtr->total_download_size, registrationPtr->title);
37 }
38
39 } // namespace
40
41 // static
42 BackgroundFetchBridge* BackgroundFetchBridge::from(
43 ServiceWorkerRegistration* serviceWorkerRegistration) {
44 DCHECK(serviceWorkerRegistration);
45
46 BackgroundFetchBridge* bridge = static_cast<BackgroundFetchBridge*>(
47 Supplement<ServiceWorkerRegistration>::from(serviceWorkerRegistration,
48 supplementName()));
49
50 if (!bridge) {
51 bridge = new BackgroundFetchBridge(*serviceWorkerRegistration);
52 Supplement<ServiceWorkerRegistration>::provideTo(*serviceWorkerRegistration,
53 supplementName(), bridge);
54 }
55
56 return bridge;
57 }
58
59 // static
60 const char* BackgroundFetchBridge::supplementName() {
61 return "BackgroundFetchBridge";
62 }
63
64 BackgroundFetchBridge::BackgroundFetchBridge(
65 ServiceWorkerRegistration& registration)
66 : Supplement<ServiceWorkerRegistration>(registration) {}
67
68 BackgroundFetchBridge::~BackgroundFetchBridge() = default;
69
70 void BackgroundFetchBridge::abort(const String& tag) {
71 getService()->Abort(supplementable()->webRegistration()->registrationId(),
72 tag);
73 }
74
75 void BackgroundFetchBridge::updateUI(
76 const String& tag,
77 const String& title,
78 std::unique_ptr<UpdateUICallback> callback) {
79 getService()->UpdateUI(supplementable()->webRegistration()->registrationId(),
80 tag, title,
81 convertToBaseCallback(std::move(callback)));
82 }
83
84 void BackgroundFetchBridge::getRegistration(
85 const String& tag,
86 std::unique_ptr<GetRegistrationCallback> callback) {
87 getService()->GetRegistration(
88 supplementable()->webRegistration()->registrationId(), tag,
89 convertToBaseCallback(
90 WTF::bind(&BackgroundFetchBridge::didGetRegistration,
91 wrapPersistent(this), WTF::passed(std::move(callback)))));
92 }
93
94 void BackgroundFetchBridge::didGetRegistration(
95 std::unique_ptr<GetRegistrationCallback> callback,
96 mojom::blink::BackgroundFetchError error,
97 mojom::blink::BackgroundFetchRegistrationPtr registrationPtr) {
98 BackgroundFetchRegistration* registration = nullptr;
99
100 if (registrationPtr) {
101 DCHECK_EQ(error, mojom::blink::BackgroundFetchError::NONE);
102 registration = CreateBackgroundFetchRegistration(
103 supplementable(), std::move(registrationPtr));
104 }
105
106 // Invoke the |callback| with the |error| and the constructed Background
107 // Fetch registration, which can't be a typemap as it's garbage collected.
dcheng 2017/03/16 07:14:08 Can you help me understand why Oilpan heap objects
Peter Beverloo 2017/03/16 15:32:55 This actually is a left-over comment -- the first
108 (*callback)(error, registration);
109 }
110
111 void BackgroundFetchBridge::getTags(std::unique_ptr<GetTagsCallback> callback) {
112 getService()->GetTags(supplementable()->webRegistration()->registrationId(),
113 convertToBaseCallback(std::move(callback)));
114 }
115
116 const mojom::blink::BackgroundFetchServicePtr&
dcheng 2017/03/16 07:14:08 It seems unusual to mark this const: it kind of ma
Peter Beverloo 2017/03/16 15:32:55 Done.
117 BackgroundFetchBridge::getService() {
118 if (!m_backgroundFetchService.get()) {
dcheng 2017/03/16 07:14:08 Nit: no .get()
Peter Beverloo 2017/03/16 15:32:55 Done.
119 Platform::current()->interfaceProvider()->getInterface(
120 mojo::MakeRequest(&m_backgroundFetchService));
121 }
122 return m_backgroundFetchService;
123 }
124
125 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698