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

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

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 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 1c1b63f929da9c6481fc3dbb6befd7b1013401b0..c65ff59ec9c440ae743fe50a027ee5407b8f2f07 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"
#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,
std::unique_ptr<AbortCallback> callback) {
getService()->Abort(supplementable()->webRegistration()->registrationId(),
@@ -85,7 +73,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(
@@ -94,15 +82,15 @@ void BackgroundFetchBridge::getRegistration(
}
void BackgroundFetchBridge::didGetRegistration(
- 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