Bug 1363318 - Part 1: Label FetchSignalProxy. r=baku
authorBevis Tseng <btseng@mozilla.com>
Tue, 16 May 2017 16:59:29 +0800
changeset 409642 d343ee1e22d265d01f6b9b466863727d3cb2357a
parent 409641 8feddea7052dc184960e887dc8f6eb67b2fa3666
child 409643 5e90e289c6f67b218a60ea7aed7993b2d3ad8319
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1363318
milestone55.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 1363318 - Part 1: Label FetchSignalProxy. r=baku Replace the use of NS_DispatchToMainThread, NS_ReleaseOnMainThread with WorkerPrivate->MainThreadEventTarget().
dom/fetch/Fetch.cpp
--- a/dom/fetch/Fetch.cpp
+++ b/dom/fetch/Fetch.cpp
@@ -54,16 +54,19 @@ namespace dom {
 using namespace workers;
 
 // This class helps the proxying of FetchSignal changes cross threads.
 class FetchSignalProxy final : public FetchSignal::Follower
 {
   // This is created and released on the main-thread.
   RefPtr<FetchSignal> mSignalMainThread;
 
+  // The main-thread event target for runnable dispatching.
+  nsCOMPtr<nsIEventTarget> mMainThreadEventTarget;
+
   // This value is used only for the creation of FetchSignal on the
   // main-thread. They are not updated.
   const bool mAborted;
 
   // This runnable propagates changes from the FetchSignal on workers to the
   // FetchSignal on main-thread.
   class FetchSignalProxyRunnable final : public Runnable
   {
@@ -82,28 +85,30 @@ class FetchSignalProxy final : public Fe
       signal->Abort();
       return NS_OK;
     }
   };
 
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FetchSignalProxy)
 
-  explicit FetchSignalProxy(FetchSignal* aSignal)
-    : mAborted(aSignal->Aborted())
+  FetchSignalProxy(FetchSignal* aSignal, nsIEventTarget* aMainThreadEventTarget)
+    : mMainThreadEventTarget(aMainThreadEventTarget)
+    , mAborted(aSignal->Aborted())
   {
+    MOZ_ASSERT(mMainThreadEventTarget);
     Follow(aSignal);
   }
 
   void
   Aborted() override
   {
     RefPtr<FetchSignalProxyRunnable> runnable =
       new FetchSignalProxyRunnable(this);
-    NS_DispatchToMainThread(runnable);
+    mMainThreadEventTarget->Dispatch(runnable.forget(), NS_DISPATCH_NORMAL);
   }
 
   FetchSignal*
   GetOrCreateSignalForMainThread()
   {
     MOZ_ASSERT(NS_IsMainThread());
     if (!mSignalMainThread) {
       mSignalMainThread = new FetchSignal(mAborted);
@@ -115,17 +120,17 @@ public:
   Shutdown()
   {
     Unfollow();
   }
 
 private:
   ~FetchSignalProxy()
   {
-    NS_ReleaseOnMainThread(mSignalMainThread.forget());
+    NS_ProxyRelease(mMainThreadEventTarget, mSignalMainThread.forget());
   }
 };
 
 class WorkerFetchResolver final : public FetchDriverObserver
 {
   friend class MainThreadFetchRunnable;
   friend class WorkerDataAvailableRunnable;
   friend class WorkerFetchResponseEndBase;
@@ -147,17 +152,18 @@ public:
     RefPtr<PromiseWorkerProxy> proxy =
       PromiseWorkerProxy::Create(aWorkerPrivate, aPromise);
     if (!proxy) {
       return nullptr;
     }
 
     RefPtr<FetchSignalProxy> signalProxy;
     if (aSignal) {
-      signalProxy = new FetchSignalProxy(aSignal);
+      signalProxy =
+        new FetchSignalProxy(aSignal, aWorkerPrivate->MainThreadEventTarget());
     }
 
     RefPtr<WorkerFetchResolver> r =
       new WorkerFetchResolver(proxy, signalProxy, aObserver);
     return r.forget();
   }
 
   FetchSignal*