diff --git a/dom/push/PushManager.cpp b/dom/push/PushManager.cpp index df874446c6d7..1e4e22fbf5f5 100644 --- a/dom/push/PushManager.cpp +++ b/dom/push/PushManager.cpp @@ -286,7 +286,6 @@ public: explicit WorkerUnsubscribeResultCallback(PromiseWorkerProxy* aProxy) : mProxy(aProxy) - , mCallbackCalled(false) { AssertIsOnMainThread(); } @@ -295,7 +294,6 @@ public: OnUnsubscribe(nsresult aStatus, bool aSuccess) override { AssertIsOnMainThread(); - mCallbackCalled = true; if (!mProxy) { return NS_OK; } @@ -314,19 +312,27 @@ public: ReleasePromiseWorkerProxy(mProxy.forget()); } + mProxy = nullptr; return NS_OK; } private: ~WorkerUnsubscribeResultCallback() { - // Enforces that UnsubscribeRunnable uses the callback for error - // reporting once it creates the callback. - MOZ_ASSERT(mCallbackCalled); + AssertIsOnMainThread(); + if (mProxy) { + MutexAutoLock lock(mProxy->GetCleanUpLock()); + if (!mProxy->IsClean()) { + AutoJSAPI jsapi; + jsapi.Init(); + nsRefPtr cr = + new PromiseWorkerProxyControlRunnable(mProxy->GetWorkerPrivate(), mProxy); + cr->Dispatch(jsapi.cx()); + } + } } nsRefPtr mProxy; - DebugOnly mCallbackCalled; }; NS_IMPL_ISUPPORTS(WorkerUnsubscribeResultCallback, nsIUnsubscribeResultCallback) @@ -477,14 +483,12 @@ public: const nsAString& aScope) : mProxy(aProxy) , mScope(aScope) - , mCallbackCalled(false) {} NS_IMETHOD OnPushEndpoint(nsresult aStatus, const nsAString& aEndpoint) override { AssertIsOnMainThread(); - mCallbackCalled = true; if (!mProxy) { return NS_OK; @@ -503,21 +507,30 @@ public: if (!r->Dispatch(jsapi.cx())) { ReleasePromiseWorkerProxy(mProxy.forget()); } + + mProxy = nullptr; return NS_OK; } protected: ~GetSubscriptionCallback() { - // Enforces that GetSubscriptionRunnable uses the callback for error - // reporting once it creates the callback. - MOZ_ASSERT(mCallbackCalled); + AssertIsOnMainThread(); + if (mProxy) { + MutexAutoLock lock(mProxy->GetCleanUpLock()); + if (!mProxy->IsClean()) { + AutoJSAPI jsapi; + jsapi.Init(); + nsRefPtr cr = + new PromiseWorkerProxyControlRunnable(mProxy->GetWorkerPrivate(), mProxy); + cr->Dispatch(jsapi.cx()); + } + } } private: nsRefPtr mProxy; nsString mScope; - DebugOnly mCallbackCalled; }; NS_IMPL_ISUPPORTS(GetSubscriptionCallback, nsIPushEndpointCallback)