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

Unified Diff: third_party/WebKit/Source/modules/background_fetch/BackgroundFetchBridge.cpp

Issue 2762573003: Implement BackgroundFetchManager.fetch() and struct traits (Closed)
Patch Set: Add a missing file 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/background_fetch/BackgroundFetchBridge.cpp
diff --git a/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchBridge.cpp b/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchBridge.cpp
index ef89640d0c848985c086ad7795aa43295e7fecae..c8b0382588be2782cf8f08ffc8ab916d7e8fee66 100644
--- a/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchBridge.cpp
+++ b/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchBridge.cpp
@@ -7,6 +7,7 @@
#include <utility>
#include "modules/background_fetch/BackgroundFetchOptions.h"
#include "modules/background_fetch/BackgroundFetchRegistration.h"
+#include "modules/background_fetch/BackgroundFetchTypeConverters.h"
dcheng 2017/03/21 07:03:20 Let's use typemapping on the Blink side. It'll sav
Peter Beverloo 2017/03/21 14:05:19 These types live in //Source/modules/, whereas the
#include "modules/background_fetch/IconDefinition.h"
#include "public/platform/InterfaceProvider.h"
#include "public/platform/Platform.h"
@@ -14,31 +15,6 @@
namespace blink {
-namespace {
-
-// Creates a new BackgroundFetchRegistration instance given a Service Worker
-// Registration and a Mojo BackgroundFetchRegistrationPtr instance.
-BackgroundFetchRegistration* CreateBackgroundFetchRegistration(
- ServiceWorkerRegistration* serviceWorkerRegistration,
- mojom::blink::BackgroundFetchRegistrationPtr registrationPtr) {
- HeapVector<IconDefinition> icons;
-
- for (const auto& iconPtr : registrationPtr->icons) {
- IconDefinition icon;
- icon.setSrc(iconPtr->src);
- icon.setSizes(iconPtr->sizes);
- icon.setType(iconPtr->type);
-
- icons.push_back(icon);
- }
-
- return new BackgroundFetchRegistration(
- serviceWorkerRegistration, registrationPtr->tag, std::move(icons),
- registrationPtr->total_download_size, registrationPtr->title);
-}
-
-} // namespace
-
// static
BackgroundFetchBridge* BackgroundFetchBridge::from(
ServiceWorkerRegistration* serviceWorkerRegistration) {
@@ -68,6 +44,18 @@ BackgroundFetchBridge::BackgroundFetchBridge(
BackgroundFetchBridge::~BackgroundFetchBridge() = default;
+void BackgroundFetchBridge::fetch(
+ const String& tag,
+ const BackgroundFetchOptions& options,
+ std::unique_ptr<RegistrationCallback> callback) {
+ getService()->Fetch(
+ supplementable()->webRegistration()->registrationId(), tag,
+ mojom::blink::BackgroundFetchOptions::From(options),
+ convertToBaseCallback(
+ WTF::bind(&BackgroundFetchBridge::didGetRegistration,
+ wrapPersistent(this), WTF::passed(std::move(callback)))));
+}
+
void BackgroundFetchBridge::abort(const String& tag) {
getService()->Abort(supplementable()->webRegistration()->registrationId(),
tag);
@@ -84,7 +72,7 @@ void BackgroundFetchBridge::updateUI(
void BackgroundFetchBridge::getRegistration(
const String& tag,
- std::unique_ptr<GetRegistrationCallback> callback) {
+ std::unique_ptr<RegistrationCallback> callback) {
getService()->GetRegistration(
supplementable()->webRegistration()->registrationId(), tag,
convertToBaseCallback(
@@ -93,15 +81,15 @@ void BackgroundFetchBridge::getRegistration(
}
void BackgroundFetchBridge::didGetRegistration(
harkness 2017/03/21 11:30:00 optional: I'm glad that we're reusing the code for
Peter Beverloo 2017/03/21 13:46:27 Can you suggest a name that you think would be cle
- std::unique_ptr<GetRegistrationCallback> callback,
+ std::unique_ptr<RegistrationCallback> callback,
mojom::blink::BackgroundFetchError error,
mojom::blink::BackgroundFetchRegistrationPtr registrationPtr) {
- BackgroundFetchRegistration* registration = nullptr;
+ BackgroundFetchRegistration* registration =
+ registrationPtr.To<BackgroundFetchRegistration*>();
- if (registrationPtr) {
+ if (registration) {
DCHECK_EQ(error, mojom::blink::BackgroundFetchError::NONE);
- registration = CreateBackgroundFetchRegistration(
- supplementable(), std::move(registrationPtr));
+ registration->setServiceWorkerRegistration(supplementable());
}
(*callback)(error, registration);

Powered by Google App Engine
This is Rietveld 408576698