Bug 1231213 - Let ServiceWorkerOpArgs be sent from the parent process to a content process. r=asuth
☠☠ backed out by ad33a9311b30 ☠ ☠
authorPerry Jiang <perry@mozilla.com>
Tue, 13 Aug 2019 19:56:33 +0000
changeset 487769 c46b31113adb6e25d1f0dae27e240bf82b13bebd
parent 487768 ea7334da65d9892b6df5048fc9dc5b32455311b1
child 487770 796c617b989fa74b53c578dfd26de1546d61e9a6
push id36430
push userdvarga@mozilla.com
push dateWed, 14 Aug 2019 04:09:17 +0000
treeherdermozilla-central@d3deef805f92 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1231213
milestone70.0a1
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
Bug 1231213 - Let ServiceWorkerOpArgs be sent from the parent process to a content process. r=asuth The args are sent from the parent process main thread to the parent process background thread and then from the background thread to a content process worker launcher thread. Differential Revision: https://phabricator.services.mozilla.com/D26173
dom/workers/remoteworkers/PRemoteWorker.ipdl
dom/workers/remoteworkers/PRemoteWorkerController.ipdl
dom/workers/remoteworkers/RemoteWorkerChild.cpp
dom/workers/remoteworkers/RemoteWorkerChild.h
dom/workers/remoteworkers/RemoteWorkerController.cpp
dom/workers/remoteworkers/RemoteWorkerController.h
dom/workers/remoteworkers/RemoteWorkerControllerParent.cpp
dom/workers/remoteworkers/RemoteWorkerControllerParent.h
--- a/dom/workers/remoteworkers/PRemoteWorker.ipdl
+++ b/dom/workers/remoteworkers/PRemoteWorker.ipdl
@@ -70,12 +70,15 @@ parent:
   async Close();
 
 child:
   async PFetchEventOpProxy(ServiceWorkerFetchEventOpArgs aArgs);
 
   async __delete__();
 
   async ExecOp(RemoteWorkerOp op);
+
+  async ExecServiceWorkerOp(ServiceWorkerOpArgs aArgs)
+      returns (ServiceWorkerOpResult aResult);
 };
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/workers/remoteworkers/PRemoteWorkerController.ipdl
+++ b/dom/workers/remoteworkers/PRemoteWorkerController.ipdl
@@ -27,12 +27,14 @@ protocol PRemoteWorkerController {
 
  parent:
   async PFetchEventOp(ServiceWorkerFetchEventOpArgs aArgs);
 
   async __delete__();
 
   async Shutdown() returns (bool aOk);
 
+  async ExecServiceWorkerOp(ServiceWorkerOpArgs aArgs)
+      returns (ServiceWorkerOpResult aResult);
 };
 
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/workers/remoteworkers/RemoteWorkerChild.cpp
+++ b/dom/workers/remoteworkers/RemoteWorkerChild.cpp
@@ -29,16 +29,17 @@
 #include "mozilla/ScopeExit.h"
 #include "mozilla/Unused.h"
 #include "mozilla/dom/FetchEventOpProxyChild.h"
 #include "mozilla/dom/IndexedDatabaseManager.h"
 #include "mozilla/dom/MessagePort.h"
 #include "mozilla/dom/RemoteWorkerTypes.h"
 #include "mozilla/dom/ServiceWorkerDescriptor.h"
 #include "mozilla/dom/ServiceWorkerInterceptController.h"
+#include "mozilla/dom/ServiceWorkerOp.h"
 #include "mozilla/dom/ServiceWorkerRegistrationDescriptor.h"
 #include "mozilla/dom/ServiceWorkerUtils.h"
 #include "mozilla/dom/workerinternals/ScriptLoader.h"
 #include "mozilla/dom/WorkerError.h"
 #include "mozilla/dom/WorkerPrivate.h"
 #include "mozilla/dom/WorkerRef.h"
 #include "mozilla/dom/WorkerRunnable.h"
 #include "mozilla/ipc/BackgroundUtils.h"
@@ -909,16 +910,28 @@ void RemoteWorkerChild::MaybeStartOp(Ref
 IPCResult RemoteWorkerChild::RecvExecOp(RemoteWorkerOp&& aOp) {
   MOZ_ASSERT(!mIsServiceWorker);
 
   MaybeStartOp(new SharedWorkerOp(std::move(aOp)));
 
   return IPC_OK();
 }
 
+IPCResult RemoteWorkerChild::RecvExecServiceWorkerOp(
+    ServiceWorkerOpArgs&& aArgs, ExecServiceWorkerOpResolver&& aResolve) {
+  MOZ_ASSERT(mIsServiceWorker);
+  MOZ_ASSERT(
+      aArgs.type() != ServiceWorkerOpArgs::TServiceWorkerFetchEventOpArgs,
+      "FetchEvent operations should be sent via PFetchEventOp(Proxy) actors!");
+
+  MaybeStartOp(ServiceWorkerOp::Create(aArgs, std::move(aResolve)));
+
+  return IPC_OK();
+}
+
 /**
  * PFetchEventOpProxy methods
  */
 PFetchEventOpProxyChild* RemoteWorkerChild::AllocPFetchEventOpProxyChild(
     const ServiceWorkerFetchEventOpArgs& aArgs) {
   RefPtr<FetchEventOpProxyChild> actor = new FetchEventOpProxyChild();
 
   return actor.forget().take();
--- a/dom/workers/remoteworkers/RemoteWorkerChild.h
+++ b/dom/workers/remoteworkers/RemoteWorkerChild.h
@@ -100,16 +100,19 @@ class RemoteWorkerChild final
 
     virtual void Cancel() = 0;
   };
 
   void ActorDestroy(ActorDestroyReason) override;
 
   mozilla::ipc::IPCResult RecvExecOp(RemoteWorkerOp&& aOp);
 
+  mozilla::ipc::IPCResult RecvExecServiceWorkerOp(
+      ServiceWorkerOpArgs&& aArgs, ExecServiceWorkerOpResolver&& aResolve);
+
   PFetchEventOpProxyChild* AllocPFetchEventOpProxyChild(
       const ServiceWorkerFetchEventOpArgs& aArgs);
 
   mozilla::ipc::IPCResult RecvPFetchEventOpProxyConstructor(
       PFetchEventOpProxyChild* aActor,
       const ServiceWorkerFetchEventOpArgs& aArgs) override;
 
   bool DeallocPFetchEventOpProxyChild(PFetchEventOpProxyChild* aActor);
--- a/dom/workers/remoteworkers/RemoteWorkerController.cpp
+++ b/dom/workers/remoteworkers/RemoteWorkerController.cpp
@@ -255,16 +255,34 @@ void RemoteWorkerController::Freeze() {
 }
 
 void RemoteWorkerController::Thaw() {
   AssertIsOnBackgroundThread();
 
   MaybeStartSharedWorkerOp(PendingSharedWorkerOp::eThaw);
 }
 
+RefPtr<ServiceWorkerOpPromise> RemoteWorkerController::ExecServiceWorkerOp(
+    ServiceWorkerOpArgs&& aArgs) {
+  AssertIsOnBackgroundThread();
+  MOZ_ASSERT(mIsServiceWorker);
+
+  RefPtr<ServiceWorkerOpPromise::Private> promise =
+      new ServiceWorkerOpPromise::Private(__func__);
+
+  UniquePtr<PendingServiceWorkerOp> op =
+      MakeUnique<PendingServiceWorkerOp>(std::move(aArgs), promise);
+
+  if (!op->MaybeStart(this)) {
+    mPendingOps.AppendElement(std::move(op));
+  }
+
+  return promise;
+}
+
 RemoteWorkerController::PendingSharedWorkerOp::PendingSharedWorkerOp(
     Type aType, uint64_t aWindowID)
     : mType(aType), mWindowID(aWindowID) {
   AssertIsOnBackgroundThread();
 }
 
 RemoteWorkerController::PendingSharedWorkerOp::PendingSharedWorkerOp(
     const MessagePortIdentifier& aPortIdentifier)
@@ -398,16 +416,29 @@ bool RemoteWorkerController::PendingServ
       mPromise->Reject(NS_ERROR_DOM_DATA_CLONE_ERR, __func__);
       mPromise = nullptr;
       return true;
     }
 
     mArgs = std::move(copyArgs);
   }
 
+  aOwner->mActor->SendExecServiceWorkerOp(mArgs)->Then(
+      GetCurrentThreadSerialEventTarget(), __func__,
+      [promise = std::move(mPromise)](
+          PRemoteWorkerParent::ExecServiceWorkerOpPromise::
+              ResolveOrRejectValue&& aResult) {
+        if (NS_WARN_IF(aResult.IsReject())) {
+          promise->Reject(NS_ERROR_DOM_ABORT_ERR, __func__);
+          return;
+        }
+
+        promise->Resolve(std::move(aResult.ResolveValue()), __func__);
+      });
+
   return true;
 }
 
 void RemoteWorkerController::PendingServiceWorkerOp::Cancel() {
   AssertIsOnBackgroundThread();
   MOZ_ASSERT(mPromise);
 
   mPromise->Reject(NS_ERROR_DOM_ABORT_ERR, __func__);
--- a/dom/workers/remoteworkers/RemoteWorkerController.h
+++ b/dom/workers/remoteworkers/RemoteWorkerController.h
@@ -127,16 +127,19 @@ class RemoteWorkerController final {
   void Suspend();
 
   void Resume();
 
   void Freeze();
 
   void Thaw();
 
+  RefPtr<ServiceWorkerOpPromise> ExecServiceWorkerOp(
+      ServiceWorkerOpArgs&& aArgs);
+
  private:
   RemoteWorkerController(const RemoteWorkerData& aData,
                          RemoteWorkerObserver* aObserver);
 
   ~RemoteWorkerController();
 
   void SetWorkerActor(RemoteWorkerParent* aActor);
 
--- a/dom/workers/remoteworkers/RemoteWorkerControllerParent.cpp
+++ b/dom/workers/remoteworkers/RemoteWorkerControllerParent.cpp
@@ -11,16 +11,17 @@
 #include "nsCOMPtr.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsThreadUtils.h"
 
 #include "mozilla/Assertions.h"
 #include "mozilla/Unused.h"
 #include "mozilla/dom/FetchEventOpParent.h"
+#include "mozilla/dom/ServiceWorkerOpPromise.h"
 #include "mozilla/ipc/BackgroundParent.h"
 
 namespace mozilla {
 
 using namespace ipc;
 
 namespace dom {
 
@@ -70,16 +71,38 @@ bool RemoteWorkerControllerParent::Deall
   AssertIsOnBackgroundThread();
   MOZ_ASSERT(aActor);
 
   RefPtr<FetchEventOpParent> actor =
       dont_AddRef(static_cast<FetchEventOpParent*>(aActor));
   return true;
 }
 
+IPCResult RemoteWorkerControllerParent::RecvExecServiceWorkerOp(
+    ServiceWorkerOpArgs&& aArgs, ExecServiceWorkerOpResolver&& aResolve) {
+  AssertIsOnBackgroundThread();
+  MOZ_ASSERT(mIPCActive);
+  MOZ_ASSERT(mRemoteWorkerController);
+
+  mRemoteWorkerController->ExecServiceWorkerOp(std::move(aArgs))
+      ->Then(GetCurrentThreadSerialEventTarget(), __func__,
+             [resolve = std::move(aResolve)](
+                 ServiceWorkerOpPromise::ResolveOrRejectValue&& aResult) {
+               if (NS_WARN_IF(aResult.IsReject())) {
+                 MOZ_ASSERT(NS_FAILED(aResult.RejectValue()));
+                 resolve(aResult.RejectValue());
+                 return;
+               }
+
+               resolve(aResult.ResolveValue());
+             });
+
+  return IPC_OK();
+}
+
 IPCResult RemoteWorkerControllerParent::RecvShutdown(
     ShutdownResolver&& aResolve) {
   AssertIsOnBackgroundThread();
   MOZ_ASSERT(mIPCActive);
   MOZ_ASSERT(mRemoteWorkerController);
 
   mIPCActive = false;
 
--- a/dom/workers/remoteworkers/RemoteWorkerControllerParent.h
+++ b/dom/workers/remoteworkers/RemoteWorkerControllerParent.h
@@ -38,16 +38,19 @@ class RemoteWorkerControllerParent final
       const ServiceWorkerFetchEventOpArgs& aArgs);
 
   mozilla::ipc::IPCResult RecvPFetchEventOpConstructor(
       PFetchEventOpParent* aActor,
       const ServiceWorkerFetchEventOpArgs& aArgs) override;
 
   bool DeallocPFetchEventOpParent(PFetchEventOpParent* aActor);
 
+  mozilla::ipc::IPCResult RecvExecServiceWorkerOp(
+      ServiceWorkerOpArgs&& aArgs, ExecServiceWorkerOpResolver&& aResolve);
+
   mozilla::ipc::IPCResult RecvShutdown(ShutdownResolver&& aResolve);
 
   mozilla::ipc::IPCResult Recv__delete__() override;
 
   void ActorDestroy(ActorDestroyReason aReason) override;
 
   void CreationFailed() override;