diff --git a/dom/serviceworkers/ServiceWorkerRegistration.cpp b/dom/serviceworkers/ServiceWorkerRegistration.cpp index a2afd2b08f45..c867c28a9a49 100644 --- a/dom/serviceworkers/ServiceWorkerRegistration.cpp +++ b/dom/serviceworkers/ServiceWorkerRegistration.cpp @@ -523,13 +523,18 @@ void ServiceWorkerRegistration::WhenVersionReached( void ServiceWorkerRegistration::MaybeScheduleUpdateFound( const Maybe& aInstallingDescriptor) { // This function sets mScheduledUpdateFoundId to note when we were told about - // a new installing worker. We rely on a call to - // MaybeDispatchUpdateFoundRunnable (called indirectly from UpdateJobCallback) - // to actually fire the event. + // a new installing worker. We rely on a call to MaybeDispatchUpdateFound via + // ServiceWorkerRegistrationChild::RecvFireUpdateFound to trigger the properly + // timed notification... uint64_t newId = aInstallingDescriptor.isSome() ? aInstallingDescriptor.ref().Id() : kInvalidUpdateFoundId; + // ...but the whole reason this logic exists is because SWRegistrations are + // bootstrapped off of inherently stale descriptor snapshots and receive + // catch-up updates once the actor is created and registered in the parent. + // To handle the catch-up case where we need to generate a synthetic + // updatefound that would otherwise be lost, we immediately flush here. if (mScheduledUpdateFoundId != kInvalidUpdateFoundId) { if (mScheduledUpdateFoundId == newId) { return; @@ -548,22 +553,6 @@ void ServiceWorkerRegistration::MaybeScheduleUpdateFound( mScheduledUpdateFoundId = newId; } -void ServiceWorkerRegistration::MaybeDispatchUpdateFoundRunnable() { - if (mScheduledUpdateFoundId == kInvalidUpdateFoundId) { - return; - } - - nsIGlobalObject* global = GetParentObject(); - NS_ENSURE_TRUE_VOID(global); - - nsCOMPtr r = NewCancelableRunnableMethod( - "ServiceWorkerRegistration::MaybeDispatchUpdateFound", this, - &ServiceWorkerRegistration::MaybeDispatchUpdateFound); - - Unused << global->SerialEventTarget()->Dispatch(r.forget(), - NS_DISPATCH_NORMAL); -} - void ServiceWorkerRegistration::MaybeDispatchUpdateFound() { uint64_t scheduledId = mScheduledUpdateFoundId; mScheduledUpdateFoundId = kInvalidUpdateFoundId; diff --git a/dom/serviceworkers/ServiceWorkerRegistration.h b/dom/serviceworkers/ServiceWorkerRegistration.h index fa638d37b656..c354e3e138f1 100644 --- a/dom/serviceworkers/ServiceWorkerRegistration.h +++ b/dom/serviceworkers/ServiceWorkerRegistration.h @@ -105,11 +105,9 @@ class ServiceWorkerRegistration final : public DOMEventTargetHelper { void WhenVersionReached(uint64_t aVersion, ServiceWorkerBoolCallback&& aCallback); - void MaybeDispatchUpdateFoundRunnable(); - void RevokeActor(ServiceWorkerRegistrationChild* aActor); - void FireUpdateFound(); + void FireUpdateFound() { MaybeDispatchUpdateFound(); } private: ServiceWorkerRegistration( diff --git a/dom/serviceworkers/ServiceWorkerRegistrationChild.cpp b/dom/serviceworkers/ServiceWorkerRegistrationChild.cpp index b382f6dcfaf9..d3ed8c4cbd98 100644 --- a/dom/serviceworkers/ServiceWorkerRegistrationChild.cpp +++ b/dom/serviceworkers/ServiceWorkerRegistrationChild.cpp @@ -34,7 +34,7 @@ IPCResult ServiceWorkerRegistrationChild::RecvUpdateState( IPCResult ServiceWorkerRegistrationChild::RecvFireUpdateFound() { if (mOwner) { - mOwner->MaybeDispatchUpdateFoundRunnable(); + mOwner->FireUpdateFound(); } return IPC_OK(); }