Bug 1365101 - Convert NS_GetCurrentThread uses in netwerk/ (r=meyhemer)
authorBill McCloskey <billm@mozilla.com>
Thu, 01 Jun 2017 13:43:44 -0700
changeset 412325 43fcf7ddd6ba
parent 412324 d4c07cb66853
child 412326 894903d30183
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmeyhemer
bugs1365101
milestone56.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 1365101 - Convert NS_GetCurrentThread uses in netwerk/ (r=meyhemer) MozReview-Commit-ID: IHBt6XAG8em
netwerk/base/BackgroundFileSaver.cpp
netwerk/base/BackgroundFileSaver.h
netwerk/base/Dashboard.cpp
netwerk/base/Predictor.cpp
netwerk/base/ProxyAutoConfig.cpp
netwerk/base/nsAsyncRedirectVerifyHelper.cpp
netwerk/base/nsAsyncRedirectVerifyHelper.h
netwerk/base/nsAsyncStreamCopier.cpp
netwerk/base/nsDNSPrefetch.cpp
netwerk/base/nsInputStreamPump.cpp
netwerk/base/nsRequestObserverProxy.cpp
netwerk/base/nsServerSocket.cpp
netwerk/base/nsSocketTransport2.cpp
netwerk/base/nsStreamTransportService.cpp
netwerk/base/nsUDPSocket.cpp
netwerk/cache/nsCacheEntry.cpp
netwerk/cache/nsCacheEntry.h
netwerk/cache/nsCacheEntryDescriptor.cpp
netwerk/cache/nsCacheRequest.h
netwerk/cache/nsCacheService.cpp
netwerk/cache/nsDiskCacheDeviceSQL.cpp
netwerk/cache/nsDiskCacheDeviceSQL.h
netwerk/cache2/CacheEntry.cpp
netwerk/cache2/CacheEntry.h
netwerk/cache2/CacheFile.cpp
netwerk/cache2/CacheFileChunk.cpp
netwerk/cache2/CacheFileInputStream.cpp
netwerk/cache2/CacheFileOutputStream.cpp
netwerk/cache2/CacheStorageService.h
netwerk/dns/DNSRequestParent.cpp
netwerk/dns/nsDNSService2.cpp
netwerk/ipc/ChannelEventQueue.h
netwerk/protocol/ftp/nsFTPChannel.cpp
netwerk/protocol/ftp/nsFtpConnectionThread.cpp
netwerk/protocol/ftp/nsFtpControlConnection.cpp
netwerk/protocol/http/HttpChannelChild.cpp
netwerk/protocol/http/nsHttpChannel.cpp
netwerk/protocol/websocket/WebSocketChannel.cpp
netwerk/protocol/websocket/WebSocketChannelChild.cpp
netwerk/sctp/datachannel/DataChannel.cpp
netwerk/socket/nsSOCKSIOLayer.cpp
netwerk/wifi/nsWifiMonitor.cpp
--- a/netwerk/base/BackgroundFileSaver.cpp
+++ b/netwerk/base/BackgroundFileSaver.cpp
@@ -84,17 +84,17 @@ private:
 
 ////////////////////////////////////////////////////////////////////////////////
 //// BackgroundFileSaver
 
 uint32_t BackgroundFileSaver::sThreadCount = 0;
 uint32_t BackgroundFileSaver::sTelemetryMaxThreadCount = 0;
 
 BackgroundFileSaver::BackgroundFileSaver()
-: mControlThread(nullptr)
+: mControlEventTarget(nullptr)
 , mWorkerThread(nullptr)
 , mPipeOutputStream(nullptr)
 , mPipeInputStream(nullptr)
 , mObserver(nullptr)
 , mLock("BackgroundFileSaver.mLock")
 , mWorkerThreadAttentionRequested(false)
 , mFinishRequested(false)
 , mComplete(false)
@@ -145,18 +145,18 @@ BackgroundFileSaver::Init()
 
   nsresult rv;
 
   rv = NS_NewPipe2(getter_AddRefs(mPipeInputStream),
                    getter_AddRefs(mPipeOutputStream), true, true, 0,
                    HasInfiniteBuffer() ? UINT32_MAX : 0);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = NS_GetCurrentThread(getter_AddRefs(mControlThread));
-  NS_ENSURE_SUCCESS(rv, rv);
+  mControlEventTarget = GetCurrentThreadEventTarget();
+  NS_ENSURE_TRUE(mControlEventTarget, NS_ERROR_NOT_INITIALIZED);
 
   rv = NS_NewNamedThread("BgFileSaver", getter_AddRefs(mWorkerThread));
   NS_ENSURE_SUCCESS(rv, rv);
 
   sThreadCount++;
   if (sThreadCount > sTelemetryMaxThreadCount) {
     sTelemetryMaxThreadCount = sThreadCount;
   }
@@ -518,17 +518,17 @@ BackgroundFileSaver::ProcessStateChange(
     nsCOMPtr<nsIFile> actualTargetToNotify;
     rv = mActualTarget->Clone(getter_AddRefs(actualTargetToNotify));
     NS_ENSURE_SUCCESS(rv, rv);
 
     RefPtr<NotifyTargetChangeRunnable> event =
       new NotifyTargetChangeRunnable(this, actualTargetToNotify);
     NS_ENSURE_TRUE(event, NS_ERROR_FAILURE);
 
-    rv = mControlThread->Dispatch(event, NS_DISPATCH_NORMAL);
+    rv = mControlEventTarget->Dispatch(event, NS_DISPATCH_NORMAL);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (isContinuation) {
     // The pending rename operation might be the last task before finishing. We
     // may return here only if we have already created the target file.
     if (CheckCompletion()) {
       return NS_OK;
@@ -742,19 +742,19 @@ BackgroundFileSaver::CheckCompletion()
     if (NS_FAILED(rv)) {
       LOG(("Unable to extract signature information [this = %p].", this));
     } else {
       LOG(("Signature extraction success! [this = %p]", this));
     }
   }
 
   // Post an event to notify that the operation completed.
-  if (NS_FAILED(mControlThread->Dispatch(NewRunnableMethod(this,
-                                                           &BackgroundFileSaver::NotifySaveComplete),
-                                         NS_DISPATCH_NORMAL))) {
+  if (NS_FAILED(mControlEventTarget->Dispatch(NewRunnableMethod(this,
+                                                                &BackgroundFileSaver::NotifySaveComplete),
+                                              NS_DISPATCH_NORMAL))) {
     NS_WARNING("Unable to post completion event to the control thread.");
   }
 
   return true;
 }
 
 // Called on the control thread.
 nsresult
@@ -1148,19 +1148,19 @@ BackgroundFileSaverStreamListener::Async
   // we have now consumed enough data.
   if (self->mReceivedTooMuchData) {
     uint64_t available;
     nsresult rv = self->mPipeInputStream->Available(&available);
     if (NS_FAILED(rv) || available < REQUEST_RESUME_AT) {
       self->mReceivedTooMuchData = false;
 
       // Post an event to verify if the request should be resumed.
-      if (NS_FAILED(self->mControlThread->Dispatch(NewRunnableMethod(self,
-                                                                     &BackgroundFileSaverStreamListener::NotifySuspendOrResume),
-                                                   NS_DISPATCH_NORMAL))) {
+      if (NS_FAILED(self->mControlEventTarget->Dispatch(NewRunnableMethod(self,
+                                                                          &BackgroundFileSaverStreamListener::NotifySuspendOrResume),
+                                                        NS_DISPATCH_NORMAL))) {
         NS_WARNING("Unable to post resume event to the control thread.");
       }
     }
   }
 }
 
 // Called on the control thread.
 nsresult
--- a/netwerk/base/BackgroundFileSaver.h
+++ b/netwerk/base/BackgroundFileSaver.h
@@ -77,17 +77,17 @@ protected:
   /**
    * Helper function for managing NSS objects (mDigestContext).
    */
   void destructorSafeDestroyNSSReference();
 
   /**
    * Thread that constructed this object.
    */
-  nsCOMPtr<nsIThread> mControlThread;
+  nsCOMPtr<nsIEventTarget> mControlEventTarget;
 
   /**
    * Thread to which the actual input/output is delegated.
    */
   nsCOMPtr<nsIThread> mWorkerThread;
 
   /**
    * Stream that receives data from derived classes.  The received data will be
--- a/netwerk/base/Dashboard.cpp
+++ b/netwerk/base/Dashboard.cpp
@@ -33,24 +33,24 @@ class SocketData
 {
 public:
     NS_DECL_THREADSAFE_ISUPPORTS
 
     SocketData()
     {
         mTotalSent = 0;
         mTotalRecv = 0;
-        mThread = nullptr;
+        mEventTarget = nullptr;
     }
 
     uint64_t mTotalSent;
     uint64_t mTotalRecv;
     nsTArray<SocketInfo> mData;
     nsMainThreadPtrHandle<NetDashboardCallback> mCallback;
-    nsIThread *mThread;
+    nsIEventTarget *mEventTarget;
 
 private:
     virtual ~SocketData()
     {
     }
 };
 
 static void GetErrorString(nsresult rv, nsAString& errorString);
@@ -65,22 +65,22 @@ class HttpData
     {
     }
 
 public:
     NS_DECL_THREADSAFE_ISUPPORTS
 
     HttpData()
     {
-        mThread = nullptr;
+        mEventTarget = nullptr;
     }
 
     nsTArray<HttpRetParams> mData;
     nsMainThreadPtrHandle<NetDashboardCallback> mCallback;
-    nsIThread *mThread;
+    nsIEventTarget *mEventTarget;
 };
 
 NS_IMPL_ISUPPORTS0(HttpData)
 
 
 class WebSocketRequest
     : public nsISupports
 {
@@ -88,21 +88,21 @@ class WebSocketRequest
     {
     }
 
 public:
     NS_DECL_THREADSAFE_ISUPPORTS
 
     WebSocketRequest()
     {
-        mThread = nullptr;
+        mEventTarget = nullptr;
     }
 
     nsMainThreadPtrHandle<NetDashboardCallback> mCallback;
-    nsIThread *mThread;
+    nsIEventTarget *mEventTarget;
 };
 
 NS_IMPL_ISUPPORTS0(WebSocketRequest)
 
 
 class DnsData
     : public nsISupports
 {
@@ -110,22 +110,22 @@ class DnsData
     {
     }
 
 public:
     NS_DECL_THREADSAFE_ISUPPORTS
 
     DnsData()
     {
-        mThread = nullptr;
+        mEventTarget = nullptr;
     }
 
     nsTArray<DNSCacheEntries> mData;
     nsMainThreadPtrHandle<NetDashboardCallback> mCallback;
-    nsIThread *mThread;
+    nsIEventTarget *mEventTarget;
 };
 
 NS_IMPL_ISUPPORTS0(DnsData)
 
 
 class ConnectionData
     : public nsITransportEventSink
     , public nsITimerCallback
@@ -142,25 +142,25 @@ public:
     NS_DECL_NSITRANSPORTEVENTSINK
     NS_DECL_NSITIMERCALLBACK
 
     void StartTimer(uint32_t aTimeout);
     void StopTimer();
 
     explicit ConnectionData(Dashboard *target)
     {
-        mThread = nullptr;
+        mEventTarget = nullptr;
         mDashboard = target;
     }
 
     nsCOMPtr<nsISocketTransport> mSocket;
     nsCOMPtr<nsIInputStream> mStreamIn;
     nsCOMPtr<nsITimer> mTimer;
     nsMainThreadPtrHandle<NetDashboardCallback> mCallback;
-    nsIThread *mThread;
+    nsIEventTarget *mEventTarget;
     Dashboard *mDashboard;
 
     nsCString mHost;
     uint32_t mPort;
     const char *mProtocol;
     uint32_t mTimeout;
 
     nsString mStatus;
@@ -176,37 +176,37 @@ class RcwnData
     {
     }
 
 public:
     NS_DECL_THREADSAFE_ISUPPORTS
 
     RcwnData()
     {
-        mThread = nullptr;
+        mEventTarget = nullptr;
     }
 
     nsMainThreadPtrHandle<NetDashboardCallback> mCallback;
-    nsIThread *mThread;
+    nsIEventTarget *mEventTarget;
 };
 
 NS_IMPL_ISUPPORTS0(RcwnData)
 
 NS_IMETHODIMP
 ConnectionData::OnTransportStatus(nsITransport *aTransport, nsresult aStatus,
                                   int64_t aProgress, int64_t aProgressMax)
 {
     if (aStatus == NS_NET_STATUS_CONNECTED_TO) {
         StopTimer();
     }
 
     GetErrorString(aStatus, mStatus);
-    mThread->Dispatch(NewRunnableMethod<RefPtr<ConnectionData>>
-		      (mDashboard, &Dashboard::GetConnectionStatus, this),
-		      NS_DISPATCH_NORMAL);
+    mEventTarget->Dispatch(NewRunnableMethod<RefPtr<ConnectionData>>
+                           (mDashboard, &Dashboard::GetConnectionStatus, this),
+                           NS_DISPATCH_NORMAL);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 ConnectionData::Notify(nsITimer *aTimer)
 {
     MOZ_ASSERT(aTimer == mTimer);
@@ -215,19 +215,19 @@ ConnectionData::Notify(nsITimer *aTimer)
         mSocket->Close(NS_ERROR_ABORT);
         mSocket = nullptr;
         mStreamIn = nullptr;
     }
 
     mTimer = nullptr;
 
     mStatus.AssignLiteral(u"NS_ERROR_NET_TIMEOUT");
-    mThread->Dispatch(NewRunnableMethod<RefPtr<ConnectionData>>
-		      (mDashboard, &Dashboard::GetConnectionStatus, this),
-		      NS_DISPATCH_NORMAL);
+    mEventTarget->Dispatch(NewRunnableMethod<RefPtr<ConnectionData>>
+                           (mDashboard, &Dashboard::GetConnectionStatus, this),
+                           NS_DISPATCH_NORMAL);
 
     return NS_OK;
 }
 
 void
 ConnectionData::StartTimer(uint32_t aTimeout)
 {
     if (!mTimer) {
@@ -289,34 +289,34 @@ public:
 
     LookupHelper() {
     }
 
     nsresult ConstructAnswer(LookupArgument *aArgument);
 public:
     nsCOMPtr<nsICancelable> mCancel;
     nsMainThreadPtrHandle<NetDashboardCallback> mCallback;
-    nsIThread *mThread;
+    nsIEventTarget *mEventTarget;
     nsresult mStatus;
 };
 
 NS_IMPL_ISUPPORTS(LookupHelper, nsIDNSListener)
 
 NS_IMETHODIMP
 LookupHelper::OnLookupComplete(nsICancelable *aRequest,
                                nsIDNSRecord *aRecord, nsresult aStatus)
 {
     MOZ_ASSERT(aRequest == mCancel);
     mCancel = nullptr;
     mStatus = aStatus;
 
     RefPtr<LookupArgument> arg = new LookupArgument(aRecord, this);
-    mThread->Dispatch(NewRunnableMethod<RefPtr<LookupArgument>>
-		      (this, &LookupHelper::ConstructAnswer, arg),
-		      NS_DISPATCH_NORMAL);
+    mEventTarget->Dispatch(NewRunnableMethod<RefPtr<LookupArgument>>
+                           (this, &LookupHelper::ConstructAnswer, arg),
+                           NS_DISPATCH_NORMAL);
 
     return NS_OK;
 }
 
 nsresult
 LookupHelper::ConstructAnswer(LookupArgument *aArgument)
 {
     nsIDNSRecord *aRecord = aArgument->mRecord;
@@ -369,35 +369,35 @@ Dashboard::~Dashboard()
 }
 
 NS_IMETHODIMP
 Dashboard::RequestSockets(NetDashboardCallback *aCallback)
 {
     RefPtr<SocketData> socketData = new SocketData();
     socketData->mCallback =
         new nsMainThreadPtrHolder<NetDashboardCallback>(aCallback, true);
-    socketData->mThread = NS_GetCurrentThread();
+    socketData->mEventTarget = GetCurrentThreadEventTarget();
     gSocketTransportService->Dispatch(NewRunnableMethod<RefPtr<SocketData>>
 				      (this, &Dashboard::GetSocketsDispatch, socketData),
 				      NS_DISPATCH_NORMAL);
     return NS_OK;
 }
 
 nsresult
 Dashboard::GetSocketsDispatch(SocketData *aSocketData)
 {
     RefPtr<SocketData> socketData = aSocketData;
     if (gSocketTransportService) {
         gSocketTransportService->GetSocketConnections(&socketData->mData);
         socketData->mTotalSent = gSocketTransportService->GetSentBytes();
         socketData->mTotalRecv = gSocketTransportService->GetReceivedBytes();
     }
-    socketData->mThread->Dispatch(NewRunnableMethod<RefPtr<SocketData>>
-				  (this, &Dashboard::GetSockets, socketData),
-				  NS_DISPATCH_NORMAL);
+    socketData->mEventTarget->Dispatch(NewRunnableMethod<RefPtr<SocketData>>
+                                       (this, &Dashboard::GetSockets, socketData),
+                                       NS_DISPATCH_NORMAL);
     return NS_OK;
 }
 
 nsresult
 Dashboard::GetSockets(SocketData *aSocketData)
 {
     RefPtr<SocketData> socketData = aSocketData;
     AutoSafeJSContext cx;
@@ -438,32 +438,32 @@ Dashboard::GetSockets(SocketData *aSocke
 }
 
 NS_IMETHODIMP
 Dashboard::RequestHttpConnections(NetDashboardCallback *aCallback)
 {
     RefPtr<HttpData> httpData = new HttpData();
     httpData->mCallback =
         new nsMainThreadPtrHolder<NetDashboardCallback>(aCallback, true);
-    httpData->mThread = NS_GetCurrentThread();
+    httpData->mEventTarget = GetCurrentThreadEventTarget();
 
     gSocketTransportService->Dispatch(NewRunnableMethod<RefPtr<HttpData>>
 				      (this, &Dashboard::GetHttpDispatch, httpData),
 				      NS_DISPATCH_NORMAL);
     return NS_OK;
 }
 
 nsresult
 Dashboard::GetHttpDispatch(HttpData *aHttpData)
 {
     RefPtr<HttpData> httpData = aHttpData;
     HttpInfo::GetHttpConnectionData(&httpData->mData);
-    httpData->mThread->Dispatch(NewRunnableMethod<RefPtr<HttpData>>
-				(this, &Dashboard::GetHttpConnections, httpData),
-				NS_DISPATCH_NORMAL);
+    httpData->mEventTarget->Dispatch(NewRunnableMethod<RefPtr<HttpData>>
+                                     (this, &Dashboard::GetHttpConnections, httpData),
+                                     NS_DISPATCH_NORMAL);
     return NS_OK;
 }
 
 
 nsresult
 Dashboard::GetHttpConnections(HttpData *aHttpData)
 {
     RefPtr<HttpData> httpData = aHttpData;
@@ -614,21 +614,21 @@ Dashboard::NewMsgReceived(const nsACStri
 }
 
 NS_IMETHODIMP
 Dashboard::RequestWebsocketConnections(NetDashboardCallback *aCallback)
 {
     RefPtr<WebSocketRequest> wsRequest = new WebSocketRequest();
     wsRequest->mCallback =
         new nsMainThreadPtrHolder<NetDashboardCallback>(aCallback, true);
-    wsRequest->mThread = NS_GetCurrentThread();
+    wsRequest->mEventTarget = GetCurrentThreadEventTarget();
 
-    wsRequest->mThread->Dispatch(NewRunnableMethod<RefPtr<WebSocketRequest>>
-				 (this, &Dashboard::GetWebSocketConnections, wsRequest),
-				 NS_DISPATCH_NORMAL);
+    wsRequest->mEventTarget->Dispatch(NewRunnableMethod<RefPtr<WebSocketRequest>>
+                                      (this, &Dashboard::GetWebSocketConnections, wsRequest),
+                                      NS_DISPATCH_NORMAL);
     return NS_OK;
 }
 
 nsresult
 Dashboard::GetWebSocketConnections(WebSocketRequest *aWsRequest)
 {
     RefPtr<WebSocketRequest> wsRequest = aWsRequest;
     AutoSafeJSContext cx;
@@ -668,17 +668,17 @@ NS_IMETHODIMP
 Dashboard::RequestDNSInfo(NetDashboardCallback *aCallback)
 {
     RefPtr<DnsData> dnsData = new DnsData();
     dnsData->mCallback =
         new nsMainThreadPtrHolder<NetDashboardCallback>(aCallback, true);
 
     nsresult rv;
     dnsData->mData.Clear();
-    dnsData->mThread = NS_GetCurrentThread();
+    dnsData->mEventTarget = GetCurrentThreadEventTarget();
 
     if (!mDnsService) {
         mDnsService = do_GetService("@mozilla.org/network/dns-service;1", &rv);
         if (NS_FAILED(rv)) {
             return rv;
         }
     }
 
@@ -690,19 +690,19 @@ Dashboard::RequestDNSInfo(NetDashboardCa
 
 nsresult
 Dashboard::GetDnsInfoDispatch(DnsData *aDnsData)
 {
     RefPtr<DnsData> dnsData = aDnsData;
     if (mDnsService) {
         mDnsService->GetDNSCacheEntries(&dnsData->mData);
     }
-    dnsData->mThread->Dispatch(NewRunnableMethod<RefPtr<DnsData>>
-			       (this, &Dashboard::GetDNSCacheEntries, dnsData),
-			       NS_DISPATCH_NORMAL);
+    dnsData->mEventTarget->Dispatch(NewRunnableMethod<RefPtr<DnsData>>
+                                    (this, &Dashboard::GetDNSCacheEntries, dnsData),
+                                    NS_DISPATCH_NORMAL);
     return NS_OK;
 }
 
 nsresult
 Dashboard::GetDNSCacheEntries(DnsData *dnsData)
 {
     AutoSafeJSContext cx;
 
@@ -765,33 +765,33 @@ Dashboard::RequestDNSLookup(const nsACSt
         if (NS_FAILED(rv)) {
             return rv;
         }
     }
 
     RefPtr<LookupHelper> helper = new LookupHelper();
     helper->mCallback =
         new nsMainThreadPtrHolder<NetDashboardCallback>(aCallback, true);
-    helper->mThread = NS_GetCurrentThread();
+    helper->mEventTarget = GetCurrentThreadEventTarget();
     OriginAttributes attrs;
     rv = mDnsService->AsyncResolveNative(aHost, 0, helper.get(),
                                          NS_GetCurrentThread(), attrs,
                                          getter_AddRefs(helper->mCancel));
     return rv;
 }
 
 NS_IMETHODIMP
 Dashboard::RequestRcwnStats(NetDashboardCallback *aCallback)
 {
     RefPtr<RcwnData> rcwnData = new RcwnData();
-    rcwnData->mThread = NS_GetCurrentThread();
+    rcwnData->mEventTarget = GetCurrentThreadEventTarget();
     rcwnData->mCallback =
         new nsMainThreadPtrHolder<NetDashboardCallback>(aCallback, true);
 
-    return rcwnData->mThread->Dispatch(
+    return rcwnData->mEventTarget->Dispatch(
         NewRunnableMethod<RefPtr<RcwnData>>(this, &Dashboard::GetRcwnData, rcwnData),
         NS_DISPATCH_NORMAL);
 }
 
 nsresult
 Dashboard::GetRcwnData(RcwnData *aData)
 {
     AutoSafeJSContext cx;
@@ -857,24 +857,24 @@ Dashboard::RequestConnection(const nsACS
     RefPtr<ConnectionData> connectionData = new ConnectionData(this);
     connectionData->mHost = aHost;
     connectionData->mPort = aPort;
     connectionData->mProtocol = aProtocol;
     connectionData->mTimeout = aTimeout;
 
     connectionData->mCallback =
         new nsMainThreadPtrHolder<NetDashboardCallback>(aCallback, true);
-    connectionData->mThread = NS_GetCurrentThread();
+    connectionData->mEventTarget = GetCurrentThreadEventTarget();
 
     rv = TestNewConnection(connectionData);
     if (NS_FAILED(rv)) {
         mozilla::net::GetErrorString(rv, connectionData->mStatus);
-        connectionData->mThread->Dispatch(NewRunnableMethod<RefPtr<ConnectionData>>
-					  (this, &Dashboard::GetConnectionStatus, connectionData),
-					  NS_DISPATCH_NORMAL);
+        connectionData->mEventTarget->Dispatch(NewRunnableMethod<RefPtr<ConnectionData>>
+                                               (this, &Dashboard::GetConnectionStatus, connectionData),
+                                               NS_DISPATCH_NORMAL);
         return rv;
     }
 
     return NS_OK;
 }
 
 nsresult
 Dashboard::GetConnectionStatus(ConnectionData *aConnectionData)
@@ -917,17 +917,17 @@ Dashboard::TestNewConnection(ConnectionD
             connectionData->mPort, nullptr,
             getter_AddRefs(connectionData->mSocket));
     }
     if (NS_FAILED(rv)) {
         return rv;
     }
 
     rv = connectionData->mSocket->SetEventSink(connectionData,
-        NS_GetCurrentThread());
+        GetCurrentThreadEventTarget());
     if (NS_FAILED(rv)) {
         return rv;
     }
 
     rv = connectionData->mSocket->OpenInputStream(
         nsITransport::OPEN_BLOCKING, 0, 0,
         getter_AddRefs(connectionData->mStreamIn));
     if (NS_FAILED(rv)) {
--- a/netwerk/base/Predictor.cpp
+++ b/netwerk/base/Predictor.cpp
@@ -1475,17 +1475,16 @@ Predictor::RunPredictions(nsIURI *referr
     predicted = true;
     if (verifier) {
       PREDICTOR_LOG(("    sending preconnect verification"));
       verifier->OnPredictPreconnect(uri);
     }
   }
 
   len = preresolves.Length();
-  nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
   for (i = 0; i < len; ++i) {
     nsCOMPtr<nsIURI> uri = preresolves[i];
     ++totalPredictions;
     ++totalPreresolves;
     nsAutoCString hostname;
     uri->GetAsciiHost(hostname);
     PREDICTOR_LOG(("    doing preresolve %s", hostname.get()));
     nsCOMPtr<nsICancelable> tmpCancelable;
--- a/netwerk/base/ProxyAutoConfig.cpp
+++ b/netwerk/base/ProxyAutoConfig.cpp
@@ -406,17 +406,17 @@ ProxyAutoConfig::ResolveAddress(const ns
     return false;
 
   RefPtr<PACResolver> helper = new PACResolver();
   OriginAttributes attrs;
 
   if (NS_FAILED(dns->AsyncResolveNative(aHostName,
                                         nsIDNSService::RESOLVE_PRIORITY_MEDIUM,
                                         helper,
-                                        NS_GetCurrentThread(),
+                                        GetCurrentThreadEventTarget(),
                                         attrs,
                                         getter_AddRefs(helper->mRequest))))
     return false;
 
   if (aTimeout && helper->mRequest) {
     if (!mTimer)
       mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
     if (mTimer) {
--- a/netwerk/base/nsAsyncRedirectVerifyHelper.cpp
+++ b/netwerk/base/nsAsyncRedirectVerifyHelper.cpp
@@ -66,17 +66,17 @@ nsresult
 nsAsyncRedirectVerifyHelper::Init(nsIChannel* oldChan, nsIChannel* newChan,
                                   uint32_t flags, bool synchronize)
 {
     LOG(("nsAsyncRedirectVerifyHelper::Init() "
          "oldChan=%p newChan=%p", oldChan, newChan));
     mOldChan           = oldChan;
     mNewChan           = newChan;
     mFlags             = flags;
-    mCallbackThread    = do_GetCurrentThread();
+    mCallbackEventTarget = GetCurrentThreadEventTarget();
 
     if (!(flags & (nsIChannelEventSink::REDIRECT_INTERNAL |
                    nsIChannelEventSink::REDIRECT_STS_UPGRADE))) {
       nsCOMPtr<nsILoadInfo> loadInfo = oldChan->GetLoadInfo();
       if (loadInfo && loadInfo->GetDontFollowRedirects()) {
         ExplicitCallback(NS_BINDING_ABORTED);
         return NS_OK;
       }
@@ -178,34 +178,34 @@ nsAsyncRedirectVerifyHelper::ExplicitCal
     LOG(("nsAsyncRedirectVerifyHelper::ExplicitCallback() "
          "result=%" PRIx32 " expectedCBs=%u mCallbackInitiated=%u mResult=%"  PRIx32,
          static_cast<uint32_t>(result), mExpectedCallbacks, mCallbackInitiated,
          static_cast<uint32_t>(mResult)));
 
     nsCOMPtr<nsIAsyncVerifyRedirectCallback>
         callback(do_QueryInterface(mOldChan));
 
-    if (!callback || !mCallbackThread) {
+    if (!callback || !mCallbackEventTarget) {
         LOG(("nsAsyncRedirectVerifyHelper::ExplicitCallback() "
-             "callback=%p mCallbackThread=%p", callback.get(), mCallbackThread.get()));
+             "callback=%p mCallbackEventTarget=%p", callback.get(), mCallbackEventTarget.get()));
         return;
     }
 
     mCallbackInitiated = false;  // reset to ensure only one callback
     mWaitingForRedirectCallback = false;
 
     // Now, dispatch the callback on the event-target which called Init()
     nsCOMPtr<nsIRunnable> event =
         new nsAsyncVerifyRedirectCallbackEvent(callback, result);
     if (!event) {
         NS_WARNING("nsAsyncRedirectVerifyHelper::ExplicitCallback() "
                    "failed creating callback event!");
         return;
     }
-    nsresult rv = mCallbackThread->Dispatch(event, NS_DISPATCH_NORMAL);
+    nsresult rv = mCallbackEventTarget->Dispatch(event, NS_DISPATCH_NORMAL);
     if (NS_FAILED(rv)) {
         NS_WARNING("nsAsyncRedirectVerifyHelper::ExplicitCallback() "
                    "failed dispatching callback event!");
     } else {
         LOG(("nsAsyncRedirectVerifyHelper::ExplicitCallback() "
              "dispatched callback event=%p", event.get()));
     }
    
--- a/netwerk/base/nsAsyncRedirectVerifyHelper.h
+++ b/netwerk/base/nsAsyncRedirectVerifyHelper.h
@@ -68,17 +68,17 @@ public:
                   uint32_t flags,
                   bool synchronize = false);
 
 protected:
     nsCOMPtr<nsIChannel> mOldChan;
     nsCOMPtr<nsIChannel> mNewChan;
     uint32_t mFlags;
     bool mWaitingForRedirectCallback;
-    nsCOMPtr<nsIThread>      mCallbackThread;
+    nsCOMPtr<nsIEventTarget> mCallbackEventTarget;
     bool                     mCallbackInitiated;
     int32_t                  mExpectedCallbacks;
     nsresult                 mResult; // value passed to callback
 
     void InitCallback();
     
     /**
      * Calls back to |oldChan| as described in Init()
--- a/netwerk/base/nsAsyncStreamCopier.cpp
+++ b/netwerk/base/nsAsyncStreamCopier.cpp
@@ -29,17 +29,17 @@ class AsyncApplyBufferingPolicyEvent fin
 {
 public:
     /**
      * @param aCopier
      *        The nsAsyncStreamCopier requesting the information.
      */
     explicit AsyncApplyBufferingPolicyEvent(nsAsyncStreamCopier* aCopier)
         : mCopier(aCopier)
-      , mTarget(NS_GetCurrentThread())
+      , mTarget(GetCurrentThreadEventTarget())
       { }
     NS_IMETHOD Run() override
     {
       nsresult rv = mCopier->ApplyBufferingPolicy();
       if (NS_FAILED(rv)) {
           mCopier->Cancel(rv);
           return NS_OK;
       }
--- a/netwerk/base/nsDNSPrefetch.cpp
+++ b/netwerk/base/nsDNSPrefetch.cpp
@@ -54,20 +54,20 @@ nsDNSPrefetch::Prefetch(uint16_t flags)
     nsCOMPtr<nsICancelable> tmpOutstanding;  
 
     if (mStoreTiming)
         mStartTimestamp = mozilla::TimeStamp::Now();
     // If AsyncResolve fails, for example because prefetching is disabled,
     // then our timing will be useless. However, in such a case,
     // mEndTimestamp will be a null timestamp and callers should check
     // TimingsValid() before using the timing.
-    nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
+    nsCOMPtr<nsIEventTarget> main = mozilla::GetMainThreadEventTarget();
     return sDNSService->AsyncResolveNative(mHostname,
                                            flags | nsIDNSService::RESOLVE_SPECULATE,
-                                           this, mainThread, mOriginAttributes,
+                                           this, main, mOriginAttributes,
                                            getter_AddRefs(tmpOutstanding));
 }
 
 nsresult
 nsDNSPrefetch::PrefetchLow(bool refreshDNS)
 {
     return Prefetch(nsIDNSService::RESOLVE_PRIORITY_LOW |
       (refreshDNS ? nsIDNSService::RESOLVE_BYPASS_CACHE : 0));
--- a/netwerk/base/nsInputStreamPump.cpp
+++ b/netwerk/base/nsInputStreamPump.cpp
@@ -128,17 +128,17 @@ nsInputStreamPump::EnsureWaiting()
     // no need to worry about multiple threads... an input stream pump lives
     // on only one thread at a time.
     MOZ_ASSERT(mAsyncStream);
     if (!mWaitingForInputStreamReady && !mProcessingCallbacks) {
         // Ensure OnStateStop is called on the main thread.
         if (mState == STATE_STOP) {
             nsCOMPtr<nsIEventTarget> mainThread = mLabeledMainThreadTarget
                 ? mLabeledMainThreadTarget
-                : do_GetMainThread();
+                : do_AddRef(GetMainThreadEventTarget());
             if (mTargetThread != mainThread) {
                 mTargetThread = do_QueryInterface(mainThread);
             }
         }
         MOZ_ASSERT(mTargetThread);
         nsresult rv = mAsyncStream->AsyncWait(this, 0, 0, mTargetThread);
         if (NS_FAILED(rv)) {
             NS_ERROR("AsyncWait failed");
@@ -378,17 +378,17 @@ nsInputStreamPump::AsyncRead(nsIStreamLi
     // to enforce the mStreamLength restriction.
     mStreamOffset = 0;
 
     // grab event queue (we must do this here by contract, since all notifications
     // must go to the thread which called AsyncRead)
     if (NS_IsMainThread() && mLabeledMainThreadTarget) {
         mTargetThread = mLabeledMainThreadTarget;
     } else {
-        mTargetThread = do_GetCurrentThread();
+        mTargetThread = GetCurrentThreadEventTarget();
     }
     NS_ENSURE_STATE(mTargetThread);
 
     rv = EnsureWaiting();
     if (NS_FAILED(rv)) return rv;
 
     if (mLoadGroup)
         mLoadGroup->AddRequest(this, nullptr);
--- a/netwerk/base/nsRequestObserverProxy.cpp
+++ b/netwerk/base/nsRequestObserverProxy.cpp
@@ -184,14 +184,14 @@ nsRequestObserverProxy::Init(nsIRequestO
 
 //-----------------------------------------------------------------------------
 // nsRequestObserverProxy implementation...
 //-----------------------------------------------------------------------------
 
 nsresult
 nsRequestObserverProxy::FireEvent(nsARequestObserverEvent *event)
 {
-    nsCOMPtr<nsIEventTarget> mainThread(do_GetMainThread());
+    nsCOMPtr<nsIEventTarget> mainThread(GetMainThreadEventTarget());
     return mainThread->Dispatch(event, NS_DISPATCH_NORMAL);
 }
 
 } // namespace net
 } // namespace mozilla
--- a/netwerk/base/nsServerSocket.cpp
+++ b/netwerk/base/nsServerSocket.cpp
@@ -418,17 +418,17 @@ namespace {
 
 class ServerSocketListenerProxy final : public nsIServerSocketListener
 {
   ~ServerSocketListenerProxy() {}
 
 public:
   explicit ServerSocketListenerProxy(nsIServerSocketListener* aListener)
     : mListener(new nsMainThreadPtrHolder<nsIServerSocketListener>(aListener))
-    , mTargetThread(do_GetCurrentThread())
+    , mTarget(GetCurrentThreadEventTarget())
   { }
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSISERVERSOCKETLISTENER
 
   class OnSocketAcceptedRunnable : public Runnable
   {
   public:
@@ -464,38 +464,38 @@ public:
   private:
     nsMainThreadPtrHandle<nsIServerSocketListener> mListener;
     nsCOMPtr<nsIServerSocket> mServ;
     nsresult mStatus;
   };
 
 private:
   nsMainThreadPtrHandle<nsIServerSocketListener> mListener;
-  nsCOMPtr<nsIEventTarget> mTargetThread;
+  nsCOMPtr<nsIEventTarget> mTarget;
 };
 
 NS_IMPL_ISUPPORTS(ServerSocketListenerProxy,
                   nsIServerSocketListener)
 
 NS_IMETHODIMP
 ServerSocketListenerProxy::OnSocketAccepted(nsIServerSocket* aServ,
                                             nsISocketTransport* aTransport)
 {
   RefPtr<OnSocketAcceptedRunnable> r =
     new OnSocketAcceptedRunnable(mListener, aServ, aTransport);
-  return mTargetThread->Dispatch(r, NS_DISPATCH_NORMAL);
+  return mTarget->Dispatch(r, NS_DISPATCH_NORMAL);
 }
 
 NS_IMETHODIMP
 ServerSocketListenerProxy::OnStopListening(nsIServerSocket* aServ,
                                            nsresult aStatus)
 {
   RefPtr<OnStopListeningRunnable> r =
     new OnStopListeningRunnable(mListener, aServ, aStatus);
-  return mTargetThread->Dispatch(r, NS_DISPATCH_NORMAL);
+  return mTarget->Dispatch(r, NS_DISPATCH_NORMAL);
 }
 
 NS_IMETHODIMP
 ServerSocketListenerProxy::OnSocketAcceptedRunnable::Run()
 {
   mListener->OnSocketAccepted(mServ, mTransport);
   return NS_OK;
 }
@@ -513,17 +513,17 @@ NS_IMETHODIMP
 nsServerSocket::AsyncListen(nsIServerSocketListener *aListener)
 {
   // ensuring mFD implies ensuring mLock
   NS_ENSURE_TRUE(mFD, NS_ERROR_NOT_INITIALIZED);
   NS_ENSURE_TRUE(mListener == nullptr, NS_ERROR_IN_PROGRESS);
   {
     MutexAutoLock lock(mLock);
     mListener = new ServerSocketListenerProxy(aListener);
-    mListenerTarget = NS_GetCurrentThread();
+    mListenerTarget = GetCurrentThreadEventTarget();
   }
 
   // Child classes may need to do additional setup just before listening begins
   nsresult rv = OnSocketListen();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
--- a/netwerk/base/nsSocketTransport2.cpp
+++ b/netwerk/base/nsSocketTransport2.cpp
@@ -2539,17 +2539,17 @@ nsSocketTransport::GetSecurityCallbacks(
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSocketTransport::SetSecurityCallbacks(nsIInterfaceRequestor *callbacks)
 {
     nsCOMPtr<nsIInterfaceRequestor> threadsafeCallbacks;
     NS_NewNotificationCallbacksAggregation(callbacks, nullptr,
-                                           NS_GetCurrentThread(),
+                                           GetCurrentThreadEventTarget(),
                                            getter_AddRefs(threadsafeCallbacks));
 
     nsCOMPtr<nsISupports> secinfo;
     {
         MutexAutoLock lock(mLock);
         mCallbacks = threadsafeCallbacks;
         SOCKET_LOG(("Reset callbacks for secinfo=%p callbacks=%p\n",
                     mSecInfo.get(), mCallbacks.get()));
--- a/netwerk/base/nsStreamTransportService.cpp
+++ b/netwerk/base/nsStreamTransportService.cpp
@@ -579,17 +579,17 @@ class AvailableEvent final : public Runn
     AvailableEvent(nsIInputStream *stream,
                    nsIInputAvailableCallback *callback)
         : mStream(stream)
         , mCallback(callback)
         , mDoingCallback(false)
         , mSize(0)
         , mResultForCallback(NS_OK)
     {
-        mCallbackTarget = NS_GetCurrentThread();
+        mCallbackTarget = GetCurrentThreadEventTarget();
     }
 
     NS_IMETHOD Run() override
     {
         if (mDoingCallback) {
             // pong
             mCallback->OnInputAvailableComplete(mSize, mResultForCallback);
             mCallback = nullptr;
--- a/netwerk/base/nsUDPSocket.cpp
+++ b/netwerk/base/nsUDPSocket.cpp
@@ -842,17 +842,17 @@ namespace {
 //-----------------------------------------------------------------------------
 class SocketListenerProxy final : public nsIUDPSocketListener
 {
   ~SocketListenerProxy() {}
 
 public:
   explicit SocketListenerProxy(nsIUDPSocketListener* aListener)
     : mListener(new nsMainThreadPtrHolder<nsIUDPSocketListener>(aListener))
-    , mTargetThread(do_GetCurrentThread())
+    , mTarget(GetCurrentThreadEventTarget())
   { }
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIUDPSOCKETLISTENER
 
   class OnPacketReceivedRunnable : public Runnable
   {
   public:
@@ -888,38 +888,38 @@ public:
   private:
     nsMainThreadPtrHandle<nsIUDPSocketListener> mListener;
     nsCOMPtr<nsIUDPSocket> mSocket;
     nsresult mStatus;
   };
 
 private:
   nsMainThreadPtrHandle<nsIUDPSocketListener> mListener;
-  nsCOMPtr<nsIEventTarget> mTargetThread;
+  nsCOMPtr<nsIEventTarget> mTarget;
 };
 
 NS_IMPL_ISUPPORTS(SocketListenerProxy,
                   nsIUDPSocketListener)
 
 NS_IMETHODIMP
 SocketListenerProxy::OnPacketReceived(nsIUDPSocket* aSocket,
                                       nsIUDPMessage* aMessage)
 {
   RefPtr<OnPacketReceivedRunnable> r =
     new OnPacketReceivedRunnable(mListener, aSocket, aMessage);
-  return mTargetThread->Dispatch(r, NS_DISPATCH_NORMAL);
+  return mTarget->Dispatch(r, NS_DISPATCH_NORMAL);
 }
 
 NS_IMETHODIMP
 SocketListenerProxy::OnStopListening(nsIUDPSocket* aSocket,
                                      nsresult aStatus)
 {
   RefPtr<OnStopListeningRunnable> r =
     new OnStopListeningRunnable(mListener, aSocket, aStatus);
-  return mTargetThread->Dispatch(r, NS_DISPATCH_NORMAL);
+  return mTarget->Dispatch(r, NS_DISPATCH_NORMAL);
 }
 
 NS_IMETHODIMP
 SocketListenerProxy::OnPacketReceivedRunnable::Run()
 {
   NetAddr netAddr;
   nsCOMPtr<nsINetAddr> nsAddr;
   mMessage->GetFromAddr(getter_AddRefs(nsAddr));
@@ -947,17 +947,17 @@ SocketListenerProxy::OnStopListeningRunn
 
 class SocketListenerProxyBackground final : public nsIUDPSocketListener
 {
   ~SocketListenerProxyBackground() {}
 
 public:
   explicit SocketListenerProxyBackground(nsIUDPSocketListener* aListener)
     : mListener(aListener)
-    , mTargetThread(do_GetCurrentThread())
+    , mTarget(GetCurrentThreadEventTarget())
   { }
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIUDPSOCKETLISTENER
 
   class OnPacketReceivedRunnable : public Runnable
   {
   public:
@@ -993,38 +993,38 @@ public:
   private:
     nsCOMPtr<nsIUDPSocketListener> mListener;
     nsCOMPtr<nsIUDPSocket> mSocket;
     nsresult mStatus;
   };
 
 private:
   nsCOMPtr<nsIUDPSocketListener> mListener;
-  nsCOMPtr<nsIEventTarget> mTargetThread;
+  nsCOMPtr<nsIEventTarget> mTarget;
 };
 
 NS_IMPL_ISUPPORTS(SocketListenerProxyBackground,
                   nsIUDPSocketListener)
 
 NS_IMETHODIMP
 SocketListenerProxyBackground::OnPacketReceived(nsIUDPSocket* aSocket,
                                                 nsIUDPMessage* aMessage)
 {
   RefPtr<OnPacketReceivedRunnable> r =
     new OnPacketReceivedRunnable(mListener, aSocket, aMessage);
-  return mTargetThread->Dispatch(r, NS_DISPATCH_NORMAL);
+  return mTarget->Dispatch(r, NS_DISPATCH_NORMAL);
 }
 
 NS_IMETHODIMP
 SocketListenerProxyBackground::OnStopListening(nsIUDPSocket* aSocket,
                                                nsresult aStatus)
 {
   RefPtr<OnStopListeningRunnable> r =
     new OnStopListeningRunnable(mListener, aSocket, aStatus);
-  return mTargetThread->Dispatch(r, NS_DISPATCH_NORMAL);
+  return mTarget->Dispatch(r, NS_DISPATCH_NORMAL);
 }
 
 NS_IMETHODIMP
 SocketListenerProxyBackground::OnPacketReceivedRunnable::Run()
 {
   NetAddr netAddr;
   nsCOMPtr<nsINetAddr> nsAddr;
   mMessage->GetFromAddr(getter_AddRefs(nsAddr));
@@ -1169,17 +1169,17 @@ SendRequestRunnable::Run()
 NS_IMETHODIMP
 nsUDPSocket::AsyncListen(nsIUDPSocketListener *aListener)
 {
   // ensuring mFD implies ensuring mLock
   NS_ENSURE_TRUE(mFD, NS_ERROR_NOT_INITIALIZED);
   NS_ENSURE_TRUE(mListener == nullptr, NS_ERROR_IN_PROGRESS);
   {
     MutexAutoLock lock(mLock);
-    mListenerTarget = NS_GetCurrentThread();
+    mListenerTarget = GetCurrentThreadEventTarget();
     if (NS_IsMainThread()) {
       // PNecko usage
       mListener = new SocketListenerProxy(aListener);
     } else {
       // PBackground usage from media/mtransport
       mListener = new SocketListenerProxyBackground(aListener);
     }
   }
--- a/netwerk/cache/nsCacheEntry.cpp
+++ b/netwerk/cache/nsCacheEntry.cpp
@@ -47,17 +47,17 @@ nsCacheEntry::nsCacheEntry(const nsACStr
 }
 
 
 nsCacheEntry::~nsCacheEntry()
 {
     MOZ_COUNT_DTOR(nsCacheEntry);
     
     if (mData)
-        nsCacheService::ReleaseObject_Locked(mData, mThread);
+        nsCacheService::ReleaseObject_Locked(mData, mEventTarget);
 }
 
 
 nsresult
 nsCacheEntry::Create( const char *          key,
                       bool                  streamBased,
                       nsCacheStoragePolicy  storagePolicy,
                       nsCacheDevice *       device,
@@ -96,23 +96,23 @@ nsCacheEntry::TouchData()
     MarkDataDirty();
 }
 
 
 void
 nsCacheEntry::SetData(nsISupports * data)
 {
     if (mData) {
-        nsCacheService::ReleaseObject_Locked(mData, mThread);
+        nsCacheService::ReleaseObject_Locked(mData, mEventTarget);
         mData = nullptr;
     }
 
     if (data) {
         NS_ADDREF(mData = data);
-        mThread = do_GetCurrentThread();
+        mEventTarget = GetCurrentThreadEventTarget();
     }
 }
 
 
 void
 nsCacheEntry::TouchMetaData()
 {
     mLastModified = SecondsFromPRTime(PR_Now());
--- a/netwerk/cache/nsCacheEntry.h
+++ b/netwerk/cache/nsCacheEntry.h
@@ -218,17 +218,17 @@ private:
     uint32_t                mExpirationTime; // 4
     uint32_t                mFlags;          // 4
     int64_t                 mPredictedDataSize;  // Size given by ContentLength.
     uint32_t                mDataSize;       // 4
     nsCacheDevice *         mCacheDevice;    // 4
     nsCacheDevice *         mCustomDevice;   // 4
     nsCOMPtr<nsISupports>   mSecurityInfo;   // 
     nsISupports *           mData;           // strong ref
-    nsCOMPtr<nsIThread>     mThread;
+    nsCOMPtr<nsIEventTarget> mEventTarget;
     nsCacheMetaData         mMetaData;       // 4
     PRCList                 mRequestQ;       // 8
     PRCList                 mDescriptorQ;    // 8
 };
 
 
 /******************************************************************************
 * nsCacheEntryInfo
--- a/netwerk/cache/nsCacheEntryDescriptor.cpp
+++ b/netwerk/cache/nsCacheEntryDescriptor.cpp
@@ -26,17 +26,17 @@
 
 class nsAsyncDoomEvent : public mozilla::Runnable {
 public:
     nsAsyncDoomEvent(nsCacheEntryDescriptor *descriptor,
                      nsICacheListener *listener)
     {
         mDescriptor = descriptor;
         mListener = listener;
-        mThread = do_GetCurrentThread();
+        mEventTarget = GetCurrentThreadEventTarget();
         // We addref the listener here and release it in nsNotifyDoomListener
         // on the callers thread. If posting of nsNotifyDoomListener event fails
         // we leak the listener which is better than releasing it on a wrong
         // thread.
         NS_IF_ADDREF(mListener);
     }
 
     NS_IMETHOD Run() override
@@ -50,29 +50,29 @@ public:
                 status = nsCacheService::gService->DoomEntry_Internal(
                              mDescriptor->mCacheEntry, true);
             } else if (!mDescriptor->mDoomedOnClose) {
                 status = NS_ERROR_NOT_AVAILABLE;
             }
         }
 
         if (mListener) {
-            mThread->Dispatch(new nsNotifyDoomListener(mListener, status),
-                              NS_DISPATCH_NORMAL);
+            mEventTarget->Dispatch(new nsNotifyDoomListener(mListener, status),
+                                   NS_DISPATCH_NORMAL);
             // posted event will release the reference on the correct thread
             mListener = nullptr;
         }
 
         return NS_OK;
     }
 
 private:
     RefPtr<nsCacheEntryDescriptor> mDescriptor;
     nsICacheListener                *mListener;
-    nsCOMPtr<nsIThread>              mThread;
+    nsCOMPtr<nsIEventTarget>       mEventTarget;
 };
 
 
 NS_IMPL_ISUPPORTS(nsCacheEntryDescriptor,
                   nsICacheEntryDescriptor,
                   nsICacheEntryInfo)
 
 nsCacheEntryDescriptor::nsCacheEntryDescriptor(nsCacheEntry * entry,
--- a/netwerk/cache/nsCacheRequest.h
+++ b/netwerk/cache/nsCacheRequest.h
@@ -53,17 +53,17 @@ private:
     }
     
     ~nsCacheRequest()
     {
         MOZ_COUNT_DTOR(nsCacheRequest);
         NS_ASSERTION(PR_CLIST_IS_EMPTY(this), "request still on a list");
 
         if (mListener)
-            nsCacheService::ReleaseObject_Locked(mListener, mThread);
+            nsCacheService::ReleaseObject_Locked(mListener, mEventTarget);
     }
     
     /**
      * Simple Accessors
      */
     enum CacheRequestInfo {
         eStoragePolicyMask         = 0x000000FF,
         eStreamBasedMask           = 0x00000100,
@@ -144,15 +144,15 @@ private:
     }
 
     /**
      * Data members
      */
     nsCString                  mKey;
     uint32_t                   mInfo;
     nsICacheListener *         mListener;  // strong ref
-    nsCOMPtr<nsIThread>        mThread;
+    nsCOMPtr<nsIEventTarget>   mEventTarget;
     Mutex                      mLock;
     CondVar                    mCondVar;
     nsCOMPtr<nsIFile>          mProfileDir;
 };
 
 #endif // _nsCacheRequest_h_
--- a/netwerk/cache/nsCacheService.cpp
+++ b/netwerk/cache/nsCacheService.cpp
@@ -1018,17 +1018,17 @@ public:
                 const nsACString &key,
                 nsICacheListener *listener)
     {
         mKey = *session->ClientID();
         mKey.Append(':');
         mKey.Append(key);
         mStoragePolicy = session->StoragePolicy();
         mListener = listener;
-        mThread = do_GetCurrentThread();
+        mEventTarget = GetCurrentThreadEventTarget();
         // We addref the listener here and release it in nsNotifyDoomListener
         // on the callers thread. If posting of nsNotifyDoomListener event fails
         // we leak the listener which is better than releasing it on a wrong
         // thread.
         NS_IF_ADDREF(mListener);
     }
 
     NS_IMETHOD Run() override
@@ -1048,30 +1048,30 @@ public:
         }
 
         if (entry) {
             status = NS_OK;
             nsCacheService::gService->DoomEntry_Internal(entry, foundActive);
         }
 
         if (mListener) {
-            mThread->Dispatch(new nsNotifyDoomListener(mListener, status),
-                              NS_DISPATCH_NORMAL);
+            mEventTarget->Dispatch(new nsNotifyDoomListener(mListener, status),
+                                   NS_DISPATCH_NORMAL);
             // posted event will release the reference on the correct thread
             mListener = nullptr;
         }
 
         return NS_OK;
     }
 
 private:
     nsCString             mKey;
     nsCacheStoragePolicy  mStoragePolicy;
     nsICacheListener     *mListener;
-    nsCOMPtr<nsIThread>   mThread;
+    nsCOMPtr<nsIEventTarget> mEventTarget;
 };
 
 /******************************************************************************
  * nsCacheService
  *****************************************************************************/
 nsCacheService *   nsCacheService::gService = nullptr;
 
 NS_IMPL_ISUPPORTS(nsCacheService, nsICacheService, nsICacheServiceInternal,
@@ -1842,17 +1842,17 @@ nsCacheService::CreateRequest(nsCacheSes
 
     // create request
     *request = new nsCacheRequest(key, listener, accessRequested,
                                   blockingMode, session);
 
     if (!listener)  return NS_OK;  // we're sync, we're done.
 
     // get the request's thread
-    (*request)->mThread = do_GetCurrentThread();
+    (*request)->mEventTarget = GetCurrentThreadEventTarget();
     
     return NS_OK;
 }
 
 
 class nsCacheListenerEvent : public Runnable
 {
 public:
@@ -1888,33 +1888,33 @@ private:
 
 
 nsresult
 nsCacheService::NotifyListener(nsCacheRequest *          request,
                                nsICacheEntryDescriptor * descriptor,
                                nsCacheAccessMode         accessGranted,
                                nsresult                  status)
 {
-    NS_ASSERTION(request->mThread, "no thread set in async request!");
+    NS_ASSERTION(request->mEventTarget, "no thread set in async request!");
 
     // Swap ownership, and release listener on target thread...
     nsICacheListener *listener = request->mListener;
     request->mListener = nullptr;
 
     nsCOMPtr<nsIRunnable> ev =
             new nsCacheListenerEvent(listener, descriptor,
                                      accessGranted, status);
     if (!ev) {
         // Better to leak listener and descriptor if we fail because we don't
         // want to destroy them inside the cache service lock or on potentially
         // the wrong thread.
         return NS_ERROR_OUT_OF_MEMORY;
     }
 
-    return request->mThread->Dispatch(ev, NS_DISPATCH_NORMAL);
+    return request->mEventTarget->Dispatch(ev, NS_DISPATCH_NORMAL);
 }
 
 
 nsresult
 nsCacheService::ProcessRequest(nsCacheRequest *           request,
                                bool                       calledFromOpenCacheEntry,
                                nsICacheEntryDescriptor ** result)
 {
--- a/netwerk/cache/nsDiskCacheDeviceSQL.cpp
+++ b/netwerk/cache/nsDiskCacheDeviceSQL.cpp
@@ -1202,17 +1202,17 @@ nsOfflineCacheDevice::InitWithSqlite(moz
   NS_ENSURE_SUCCESS(rv, rv);
 
   MOZ_ASSERT(ss, "nsOfflineCacheDevice::InitWithSqlite called before nsCacheService::Init() ?");
   NS_ENSURE_TRUE(ss, NS_ERROR_UNEXPECTED);
 
   rv = ss->OpenDatabase(indexFile, getter_AddRefs(mDB));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  mInitThread = do_GetCurrentThread();
+  mInitEventTarget = GetCurrentThreadEventTarget();
 
   mDB->ExecuteSimpleSQL(NS_LITERAL_CSTRING("PRAGMA synchronous = OFF;"));
 
   // XXX ... other initialization steps
 
   // XXX in the future we may wish to verify the schema for moz_cache
   //     perhaps using "PRAGMA table_info" ?
 
@@ -1487,32 +1487,32 @@ nsOfflineCacheDevice::Shutdown()
   mStatement_FindClientByNamespace = nullptr;
   mStatement_EnumerateApps = nullptr;
   mStatement_EnumerateGroups = nullptr;
   mStatement_EnumerateGroupsTimeOrder = nullptr;
   }
 
   // Close Database on the correct thread
   bool isOnCurrentThread = true;
-  if (mInitThread)
-    mInitThread->IsOnCurrentThread(&isOnCurrentThread);
+  if (mInitEventTarget)
+    isOnCurrentThread = mInitEventTarget->IsOnCurrentThread();
 
   if (!isOnCurrentThread) {
     nsCOMPtr<nsIRunnable> ev = new nsCloseDBEvent(mDB);
 
     if (ev) {
-      mInitThread->Dispatch(ev, NS_DISPATCH_NORMAL);
+      mInitEventTarget->Dispatch(ev, NS_DISPATCH_NORMAL);
     }
   }
   else {
     mDB->Close();
   }
 
   mDB = nullptr;
-  mInitThread = nullptr;
+  mInitEventTarget = nullptr;
 
   return NS_OK;
 }
 
 const char *
 nsOfflineCacheDevice::GetDeviceID()
 {
   return OFFLINE_CACHE_DEVICE_ID;
--- a/netwerk/cache/nsDiskCacheDeviceSQL.h
+++ b/netwerk/cache/nsDiskCacheDeviceSQL.h
@@ -279,12 +279,12 @@ private:
 
   mozilla::Mutex                  mLock;
 
   nsInterfaceHashtable<nsCStringHashKey, nsIWeakReference> mCaches;
   nsClassHashtable<nsCStringHashKey, nsCString> mActiveCachesByGroup;
   nsTHashtable<nsCStringHashKey> mActiveCaches;
   nsTHashtable<nsCStringHashKey> mLockedEntries;
 
-  nsCOMPtr<nsIThread> mInitThread;
+  nsCOMPtr<nsIEventTarget> mInitEventTarget;
 };
 
 #endif // nsOfflineCacheDevice_h__
--- a/netwerk/cache2/CacheEntry.cpp
+++ b/netwerk/cache2/CacheEntry.cpp
@@ -72,17 +72,17 @@ CacheEntryHandle::~CacheEntryHandle()
 // CacheEntry::Callback
 
 CacheEntry::Callback::Callback(CacheEntry* aEntry,
                                nsICacheEntryOpenCallback *aCallback,
                                bool aReadOnly, bool aCheckOnAnyThread,
                                bool aSecret)
 : mEntry(aEntry)
 , mCallback(aCallback)
-, mTargetThread(do_GetCurrentThread())
+, mTarget(GetCurrentThreadEventTarget())
 , mReadOnly(aReadOnly)
 , mRevalidating(false)
 , mCheckOnAnyThread(aCheckOnAnyThread)
 , mRecheckAfterWrite(false)
 , mNotWanted(false)
 , mSecret(aSecret)
 , mDoomWhenFoundPinned(false)
 , mDoomWhenFoundNonPinned(false)
@@ -109,17 +109,17 @@ CacheEntry::Callback::Callback(CacheEntr
   MOZ_COUNT_CTOR(CacheEntry::Callback);
   MOZ_ASSERT(mEntry->HandlesCount());
   mEntry->AddHandleRef();
 }
 
 CacheEntry::Callback::Callback(CacheEntry::Callback const &aThat)
 : mEntry(aThat.mEntry)
 , mCallback(aThat.mCallback)
-, mTargetThread(aThat.mTargetThread)
+, mTarget(aThat.mTarget)
 , mReadOnly(aThat.mReadOnly)
 , mRevalidating(aThat.mRevalidating)
 , mCheckOnAnyThread(aThat.mCheckOnAnyThread)
 , mRecheckAfterWrite(aThat.mRecheckAfterWrite)
 , mNotWanted(aThat.mNotWanted)
 , mSecret(aThat.mSecret)
 , mDoomWhenFoundPinned(aThat.mDoomWhenFoundPinned)
 , mDoomWhenFoundNonPinned(aThat.mDoomWhenFoundNonPinned)
@@ -129,17 +129,17 @@ CacheEntry::Callback::Callback(CacheEntr
   // The counter may go from zero to non-null only under the service lock
   // but here we expect it to be already positive.
   MOZ_ASSERT(mEntry->HandlesCount());
   mEntry->AddHandleRef();
 }
 
 CacheEntry::Callback::~Callback()
 {
-  ProxyRelease(mCallback, mTargetThread);
+  ProxyRelease(mCallback, mTarget);
 
   mEntry->ReleaseHandleRef();
   MOZ_COUNT_DTOR(CacheEntry::Callback);
 }
 
 void CacheEntry::Callback::ExchangeEntry(CacheEntry* aEntry)
 {
   if (mEntry == aEntry)
@@ -166,27 +166,27 @@ bool CacheEntry::Callback::DeferDoom(boo
 
   return false;
 }
 
 nsresult CacheEntry::Callback::OnCheckThread(bool *aOnCheckThread) const
 {
   if (!mCheckOnAnyThread) {
     // Check we are on the target
-    return mTargetThread->IsOnCurrentThread(aOnCheckThread);
+    return mTarget->IsOnCurrentThread(aOnCheckThread);
   }
 
   // We can invoke check anywhere
   *aOnCheckThread = true;
   return NS_OK;
 }
 
 nsresult CacheEntry::Callback::OnAvailThread(bool *aOnAvailThread) const
 {
-  return mTargetThread->IsOnCurrentThread(aOnAvailThread);
+  return mTarget->IsOnCurrentThread(aOnAvailThread);
 }
 
 // CacheEntry
 
 NS_IMPL_ISUPPORTS(CacheEntry,
                   nsICacheEntry,
                   nsIRunnable,
                   CacheFileListener)
@@ -658,19 +658,19 @@ bool CacheEntry::InvokeCallbacks(bool aR
       continue;
     }
 
     bool onCheckThread;
     nsresult rv = mCallbacks[i].OnCheckThread(&onCheckThread);
 
     if (NS_SUCCEEDED(rv) && !onCheckThread) {
       // Redispatch to the target thread
-      rv = mCallbacks[i].mTargetThread->Dispatch(NewRunnableMethod(this,
-								   &CacheEntry::InvokeCallbacksLock),
-						 nsIEventTarget::DISPATCH_NORMAL);
+      rv = mCallbacks[i].mTarget->Dispatch(NewRunnableMethod(this,
+                                                             &CacheEntry::InvokeCallbacksLock),
+                                           nsIEventTarget::DISPATCH_NORMAL);
       if (NS_SUCCEEDED(rv)) {
         LOG(("  re-dispatching to target thread"));
         return false;
       }
     }
 
     Callback callback = mCallbacks[i];
     mCallbacks.RemoveElementAt(i);
@@ -834,17 +834,17 @@ void CacheEntry::InvokeAvailableCallback
     return;
   }
 
   if (!onAvailThread) {
     // Dispatch to the right thread
     RefPtr<AvailableCallbackRunnable> event =
       new AvailableCallbackRunnable(this, aCallback);
 
-    rv = aCallback.mTargetThread->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
+    rv = aCallback.mTarget->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
     LOG(("  redispatched, (rv = 0x%08" PRIx32 ")", static_cast<uint32_t>(rv)));
     return;
   }
 
   if (mIsDoomed || aCallback.mNotWanted) {
     LOG(("  doomed or not wanted, notifying OCEA with NS_ERROR_CACHE_KEY_NOT_FOUND"));
     aCallback.mCallback->OnCacheEntryAvailable(
       nullptr, false, nullptr, NS_ERROR_CACHE_KEY_NOT_FOUND);
--- a/netwerk/cache2/CacheEntry.h
+++ b/netwerk/cache2/CacheEntry.h
@@ -155,17 +155,17 @@ private:
     // a "defer" callback.
     bool DeferDoom(bool *aDoom) const;
 
     // We are raising reference count here to take into account the pending
     // callback (that virtually holds a ref to this entry before it gets
     // it's pointer).
     RefPtr<CacheEntry> mEntry;
     nsCOMPtr<nsICacheEntryOpenCallback> mCallback;
-    nsCOMPtr<nsIThread> mTargetThread;
+    nsCOMPtr<nsIEventTarget> mTarget;
     bool mReadOnly : 1;
     bool mRevalidating : 1;
     bool mCheckOnAnyThread : 1;
     bool mRecheckAfterWrite : 1;
     bool mNotWanted : 1;
     bool mSecret : 1;
 
     // These are set only for the defer-doomer Callback instance inserted
--- a/netwerk/cache2/CacheFile.cpp
+++ b/netwerk/cache2/CacheFile.cpp
@@ -2130,17 +2130,17 @@ CacheFile::QueueChunkListener(uint32_t a
 
   MOZ_ASSERT(aCallback);
 
   ChunkListenerItem *item = new ChunkListenerItem();
   item->mTarget = CacheFileIOManager::IOTarget();
   if (!item->mTarget) {
     LOG(("CacheFile::QueueChunkListener() - Cannot get Cache I/O thread! Using "
          "main thread for callback."));
-    item->mTarget = do_GetMainThread();
+    item->mTarget = GetMainThreadEventTarget();
   }
   item->mCallback = aCallback;
 
   ChunkListeners *listeners;
   if (!mChunkListeners.Get(aIndex, &listeners)) {
     listeners = new ChunkListeners();
     mChunkListeners.Put(aIndex, listeners);
   }
--- a/netwerk/cache2/CacheFileChunk.cpp
+++ b/netwerk/cache2/CacheFileChunk.cpp
@@ -482,17 +482,17 @@ CacheFileChunk::WaitForUpdate(CacheFileC
   }
 #endif
 
   ChunkListenerItem *item = new ChunkListenerItem();
   item->mTarget = CacheFileIOManager::IOTarget();
   if (!item->mTarget) {
     LOG(("CacheFileChunk::WaitForUpdate() - Cannot get Cache I/O thread! Using "
          "main thread for callback."));
-    item->mTarget = do_GetMainThread();
+    item->mTarget = GetMainThreadEventTarget();
   }
   item->mCallback = aCallback;
   MOZ_ASSERT(item->mTarget);
   item->mCallback = aCallback;
 
   mUpdateListeners.AppendElement(item);
 }
 
--- a/netwerk/cache2/CacheFileInputStream.cpp
+++ b/netwerk/cache2/CacheFileInputStream.cpp
@@ -625,17 +625,17 @@ CacheFileInputStream::NotifyListener()
   MOZ_ASSERT(mCallback);
   MOZ_ASSERT(!mInReadSegments);
 
   if (!mCallbackTarget) {
     mCallbackTarget = CacheFileIOManager::IOTarget();
     if (!mCallbackTarget) {
       LOG(("CacheFileInputStream::NotifyListener() - Cannot get Cache I/O "
            "thread! Using main thread for callback."));
-      mCallbackTarget = do_GetMainThread();
+      mCallbackTarget = GetMainThreadEventTarget();
     }
   }
 
   nsCOMPtr<nsIInputStreamCallback> asyncCallback =
     NS_NewInputStreamReadyEvent(mCallback, mCallbackTarget);
 
   mCallback = nullptr;
   mCallbackTarget = nullptr;
--- a/netwerk/cache2/CacheFileOutputStream.cpp
+++ b/netwerk/cache2/CacheFileOutputStream.cpp
@@ -447,17 +447,17 @@ CacheFileOutputStream::NotifyListener()
 
   MOZ_ASSERT(mCallback);
 
   if (!mCallbackTarget) {
     mCallbackTarget = CacheFileIOManager::IOTarget();
     if (!mCallbackTarget) {
       LOG(("CacheFileOutputStream::NotifyListener() - Cannot get Cache I/O "
            "thread! Using main thread for callback."));
-      mCallbackTarget = do_GetMainThread();
+      mCallbackTarget = GetMainThreadEventTarget();
     }
   }
 
   nsCOMPtr<nsIOutputStreamCallback> asyncCallback =
     NS_NewOutputStreamReadyEvent(mCallback, mCallbackTarget);
 
   mCallback = nullptr;
   mCallbackTarget = nullptr;
--- a/netwerk/cache2/CacheStorageService.h
+++ b/netwerk/cache2/CacheStorageService.h
@@ -395,26 +395,25 @@ private:
     Monitor mMon;
     bool mSignaled;
   };
 
   RefPtr<IOThreadSuspender> mActiveIOSuspender;
 };
 
 template<class T>
-void ProxyRelease(nsCOMPtr<T> &object, nsIThread* thread)
+void ProxyRelease(nsCOMPtr<T> &object, nsIEventTarget* target)
 {
-  NS_ProxyRelease(thread, object.forget());
+  NS_ProxyRelease(target, object.forget());
 }
 
 template<class T>
 void ProxyReleaseMainThread(nsCOMPtr<T> &object)
 {
-  nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
-  ProxyRelease(object, mainThread);
+  ProxyRelease(object, GetMainThreadEventTarget());
 }
 
 } // namespace net
 } // namespace mozilla
 
 #define NS_CACHE_STORAGE_SERVICE_CID \
   { 0xea70b098, 0x5014, 0x4e21, \
   { 0xae, 0xe1, 0x75, 0xe6, 0xb2, 0xc4, 0xb8, 0xe0 } } \
--- a/netwerk/dns/DNSRequestParent.cpp
+++ b/netwerk/dns/DNSRequestParent.cpp
@@ -36,21 +36,21 @@ DNSRequestParent::DoAsyncResolve(const n
                                  const OriginAttributes &originAttributes,
                                  uint32_t flags,
                                  const nsACString &networkInterface)
 {
   nsresult rv;
   mFlags = flags;
   nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
   if (NS_SUCCEEDED(rv)) {
-    nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
+    nsCOMPtr<nsIEventTarget> main = GetMainThreadEventTarget();
     nsCOMPtr<nsICancelable> unused;
     rv = dns->AsyncResolveExtendedNative(hostname, flags,
                                          networkInterface, this,
-                                         mainThread, originAttributes,
+                                         main, originAttributes,
                                          getter_AddRefs(unused));
   }
 
   if (NS_FAILED(rv) && !mIPCClosed) {
     mIPCClosed = true;
     Unused << SendLookupCompleted(DNSRequestResponse(rv));
   }
 }
--- a/netwerk/dns/nsDNSService2.cpp
+++ b/netwerk/dns/nsDNSService2.cpp
@@ -837,19 +837,17 @@ nsDNSService::AsyncResolveExtendedNative
     if (GetOffline() &&
         (!mOfflineLocalhost || !hostname.LowerCaseEqualsASCII("localhost"))) {
         flags |= RESOLVE_OFFLINE;
     }
 
     // make sure JS callers get notification on the main thread
     nsCOMPtr<nsIXPConnectWrappedJS> wrappedListener = do_QueryInterface(listener);
     if (wrappedListener && !target) {
-        nsCOMPtr<nsIThread> mainThread;
-        NS_GetMainThread(getter_AddRefs(mainThread));
-        target = do_QueryInterface(mainThread);
+        target = GetMainThreadEventTarget();
     }
 
     if (target) {
         listener = new DNSListenerProxy(listener, target);
     }
 
     uint16_t af = GetAFForLookup(hostname, flags);
 
--- a/netwerk/ipc/ChannelEventQueue.h
+++ b/netwerk/ipc/ChannelEventQueue.h
@@ -41,17 +41,17 @@ class MainThreadChannelEvent : public Ch
   MainThreadChannelEvent() { MOZ_COUNT_CTOR(MainThreadChannelEvent); }
   virtual ~MainThreadChannelEvent() { MOZ_COUNT_DTOR(MainThreadChannelEvent); }
 
   already_AddRefed<nsIEventTarget>
   GetEventTarget() override
   {
     MOZ_ASSERT(XRE_IsParentProcess());
 
-    return do_GetMainThread();
+    return do_AddRef(GetMainThreadEventTarget());
   }
 };
 
 // This event is designed to be only used for e10s child channels.
 // The goal is to force the child channel to implement GetNeckoTarget()
 // which should return a labeled main thread event target so that this
 // channel event can be dispatched correctly.
 template<typename T>
--- a/netwerk/protocol/ftp/nsFTPChannel.cpp
+++ b/netwerk/protocol/ftp/nsFTPChannel.cpp
@@ -134,17 +134,17 @@ namespace {
 
 class FTPEventSinkProxy final : public nsIFTPEventSink
 {
     ~FTPEventSinkProxy() {}
 
 public:
     explicit FTPEventSinkProxy(nsIFTPEventSink* aTarget)
         : mTarget(aTarget)
-        , mTargetThread(do_GetCurrentThread())
+        , mEventTarget(GetCurrentThreadEventTarget())
     { }
         
     NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSIFTPEVENTSINK
 
     class OnFTPControlLogRunnable : public Runnable
     {
     public:
@@ -161,27 +161,27 @@ public:
     private:
         nsCOMPtr<nsIFTPEventSink> mTarget;
         bool mServer;
         nsCString mMessage;
     };
 
 private:
     nsCOMPtr<nsIFTPEventSink> mTarget;
-    nsCOMPtr<nsIThread> mTargetThread;
+    nsCOMPtr<nsIEventTarget> mEventTarget;
 };
 
 NS_IMPL_ISUPPORTS(FTPEventSinkProxy, nsIFTPEventSink)
 
 NS_IMETHODIMP
 FTPEventSinkProxy::OnFTPControlLog(bool aServer, const char* aMsg)
 {
     RefPtr<OnFTPControlLogRunnable> r =
         new OnFTPControlLogRunnable(mTarget, aServer, aMsg);
-    return mTargetThread->Dispatch(r, NS_DISPATCH_NORMAL);
+    return mEventTarget->Dispatch(r, NS_DISPATCH_NORMAL);
 }
 
 NS_IMETHODIMP
 FTPEventSinkProxy::OnFTPControlLogRunnable::Run()
 {
     mTarget->OnFTPControlLog(mServer, mMessage.get());
     return NS_OK;
 }
--- a/netwerk/protocol/ftp/nsFtpConnectionThread.cpp
+++ b/netwerk/protocol/ftp/nsFtpConnectionThread.cpp
@@ -1499,17 +1499,17 @@ nsFtpState::R_pasv() {
             return FTP_ERROR;
         mDataTransport = strans;
 
         strans->SetQoSBits(gFtpHandler->GetDataQoSBits());
         
         LOG(("FTP:(%p) created DT (%s:%x)\n", this, host.get(), port));
         
         // hook ourself up as a proxy for status notifications
-        rv = mDataTransport->SetEventSink(this, NS_GetCurrentThread());
+        rv = mDataTransport->SetEventSink(this, GetCurrentThreadEventTarget());
         NS_ENSURE_SUCCESS(rv, FTP_ERROR);
 
         if (mAction == PUT) {
             NS_ASSERTION(!mRETRFailed, "Failed before uploading");
 
             // nsIUploadChannel requires the upload stream to support ReadSegments.
             // therefore, we can open an unbuffered socket output stream.
             nsCOMPtr<nsIOutputStream> output;
--- a/netwerk/protocol/ftp/nsFtpControlConnection.cpp
+++ b/netwerk/protocol/ftp/nsFtpControlConnection.cpp
@@ -105,17 +105,17 @@ nsFtpControlConnection::Connect(nsIProxy
                               getter_AddRefs(mSocket)); // the command transport
     if (NS_FAILED(rv))
         return rv;
 
     mSocket->SetQoSBits(gFtpHandler->GetControlQoSBits());
 
     // proxy transport events back to current thread
     if (eventSink)
-        mSocket->SetEventSink(eventSink, NS_GetCurrentThread());
+        mSocket->SetEventSink(eventSink, GetCurrentThreadEventTarget());
 
     // open buffered, blocking output stream to socket.  so long as commands
     // do not exceed 1024 bytes in length, the writing thread (the main thread)
     // will not block.  this should be OK.
     rv = mSocket->OpenOutputStream(nsITransport::OPEN_BLOCKING, 1024, 1,
                                    getter_AddRefs(mSocketOutput));
     if (NS_FAILED(rv))
         return rv;
@@ -142,17 +142,17 @@ nsFtpControlConnection::WaitData(nsFtpCo
     if (!listener) {
         mListener = nullptr;
         return NS_OK;
     }
 
     NS_ENSURE_STATE(mSocketInput);
 
     mListener = listener;
-    return mSocketInput->AsyncWait(this, 0, 0, NS_GetCurrentThread());
+    return mSocketInput->AsyncWait(this, 0, 0, GetCurrentThreadEventTarget());
 }
 
 nsresult 
 nsFtpControlConnection::Disconnect(nsresult status)
 {
     if (!mSocket)
         return NS_OK;  // already disconnected
     
--- a/netwerk/protocol/http/HttpChannelChild.cpp
+++ b/netwerk/protocol/http/HttpChannelChild.cpp
@@ -2279,32 +2279,32 @@ HttpChannelChild::GetNeckoTarget()
 {
   nsCOMPtr<nsIEventTarget> target;
   {
     MutexAutoLock lock(mEventTargetMutex);
     target = mNeckoTarget;
   }
 
   if (!target) {
-    target = do_GetMainThread();
+    target = GetMainThreadEventTarget();
   }
   return target.forget();
 }
 
 already_AddRefed<nsIEventTarget>
 HttpChannelChild::GetODATarget()
 {
   nsCOMPtr<nsIEventTarget> target;
   {
     MutexAutoLock lock(mEventTargetMutex);
     target = mODATarget ? mODATarget : mNeckoTarget;
   }
 
   if (!target) {
-    target = do_GetMainThread();
+    target = GetMainThreadEventTarget();
   }
   return target.forget();
 }
 
 nsresult
 HttpChannelChild::ContinueAsyncOpen()
 {
   nsCString appCacheClientId;
@@ -3118,17 +3118,17 @@ HttpChannelChild::RetargetDeliveryTo(nsI
   LOG(("HttpChannelChild::RetargetDeliveryTo [this=%p, aNewTarget=%p]",
        this, aNewTarget));
 
   MOZ_ASSERT(NS_IsMainThread(), "Should be called on main thread only");
   MOZ_ASSERT(!mODATarget);
   MOZ_ASSERT(aNewTarget);
 
   NS_ENSURE_ARG(aNewTarget);
-  if (aNewTarget == NS_GetCurrentThread()) {
+  if (aNewTarget->IsOnCurrentThread()) {
     NS_WARNING("Retargeting delivery to same thread");
     return NS_OK;
   }
 
   // Ensure that |mListener| and any subsequent listeners can be retargeted
   // to another thread.
   nsresult rv = NS_OK;
   nsCOMPtr<nsIThreadRetargetableStreamListener> retargetableListener =
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -1113,17 +1113,17 @@ nsHttpChannel::SetupTransaction()
     }
 
     EnsureTopLevelOuterContentWindowId();
 
     nsCOMPtr<nsIAsyncInputStream> responseStream;
     rv = mTransaction->Init(mCaps, mConnectionInfo, &mRequestHead,
                             mUploadStream, mReqContentLength,
                             mUploadStreamHasHeaders,
-                            NS_GetCurrentThread(), callbacks, this,
+                            GetCurrentThreadEventTarget(), callbacks, this,
                             mTopLevelOuterContentWindowId,
                             getter_AddRefs(responseStream));
     if (NS_FAILED(rv)) {
         mTransaction = nullptr;
         return rv;
     }
 
     mTransaction->SetClassOfService(mClassOfService);
@@ -7562,17 +7562,17 @@ nsHttpChannel::OnDataAvailable(nsIReques
 //-----------------------------------------------------------------------------
 
 NS_IMETHODIMP
 nsHttpChannel::RetargetDeliveryTo(nsIEventTarget* aNewTarget)
 {
     MOZ_ASSERT(NS_IsMainThread(), "Should be called on main thread only");
 
     NS_ENSURE_ARG(aNewTarget);
-    if (aNewTarget == NS_GetCurrentThread()) {
+    if (aNewTarget->IsOnCurrentThread()) {
         NS_WARNING("Retargeting delivery to same thread");
         return NS_OK;
     }
     if (!mTransactionPump && !mCachePump) {
         LOG(("nsHttpChannel::RetargetDeliveryTo %p %p no pump available\n",
              this, aNewTarget));
         return NS_ERROR_NOT_AVAILABLE;
     }
@@ -7591,20 +7591,19 @@ nsHttpChannel::RetargetDeliveryTo(nsIEve
     if (NS_SUCCEEDED(rv) && mTransactionPump) {
         retargetableTransactionPump = do_QueryObject(mTransactionPump);
         // nsInputStreamPump should implement this interface.
         MOZ_ASSERT(retargetableTransactionPump);
         rv = retargetableTransactionPump->RetargetDeliveryTo(aNewTarget);
 
         // If retarget fails for transaction pump, we must restore mCachePump.
         if (NS_FAILED(rv) && retargetableCachePump) {
-            nsCOMPtr<nsIThread> mainThread;
-            rv = NS_GetMainThread(getter_AddRefs(mainThread));
-            NS_ENSURE_SUCCESS(rv, rv);
-            rv = retargetableCachePump->RetargetDeliveryTo(mainThread);
+            nsCOMPtr<nsIEventTarget> main = GetMainThreadEventTarget();
+            NS_ENSURE_TRUE(main, NS_ERROR_UNEXPECTED);
+            rv = retargetableCachePump->RetargetDeliveryTo(main);
         }
     }
     return rv;
 }
 
 //-----------------------------------------------------------------------------
 // nsHttpChannel::nsThreadRetargetableStreamListener
 //-----------------------------------------------------------------------------
@@ -8420,17 +8419,17 @@ nsHttpChannel::AsyncOnExamineCachedRespo
 void
 nsHttpChannel::UpdateAggregateCallbacks()
 {
     if (!mTransaction) {
         return;
     }
     nsCOMPtr<nsIInterfaceRequestor> callbacks;
     NS_NewNotificationCallbacksAggregation(mCallbacks, mLoadGroup,
-                                           NS_GetCurrentThread(),
+                                           GetCurrentThreadEventTarget(),
                                            getter_AddRefs(callbacks));
     mTransaction->SetSecurityCallbacks(callbacks);
 }
 
 NS_IMETHODIMP
 nsHttpChannel::SetLoadGroup(nsILoadGroup *aLoadGroup)
 {
     MOZ_ASSERT(NS_IsMainThread(), "Wrong thread.");
--- a/netwerk/protocol/websocket/WebSocketChannel.cpp
+++ b/netwerk/protocol/websocket/WebSocketChannel.cpp
@@ -2886,21 +2886,20 @@ WebSocketChannel::DoAdmissionDNS()
   NS_ENSURE_SUCCESS(rv, rv);
   mAddress = hostName;
   rv = mURI->GetPort(&mPort);
   NS_ENSURE_SUCCESS(rv, rv);
   if (mPort == -1)
     mPort = (mEncrypted ? kDefaultWSSPort : kDefaultWSPort);
   nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
-  nsCOMPtr<nsIThread> mainThread;
-  NS_GetMainThread(getter_AddRefs(mainThread));
+  nsCOMPtr<nsIEventTarget> main = GetMainThreadEventTarget();
   MOZ_ASSERT(!mCancelable);
   return dns->AsyncResolveNative(hostName, 0, this,
-                                 mainThread, mLoadInfo->GetOriginAttributes(),
+                                 main, mLoadInfo->GetOriginAttributes(),
                                  getter_AddRefs(mCancelable));
 }
 
 nsresult
 WebSocketChannel::ApplyForAdmission()
 {
   LOG(("WebSocketChannel::ApplyForAdmission() %p\n", this));
 
@@ -3337,17 +3336,17 @@ WebSocketChannel::AsyncOpen(nsIURI *aURI
 
   if (mListenerMT || mWasOpened)
     return NS_ERROR_ALREADY_OPENED;
 
   nsresult rv;
 
   // Ensure target thread is set.
   if (!mTargetThread) {
-    mTargetThread = do_GetMainThread();
+    mTargetThread = GetMainThreadEventTarget();
   }
 
   mSocketThread = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
   if (NS_FAILED(rv)) {
     NS_WARNING("unable to continue without socket transport service");
     return rv;
   }
 
--- a/netwerk/protocol/websocket/WebSocketChannelChild.cpp
+++ b/netwerk/protocol/websocket/WebSocketChannelChild.cpp
@@ -175,17 +175,17 @@ public:
 
     mChannelEvent->Run();
   }
 
   already_AddRefed<nsIEventTarget> GetEventTarget()
   {
     nsCOMPtr<nsIEventTarget> target = mEventTarget;
     if (!target) {
-      target = do_GetMainThread();
+      target = GetMainThreadEventTarget();
     }
     return target.forget();
   }
 
 private:
   nsAutoPtr<ChannelEvent> mChannelEvent;
   nsCOMPtr<nsIEventTarget> mEventTarget;
 };
@@ -207,18 +207,17 @@ class StartEvent : public ChannelEvent
 
   void Run()
   {
     mChild->OnStart(mProtocol, mExtensions, mEffectiveURL, mEncrypted);
   }
 
   already_AddRefed<nsIEventTarget> GetEventTarget()
   {
-    nsCOMPtr<nsIEventTarget> target = do_GetCurrentThread();
-    return target.forget();
+    return do_AddRef(GetCurrentThreadEventTarget());
   }
 
  private:
   RefPtr<WebSocketChannelChild> mChild;
   nsCString mProtocol;
   nsCString mExtensions;
   nsString mEffectiveURL;
   bool mEncrypted;
@@ -272,18 +271,17 @@ class StopEvent : public ChannelEvent
 
   void Run()
   {
     mChild->OnStop(mStatusCode);
   }
 
   already_AddRefed<nsIEventTarget> GetEventTarget()
   {
-    nsCOMPtr<nsIEventTarget> target = do_GetCurrentThread();
-    return target.forget();
+    return do_AddRef(GetCurrentThreadEventTarget());
   }
 
  private:
   RefPtr<WebSocketChannelChild> mChild;
   nsresult mStatusCode;
 };
 
 mozilla::ipc::IPCResult
@@ -329,18 +327,17 @@ class MessageEvent : public ChannelEvent
       mChild->OnMessageAvailable(mMessage);
     } else {
       mChild->OnBinaryMessageAvailable(mMessage);
     }
   }
 
   already_AddRefed<nsIEventTarget> GetEventTarget()
   {
-    nsCOMPtr<nsIEventTarget> target = do_GetCurrentThread();
-    return target.forget();
+    return do_AddRef(GetCurrentThreadEventTarget());
   }
 
  private:
   RefPtr<WebSocketChannelChild> mChild;
   nsCString mMessage;
   bool mBinary;
 };
 
@@ -408,18 +405,17 @@ class AcknowledgeEvent : public ChannelE
 
   void Run()
   {
     mChild->OnAcknowledge(mSize);
   }
 
   already_AddRefed<nsIEventTarget> GetEventTarget()
   {
-    nsCOMPtr<nsIEventTarget> target = do_GetCurrentThread();
-    return target.forget();
+    return do_AddRef(GetCurrentThreadEventTarget());
   }
 
  private:
   RefPtr<WebSocketChannelChild> mChild;
   uint32_t mSize;
 };
 
 mozilla::ipc::IPCResult
@@ -461,18 +457,17 @@ class ServerCloseEvent : public ChannelE
 
   void Run()
   {
     mChild->OnServerClose(mCode, mReason);
   }
 
   already_AddRefed<nsIEventTarget> GetEventTarget()
   {
-    nsCOMPtr<nsIEventTarget> target = do_GetCurrentThread();
-    return target.forget();
+    return do_AddRef(GetCurrentThreadEventTarget());
   }
 
  private:
   RefPtr<WebSocketChannelChild> mChild;
   uint16_t mCode;
   nsCString mReason;
 };
 
@@ -606,17 +601,17 @@ private:
   uint16_t                        mCode;
   nsCString                       mReason;
 };
 
 NS_IMETHODIMP
 WebSocketChannelChild::Close(uint16_t code, const nsACString & reason)
 {
   if (!NS_IsMainThread()) {
-    MOZ_RELEASE_ASSERT(NS_GetCurrentThread() == mTargetThread);
+    MOZ_RELEASE_ASSERT(mTargetThread->IsOnCurrentThread());
     return NS_DispatchToMainThread(new CloseEvent(this, code, reason));
   }
   LOG(("WebSocketChannelChild::Close() %p\n", this));
 
   {
     MutexAutoLock lock(mMutex);
     if (mIPCState != Opened) {
       return NS_ERROR_UNEXPECTED;
@@ -734,17 +729,17 @@ private:
   uint32_t mLength;
 };
 
 NS_IMETHODIMP
 WebSocketChannelChild::SendBinaryStream(nsIInputStream *aStream,
                                         uint32_t aLength)
 {
   if (!NS_IsMainThread()) {
-    MOZ_RELEASE_ASSERT(NS_GetCurrentThread() == mTargetThread);
+    MOZ_RELEASE_ASSERT(mTargetThread->IsOnCurrentThread());
     return NS_DispatchToMainThread(new BinaryStreamEvent(this, aStream, aLength));
   }
 
   LOG(("WebSocketChannelChild::SendBinaryStream() %p\n", this));
 
   AutoIPCStream autoStream;
   autoStream.Serialize(aStream,
                        static_cast<mozilla::dom::ContentChild*>(gNeckoChild->Manager()));
--- a/netwerk/sctp/datachannel/DataChannel.cpp
+++ b/netwerk/sctp/datachannel/DataChannel.cpp
@@ -2392,32 +2392,30 @@ DataChannelConnection::ReadBlob(already_
   // output socket.  We need a sender thread(s?) to enqueue data into the
   // socket and to avoid main-thread IO that might block.  Even on a
   // background thread, we may not want to block on one stream's data.
   // I.e. run non-blocking and service multiple channels.
 
   // For now as a hack, send as a single blast of queued packets which may
   // be deferred until buffer space is available.
   uint64_t len;
-  nsCOMPtr<nsIThread> mainThread;
-  NS_GetMainThread(getter_AddRefs(mainThread));
 
   // Must not let Dispatching it cause the DataChannelConnection to get
   // released on the wrong thread.  Using WrapRunnable(RefPtr<DataChannelConnection>(aThis),...
   // will occasionally cause aThis to get released on this thread.  Also, an explicit Runnable
   // lets us avoid copying the blob data an extra time.
   RefPtr<DataChannelBlobSendRunnable> runnable = new DataChannelBlobSendRunnable(aThis,
                                                                                    aStream);
   // avoid copying the blob data by passing the mData from the runnable
   if (NS_FAILED(aBlob->Available(&len)) ||
       NS_FAILED(NS_ReadInputStreamToString(aBlob, runnable->mData, len))) {
     // Bug 966602:  Doesn't return an error to the caller via onerror.
     // We must release DataChannelConnection on MainThread to avoid issues (bug 876167)
     // aThis is now owned by the runnable; release it there
-    NS_ProxyRelease(mainThread, runnable.forget());
+    NS_ReleaseOnMainThread(runnable.forget());
     return;
   }
   aBlob->Close();
   NS_DispatchToMainThread(runnable, NS_DISPATCH_NORMAL);
 }
 
 void
 DataChannelConnection::GetStreamIds(std::vector<uint16_t>* aStreamList)
--- a/netwerk/socket/nsSOCKSIOLayer.cpp
+++ b/netwerk/socket/nsSOCKSIOLayer.cpp
@@ -465,17 +465,17 @@ nsSOCKSSocketInfo::StartDNS(PRFileDesc *
 
     nsCString proxyHost;
     mProxy->GetHost(proxyHost);
 
     mozilla::OriginAttributes attrs;
 
     mFD  = fd;
     nsresult rv = dns->AsyncResolveNative(proxyHost, 0, this,
-                                          NS_GetCurrentThread(), attrs,
+                                          mozilla::GetCurrentThreadEventTarget(), attrs,
                                           getter_AddRefs(mLookup));
 
     if (NS_FAILED(rv)) {
         LOGERROR(("socks: DNS lookup for SOCKS proxy %s failed",
                   proxyHost.get()));
         return PR_FAILURE;
     }
     mState = SOCKS_DNS_IN_PROGRESS;
--- a/netwerk/wifi/nsWifiMonitor.cpp
+++ b/netwerk/wifi/nsWifiMonitor.cpp
@@ -169,25 +169,25 @@ NS_IMETHODIMP nsWifiMonitor::Run()
           currentListeners = new WifiListenerArray(mListeners.Length());
           for (uint32_t i = 0; i < mListeners.Length(); i++)
               currentListeners->AppendElement(mListeners[i].mListener);
       }
       mThreadComplete = true;
   }
 
   if (doError) {
-    nsCOMPtr<nsIThread> thread = do_GetMainThread();
-    if (!thread)
+    nsCOMPtr<nsIEventTarget> target = GetMainThreadEventTarget();
+    if (!target)
       return NS_ERROR_UNEXPECTED;
 
     nsCOMPtr<nsIRunnable> runnable(new nsPassErrorToWifiListeners(currentListeners, rv));
     if (!runnable)
       return NS_ERROR_OUT_OF_MEMORY;
 
-    thread->Dispatch(runnable, NS_DISPATCH_SYNC);
+    target->Dispatch(runnable, NS_DISPATCH_SYNC);
   }
 
   LOG(("@@@@@ wifi monitor run complete\n"));
   return NS_OK;
 }
 
 class nsCallWifiListeners final : public nsIRunnable
 {