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

Unified Diff: third_party/WebKit/Source/modules/background_fetch/BackgroundFetchManager.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/BackgroundFetchManager.cpp
diff --git a/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchManager.cpp b/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchManager.cpp
index 3da171194c03a8ec9233e372f90aa0e8722fe036..d1018f8b240c4e73c7b5495d3bdc352066f93e24 100644
--- a/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchManager.cpp
+++ b/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchManager.cpp
@@ -7,6 +7,8 @@
#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "bindings/core/v8/ScriptState.h"
#include "bindings/core/v8/V8ThrowException.h"
+#include "core/dom/DOMException.h"
+#include "core/dom/ExceptionCode.h"
#include "modules/background_fetch/BackgroundFetchBridge.h"
#include "modules/background_fetch/BackgroundFetchOptions.h"
#include "modules/background_fetch/BackgroundFetchRegistration.h"
@@ -37,18 +39,38 @@ ScriptPromise BackgroundFetchManager::fetch(
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
- // TODO(peter): Register the fetch() with the browser process. The reject
- // cases there are storage errors and duplicated registrations for the `tag`
- // given the `m_registration`.
- BackgroundFetchRegistration* registration = new BackgroundFetchRegistration(
- m_registration.get(), tag, options.icons(), options.totalDownloadSize(),
- options.title());
+ // TODO(peter): Include the |requests| in the Mojo call.
- resolver->resolve(registration);
+ m_bridge->fetch(tag, options,
+ WTF::bind(&BackgroundFetchManager::didFetch,
+ wrapPersistent(this), wrapPersistent(resolver)));
return promise;
}
+void BackgroundFetchManager::didFetch(
+ ScriptPromiseResolver* resolver,
+ mojom::blink::BackgroundFetchError error,
+ BackgroundFetchRegistration* registration) {
+ switch (error) {
+ case mojom::blink::BackgroundFetchError::NONE:
+ DCHECK(registration);
+ resolver->resolve(registration);
+ return;
+ case mojom::blink::BackgroundFetchError::DUPLICATED_TAG:
+ DCHECK(!registration);
+ resolver->reject(DOMException::create(
+ InvalidStateError,
+ "There already is a registration for the given tag."));
+ return;
+ case mojom::blink::BackgroundFetchError::INVALID_TAG:
+ // Not applicable for this callback.
+ break;
+ }
+
+ NOTREACHED();
+}
+
ScriptPromise BackgroundFetchManager::get(ScriptState* scriptState,
const String& tag) {
if (!m_registration->active()) {

Powered by Google App Engine
This is Rietveld 408576698