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

Unified Diff: third_party/WebKit/Source/modules/background_fetch/BackgroundFetchedEvent.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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/background_fetch/BackgroundFetchedEvent.cpp
diff --git a/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchedEvent.cpp b/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchedEvent.cpp
index d5cc50da50f26fc97d8016b63f06b37a45a91a44..bb56ed60279333a4a69bf187cba3fcb76536cede 100644
--- a/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchedEvent.cpp
+++ b/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchedEvent.cpp
@@ -4,9 +4,11 @@
#include "modules/background_fetch/BackgroundFetchedEvent.h"
+#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "bindings/core/v8/ScriptState.h"
#include "core/dom/DOMException.h"
#include "modules/EventModulesNames.h"
+#include "modules/background_fetch/BackgroundFetchBridge.h"
#include "modules/background_fetch/BackgroundFetchSettledRequest.h"
#include "modules/background_fetch/BackgroundFetchedEventInit.h"
@@ -14,9 +16,11 @@ namespace blink {
BackgroundFetchedEvent::BackgroundFetchedEvent(
const AtomicString& type,
- const BackgroundFetchedEventInit& init)
+ const BackgroundFetchedEventInit& init,
+ ServiceWorkerRegistration* registration)
: BackgroundFetchEvent(type, init),
- m_completedFetches(init.completedFetches()) {}
+ m_completedFetches(init.completedFetches()),
+ m_registration(registration) {}
BackgroundFetchedEvent::~BackgroundFetchedEvent() = default;
@@ -26,10 +30,37 @@ BackgroundFetchedEvent::completedFetches() const {
}
ScriptPromise BackgroundFetchedEvent::updateUI(ScriptState* scriptState,
- String title) {
- return ScriptPromise::rejectWithDOMException(
- scriptState,
- DOMException::create(NotSupportedError, "Not implemented yet."));
+ const String& title) {
+ if (!m_registration) {
+ // Return a Promise that will never settles when a developer calls this
haraken 2017/03/14 09:13:14 settle
Peter Beverloo 2017/03/14 15:17:21 Done.
+ // method on a BackgroundFetchedEvent instance they created themselves.
+ return ScriptPromise();
+ }
+
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+
+ BackgroundFetchBridge::from(m_registration)
+ ->updateUI(tag(), title,
+ WTF::bind(&BackgroundFetchedEvent::didUpdateUI,
+ wrapPersistent(this), wrapPersistent(resolver)));
+
+ return promise;
+}
+
+void BackgroundFetchedEvent::didUpdateUI(
+ ScriptPromiseResolver* resolver,
+ mojom::blink::BackgroundFetchError error) {
+ switch (error) {
+ case mojom::blink::BackgroundFetchError::NONE:
+ resolver->resolve();
+ break;
+ case mojom::blink::BackgroundFetchError::DUPLICATED_TAG:
+ // Not applicable for this callback.
haraken 2017/03/14 09:13:14 Ditto. Who resolves or rejects in this case?
Peter Beverloo 2017/03/14 15:17:21 Acknowledged.
+ break;
+ }
+
+ NOTREACHED();
}
const AtomicString& BackgroundFetchedEvent::interfaceName() const {
@@ -38,6 +69,7 @@ const AtomicString& BackgroundFetchedEvent::interfaceName() const {
DEFINE_TRACE(BackgroundFetchedEvent) {
visitor->trace(m_completedFetches);
+ visitor->trace(m_registration);
BackgroundFetchEvent::trace(visitor);
}

Powered by Google App Engine
This is Rietveld 408576698