Bug 1455242 - Get rid of SimpleHolder and replace it with WorkerRef, r=asuth
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 18 Jun 2018 16:37:21 -0400
changeset 479642 171c0f2ef4b982e0bd1f3f55fc7eb9f2c5599bb9
parent 479641 247a38811560f6f2859619a8783e174c165440e3
child 479643 6625e63ecaf5af69387fac13b2c0ac0ce22cc69b
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1455242
milestone62.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 1455242 - Get rid of SimpleHolder and replace it with WorkerRef, r=asuth
dom/workers/WorkerPrivate.cpp
dom/workers/WorkerRef.h
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -53,16 +53,17 @@
 #include "mozilla/dom/ServiceWorkerEvents.h"
 #include "mozilla/dom/ServiceWorkerManager.h"
 #include "SharedWorker.h"
 #include "WorkerDebugger.h"
 #include "WorkerDebuggerManager.h"
 #include "WorkerError.h"
 #include "WorkerEventTarget.h"
 #include "WorkerNavigator.h"
+#include "WorkerRef.h"
 #include "WorkerRunnable.h"
 #include "WorkerScope.h"
 #include "WorkerThread.h"
 
 #include "nsThreadManager.h"
 
 #ifdef XP_WIN
 #undef PostMessage
@@ -963,26 +964,16 @@ PRThreadFromThread(nsIThread* aThread)
 
   PRThread* result;
   MOZ_ALWAYS_SUCCEEDS(aThread->GetPRThread(&result));
   MOZ_ASSERT(result);
 
   return result;
 }
 
-class SimpleWorkerHolder final : public WorkerHolder
-{
-public:
-  SimpleWorkerHolder()
-    : WorkerHolder("SimpleWorkerHolder")
-  {}
-
-  virtual bool Notify(WorkerStatus aStatus) override { return true; }
-};
-
 // A runnable to cancel the worker from the parent thread when self.close() is
 // called. This runnable is executed on the parent process in order to cancel
 // the current runnable. It uses a normal WorkerRunnable in order to be sure
 // that all the pending WorkerRunnables are executed before this.
 class CancelingOnParentRunnable final : public WorkerRunnable
 {
 public:
   explicit CancelingOnParentRunnable(WorkerPrivate* aWorkerPrivate)
@@ -2790,28 +2781,29 @@ WorkerPrivate::~WorkerPrivate()
 already_AddRefed<WorkerPrivate>
 WorkerPrivate::Constructor(JSContext* aCx,
                            const nsAString& aScriptURL,
                            bool aIsChromeWorker, WorkerType aWorkerType,
                            const nsAString& aWorkerName,
                            const nsACString& aServiceWorkerScope,
                            WorkerLoadInfo* aLoadInfo, ErrorResult& aRv)
 {
-  // If this is a sub-worker, we need to keep the parent worker alive until this
-  // one is registered.
-  UniquePtr<SimpleWorkerHolder> holder;
-
   WorkerPrivate* parent = NS_IsMainThread() ?
                           nullptr :
                           GetCurrentThreadWorkerPrivate();
+
+  // If this is a sub-worker, we need to keep the parent worker alive until this
+  // one is registered.
+  RefPtr<StrongWorkerRef> workerRef;
   if (parent) {
     parent->AssertIsOnWorkerThread();
 
-    holder.reset(new SimpleWorkerHolder());
-    if (!holder->HoldWorker(parent, Canceling)) {
+    workerRef =
+      StrongWorkerRef::Create(parent, "WorkerPrivate::Constructor");
+    if (NS_WARN_IF(!workerRef)) {
       aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
       return nullptr;
     }
   } else {
     AssertIsOnMainThread();
   }
 
   Maybe<WorkerLoadInfo> stackLoadInfo;
--- a/dom/workers/WorkerRef.h
+++ b/dom/workers/WorkerRef.h
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_workers_WorkerRef_h
 #define mozilla_dom_workers_WorkerRef_h
 
 #include "mozilla/dom/WorkerCommon.h"
 #include "mozilla/dom/WorkerHolder.h"
 #include "mozilla/UniquePtr.h"
+#include <functional>
 
 namespace mozilla {
 namespace dom {
 
 /*
  * If you want to play with a DOM Worker, you must know that it can go away
  * at any time if nothing prevents its shutting down. This documentation helps
  * to understand how to play with DOM Workers correctly.