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

Unified Diff: third_party/WebKit/Source/modules/serviceworkers/WaitUntilObserver.cpp

Issue 2517223002: Move content/renderer/background_sync to Blink (Closed)
Patch Set: Fix broken WebEmbeddedWorker test Created 4 years, 1 month 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/serviceworkers/WaitUntilObserver.cpp
diff --git a/third_party/WebKit/Source/modules/serviceworkers/WaitUntilObserver.cpp b/third_party/WebKit/Source/modules/serviceworkers/WaitUntilObserver.cpp
index e233f906a948890ee118987916c53ebb8b512f1b..daf6d1bbd4e81d23fa8e8d9577f0de22d4561119 100644
--- a/third_party/WebKit/Source/modules/serviceworkers/WaitUntilObserver.cpp
+++ b/third_party/WebKit/Source/modules/serviceworkers/WaitUntilObserver.cpp
@@ -80,7 +80,14 @@ class WaitUntilObserver::ThenFunction final : public ScriptFunction {
WaitUntilObserver* WaitUntilObserver::create(ExecutionContext* context,
EventType type,
int eventID) {
- return new WaitUntilObserver(context, type, eventID);
+ return new WaitUntilObserver(context, type, eventID, nullptr);
+}
+
+WaitUntilObserver* WaitUntilObserver::create(
+ ExecutionContext* context,
+ EventType type,
+ std::unique_ptr<Callback> callback) {
+ return new WaitUntilObserver(context, type, -1, std::move(callback));
}
void WaitUntilObserver::willDispatchEvent() {
@@ -132,13 +139,15 @@ void WaitUntilObserver::waitUntil(ScriptState* scriptState,
WaitUntilObserver::WaitUntilObserver(ExecutionContext* context,
EventType type,
- int eventID)
+ int eventID,
+ std::unique_ptr<Callback> callback)
: ContextLifecycleObserver(context),
m_type(type),
m_eventID(eventID),
m_consumeWindowInteractionTimer(
this,
- &WaitUntilObserver::consumeWindowInteraction) {}
+ &WaitUntilObserver::consumeWindowInteraction),
+ m_callback(std::move(callback)) {}
void WaitUntilObserver::reportError(const ScriptValue& value) {
// FIXME: Propagate error message to the client for onerror handling.
@@ -189,7 +198,11 @@ void WaitUntilObserver::decrementPendingActivity() {
client->didHandlePushEvent(m_eventID, result, m_eventDispatchTime);
break;
case Sync:
- client->didHandleSyncEvent(m_eventID, result, m_eventDispatchTime);
+ DCHECK(m_callback);
+ (*m_callback)(m_hasError
+ ? blink::mojom::ServiceWorkerEventStatus::REJECTED
+ : blink::mojom::ServiceWorkerEventStatus::COMPLETED,
+ m_eventDispatchTime);
break;
}
setContext(nullptr);
@@ -201,6 +214,16 @@ void WaitUntilObserver::consumeWindowInteraction(TimerBase*) {
getExecutionContext()->consumeWindowInteraction();
}
+void WaitUntilObserver::contextDestroyed() {
+ if (m_type == Sync && !m_eventDispatched) {
+ DCHECK(m_callback);
+ (*m_callback)(blink::mojom::ServiceWorkerEventStatus::ABORTED,
+ WTF::currentTime());
+ m_eventDispatched = true;
+ }
+ ContextLifecycleObserver::contextDestroyed();
+}
+
DEFINE_TRACE(WaitUntilObserver) {
ContextLifecycleObserver::trace(visitor);
}

Powered by Google App Engine
This is Rietveld 408576698