Backed out changeset 77fc6f341fef (bug 1346247)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Fri, 24 Mar 2017 15:04:23 +0100
changeset 349512 249037d28c7896fadafe4b58e2458b11a4866cf4
parent 349511 adb38e68486ec6f5b8114d776c2f806dac7c536b
child 349513 d1167c61611315834bbf07d13423069a155d1ed0
push id88436
push userarchaeopteryx@coole-files.de
push dateFri, 24 Mar 2017 14:05:22 +0000
treeherdermozilla-inbound@ee590a4887b7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1346247
milestone55.0a1
backs out77fc6f341fef9ff125624a9544c683a3d3b3047d
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset 77fc6f341fef (bug 1346247)
dom/workers/ServiceWorkerManager.cpp
dom/workers/ServiceWorkerManager.h
dom/workers/ServiceWorkerUpdaterChild.cpp
dom/workers/ServiceWorkerUpdaterChild.h
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -504,103 +504,56 @@ public:
     return NS_OK;
   }
 
 private:
   ~PropagateRemoveAllRunnable()
   {}
 };
 
-class PromiseResolverCallback final : public ServiceWorkerUpdateFinishCallback
-{
-public:
-  PromiseResolverCallback(ServiceWorkerUpdateFinishCallback* aCallback,
-                          GenericPromise::Private* aPromise)
-    : mCallback(aCallback)
-    , mPromise(aPromise)
-  {
-    MOZ_DIAGNOSTIC_ASSERT(mPromise);
-  }
-
-  void UpdateSucceeded(ServiceWorkerRegistrationInfo* aInfo) override
-  {
-    MOZ_DIAGNOSTIC_ASSERT(mPromise);
-
-    if (mCallback) {
-      mCallback->UpdateSucceeded(aInfo);
-    }
-
-    mPromise->Resolve(true, __func__);
-    mPromise = nullptr;
-  }
-
-  void UpdateFailed(ErrorResult& aStatus) override
-  {
-    MOZ_DIAGNOSTIC_ASSERT(mPromise);
-
-    if (mCallback) {
-      mCallback->UpdateFailed(aStatus);
-    }
-
-    mPromise->Resolve(true, __func__);
-    mPromise = nullptr;
-  }
-
-private:
-  RefPtr<ServiceWorkerUpdateFinishCallback> mCallback;
-  RefPtr<GenericPromise::Private> mPromise;
-};
-
 // This runnable is used for 2 different tasks:
 // - to postpone the SoftUpdate() until the IPC SWM actor is created
 //   (aInternalMethod == false)
 // - to call the 'real' SoftUpdate when the ServiceWorkerUpdaterChild is
 //   notified by the parent (aInternalMethod == true)
 class SoftUpdateRunnable final : public Runnable
 {
 public:
   SoftUpdateRunnable(const OriginAttributes& aOriginAttributes,
-                     const nsACString& aScope, bool aInternalMethod,
-                     GenericPromise::Private* aPromise)
+                     const nsACString& aScope, bool aInternalMethod)
     : mAttrs(aOriginAttributes)
     , mScope(aScope)
     , mInternalMethod(aInternalMethod)
-    , mPromise(aPromise)
   {}
 
   NS_IMETHOD Run() override
   {
     AssertIsOnMainThread();
 
     RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
     if (!swm) {
       return NS_ERROR_FAILURE;
     }
 
     if (mInternalMethod) {
-      RefPtr<PromiseResolverCallback> callback =
-        new PromiseResolverCallback(nullptr, mPromise);
-
-      swm->SoftUpdateInternal(mAttrs, mScope, callback);
+      swm->SoftUpdateInternal(mAttrs, mScope);
     } else {
       swm->SoftUpdate(mAttrs, mScope);
     }
 
     return NS_OK;
   }
 
 private:
   ~SoftUpdateRunnable()
   {}
 
   const OriginAttributes mAttrs;
   const nsCString mScope;
   bool mInternalMethod;
-
-  RefPtr<GenericPromise::Private> mPromise;
 };
 
 // This runnable is used for 3 different tasks:
 // - to postpone the Update() until the IPC SWM actor is created
 //   (aType == ePostpone)
 // - to call the 'real' Update when the ServiceWorkerUpdaterChild is
 //   notified by the parent (aType == eSuccess)
 // - an error must be propagated (aType == eFailure)
@@ -611,82 +564,55 @@ public:
     ePostpone,
     eSuccess,
     eFailure,
   };
 
   UpdateRunnable(nsIPrincipal* aPrincipal,
                  const nsACString& aScope,
                  ServiceWorkerUpdateFinishCallback* aCallback,
-                 Type aType,
-                 GenericPromise::Private* aPromise)
+                 Type aType)
     : mPrincipal(aPrincipal)
     , mScope(aScope)
     , mCallback(aCallback)
     , mType(aType)
-    , mPromise(aPromise)
   {}
 
   NS_IMETHOD Run() override
   {
     AssertIsOnMainThread();
 
     RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
     if (!swm) {
       return NS_ERROR_FAILURE;
     }
 
     if (mType == ePostpone) {
       swm->Update(mPrincipal, mScope, mCallback);
       return NS_OK;
     }
 
-    MOZ_ASSERT(mPromise);
-
-    RefPtr<PromiseResolverCallback> callback =
-      new PromiseResolverCallback(mCallback, mPromise);
-
     if (mType == eSuccess) {
-      swm->UpdateInternal(mPrincipal, mScope, callback);
+      swm->UpdateInternal(mPrincipal, mScope, mCallback);
       return NS_OK;
     }
 
     ErrorResult error(NS_ERROR_DOM_ABORT_ERR);
-    callback->UpdateFailed(error);
+    mCallback->UpdateFailed(error);
     return NS_OK;
   }
 
 private:
   ~UpdateRunnable()
   {}
 
   nsCOMPtr<nsIPrincipal> mPrincipal;
   const nsCString mScope;
   RefPtr<ServiceWorkerUpdateFinishCallback> mCallback;
   Type mType;
-
-  RefPtr<GenericPromise::Private> mPromise;
-};
-
-class ResolvePromiseRunnable final : public Runnable
-{
-public:
-  explicit ResolvePromiseRunnable(GenericPromise::Private* aPromise)
-    : mPromise(aPromise)
-  {}
-
-  NS_IMETHOD
-  Run() override
-  {
-    mPromise->Resolve(true, __func__);
-    return NS_OK;
-  }
-
-private:
-  RefPtr<GenericPromise::Private> mPromise;
 };
 
 } // namespace
 
 // This function implements parts of the step 3 of the following algorithm:
 // https://w3c.github.io/webappsec/specs/powerfulfeatures/#settings-secure
 static bool
 IsFromAuthenticatedOrigin(nsIDocument* aDoc)
@@ -2899,83 +2825,35 @@ ServiceWorkerManager::SoftUpdate(const O
   AssertIsOnMainThread();
 
   if (mShuttingDown) {
     return;
   }
 
   if (!mActor) {
     RefPtr<Runnable> runnable =
-      new SoftUpdateRunnable(aOriginAttributes, aScope, false, nullptr);
+      new SoftUpdateRunnable(aOriginAttributes, aScope, false);
     AppendPendingOperation(runnable);
     return;
   }
 
-  RefPtr<GenericPromise::Private> promise =
-    new GenericPromise::Private(__func__);
-
-  RefPtr<Runnable> successRunnable =
-    new SoftUpdateRunnable(aOriginAttributes, aScope, true, promise);
-
-  RefPtr<Runnable> failureRunnable =
-    new ResolvePromiseRunnable(promise);
+  RefPtr<Runnable> runnable =
+    new SoftUpdateRunnable(aOriginAttributes, aScope, true);
 
   ServiceWorkerUpdaterChild* actor =
-    new ServiceWorkerUpdaterChild(promise, successRunnable, failureRunnable);
-
+    new ServiceWorkerUpdaterChild(runnable, nullptr);
   mActor->SendPServiceWorkerUpdaterConstructor(actor, aOriginAttributes,
                                                nsCString(aScope));
 }
 
-namespace {
-
-class UpdateJobCallback final : public ServiceWorkerJob::Callback
-{
-  RefPtr<ServiceWorkerUpdateFinishCallback> mCallback;
-
-  ~UpdateJobCallback() = default;
-
-public:
-  explicit UpdateJobCallback(ServiceWorkerUpdateFinishCallback* aCallback)
-    : mCallback(aCallback)
-  {
-    AssertIsOnMainThread();
-    MOZ_ASSERT(mCallback);
-  }
-
-  void
-  JobFinished(ServiceWorkerJob* aJob, ErrorResult& aStatus)
-  {
-    AssertIsOnMainThread();
-    MOZ_ASSERT(aJob);
-
-    if (aStatus.Failed()) {
-      mCallback->UpdateFailed(aStatus);
-      return;
-    }
-
-    MOZ_DIAGNOSTIC_ASSERT(aJob->GetType() == ServiceWorkerJob::Type::Update);
-    RefPtr<ServiceWorkerUpdateJob> updateJob =
-      static_cast<ServiceWorkerUpdateJob*>(aJob);
-    RefPtr<ServiceWorkerRegistrationInfo> reg = updateJob->GetRegistration();
-    mCallback->UpdateSucceeded(reg);
-  }
-
-  NS_INLINE_DECL_REFCOUNTING(UpdateJobCallback)
-};
-
-} // anonymous namespace
-
 void
 ServiceWorkerManager::SoftUpdateInternal(const OriginAttributes& aOriginAttributes,
-                                         const nsACString& aScope,
-                                         ServiceWorkerUpdateFinishCallback* aCallback)
+                                         const nsACString& aScope)
 {
   AssertIsOnMainThread();
-  MOZ_ASSERT(aCallback);
 
   if (mShuttingDown) {
     return;
   }
 
   nsCOMPtr<nsIURI> scopeURI;
   nsresult rv = NS_NewURI(getter_AddRefs(scopeURI), aScope);
   if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -3024,52 +2902,85 @@ ServiceWorkerManager::SoftUpdateInternal
   // See: https://github.com/slightlyoff/ServiceWorker/issues/759
   RefPtr<ServiceWorkerJobQueue> queue = GetOrCreateJobQueue(scopeKey,
                                                             aScope);
 
   RefPtr<ServiceWorkerUpdateJob> job =
     new ServiceWorkerUpdateJob(principal, registration->mScope,
                                newest->ScriptSpec(), nullptr,
                                registration->GetLoadFlags());
-
-  RefPtr<UpdateJobCallback> cb = new UpdateJobCallback(aCallback);
-  job->AppendResultCallback(cb);
-
   queue->ScheduleJob(job);
 }
 
+namespace {
+
+class UpdateJobCallback final : public ServiceWorkerJob::Callback
+{
+  RefPtr<ServiceWorkerUpdateFinishCallback> mCallback;
+
+  ~UpdateJobCallback()
+  {
+  }
+
+public:
+  explicit UpdateJobCallback(ServiceWorkerUpdateFinishCallback* aCallback)
+    : mCallback(aCallback)
+  {
+    AssertIsOnMainThread();
+    MOZ_ASSERT(mCallback);
+  }
+
+  void
+  JobFinished(ServiceWorkerJob* aJob, ErrorResult& aStatus)
+  {
+    AssertIsOnMainThread();
+    MOZ_ASSERT(aJob);
+
+    if (aStatus.Failed()) {
+      mCallback->UpdateFailed(aStatus);
+      return;
+    }
+
+    MOZ_ASSERT(aJob->GetType() == ServiceWorkerJob::Type::Update);
+    RefPtr<ServiceWorkerUpdateJob> updateJob =
+      static_cast<ServiceWorkerUpdateJob*>(aJob);
+    RefPtr<ServiceWorkerRegistrationInfo> reg = updateJob->GetRegistration();
+    mCallback->UpdateSucceeded(reg);
+  }
+
+  NS_INLINE_DECL_REFCOUNTING(UpdateJobCallback)
+};
+
+} // anonymous namespace
+
 void
 ServiceWorkerManager::Update(nsIPrincipal* aPrincipal,
                              const nsACString& aScope,
                              ServiceWorkerUpdateFinishCallback* aCallback)
 {
   AssertIsOnMainThread();
 
   if (!mActor) {
     RefPtr<Runnable> runnable =
       new UpdateRunnable(aPrincipal, aScope, aCallback,
-                         UpdateRunnable::ePostpone, nullptr);
+                         UpdateRunnable::ePostpone);
     AppendPendingOperation(runnable);
     return;
   }
 
-  RefPtr<GenericPromise::Private> promise =
-    new GenericPromise::Private(__func__);
-
   RefPtr<Runnable> successRunnable =
     new UpdateRunnable(aPrincipal, aScope, aCallback,
-                       UpdateRunnable::eSuccess, promise);
+                       UpdateRunnable::eSuccess);
 
   RefPtr<Runnable> failureRunnable =
     new UpdateRunnable(aPrincipal, aScope, aCallback,
-                       UpdateRunnable::eFailure, promise);
+                       UpdateRunnable::eFailure);
 
   ServiceWorkerUpdaterChild* actor =
-    new ServiceWorkerUpdaterChild(promise, successRunnable, failureRunnable);
-
+    new ServiceWorkerUpdaterChild(successRunnable, failureRunnable);
   mActor->SendPServiceWorkerUpdaterConstructor(actor,
                                                aPrincipal->OriginAttributesRef(),
                                                nsCString(aScope));
 }
 
 void
 ServiceWorkerManager::UpdateInternal(nsIPrincipal* aPrincipal,
                                      const nsACString& aScope,
--- a/dom/workers/ServiceWorkerManager.h
+++ b/dom/workers/ServiceWorkerManager.h
@@ -170,18 +170,17 @@ public:
                  ServiceWorkerUpdateFinishCallback* aCallback);
 
   void
   SoftUpdate(const OriginAttributes& aOriginAttributes,
              const nsACString& aScope);
 
   void
   SoftUpdateInternal(const OriginAttributes& aOriginAttributes,
-                     const nsACString& aScope,
-                     ServiceWorkerUpdateFinishCallback* aCallback);
+                     const nsACString& aScope);
 
 
   void
   PropagateSoftUpdate(const OriginAttributes& aOriginAttributes,
                       const nsAString& aScope);
 
   void
   PropagateRemove(const nsACString& aHost);
--- a/dom/workers/ServiceWorkerUpdaterChild.cpp
+++ b/dom/workers/ServiceWorkerUpdaterChild.cpp
@@ -5,48 +5,32 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ServiceWorkerUpdaterChild.h"
 
 namespace mozilla {
 namespace dom {
 namespace workers {
 
-ServiceWorkerUpdaterChild::ServiceWorkerUpdaterChild(GenericPromise* aPromise,
-                                                     Runnable* aSuccessRunnable,
+ServiceWorkerUpdaterChild::ServiceWorkerUpdaterChild(Runnable* aSuccessRunnable,
                                                      Runnable* aFailureRunnable)
   : mSuccessRunnable(aSuccessRunnable)
   , mFailureRunnable(aFailureRunnable)
 {
-  MOZ_ASSERT(aPromise);
   MOZ_ASSERT(aSuccessRunnable);
-  MOZ_ASSERT(aFailureRunnable);
-
-  aPromise->Then(AbstractThread::GetCurrent(), __func__,
-    [this]() {
-      mPromiseHolder.Complete();
-      Unused << Send__delete__(this);
-  }).Track(mPromiseHolder);
 }
 
 mozilla::ipc::IPCResult
 ServiceWorkerUpdaterChild::RecvProceed(const bool& aAllowed)
 {
-  // If we have a callback, it will resolve the promise.
-
   if (aAllowed) {
     mSuccessRunnable->Run();
-  } else {
+  } else if (mFailureRunnable) {
     mFailureRunnable->Run();
   }
 
+  Unused << Send__delete__(this);
   return IPC_OK();
 }
 
-void
-ServiceWorkerUpdaterChild::ActorDestroy(ActorDestroyReason aWhy)
-{
-  mPromiseHolder.DisconnectIfExists();
-}
-
 } // namespace workers
 } // namespace dom
 } // namespace mozilla
--- a/dom/workers/ServiceWorkerUpdaterChild.h
+++ b/dom/workers/ServiceWorkerUpdaterChild.h
@@ -4,38 +4,31 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_ServiceWorkerUpdaterChild_h
 #define mozilla_dom_ServiceWorkerUpdaterChild_h
 
 #include "mozilla/dom/PServiceWorkerUpdaterChild.h"
 #include "mozilla/BasePrincipal.h"
-#include "mozilla/MozPromise.h"
 
 namespace mozilla {
 namespace dom {
 namespace workers {
 
 class ServiceWorkerUpdaterChild final : public PServiceWorkerUpdaterChild
 {
 public:
-  ServiceWorkerUpdaterChild(GenericPromise* aPromise,
-                            Runnable* aSuccessRunnable,
+  ServiceWorkerUpdaterChild(Runnable* aSuccessRunnable,
                             Runnable* aFailureRunnable);
 
   mozilla::ipc::IPCResult
   RecvProceed(const bool& aAllowed) override;
 
 private:
-  void
-  ActorDestroy(ActorDestroyReason aWhy) override;
-
-  MozPromiseRequestHolder<GenericPromise> mPromiseHolder;
-
   RefPtr<Runnable> mSuccessRunnable;
   RefPtr<Runnable> mFailureRunnable;
 };
 
 } // namespace workers
 } // namespace dom
 } // namespace mozilla