Bug 1268432: Replace |Task| with |Runnable| in B2G code r=fabrice
authorThomas Zimmermann <tdz@users.sourceforge.net>
Mon, 02 May 2016 10:27:15 -0700
changeset 295806 413335e6452af2fb0768056b652953ca5da0fe96
parent 295805 134d9f44aeb804097f891c328dec5e516dc92628
child 295807 345bdee7e864765965f8ed3a24ce7a7796f77ea3
push id19043
push usercbook@mozilla.com
push dateTue, 03 May 2016 14:20:17 +0000
treeherderfx-team@7f959c47385b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs1268432, 1266595
milestone49.0a1
Bug 1268432: Replace |Task| with |Runnable| in B2G code r=fabrice This patch converts the remaining B2G code from |Task| to |Runnable| and fixes related API calls. This is a follow-up to bug 1266595.
dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.cpp
dom/bluetooth/bluedroid/BluetoothOppManager.cpp
dom/bluetooth/bluedroid/BluetoothSocket.cpp
dom/bluetooth/bluedroid/BluetoothSocketMessageWatcher.cpp
dom/bluetooth/bluedroid/BluetoothSocketMessageWatcher.h
dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
dom/bluetooth/bluez/BluetoothDBusService.cpp
dom/bluetooth/bluez/BluetoothHfpManager.cpp
dom/bluetooth/bluez/BluetoothOppManager.cpp
dom/bluetooth/bluez/BluetoothSocket.cpp
dom/ipc/NuwaChild.cpp
dom/ipc/PreallocatedProcessManager.cpp
dom/system/gonk/AudioManager.cpp
dom/system/gonk/AutoMounter.cpp
dom/system/gonk/VolumeManager.cpp
dom/system/gonk/nsVolume.cpp
dom/system/gonk/nsVolumeService.cpp
hal/gonk/GonkDiskSpaceWatcher.cpp
hal/gonk/GonkHal.cpp
hal/gonk/GonkSensor.cpp
hal/gonk/GonkSwitch.cpp
hal/gonk/UeventPoller.cpp
ipc/glue/ProcessUtils_linux.cpp
ipc/hal/DaemonSocket.cpp
ipc/netd/Netd.cpp
ipc/netd/Netd.h
ipc/ril/RilSocket.cpp
ipc/unixsocket/ConnectionOrientedSocket.cpp
ipc/unixsocket/DataSocket.cpp
ipc/unixsocket/DataSocket.h
ipc/unixsocket/ListenSocket.cpp
ipc/unixsocket/SocketBase.cpp
ipc/unixsocket/SocketBase.h
ipc/unixsocket/StreamSocket.cpp
widget/gonk/nativewindow/FakeSurfaceComposer.cpp
widget/gonk/nativewindow/GonkBufferQueueJB.cpp
widget/gonk/nativewindow/GonkBufferQueueKK.cpp
widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueCore.cpp
widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueProducer.cpp
widget/gonk/nativewindow/GonkNativeWindowICS.cpp
widget/gonk/nsScreenManagerGonk.cpp
widget/gonk/nsWindow.cpp
--- a/dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonSocketInterface.cpp
@@ -83,26 +83,27 @@ BluetoothDaemonSocketModule::ConnectCmd(
   }
   Unused << pdu.release();
   return rv;
 }
 
 /* |DeleteTask| deletes a class instance on the I/O thread
  */
 template <typename T>
-class DeleteTask final : public Task
+class DeleteTask final : public Runnable
 {
 public:
   DeleteTask(T* aPtr)
   : mPtr(aPtr)
   { }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     mPtr = nullptr;
+    return NS_OK;
   }
 
 private:
   UniquePtr<T> mPtr;
 };
 
 /* |AcceptWatcher| specializes SocketMessageWatcher for Accept
  * operations by reading the socket messages from Bluedroid and
@@ -129,41 +130,41 @@ public:
                                                     GetConnectionStatus()));
     } else {
       ErrorRunnable::Dispatch(GetResultHandler(),
                               &BluetoothSocketResultHandler::OnError,
                               ConstantInitOp1<BluetoothStatus>(aStatus));
     }
 
     MessageLoopForIO::current()->PostTask(
-      FROM_HERE, new DeleteTask<AcceptWatcher>(this));
+      MakeAndAddRef<DeleteTask<AcceptWatcher>>(this));
   }
 };
 
 nsresult
 BluetoothDaemonSocketModule::AcceptCmd(int aFd,
                                        BluetoothSocketResultHandler* aRes)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   /* receive Bluedroid's socket-setup messages and client fd */
-  Task* t = new SocketMessageWatcherTask(new AcceptWatcher(aFd, aRes));
-  XRE_GetIOMessageLoop()->PostTask(FROM_HERE, t);
+  XRE_GetIOMessageLoop()->PostTask(
+    MakeAndAddRef<SocketMessageWatcherTask>(new AcceptWatcher(aFd, aRes)));
 
   return NS_OK;
 }
 
 nsresult
 BluetoothDaemonSocketModule::CloseCmd(BluetoothSocketResultHandler* aRes)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   /* stop the watcher corresponding to |aRes| */
-  Task* t = new DeleteSocketMessageWatcherTask(aRes);
-  XRE_GetIOMessageLoop()->PostTask(FROM_HERE, t);
+  XRE_GetIOMessageLoop()->PostTask(
+    MakeAndAddRef<DeleteSocketMessageWatcherTask>(aRes));
 
   return NS_OK;
 }
 
 void
 BluetoothDaemonSocketModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
                                        DaemonSocketPDU& aPDU,
                                        DaemonSocketResultHandler* aRes)
@@ -268,17 +269,17 @@ public:
                                                     GetConnectionStatus()));
     } else {
       ErrorRunnable::Dispatch(GetResultHandler(),
                               &BluetoothSocketResultHandler::OnError,
                               ConstantInitOp1<BluetoothStatus>(aStatus));
     }
 
     MessageLoopForIO::current()->PostTask(
-      FROM_HERE, new DeleteTask<ConnectWatcher>(this));
+      MakeAndAddRef<DeleteTask<ConnectWatcher>>(this));
   }
 };
 
 void
 BluetoothDaemonSocketModule::ConnectRsp(const DaemonSocketPDUHeader& aHeader,
                                         DaemonSocketPDU& aPDU,
                                         BluetoothSocketResultHandler* aRes)
 {
@@ -293,18 +294,18 @@ BluetoothDaemonSocketModule::ConnectRsp(
   fd = receiveFds[0];
   if (fd < 0) {
     ErrorRunnable::Dispatch(aRes, &BluetoothSocketResultHandler::OnError,
                             ConstantInitOp1<BluetoothStatus>(STATUS_FAIL));
     return;
   }
 
   /* receive Bluedroid's socket-setup messages */
-  Task* t = new SocketMessageWatcherTask(new ConnectWatcher(fd, aRes));
-  XRE_GetIOMessageLoop()->PostTask(FROM_HERE, t);
+  XRE_GetIOMessageLoop()->PostTask(
+    MakeAndAddRef<SocketMessageWatcherTask>(new ConnectWatcher(fd, aRes)));
 }
 
 //
 // Socket interface
 //
 
 BluetoothDaemonSocketInterface::BluetoothDaemonSocketInterface(
   BluetoothDaemonSocketModule* aModule)
--- a/dom/bluetooth/bluedroid/BluetoothOppManager.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothOppManager.cpp
@@ -167,28 +167,29 @@ public:
     return NS_OK;
   };
 
 private:
   nsCOMPtr<nsIInputStream> mInputStream;
   uint32_t mAvailablePacketSize;
 };
 
-class BluetoothOppManager::CloseSocketTask final : public Task
+class BluetoothOppManager::CloseSocketTask final : public Runnable
 {
 public:
   CloseSocketTask(BluetoothSocket* aSocket) : mSocket(aSocket)
   {
     MOZ_ASSERT(aSocket);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(NS_IsMainThread());
     mSocket->Close();
+    return NS_OK;
   }
 
 private:
   RefPtr<BluetoothSocket> mSocket;
 };
 
 BluetoothOppManager::BluetoothOppManager() : mConnected(false)
                                            , mRemoteObexVersion(0)
@@ -1153,18 +1154,18 @@ BluetoothOppManager::ClientDataHandler(U
     SendDisconnectRequest();
     FileTransferComplete();
   } else if (mLastCommand == ObexRequestCode::Disconnect) {
     AfterOppDisconnected();
     // Most devices will directly terminate connection after receiving
     // Disconnect request, so we make a delay here. If the socket hasn't been
     // disconnected, we will close it.
     if (mSocket) {
-      MessageLoop::current()->
-        PostDelayedTask(FROM_HERE, new CloseSocketTask(mSocket), 1000);
+      MessageLoop::current()->PostDelayedTask(
+        MakeAndAddRef<CloseSocketTask>(mSocket), 1000);
     }
   } else if (mLastCommand == ObexRequestCode::Connect) {
     MOZ_ASSERT(!mFileName.IsEmpty());
     MOZ_ASSERT(mBlob);
 
     AfterOppConnected();
 
     // Ensure valid access to remote information
--- a/dom/bluetooth/bluedroid/BluetoothSocket.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothSocket.cpp
@@ -195,61 +195,66 @@ private:
 class SocketConnectTask final : public SocketIOTask<DroidSocketImpl>
 {
 public:
   SocketConnectTask(DroidSocketImpl* aDroidSocketImpl, int aFd)
   : SocketIOTask<DroidSocketImpl>(aDroidSocketImpl)
   , mFd(aFd)
   { }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!GetIO()->IsConsumerThread());
     MOZ_ASSERT(!IsCanceled());
 
     GetIO()->Connect(mFd);
+
+    return NS_OK;
   }
 
 private:
   int mFd;
 };
 
 class SocketListenTask final : public SocketIOTask<DroidSocketImpl>
 {
 public:
   SocketListenTask(DroidSocketImpl* aDroidSocketImpl, int aFd)
   : SocketIOTask<DroidSocketImpl>(aDroidSocketImpl)
   , mFd(aFd)
   { }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!GetIO()->IsConsumerThread());
 
     if (!IsCanceled()) {
       GetIO()->Listen(mFd);
     }
+    return NS_OK;
   }
 
 private:
   int mFd;
 };
 
 class SocketConnectClientFdTask final
 : public SocketIOTask<DroidSocketImpl>
 {
   SocketConnectClientFdTask(DroidSocketImpl* aImpl)
   : SocketIOTask<DroidSocketImpl>(aImpl)
   { }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!GetIO()->IsConsumerThread());
 
     GetIO()->ConnectClientFd();
+
+    return NS_OK;
   }
 };
 
 void
 DroidSocketImpl::Connect(int aFd)
 {
   MOZ_ASSERT(aFd >= 0);
 
@@ -298,17 +303,17 @@ DroidSocketImpl::Accept(int aFd)
     int res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags | O_NONBLOCK));
     NS_ENSURE_TRUE_VOID(!res);
   }
 
   SetFd(aFd);
   mConnectionStatus = SOCKET_IS_CONNECTED;
 
   GetConsumerThread()->PostTask(
-    FROM_HERE, new SocketEventTask(this, SocketEventTask::CONNECT_SUCCESS));
+    MakeAndAddRef<SocketEventTask>(this, SocketEventTask::CONNECT_SUCCESS));
 
   AddWatchers(READ_WATCHER, true);
   if (HasPendingData()) {
     AddWatchers(WRITE_WATCHER, false);
   }
 }
 
 void
@@ -342,22 +347,24 @@ DroidSocketImpl::OnSocketCanReceiveWitho
 class AcceptTask final : public SocketIOTask<DroidSocketImpl>
 {
 public:
   AcceptTask(DroidSocketImpl* aDroidSocketImpl, int aFd)
   : SocketIOTask<DroidSocketImpl>(aDroidSocketImpl)
   , mFd(aFd)
   { }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!GetIO()->IsConsumerThread());
     MOZ_ASSERT(!IsCanceled());
 
     GetIO()->Accept(mFd);
+
+    return NS_OK;
   }
 
 private:
   int mFd;
 };
 
 class AcceptResultHandler final : public BluetoothSocketResultHandler
 {
@@ -381,18 +388,18 @@ public:
     }
 
     if (aConnectionStatus != 0) {
       mImpl->mConsumer->NotifyError();
       return;
     }
 
     mImpl->mConsumer->SetAddress(aBdAddress);
-    mImpl->GetIOLoop()->PostTask(FROM_HERE,
-                                 new AcceptTask(mImpl, fd.forget()));
+    mImpl->GetIOLoop()->PostTask(
+      mozilla::MakeAndAddRef<AcceptTask>(mImpl, fd.forget()));
   }
 
   void OnError(BluetoothStatus aStatus) override
   {
     MOZ_ASSERT(mImpl->IsConsumerThread());
     BT_LOGR("BluetoothSocketInterface::Accept failed: %d", (int)aStatus);
 
     if (!mImpl->IsShutdownOnConsumerThread()) {
@@ -411,21 +418,23 @@ private:
 class InvokeAcceptTask final : public SocketTask<DroidSocketImpl>
 {
 public:
   InvokeAcceptTask(DroidSocketImpl* aImpl, int aListenFd)
     : SocketTask<DroidSocketImpl>(aImpl)
     , mListenFd(aListenFd)
   { }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(GetIO()->IsConsumerThread());
 
     GetIO()->mConsumer->Accept(mListenFd, new AcceptResultHandler(GetIO()));
+
+    return NS_OK;
   }
 
 private:
   int mListenFd;
 };
 
 void
 DroidSocketImpl::OnSocketCanAcceptWithoutBlocking(int aFd)
@@ -433,17 +442,17 @@ DroidSocketImpl::OnSocketCanAcceptWithou
   MOZ_ASSERT(!IsConsumerThread());
   MOZ_ASSERT(!mShuttingDownOnIOThread);
 
   /* When a listening socket is ready for receiving data,
    * we can call |Accept| on it.
    */
 
   RemoveWatchers(READ_WATCHER);
-  GetConsumerThread()->PostTask(FROM_HERE, new InvokeAcceptTask(this, aFd));
+  GetConsumerThread()->PostTask(MakeAndAddRef<InvokeAcceptTask>(this, aFd));
 }
 
 void
 DroidSocketImpl::OnFileCanWriteWithoutBlocking(int aFd)
 {
   if (mConnectionStatus == SOCKET_IS_CONNECTED) {
     OnSocketCanSendWithoutBlocking(aFd);
   } else if (mConnectionStatus == SOCKET_IS_CONNECTING) {
@@ -478,17 +487,17 @@ DroidSocketImpl::OnSocketCanConnectWitho
 
   /* We follow Posix behaviour here: Connect operations are
    * complete once we can write to the connecting socket.
    */
 
   mConnectionStatus = SOCKET_IS_CONNECTED;
 
   GetConsumerThread()->PostTask(
-    FROM_HERE, new SocketEventTask(this, SocketEventTask::CONNECT_SUCCESS));
+    MakeAndAddRef<SocketEventTask>(this, SocketEventTask::CONNECT_SUCCESS));
 
   AddWatchers(READ_WATCHER, true);
   if (HasPendingData()) {
     AddWatchers(WRITE_WATCHER, false);
   }
 }
 
 // |DataSocketIO|
@@ -514,43 +523,45 @@ DroidSocketImpl::QueryReceiveBuffer(
 class DroidSocketImpl::ReceiveTask final : public SocketTask<DroidSocketImpl>
 {
 public:
   ReceiveTask(DroidSocketImpl* aIO, UnixSocketBuffer* aBuffer)
     : SocketTask<DroidSocketImpl>(aIO)
     , mBuffer(aBuffer)
   { }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     DroidSocketImpl* io = SocketTask<DroidSocketImpl>::GetIO();
 
     MOZ_ASSERT(io->IsConsumerThread());
 
     if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
       // Since we've already explicitly closed and the close
       // happened before this, this isn't really an error.
-      return;
+      return NS_OK;
     }
 
     BluetoothSocket* bluetoothSocket = io->GetBluetoothSocket();
     MOZ_ASSERT(bluetoothSocket);
 
     bluetoothSocket->ReceiveSocketData(mBuffer);
+
+    return NS_OK;
   }
 
 private:
   UniquePtr<UnixSocketBuffer> mBuffer;
 };
 
 void
 DroidSocketImpl::ConsumeBuffer()
 {
-  GetConsumerThread()->PostTask(FROM_HERE,
-                                new ReceiveTask(this, mBuffer.release()));
+  GetConsumerThread()->PostTask(
+    MakeAndAddRef<ReceiveTask>(this, mBuffer.release()));
 }
 
 void
 DroidSocketImpl::DiscardBuffer()
 {
   // Nothing to do.
 }
 
@@ -600,18 +611,18 @@ public:
     }
 
     if (aConnectionStatus != 0) {
       mImpl->mConsumer->NotifyError();
       return;
     }
 
     mImpl->mConsumer->SetAddress(aBdAddress);
-    mImpl->GetIOLoop()->PostTask(FROM_HERE,
-                                 new SocketConnectTask(mImpl, aFd));
+    mImpl->GetIOLoop()->PostTask(
+      mozilla::MakeAndAddRef<SocketConnectTask>(mImpl, aFd));
   }
 
   void OnError(BluetoothStatus aStatus) override
   {
     MOZ_ASSERT(mImpl->IsConsumerThread());
     BT_WARNING("Connect failed: %d", (int)aStatus);
 
     if (!mImpl->IsShutdownOnConsumerThread()) {
@@ -677,17 +688,18 @@ public:
   {
     MOZ_ASSERT(mImpl);
   }
 
   void Listen(int aFd) override
   {
     MOZ_ASSERT(mImpl->IsConsumerThread());
 
-    mImpl->GetIOLoop()->PostTask(FROM_HERE, new SocketListenTask(mImpl, aFd));
+    mImpl->GetIOLoop()->PostTask(
+      mozilla::MakeAndAddRef<SocketListenTask>(mImpl, aFd));
   }
 
   void OnError(BluetoothStatus aStatus) override
   {
     MOZ_ASSERT(mImpl->IsConsumerThread());
 
     BT_WARNING("Listen failed: %d", (int)aStatus);
   }
@@ -771,18 +783,18 @@ BluetoothSocket::ReceiveSocketData(Uniqu
 void
 BluetoothSocket::SendSocketData(UnixSocketIOBuffer* aBuffer)
 {
   MOZ_ASSERT(mImpl);
   MOZ_ASSERT(mImpl->IsConsumerThread());
   MOZ_ASSERT(!mImpl->IsShutdownOnConsumerThread());
 
   mImpl->GetIOLoop()->PostTask(
-    FROM_HERE,
-    new SocketIOSendTask<DroidSocketImpl, UnixSocketIOBuffer>(mImpl, aBuffer));
+    MakeAndAddRef<SocketIOSendTask<DroidSocketImpl, UnixSocketIOBuffer>>(
+      mImpl, aBuffer));
 }
 
 // |SocketBase|
 
 void
 BluetoothSocket::Close()
 {
   if (!mImpl) {
@@ -855,16 +867,16 @@ BluetoothSocket::Cleanup()
   if (mCurrentRes) {
     mSocketInterface->Close(mCurrentRes);
   }
 
   // From this point on, we consider mImpl as being deleted. We
   // sever the relationship here so any future calls to listen
   // or connect will create a new implementation.
   mImpl->ShutdownOnConsumerThread();
-  mImpl->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mImpl));
+  mImpl->GetIOLoop()->PostTask(MakeAndAddRef<SocketIOShutdownTask>(mImpl));
   mImpl = nullptr;
 
   mSocketInterface = nullptr;
   mObserver = nullptr;
   mCurrentRes = nullptr;
   mDeviceAddress.Clear();
 }
--- a/dom/bluetooth/bluedroid/BluetoothSocketMessageWatcher.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothSocketMessageWatcher.cpp
@@ -272,41 +272,43 @@ SocketMessageWatcher::ReadBdAddress(unsi
 
 SocketMessageWatcherTask::SocketMessageWatcherTask(
   SocketMessageWatcher* aWatcher)
   : mWatcher(aWatcher)
 {
   MOZ_ASSERT(mWatcher);
 }
 
-void
+NS_IMETHODIMP
 SocketMessageWatcherTask::Run()
 {
   mWatcher->Watch();
+  return NS_OK;
 }
 
 //
 // DeleteSocketMessageWatcherTask
 //
 
 DeleteSocketMessageWatcherTask::DeleteSocketMessageWatcherTask(
   BluetoothSocketResultHandler* aRes)
   : mRes(aRes)
 {
   MOZ_ASSERT(mRes);
 }
 
-void
+NS_IMETHODIMP
 DeleteSocketMessageWatcherTask::Run()
 {
   // look up hash table for the watcher corresponding to |mRes|
   SocketMessageWatcherWrapper* wrapper = sWatcherHashtable.Get(mRes);
   if (!wrapper) {
-    return;
+    return NS_OK;
   }
 
   // stop the watcher if it exists
   SocketMessageWatcher* watcher = wrapper->GetSocketMessageWatcher();
   watcher->StopWatching();
   watcher->Proceed(STATUS_DONE);
+  return NS_OK;
 }
 
 END_BLUETOOTH_NAMESPACE
--- a/dom/bluetooth/bluedroid/BluetoothSocketMessageWatcher.h
+++ b/dom/bluetooth/bluedroid/BluetoothSocketMessageWatcher.h
@@ -79,36 +79,36 @@ private:
   unsigned char mLen;
   uint8_t mBuf[MSG1_SIZE + MSG2_SIZE];
   RefPtr<BluetoothSocketResultHandler> mRes;
 };
 
 /* |SocketMessageWatcherTask| starts a SocketMessageWatcher
  * on the I/O task
  */
-class SocketMessageWatcherTask final : public Task
+class SocketMessageWatcherTask final : public Runnable
 {
 public:
   SocketMessageWatcherTask(SocketMessageWatcher* aWatcher);
 
-  void Run() override;
+  NS_IMETHOD Run() override;
 
 private:
   SocketMessageWatcher* mWatcher;
 };
 
 /* |DeleteSocketMessageWatcherTask| deletes a watching SocketMessageWatcher
  * on the I/O task
  */
-class DeleteSocketMessageWatcherTask final : public Task
+class DeleteSocketMessageWatcherTask final : public Runnable
 {
 public:
   DeleteSocketMessageWatcherTask(BluetoothSocketResultHandler* aRes);
 
-  void Run() override;
+  NS_IMETHOD Run() override;
 
 private:
   BluetoothSocketResultHandler* mRes;
 };
 
 END_BLUETOOTH_NAMESPACE
 
 #endif // mozilla_dom_bluetooth_bluedroid_BluetoothSocketMessageWatcher_h
--- a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
+++ b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
@@ -103,51 +103,53 @@ public:
     BT_WARNING("Unable to get value for '" AUDIO_VOLUME_BT_SCO_ID "'");
     return NS_OK;
   }
 
 protected:
   ~GetVolumeTask() { }
 };
 
-class BluetoothHfpManager::CloseScoTask : public Task
+class BluetoothHfpManager::CloseScoTask : public Runnable
 {
 private:
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(sBluetoothHfpManager);
     sBluetoothHfpManager->DisconnectSco();
+    return NS_OK;
   }
 };
 
 class BluetoothHfpManager::CloseScoRunnable : public Runnable
 {
 public:
   NS_IMETHOD Run() override
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     MessageLoop::current()->PostDelayedTask(
-      FROM_HERE, new CloseScoTask(), sBusyToneInterval);
+      MakeAndAddRef<CloseScoTask>(), sBusyToneInterval);
 
     return NS_OK;
   }
 };
 
-class BluetoothHfpManager::RespondToBLDNTask : public Task
+class BluetoothHfpManager::RespondToBLDNTask : public Runnable
 {
 private:
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(sBluetoothHfpManager);
 
     if (!sBluetoothHfpManager->mDialingRequestProcessed) {
       sBluetoothHfpManager->mDialingRequestProcessed = true;
       sBluetoothHfpManager->SendResponse(HFP_AT_RESPONSE_ERROR);
     }
+    return NS_OK;
   }
 };
 
 NS_IMPL_ISUPPORTS(BluetoothHfpManager::GetVolumeTask,
                   nsISettingsServiceCallback);
 
 /**
  *  Call
@@ -1592,28 +1594,26 @@ void BluetoothHfpManager::DialCallNotifi
   // We need to respond OK/Error for dial requests for every case listed above,
   // 1) and 2):         Respond in either RespondToBLDNTask or
   //                    HandleCallStateChanged()
   // 3):                Respond here
   if (message.IsEmpty()) {
     mDialingRequestProcessed = false;
     NotifyDialer(NS_LITERAL_STRING("BLDN"));
 
-    MessageLoop::current()->PostDelayedTask(FROM_HERE,
-                                            new RespondToBLDNTask(),
+    MessageLoop::current()->PostDelayedTask(MakeAndAddRef<RespondToBLDNTask>(),
                                             sWaitingForDialingInterval);
   } else if (message[0] == '>') {
     mDialingRequestProcessed = false;
 
     nsAutoCString newMsg("ATD");
     newMsg += StringHead(message, message.Length() - 1);
     NotifyDialer(NS_ConvertUTF8toUTF16(newMsg));
 
-    MessageLoop::current()->PostDelayedTask(FROM_HERE,
-                                            new RespondToBLDNTask(),
+    MessageLoop::current()->PostDelayedTask(MakeAndAddRef<RespondToBLDNTask>(),
                                             sWaitingForDialingInterval);
   } else {
     SendResponse(HFP_AT_RESPONSE_OK);
 
     nsAutoCString newMsg("ATD");
     newMsg += StringHead(message, message.Length() - 1);
     NotifyDialer(NS_ConvertUTF8toUTF16(newMsg));
   }
@@ -1761,15 +1761,14 @@ BluetoothHfpManager::KeyPressedNotificat
        */
       NotifyDialer(NS_LITERAL_STRING("CHUP"));
     }
   } else {
     // BLDN
 
     NotifyDialer(NS_LITERAL_STRING("BLDN"));
 
-    MessageLoop::current()->PostDelayedTask(FROM_HERE,
-                                            new RespondToBLDNTask(),
+    MessageLoop::current()->PostDelayedTask(MakeAndAddRef<RespondToBLDNTask>(),
                                             sWaitingForDialingInterval);
   }
 }
 
 NS_IMPL_ISUPPORTS(BluetoothHfpManager, nsIObserver)
--- a/dom/bluetooth/bluez/BluetoothDBusService.cpp
+++ b/dom/bluetooth/bluez/BluetoothDBusService.cpp
@@ -379,19 +379,19 @@ static StaticAutoPtr<Monitor> sStopBluet
 // Protects against bug 969447.
 static StaticAutoPtr<Monitor> sGetPropertyMonitor;
 
 typedef void (*UnpackFunc)(DBusMessage*, DBusError*,
                            BluetoothValue&, nsAString&);
 typedef bool (*FilterFunc)(const BluetoothValue&);
 
 static void
-DispatchToDBusThread(Task* task)
+DispatchToDBusThread(already_AddRefed<Runnable> task)
 {
-  XRE_GetIOMessageLoop()->PostTask(FROM_HERE, task);
+  XRE_GetIOMessageLoop()->PostTask(Move(task));
 }
 
 static nsresult
 DispatchToBtThread(nsIRunnable* aRunnable)
 {
   /* Due to the fact that the startup and shutdown of the Bluetooth
    * system can take an indefinite amount of time, a separate thread
    * is used for running blocking calls. The thread is not intended
@@ -623,43 +623,44 @@ public:
     hid->HandleInputPropertyChanged(mSignal);
     return NS_OK;
   }
 
 private:
   BluetoothSignal mSignal;
 };
 
-class TryFiringAdapterAddedTask : public Task
+class TryFiringAdapterAddedTask : public Runnable
 {
 public:
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(NS_IsMainThread());
+    return NS_OK;
   }
 };
 
 class TryFiringAdapterAddedRunnable : public Runnable
 {
 public:
   TryFiringAdapterAddedRunnable(bool aDelay)
     : mDelay(aDelay)
   { }
 
   nsresult Run()
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     if (mDelay) {
       MessageLoop::current()->
-        PostDelayedTask(FROM_HERE, new TryFiringAdapterAddedTask(),
+        PostDelayedTask(MakeAndAddRef<TryFiringAdapterAddedTask>(),
                         sWaitingForAdapterNameInterval);
     } else {
       MessageLoop::current()->
-        PostTask(FROM_HERE, new TryFiringAdapterAddedTask());
+        PostTask(MakeAndAddRef<TryFiringAdapterAddedTask>());
     }
 
     return NS_OK;
   }
 
 private:
   bool mDelay;
 };
@@ -1251,44 +1252,44 @@ AppendDeviceName(BluetoothSignal& aSigna
     BLUEZ_DBUS_BASE_IFC, NS_ConvertUTF16toUTF8(devicePath).get(),
     DBUS_DEVICE_IFACE, "GetProperties", DBUS_TYPE_INVALID);
 
   NS_ENSURE_TRUE_VOID(success);
 
   Unused << handler.forget(); // picked up by callback handler
 }
 
-class SetPairingConfirmationTask : public Task
+class SetPairingConfirmationTask : public Runnable
 {
 public:
   SetPairingConfirmationTask(const BluetoothAddress& aDeviceAddress,
                              bool aConfirm,
                              BluetoothReplyRunnable* aRunnable)
     : mDeviceAddress(aDeviceAddress)
     , mConfirm(aConfirm)
     , mRunnable(aRunnable)
   {
     MOZ_ASSERT(!mDeviceAddress.IsCleared());
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
     MOZ_ASSERT(sDBusConnection);
 
     nsAutoString errorStr;
     BluetoothValue v = true;
     DBusMessage *msg = nullptr;
 
     if (!sPairingReqTable->Get(mDeviceAddress, &msg) && mRunnable) {
       BT_WARNING("%s: Couldn't get original request message.", __FUNCTION__);
       errorStr.AssignLiteral("Couldn't get original request message.");
       DispatchBluetoothReply(mRunnable, v, errorStr);
 
-      return;
+      return NS_OK;
     }
 
     DBusMessage *reply;
 
     if (mConfirm) {
       reply = dbus_message_new_method_return(msg);
     } else {
       reply = dbus_message_new_error(msg, "org.bluez.Error.Rejected",
@@ -1297,30 +1298,31 @@ public:
 
     if (!reply) {
       BT_WARNING("%s: Memory can't be allocated for the message.", __FUNCTION__);
       dbus_message_unref(msg);
       errorStr.AssignLiteral("Memory can't be allocated for the message.");
       if (mRunnable) {
         DispatchBluetoothReply(mRunnable, v, errorStr);
       }
-      return;
+      return NS_OK;
     }
 
     bool result = sDBusConnection->Send(reply);
     if (!result) {
       errorStr.AssignLiteral("Can't send message!");
     }
 
     dbus_message_unref(msg);
     dbus_message_unref(reply);
     sPairingReqTable->Remove(mDeviceAddress);
     if (mRunnable) {
       DispatchBluetoothReply(mRunnable, v, errorStr);
     }
+    return NS_OK;
   }
 
 private:
   BluetoothAddress mDeviceAddress;
   bool mConfirm;
   RefPtr<BluetoothReplyRunnable> mRunnable;
 };
 
@@ -1504,18 +1506,18 @@ AgentEventFilter(DBusConnection *conn, D
       errorStr.AssignLiteral("Invalid arguments: RequestPairingConsent()");
       goto handle_error;
     }
 
     BluetoothAddress address;
     GetAddressFromObjectPath(NS_ConvertUTF8toUTF16(objectPath), address);
 
     sPairingReqTable->Put(address, msg);
-    Task* task = new SetPairingConfirmationTask(address, true, nullptr);
-    DispatchToDBusThread(task);
+    DispatchToDBusThread(
+      MakeAndAddRef<SetPairingConfirmationTask>(address, true, nullptr));
     // Increase dbus message reference counts, it will be decreased in
     // SetPairingConfirmationTask
     dbus_message_ref(msg);
     // Do not send a notification to upper layer
     return DBUS_HANDLER_RESULT_HANDLED;
   } else {
 #ifdef DEBUG
     BT_WARNING("agent handler %s: Unhandled event. Ignore.", __FUNCTION__);
@@ -1684,23 +1686,23 @@ private:
     NS_ENSURE_TRUE(success, false);
 
     Unused << handler.forget(); // picked up by callback handler
 
     return true;
   }
 };
 
-class AddReservedServiceRecordsTask : public Task
+class AddReservedServiceRecordsTask : public Runnable
 {
 public:
   AddReservedServiceRecordsTask()
   { }
 
-  void Run()
+  NS_IMETHOD Run() override
   {
     static const dbus_uint32_t sServices[] = {
       BluetoothServiceClass::HANDSFREE_AG,
       BluetoothServiceClass::HEADSET_AG,
       BluetoothServiceClass::OBJECT_PUSH
     };
 
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
@@ -1715,34 +1717,35 @@ public:
     bool success = sDBusConnection->SendWithReply(
       DBusReplyHandler::Callback, handler.get(), -1,
       BLUEZ_DBUS_BASE_IFC,
       NS_ConvertUTF16toUTF8(sAdapterPath).get(),
       DBUS_ADAPTER_IFACE, "AddReservedServiceRecords",
       DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32,
       &services, ArrayLength(sServices), DBUS_TYPE_INVALID);
 
-    NS_ENSURE_TRUE_VOID(success);
+    NS_ENSURE_TRUE(success, NS_OK);
 
     Unused << handler.forget(); /* picked up by callback handler */
+
+    return NS_OK;
   }
 };
 
 class PrepareAdapterRunnable : public Runnable
 {
 public:
   PrepareAdapterRunnable()
   { }
 
   NS_IMETHOD Run()
   {
     MOZ_ASSERT(NS_IsMainThread());
 
-    Task* task = new AddReservedServiceRecordsTask();
-    DispatchToDBusThread(task);
+    DispatchToDBusThread(MakeAndAddRef<AddReservedServiceRecordsTask>());
 
     return NS_OK;
   }
 };
 
 class RequestPlayStatusTask : public Runnable
 {
 public:
@@ -2066,62 +2069,62 @@ BluetoothDBusService::IsReady()
 {
   if (!IsEnabled() || !sDBusConnection || IsToggling()) {
     BT_WARNING("Bluetooth service is not ready yet!");
     return false;
   }
   return true;
 }
 
-class StartDBusConnectionTask : public Task
+class StartDBusConnectionTask : public Runnable
 {
 public:
   StartDBusConnectionTask(RawDBusConnection* aConnection)
   : mConnection(aConnection)
   {
     MOZ_ASSERT(mConnection);
   }
 
-  void Run()
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
 
     if (sDBusConnection) {
       BT_WARNING("DBus connection has already been established.");
       RefPtr<Runnable> runnable = new BluetoothService::ToggleBtAck(true);
       if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
         BT_WARNING("Failed to dispatch to main thread!");
       }
-      return;
+      return NS_OK;
     }
 
     // Add a filter for all incoming messages_base
     if (!dbus_connection_add_filter(mConnection->GetConnection(),
                                     EventFilter, nullptr, nullptr)) {
       BT_WARNING("Cannot create DBus Event Filter for DBus Thread!");
       RefPtr<Runnable> runnable = new BluetoothService::ToggleBtAck(false);
       if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
         BT_WARNING("Failed to dispatch to main thread!");
       }
-      return;
+      return NS_OK;
     }
 
     mConnection->Watch();
 
     if (!sPairingReqTable) {
       sPairingReqTable = new nsDataHashtable<BluetoothAddressHashKey, DBusMessage* >;
     }
 
     sDBusConnection = mConnection.release();
 
     RefPtr<Runnable> runnable =
       new BluetoothService::ToggleBtAck(true);
-    if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
+    if (NS_FAILED(NS_DispatchToMainThread(runnable.forget()))) {
       BT_WARNING("Failed to dispatch to main thread!");
-      return;
+      return NS_OK;
     }
 
     /* Normally we'll receive the signal 'AdapterAdded' with the adapter object
      * path from the DBus daemon during start up. So, there's no need to query
      * the object path of default adapter here. However, if we restart from a
      * crash, the default adapter might already be available, so we ask the
      * daemon explicitly here.
      */
@@ -2131,16 +2134,17 @@ public:
                                                     BLUEZ_DBUS_BASE_IFC, "/",
                                                     DBUS_MANAGER_IFACE,
                                                     "DefaultAdapter",
                                                     DBUS_TYPE_INVALID);
       if (!success) {
         BT_WARNING("Failed to query default adapter!");
       }
     }
+    return NS_OK;
   }
 
 private:
   UniquePtr<RawDBusConnection> mConnection;
 };
 
 class StartBluetoothRunnable final : public Runnable
 {
@@ -2185,18 +2189,17 @@ public:
       dbus_bus_add_match(connection->GetConnection(),
                          sBluetoothDBusSignals[i],
                          &err);
       if (dbus_error_is_set(&err)) {
         LOG_AND_FREE_DBUS_ERROR(&err);
       }
     }
 
-    Task* task = new StartDBusConnectionTask(connection);
-    DispatchToDBusThread(task);
+    DispatchToDBusThread(MakeAndAddRef<StartDBusConnectionTask>(connection));
 
     return NS_OK;
   }
 };
 
 nsresult
 BluetoothDBusService::StartInternal(BluetoothReplyRunnable* aRunnable)
 {
@@ -2235,33 +2238,33 @@ public:
     nsresult rv = NS_DispatchToMainThread(runnable);
     if (NS_FAILED(rv)) {
       BT_WARNING("Failed to dispatch to main thread!");
     }
     return rv;
   }
 };
 
-class DeleteDBusConnectionTask final : public Task
+class DeleteDBusConnectionTask final : public Runnable
 {
 public:
   DeleteDBusConnectionTask()
   { }
 
-  void Run()
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
 
     if (!sDBusConnection) {
       BT_WARNING("DBus connection has not been established.");
       RefPtr<Runnable> runnable = new BluetoothService::ToggleBtAck(false);
       if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
         BT_WARNING("Failed to dispatch to main thread!");
       }
-      return;
+      return NS_OK;
     }
 
     for (uint32_t i = 0; i < ArrayLength(sBluetoothDBusSignals); ++i) {
       dbus_bus_remove_match(sDBusConnection->GetConnection(),
                             sBluetoothDBusSignals[i], NULL);
     }
 
     dbus_connection_remove_filter(sDBusConnection->GetConnection(),
@@ -2294,33 +2297,34 @@ public:
 
     // We can only dispatch to the BT thread if we're on the main
     // thread. Thus we dispatch our runnable to the main thread
     // from where it will forward itself to the BT thread.
     RefPtr<Runnable> runnable = new DisableBluetoothRunnable();
     if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
       BT_WARNING("Failed to dispatch to BT thread!");
     }
+    return NS_OK;
   }
 };
 
 class StopBluetoothRunnable final : public Runnable
 {
 public:
   NS_IMETHOD Run()
   {
     MOZ_ASSERT(!NS_IsMainThread()); // BT thread
 
     // This could block. It should never be run on the main thread.
     MonitorAutoLock lock(*sStopBluetoothMonitor);
     if (sConnectedDeviceCount > 0) {
       lock.Wait(PR_SecondsToInterval(TIMEOUT_FORCE_TO_DISABLE_BT));
     }
 
-    DispatchToDBusThread(new DeleteDBusConnectionTask());
+    DispatchToDBusThread(MakeAndAddRef<DeleteDBusConnectionTask>());
 
     return NS_OK;
   }
 };
 
 nsresult
 BluetoothDBusService::StopInternal(BluetoothReplyRunnable* aRunnable)
 {
@@ -2438,41 +2442,43 @@ protected:
     return true;
   }
 
 private:
   RefPtr<BluetoothReplyRunnable> mRunnable;
   nsString mAdapterPath;
 };
 
-class DefaultAdapterTask : public Task
+class DefaultAdapterTask : public Runnable
 {
 public:
   DefaultAdapterTask(BluetoothReplyRunnable* aRunnable)
     : mRunnable(aRunnable)
   {
     MOZ_ASSERT(mRunnable);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
     MOZ_ASSERT(sDBusConnection);
 
     RefPtr<DefaultAdapterPathReplyHandler> handler =
       new DefaultAdapterPathReplyHandler(mRunnable);
 
     bool success = sDBusConnection->SendWithReply(
       DefaultAdapterPathReplyHandler::Callback,
       handler.get(), 1000, BLUEZ_DBUS_BASE_IFC,
       "/", DBUS_MANAGER_IFACE, "DefaultAdapter",
       DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE_VOID(success);
+    NS_ENSURE_TRUE(success, NS_OK);
 
     Unused << handler.forget(); // picked up by callback handler
+
+    return NS_OK;
   }
 
 private:
   RefPtr<BluetoothReplyRunnable> mRunnable;
 };
 
 nsresult
 BluetoothDBusService::GetAdaptersInternal(BluetoothReplyRunnable* aRunnable)
@@ -2484,18 +2490,17 @@ BluetoothDBusService::GetAdaptersInterna
    */
 
   if (!IsReady()) {
     NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!");
     DispatchBluetoothReply(aRunnable, BluetoothValue(), errorStr);
     return NS_OK;
   }
 
-  Task* task = new DefaultAdapterTask(aRunnable);
-  DispatchToDBusThread(task);
+  DispatchToDBusThread(MakeAndAddRef<DefaultAdapterTask>(aRunnable));
 
   return NS_OK;
 }
 
 static void
 OnSendDiscoveryMessageReply(DBusMessage *aReply, void *aData)
 {
   MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
@@ -2508,44 +2513,46 @@ OnSendDiscoveryMessageReply(DBusMessage 
 
   RefPtr<BluetoothReplyRunnable> runnable =
     dont_AddRef<BluetoothReplyRunnable>(
       static_cast<BluetoothReplyRunnable*>(aData));
 
   DispatchBluetoothReply(runnable.get(), BluetoothValue(true), errorStr);
 }
 
-class SendDiscoveryMessageTask : public Task
+class SendDiscoveryMessageTask : public Runnable
 {
 public:
   SendDiscoveryMessageTask(const char* aMessageName,
                            BluetoothReplyRunnable* aRunnable)
     : mMessageName(aMessageName)
     , mRunnable(aRunnable)
   {
     MOZ_ASSERT(!mMessageName.IsEmpty());
     MOZ_ASSERT(mRunnable);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
     MOZ_ASSERT(sDBusConnection);
     MOZ_ASSERT(!sAdapterPath.IsEmpty());
 
     bool success = sDBusConnection->SendWithReply(
       OnSendDiscoveryMessageReply,
       static_cast<void*>(mRunnable.get()), -1,
       BLUEZ_DBUS_BASE_IFC,
       NS_ConvertUTF16toUTF8(sAdapterPath).get(),
       DBUS_ADAPTER_IFACE, mMessageName.get(),
       DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE_VOID(success);
+    NS_ENSURE_TRUE(success, NS_OK);
 
     Unused << mRunnable.forget(); // picked up by callback handler
+
+    return NS_OK;
   }
 
 private:
   const nsCString mMessageName;
   RefPtr<BluetoothReplyRunnable> mRunnable;
 };
 
 nsresult
@@ -2557,18 +2564,18 @@ BluetoothDBusService::SendDiscoveryMessa
 
   if (!IsReady()) {
     NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!");
     DispatchBluetoothReply(aRunnable, BluetoothValue(), errorStr);
 
     return NS_OK;
   }
 
-  Task* task = new SendDiscoveryMessageTask(aMessageName, aRunnable);
-  DispatchToDBusThread(task);
+  DispatchToDBusThread(
+    MakeAndAddRef<SendDiscoveryMessageTask>(aMessageName, aRunnable));
 
   return NS_OK;
 }
 
 nsresult
 BluetoothDBusService::SendInputMessage(const nsAString& aDeviceAddress,
                                        const nsAString& aMessage)
 {
@@ -2582,17 +2589,17 @@ BluetoothDBusService::SendInputMessage(c
     return NS_ERROR_FAILURE;
   }
 
   MOZ_ASSERT(!sAdapterPath.IsEmpty());
   nsString objectPath = GetObjectPathFromAddress(sAdapterPath, aDeviceAddress);
   return SendAsyncDBusMessage(objectPath, DBUS_INPUT_IFACE, aMessage, callback);
 }
 
-class SendAsyncDBusMessageTask : public Task
+class SendAsyncDBusMessageTask : public Runnable
 {
 public:
   SendAsyncDBusMessageTask(DBusReplyCallback aCallback,
                            BluetoothServiceClass aServiceClass,
                            const nsACString& aObjectPath,
                            const char* aInterface,
                            const nsACString& aMessage)
     : mCallback(aCallback)
@@ -2601,28 +2608,30 @@ public:
     , mInterface(aInterface)
     , mMessage(aMessage)
   {
     MOZ_ASSERT(!mObjectPath.IsEmpty());
     MOZ_ASSERT(!mInterface.IsEmpty());
     MOZ_ASSERT(!mMessage.IsEmpty());
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
     MOZ_ASSERT(sDBusConnection);
 
     static_assert(sizeof(BluetoothServiceClass) <= sizeof(intptr_t),
                   "BluetoothServiceClass cannot be passed via intptr_t");
     bool success = sDBusConnection->SendWithReply(
       mCallback, NS_INT32_TO_PTR(mServiceClass), -1,
       BLUEZ_DBUS_BASE_IFC, mObjectPath.get(), mInterface.get(),
       mMessage.get(), DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE_VOID(success);
+    NS_ENSURE_TRUE(success, NS_OK);
+
+    return NS_OK;
   }
 
 private:
   DBusReplyCallback mCallback;
   BluetoothServiceClass mServiceClass;
   const nsCString mObjectPath;
   const nsCString mInterface;
   const nsCString mMessage;
@@ -2645,22 +2654,22 @@ BluetoothDBusService::SendAsyncDBusMessa
     serviceClass = BluetoothServiceClass::A2DP;
   } else if (!strcmp(aInterface, DBUS_INPUT_IFACE)) {
     serviceClass = BluetoothServiceClass::HID;
   } else {
     MOZ_ASSERT(false);
     return NS_ERROR_FAILURE;
   }
 
-  Task* task = new SendAsyncDBusMessageTask(aCallback,
+  DispatchToDBusThread(
+    MakeAndAddRef<SendAsyncDBusMessageTask>(aCallback,
                                             serviceClass,
                                             NS_ConvertUTF16toUTF8(aObjectPath),
                                             aInterface,
-                                            NS_ConvertUTF16toUTF8(aMessage));
-  DispatchToDBusThread(task);
+                                            NS_ConvertUTF16toUTF8(aMessage)));
 
   return NS_OK;
 }
 
 nsresult
 BluetoothDBusService::SendSinkMessage(const nsAString& aDeviceAddress,
                                       const nsAString& aMessage)
 {
@@ -2819,34 +2828,36 @@ private:
   nsString mObjectPath;
   const nsTArray<BluetoothAddress> mDeviceAddresses;
   nsTArray<nsString>::size_type mProcessedDeviceAddresses;
   const FilterFunc mFilterFunc;
   RefPtr<BluetoothReplyRunnable> mRunnable;
   BluetoothValue mValues;
 };
 
-class ProcessRemainingDeviceAddressesTask : public Task
+class ProcessRemainingDeviceAddressesTask : public Runnable
 {
 public:
   ProcessRemainingDeviceAddressesTask(
     BluetoothArrayOfDevicePropertiesReplyHandler* aHandler,
     BluetoothReplyRunnable* aRunnable)
     : mHandler(aHandler)
     , mRunnable(aRunnable)
   {
     MOZ_ASSERT(mHandler);
     MOZ_ASSERT(mRunnable);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
 
     mHandler->ProcessRemainingDeviceAddresses();
+
+    return NS_OK;
   }
 
 private:
   RefPtr<BluetoothArrayOfDevicePropertiesReplyHandler> mHandler;
   RefPtr<BluetoothReplyRunnable> mRunnable;
 };
 
 nsresult
@@ -2878,18 +2889,18 @@ BluetoothDBusService::GetConnectedDevice
     profile->GetAddress(address);
     deviceAddresses.AppendElement(address);
   }
 
   BluetoothArrayOfDevicePropertiesReplyHandler* handler =
     new BluetoothArrayOfDevicePropertiesReplyHandler(deviceAddresses,
                                                      GetConnectedDevicesFilter,
                                                      aRunnable);
-  Task* task = new ProcessRemainingDeviceAddressesTask(handler, aRunnable);
-  DispatchToDBusThread(task);
+  DispatchToDBusThread(
+    MakeAndAddRef<ProcessRemainingDeviceAddressesTask>(handler, aRunnable));
 
   return NS_OK;
 }
 
 nsresult
 BluetoothDBusService::GetPairedDevicePropertiesInternal(
   const nsTArray<BluetoothAddress>& aDeviceAddresses,
   BluetoothReplyRunnable* aRunnable)
@@ -2901,30 +2912,30 @@ BluetoothDBusService::GetPairedDevicePro
     DispatchBluetoothReply(aRunnable, BluetoothValue(), errorStr);
     return NS_OK;
   }
 
   BluetoothArrayOfDevicePropertiesReplyHandler* handler =
     new BluetoothArrayOfDevicePropertiesReplyHandler(aDeviceAddresses,
                                                      GetPairedDevicesFilter,
                                                      aRunnable);
-  Task* task = new ProcessRemainingDeviceAddressesTask(handler, aRunnable);
-  DispatchToDBusThread(task);
+  DispatchToDBusThread(
+    MakeAndAddRef<ProcessRemainingDeviceAddressesTask>(handler, aRunnable));
 
   return NS_OK;
 }
 
 nsresult
 BluetoothDBusService::FetchUuidsInternal(const BluetoothAddress& aDeviceAddress,
                                          BluetoothReplyRunnable* aRunnable)
 {
   return NS_OK;
 }
 
-class SetPropertyTask : public Task
+class SetPropertyTask : public Runnable
 {
 public:
   SetPropertyTask(BluetoothObjectType aType,
                   const nsACString& aName,
                   BluetoothReplyRunnable* aRunnable)
     : mType(aType)
     , mName(aName)
     , mRunnable(aRunnable)
@@ -2989,19 +3000,21 @@ public:
   SetUInt32PropertyTask(BluetoothObjectType aType,
                         const nsACString& aName,
                         uint32_t aValue,
                         BluetoothReplyRunnable* aRunnable)
     : SetPropertyTask(aType, aName, aRunnable)
     , mValue(aValue)
   { }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     Send(DBUS_TYPE_UINT32, &mValue);
+
+    return NS_OK;
   }
 
 private:
   dbus_uint32_t mValue;
 };
 
 class SetStringPropertyTask : public SetPropertyTask
 {
@@ -3009,20 +3022,22 @@ public:
   SetStringPropertyTask(BluetoothObjectType aType,
                         const nsACString& aName,
                         const nsACString& aValue,
                         BluetoothReplyRunnable* aRunnable)
     : SetPropertyTask(aType, aName, aRunnable)
     , mValue(aValue)
   { }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     const char* value = mValue.get();
     Send(DBUS_TYPE_STRING, &value);
+
+    return NS_OK;
   }
 
 private:
   const nsCString mValue;
 };
 
 class SetBooleanPropertyTask : public SetPropertyTask
 {
@@ -3031,19 +3046,21 @@ public:
                          const nsACString& aName,
                          dbus_bool_t aValue,
                          BluetoothReplyRunnable* aRunnable)
     : SetPropertyTask(aType, aName, aRunnable)
     , mValue(aValue)
   {
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     Send(DBUS_TYPE_BOOLEAN, &mValue);
+
+    return NS_OK;
   }
 
 private:
   dbus_bool_t mValue;
 };
 
 nsresult
 BluetoothDBusService::SetProperty(BluetoothObjectType aType,
@@ -3053,54 +3070,54 @@ BluetoothDBusService::SetProperty(Blueto
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!IsReady()) {
     NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!");
     DispatchBluetoothReply(aRunnable, BluetoothValue(), errorStr);
     return NS_OK;
   }
 
-  Task* task;
+  RefPtr<Runnable> task;
 
   if (aValue.value().type() == BluetoothValue::Tuint32_t) {
-    task = new SetUInt32PropertyTask(aType,
+    task = MakeAndAddRef<SetUInt32PropertyTask>(aType,
       NS_ConvertUTF16toUTF8(aValue.name()),
       aValue.value().get_uint32_t(), aRunnable);
   } else if (aValue.value().type() == BluetoothValue::TnsString) {
-    task = new SetStringPropertyTask(aType,
+    task = MakeAndAddRef<SetStringPropertyTask>(aType,
       NS_ConvertUTF16toUTF8(aValue.name()),
       NS_ConvertUTF16toUTF8(aValue.value().get_nsString()), aRunnable);
   } else if (aValue.value().type() == BluetoothValue::Tbool) {
-    task = new SetBooleanPropertyTask(aType,
+    task = MakeAndAddRef<SetBooleanPropertyTask>(aType,
       NS_ConvertUTF16toUTF8(aValue.name()),
       aValue.value().get_bool(), aRunnable);
   } else {
     BT_WARNING("Property type not handled!");
     return NS_ERROR_FAILURE;
   }
-  DispatchToDBusThread(task);
+  DispatchToDBusThread(task.forget());
 
   return NS_OK;
 }
 
-class CreatePairedDeviceInternalTask : public Task
+class CreatePairedDeviceInternalTask : public Runnable
 {
 public:
   CreatePairedDeviceInternalTask(const BluetoothAddress& aDeviceAddress,
                                  int aTimeout,
                                  BluetoothReplyRunnable* aRunnable)
     : mDeviceAddress(aDeviceAddress)
     , mTimeout(aTimeout)
     , mRunnable(aRunnable)
   {
     MOZ_ASSERT(!mDeviceAddress.IsCleared());
     MOZ_ASSERT(mRunnable);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
     MOZ_ASSERT(sDBusConnection);
     MOZ_ASSERT(!sAdapterPath.IsEmpty());
 
     nsString deviceAddressStr;
     AddressToString(mDeviceAddress, deviceAddressStr);
     auto utf8DeviceAddressStr = NS_ConvertUTF16toUTF8(deviceAddressStr);
@@ -3116,68 +3133,70 @@ public:
       BLUEZ_DBUS_BASE_IFC,
       NS_ConvertUTF16toUTF8(sAdapterPath).get(),
       DBUS_ADAPTER_IFACE,
       "CreatePairedDevice",
       DBUS_TYPE_STRING, &deviceAddress,
       DBUS_TYPE_OBJECT_PATH, &deviceAgentPath,
       DBUS_TYPE_STRING, &capabilities,
       DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE_VOID(success);
+    NS_ENSURE_TRUE(success, NS_OK);
 
     Unused << mRunnable.forget(); // picked up by callback handler
 
     /**
      * FIXME: Bug 820274
      *
      * If the user turns off Bluetooth in the middle of pairing process,
      * the callback function GetObjectPathCallback may still be called
      * while enabling next time by dbus daemon. To prevent this from
      * happening, added a flag to distinguish if Bluetooth has been
      * turned off. Nevertheless, we need a check if there is a better
      * solution.
      *
      * Please see Bug 818696 for more information.
      */
     sIsPairing++;
+
+    return NS_OK;
   }
 
 private:
   BluetoothAddress mDeviceAddress;
   int mTimeout;
   RefPtr<BluetoothReplyRunnable> mRunnable;
 };
 
 nsresult
 BluetoothDBusService::CreatePairedDeviceInternal(
   const BluetoothAddress& aDeviceAddress,
   int aTimeout,
   BluetoothReplyRunnable* aRunnable)
 {
-  Task* task = new CreatePairedDeviceInternalTask(aDeviceAddress,
+  DispatchToDBusThread(
+    MakeAndAddRef<CreatePairedDeviceInternalTask>(aDeviceAddress,
                                                   aTimeout,
-                                                  aRunnable);
-  DispatchToDBusThread(task);
+                                                  aRunnable));
 
   return NS_OK;
 }
 
-class RemoveDeviceTask : public Task
+class RemoveDeviceTask : public Runnable
 {
 public:
   RemoveDeviceTask(const BluetoothAddress& aDeviceAddress,
                    BluetoothReplyRunnable* aRunnable)
     : mDeviceAddress(aDeviceAddress)
     , mRunnable(aRunnable)
   {
     MOZ_ASSERT(!mDeviceAddress.IsCleared());
     MOZ_ASSERT(mRunnable);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
     MOZ_ASSERT(sDBusConnection);
     MOZ_ASSERT(!sAdapterPath.IsEmpty());
 
     nsCString deviceObjectPath =
       NS_ConvertUTF16toUTF8(GetObjectPathFromAddress(sAdapterPath,
                                                      mDeviceAddress));
@@ -3185,19 +3204,21 @@ public:
 
     bool success = sDBusConnection->SendWithReply(
       OnRemoveDeviceReply, static_cast<void*>(mRunnable.get()), -1,
       BLUEZ_DBUS_BASE_IFC,
       NS_ConvertUTF16toUTF8(sAdapterPath).get(),
       DBUS_ADAPTER_IFACE, "RemoveDevice",
       DBUS_TYPE_OBJECT_PATH, &cstrDeviceObjectPath,
       DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE_VOID(success);
+    NS_ENSURE_TRUE(success, NS_OK);
 
     Unused << mRunnable.forget(); // picked up by callback handler
+
+    return NS_OK;
   }
 
 protected:
   static void OnRemoveDeviceReply(DBusMessage* aReply, void* aData)
   {
     nsAutoString errorStr;
 
     if (!aReply) {
@@ -3224,68 +3245,68 @@ BluetoothDBusService::RemoveDeviceIntern
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!IsReady()) {
     NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!");
     DispatchBluetoothReply(aRunnable, BluetoothValue(), errorStr);
     return NS_OK;
   }
 
-  Task* task = new RemoveDeviceTask(aDeviceAddress, aRunnable);
-  DispatchToDBusThread(task);
+  DispatchToDBusThread(
+    MakeAndAddRef<RemoveDeviceTask>(aDeviceAddress, aRunnable));
 
   return NS_OK;
 }
 
-class SetPinCodeTask : public Task
+class SetPinCodeTask : public Runnable
 {
 public:
   SetPinCodeTask(const BluetoothAddress& aDeviceAddress,
                  const BluetoothPinCode& aPinCode,
                  BluetoothReplyRunnable* aRunnable)
     : mDeviceAddress(aDeviceAddress)
     , mPinCode(aPinCode)
     , mRunnable(aRunnable)
   {
     MOZ_ASSERT(!mDeviceAddress.IsCleared());
     MOZ_ASSERT(mRunnable);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
 
     nsAutoString errorStr;
     BluetoothValue v = true;
     DBusMessage *msg;
     if (!sPairingReqTable->Get(mDeviceAddress, &msg)) {
       BT_WARNING("%s: Couldn't get original request message.", __FUNCTION__);
       errorStr.AssignLiteral("Couldn't get original request message.");
       DispatchBluetoothReply(mRunnable, v, errorStr);
-      return;
+      return NS_OK;
     }
 
     DBusMessage *reply = dbus_message_new_method_return(msg);
 
     if (!reply) {
       BT_WARNING("%s: Memory can't be allocated for the message.", __FUNCTION__);
       dbus_message_unref(msg);
       errorStr.AssignLiteral("Memory can't be allocated for the message.");
       DispatchBluetoothReply(mRunnable, v, errorStr);
-      return;
+      return NS_OK;
     }
 
     nsAutoString pinCodeStr;
     if (NS_FAILED(PinCodeToString(mPinCode, pinCodeStr))) {
       BT_WARNING("%s: Cannot convert pin code to string.", __FUNCTION__);
       dbus_message_unref(msg);
       dbus_message_unref(reply);
       errorStr.AssignLiteral("Cannot convert pin code to string.");
       DispatchBluetoothReply(mRunnable, v, errorStr);
-      return;
+      return NS_OK;
     }
 
     auto utf8PinCodeStr = NS_ConvertUTF16toUTF8(pinCodeStr);
 
     const char* pinCode = utf8PinCodeStr.get();
 
     if (!dbus_message_append_args(reply,
                                   DBUS_TYPE_STRING, &pinCode,
@@ -3297,16 +3318,18 @@ public:
       sDBusConnection->Send(reply);
     }
 
     dbus_message_unref(msg);
     dbus_message_unref(reply);
 
     sPairingReqTable->Remove(mDeviceAddress);
     DispatchBluetoothReply(mRunnable, v, errorStr);
+
+    return NS_OK;
   }
 
 private:
   const BluetoothAddress mDeviceAddress;
   const BluetoothPinCode mPinCode;
   RefPtr<BluetoothReplyRunnable> mRunnable;
 };
 
@@ -3326,56 +3349,56 @@ BluetoothDBusService::SspReplyInternal(
   // Legacy interface used by Bluedroid only.
 }
 
 void
 BluetoothDBusService::SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
                                          const BluetoothPinCode& aPinCode,
                                          BluetoothReplyRunnable* aRunnable)
 {
-  Task* task = new SetPinCodeTask(aDeviceAddress, aPinCode, aRunnable);
-  DispatchToDBusThread(task);
+  DispatchToDBusThread(
+    MakeAndAddRef<SetPinCodeTask>(aDeviceAddress, aPinCode, aRunnable));
 }
 
-class SetPasskeyTask : public Task
+class SetPasskeyTask : public Runnable
 {
 public:
   SetPasskeyTask(const BluetoothAddress& aDeviceAddress,
                  uint32_t aPasskey,
                  BluetoothReplyRunnable* aRunnable)
     : mDeviceAddress(aDeviceAddress)
     , mPasskey(aPasskey)
     , mRunnable(aRunnable)
   {
     MOZ_ASSERT(!mDeviceAddress.IsCleared());
     MOZ_ASSERT(mRunnable);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
 
     nsAutoString errorStr;
     BluetoothValue v = true;
     DBusMessage *msg;
     if (!sPairingReqTable->Get(mDeviceAddress, &msg)) {
       BT_WARNING("%s: Couldn't get original request message.", __FUNCTION__);
       errorStr.AssignLiteral("Couldn't get original request message.");
       DispatchBluetoothReply(mRunnable, v, errorStr);
-      return;
+      return NS_OK;
     }
 
     DBusMessage *reply = dbus_message_new_method_return(msg);
 
     if (!reply) {
       BT_WARNING("%s: Memory can't be allocated for the message.", __FUNCTION__);
       dbus_message_unref(msg);
       errorStr.AssignLiteral("Memory can't be allocated for the message.");
       DispatchBluetoothReply(mRunnable, v, errorStr);
-      return;
+      return NS_OK;
     }
 
     uint32_t passkey = mPasskey;
 
     if (!dbus_message_append_args(reply,
                                   DBUS_TYPE_UINT32, &passkey,
                                   DBUS_TYPE_INVALID)) {
       BT_WARNING("%s: Couldn't append arguments to dbus message.", __FUNCTION__);
@@ -3385,48 +3408,50 @@ public:
       sDBusConnection->Send(reply);
     }
 
     dbus_message_unref(msg);
     dbus_message_unref(reply);
 
     sPairingReqTable->Remove(mDeviceAddress);
     DispatchBluetoothReply(mRunnable, v, errorStr);
+
+    return NS_OK;
   }
 
 private:
   BluetoothAddress mDeviceAddress;
   uint32_t mPasskey;
   RefPtr<BluetoothReplyRunnable> mRunnable;
 };
 
 void
 BluetoothDBusService::SetPasskeyInternal(
   const BluetoothAddress& aDeviceAddress,
   uint32_t aPasskey,
   BluetoothReplyRunnable* aRunnable)
 {
-  Task* task = new SetPasskeyTask(aDeviceAddress,
+  DispatchToDBusThread(
+    MakeAndAddRef<SetPasskeyTask>(aDeviceAddress,
                                   aPasskey,
-                                  aRunnable);
-  DispatchToDBusThread(task);
+                                  aRunnable));
 }
 
 void
 BluetoothDBusService::SetPairingConfirmationInternal(
   const BluetoothAddress& aDeviceAddress,
   bool aConfirm,
   BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  Task* task = new SetPairingConfirmationTask(aDeviceAddress,
+  DispatchToDBusThread(
+    MakeAndAddRef<SetPairingConfirmationTask>(aDeviceAddress,
                                               aConfirm,
-                                              aRunnable);
-  DispatchToDBusThread(task);
+                                              aRunnable));
 }
 
 static void
 NextBluetoothProfileController()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // First, remove the task at the front which has been already done.
@@ -3611,31 +3636,31 @@ public:
   }
 
 private:
   BluetoothAddress mDeviceAddress;
   BluetoothUuid mServiceUUID;
   BluetoothProfileManagerBase* mBluetoothProfileManager;
 };
 
-class GetServiceChannelTask : public Task
+class GetServiceChannelTask : public Runnable
 {
 public:
   GetServiceChannelTask(const BluetoothAddress& aDeviceAddress,
                         const BluetoothUuid& aServiceUUID,
                         BluetoothProfileManagerBase* aBluetoothProfileManager)
     : mDeviceAddress(aDeviceAddress)
     , mServiceUUID(aServiceUUID)
     , mBluetoothProfileManager(aBluetoothProfileManager)
   {
     MOZ_ASSERT(!mDeviceAddress.IsCleared());
     MOZ_ASSERT(mBluetoothProfileManager);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     static const int sProtocolDescriptorList = 0x0004;
 
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
     MOZ_ASSERT(sDBusConnection);
     MOZ_ASSERT(!sAdapterPath.IsEmpty());
 
     const nsString objectPath =
@@ -3654,19 +3679,21 @@ public:
     bool success = sDBusConnection->SendWithReply(
       OnGetServiceChannelReplyHandler::Callback, handler, -1,
       BLUEZ_DBUS_BASE_IFC,
       NS_ConvertUTF16toUTF8(objectPath).get(),
       DBUS_DEVICE_IFACE, "GetServiceAttributeValue",
       DBUS_TYPE_STRING, &cstrServiceUUID,
       DBUS_TYPE_UINT16, &sProtocolDescriptorList,
       DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE_VOID(success);
+    NS_ENSURE_TRUE(success, NS_OK);
 
     Unused << handler.forget(); // picked up by callback handler
+
+    return NS_OK;
   }
 
 private:
   BluetoothAddress mDeviceAddress;
   BluetoothUuid mServiceUUID;
   BluetoothProfileManagerBase* mBluetoothProfileManager;
 };
 
@@ -3680,20 +3707,20 @@ BluetoothDBusService::GetServiceChannel(
   if (!IsReady()) {
     NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth service is not ready yet!");
     return NS_OK;
   }
 
 #ifdef MOZ_WIDGET_GONK
   // GetServiceAttributeValue only exists in android's bluez dbus binding
   // implementation
-  Task* task = new GetServiceChannelTask(aDeviceAddress,
+  DispatchToDBusThread(
+    MakeAndAddRef<GetServiceChannelTask>(aDeviceAddress,
                                          aServiceUUID,
-                                         aManager);
-  DispatchToDBusThread(task);
+                                         aManager));
 #else
   // FIXME/Bug 793977 qdot: Just set something for desktop, until we have a
   // parser for the GetServiceAttributes xml block
   //
   // Even though we are on the main thread already, we need to dispatch a
   // runnable here. OnGetServiceChannel needs mRunnable to be set, which
   // happens after GetServiceChannel returns.
   RefPtr<Runnable> r = new OnGetServiceChannelRunnable(aDeviceAddress,
@@ -3701,29 +3728,29 @@ BluetoothDBusService::GetServiceChannel(
                                                          1,
                                                          aManager);
   NS_DispatchToMainThread(r);
 #endif
 
   return NS_OK;
 }
 
-class UpdateSdpRecordsTask : public Task
+class UpdateSdpRecordsTask : public Runnable
 {
 public:
   UpdateSdpRecordsTask(const BluetoothAddress& aDeviceAddress,
                        BluetoothProfileManagerBase* aBluetoothProfileManager)
     : mDeviceAddress(aDeviceAddress)
     , mBluetoothProfileManager(aBluetoothProfileManager)
   {
     MOZ_ASSERT(!mDeviceAddress.IsCleared());
     MOZ_ASSERT(mBluetoothProfileManager);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
     MOZ_ASSERT(sDBusConnection);
     MOZ_ASSERT(!sAdapterPath.IsEmpty());
 
     const nsString objectPath =
       GetObjectPathFromAddress(sAdapterPath, mDeviceAddress);
 
@@ -3735,16 +3762,17 @@ public:
     sDBusConnection->SendWithReply(DiscoverServicesCallback,
                                    (void*)callbackRunnable, -1,
                                    BLUEZ_DBUS_BASE_IFC,
                                    NS_ConvertUTF16toUTF8(objectPath).get(),
                                    DBUS_DEVICE_IFACE,
                                    "DiscoverServices",
                                    DBUS_TYPE_STRING, &EmptyCString(),
                                    DBUS_TYPE_INVALID);
+    return NS_OK;
   }
 
 protected:
   static void DiscoverServicesCallback(DBusMessage* aMsg, void* aData)
   {
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
 
     RefPtr<OnUpdateSdpRecordsRunnable> r(
@@ -3758,18 +3786,18 @@ private:
 };
 
 bool
 BluetoothDBusService::UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
                                        BluetoothProfileManagerBase* aManager)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  Task* task = new UpdateSdpRecordsTask(aDeviceAddress, aManager);
-  DispatchToDBusThread(task);
+  DispatchToDBusThread(
+    MakeAndAddRef<UpdateSdpRecordsTask>(aDeviceAddress, aManager));
 
   return true;
 }
 
 void
 BluetoothDBusService::SendFile(const BluetoothAddress& aDeviceAddress,
                                BlobParent* aBlobParent,
                                BlobChild* aBlobChild,
@@ -3887,17 +3915,17 @@ BluetoothDBusService::IsScoConnected(Blu
     NS_NAMED_LITERAL_STRING(replyError, "Fail to get BluetoothHfpManager");
     DispatchBluetoothReply(aRunnable, BluetoothValue(), replyError);
     return;
   }
 
   DispatchBluetoothReply(aRunnable, hfp->IsScoConnected(), EmptyString());
 }
 
-class SendMetadataTask : public Task
+class SendMetadataTask : public Runnable
 {
 public:
   SendMetadataTask(const BluetoothAddress& aDeviceAddress,
                    const nsACString& aTitle,
                    const nsACString& aArtist,
                    const nsACString& aAlbum,
                    int64_t aMediaNumber,
                    int64_t aTotalMediaCount,
@@ -3911,17 +3939,17 @@ public:
     , mTotalMediaCount(aTotalMediaCount)
     , mDuration(aDuration)
     , mRunnable(aRunnable)
   {
     MOZ_ASSERT(!mDeviceAddress.IsCleared());
     MOZ_ASSERT(mRunnable);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
     MOZ_ASSERT(sDBusConnection);
     MOZ_ASSERT(!sAdapterPath.IsEmpty());
 
     // We currently don't support genre field in music player.
     // In order to send media metadata through AVRCP, we set genre to an empty
     // string to match the BlueZ method "UpdateMetaData" with signature
@@ -3960,19 +3988,21 @@ public:
       DBUS_TYPE_STRING, &title,
       DBUS_TYPE_STRING, &artist,
       DBUS_TYPE_STRING, &album,
       DBUS_TYPE_STRING, &mediaNumber,
       DBUS_TYPE_STRING, &totalMediaCount,
       DBUS_TYPE_STRING, &duration,
       DBUS_TYPE_STRING, &genre,
       DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE_VOID(success);
+    NS_ENSURE_TRUE(success, NS_OK);
 
     Unused << mRunnable.forget(); // picked up by callback handler
+
+    return NS_OK;
   }
 
 private:
   const BluetoothAddress mDeviceAddress;
   const nsCString mTitle;
   const nsCString mArtist;
   const nsCString mAlbum;
   int64_t mMediaNumber;
@@ -4016,32 +4046,32 @@ BluetoothDBusService::SendMetaData(const
       !aTitle.Equals(prevTitle) ||
       !aAlbum.Equals(prevAlbum)) {
     UpdateNotification(ControlEventId::EVENT_TRACK_CHANGED, aMediaNumber);
   }
 
   BluetoothAddress deviceAddress;
   avrcp->GetAddress(deviceAddress);
 
-  Task* task = new SendMetadataTask(
-    deviceAddress,
-    NS_ConvertUTF16toUTF8(aTitle),
-    NS_ConvertUTF16toUTF8(aArtist),
-    NS_ConvertUTF16toUTF8(aAlbum),
-    aMediaNumber,
-    aTotalMediaCount,
-    aDuration,
-    aRunnable);
-  DispatchToDBusThread(task);
+  DispatchToDBusThread(
+    MakeAndAddRef<SendMetadataTask>(
+      deviceAddress,
+      NS_ConvertUTF16toUTF8(aTitle),
+      NS_ConvertUTF16toUTF8(aArtist),
+      NS_ConvertUTF16toUTF8(aAlbum),
+      aMediaNumber,
+      aTotalMediaCount,
+      aDuration,
+      aRunnable));
 
   avrcp->UpdateMetaData(aTitle, aArtist, aAlbum,
                         aMediaNumber, aTotalMediaCount, aDuration);
 }
 
-class SendPlayStatusTask : public Task
+class SendPlayStatusTask : public Runnable
 {
 public:
   SendPlayStatusTask(const BluetoothAddress& aDeviceAddress,
                      int64_t aDuration,
                      int64_t aPosition,
                      ControlPlayStatus aPlayStatus,
                      BluetoothReplyRunnable* aRunnable)
     : mDeviceAddress(aDeviceAddress)
@@ -4049,17 +4079,17 @@ public:
     , mPosition(aPosition)
     , mPlayStatus(aPlayStatus)
     , mRunnable(aRunnable)
   {
     MOZ_ASSERT(!mDeviceAddress.IsCleared());
     MOZ_ASSERT(mRunnable);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
     MOZ_ASSERT(sDBusConnection);
     MOZ_ASSERT(!sAdapterPath.IsEmpty());
 
     const nsCString objectPath = NS_ConvertUTF16toUTF8(
       GetObjectPathFromAddress(sAdapterPath, mDeviceAddress));
 
@@ -4069,19 +4099,21 @@ public:
       GetVoidCallback, static_cast<void*>(mRunnable.get()), -1,
       BLUEZ_DBUS_BASE_IFC,
       objectPath.get(),
       DBUS_CTL_IFACE, "UpdatePlayStatus",
       DBUS_TYPE_UINT32, &mDuration,
       DBUS_TYPE_UINT32, &mPosition,
       DBUS_TYPE_UINT32, &tempPlayStatus,
       DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE_VOID(success);
+    NS_ENSURE_TRUE(success, NS_OK);
 
     Unused << mRunnable.forget(); // picked up by callback handler
+
+    return NS_OK;
   }
 
 private:
   const BluetoothAddress mDeviceAddress;
   int64_t mDuration;
   int64_t mPosition;
   ControlPlayStatus mPlayStatus;
   RefPtr<BluetoothReplyRunnable> mRunnable;
@@ -4129,22 +4161,22 @@ BluetoothDBusService::SendPlayStatus(int
                        aPlayStatus);
   } else if (aPosition != avrcp->GetPosition()) {
     UpdateNotification(ControlEventId::EVENT_PLAYBACK_POS_CHANGED, aPosition);
   }
 
   BluetoothAddress deviceAddress;
   avrcp->GetAddress(deviceAddress);
 
-  Task* task = new SendPlayStatusTask(deviceAddress,
+  DispatchToDBusThread(
+    MakeAndAddRef<SendPlayStatusTask>(deviceAddress,
                                       aDuration,
                                       aPosition,
                                       aPlayStatus,
-                                      aRunnable);
-  DispatchToDBusThread(task);
+                                      aRunnable));
 
   avrcp->UpdatePlayStatus(aDuration, aPosition, aPlayStatus);
 }
 
 static void
 ControlCallback(DBusMessage* aMsg, void* aParam)
 {
   NS_ENSURE_TRUE_VOID(aMsg);
@@ -4152,32 +4184,32 @@ ControlCallback(DBusMessage* aMsg, void*
   BluetoothValue v;
   nsAutoString replyError;
   UnpackVoidMessage(aMsg, nullptr, v, replyError);
   if (!v.get_bool()) {
     BT_WARNING(NS_ConvertUTF16toUTF8(replyError).get());
   }
 }
 
-class UpdatePlayStatusTask : public Task
+class UpdatePlayStatusTask : public Runnable
 {
 public:
   UpdatePlayStatusTask(const BluetoothAddress& aDeviceAddress,
                        int32_t aDuration,
                        int32_t aPosition,
                        ControlPlayStatus aPlayStatus)
     : mDeviceAddress(aDeviceAddress)
     , mDuration(aDuration)
     , mPosition(aPosition)
     , mPlayStatus(aPlayStatus)
   {
     MOZ_ASSERT(!mDeviceAddress.IsCleared());
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
     MOZ_ASSERT(sDBusConnection);
     MOZ_ASSERT(!sAdapterPath.IsEmpty());
 
     const nsCString objectPath = NS_ConvertUTF16toUTF8(
       GetObjectPathFromAddress(sAdapterPath, mDeviceAddress));
 
@@ -4187,17 +4219,19 @@ public:
       ControlCallback, nullptr, -1,
       BLUEZ_DBUS_BASE_IFC,
       objectPath.get(),
       DBUS_CTL_IFACE, "UpdatePlayStatus",
       DBUS_TYPE_UINT32, &mDuration,
       DBUS_TYPE_UINT32, &mPosition,
       DBUS_TYPE_UINT32, &tempPlayStatus,
       DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE_VOID(success);
+    NS_ENSURE_TRUE(success, NS_OK);
+
+    return NS_OK;
   }
 
 private:
   const BluetoothAddress mDeviceAddress;
   int32_t mDuration;
   int32_t mPosition;
   ControlPlayStatus mPlayStatus;
 };
@@ -4213,37 +4247,37 @@ BluetoothDBusService::UpdatePlayStatus(u
   BluetoothAvrcpManager* avrcp = BluetoothAvrcpManager::Get();
   NS_ENSURE_TRUE_VOID(avrcp);
   MOZ_ASSERT(avrcp->IsConnected());
   MOZ_ASSERT(!sAdapterPath.IsEmpty());
 
   BluetoothAddress deviceAddress;
   avrcp->GetAddress(deviceAddress);
 
-  Task* task = new UpdatePlayStatusTask(deviceAddress,
+  DispatchToDBusThread(
+    MakeAndAddRef<UpdatePlayStatusTask>(deviceAddress,
                                         aDuration,
                                         aPosition,
-                                        aPlayStatus);
-  DispatchToDBusThread(task);
+                                        aPlayStatus));
 }
 
-class UpdateNotificationTask : public Task
+class UpdateNotificationTask : public Runnable
 {
 public:
   UpdateNotificationTask(const BluetoothAddress& aDeviceAddress,
                          BluetoothDBusService::ControlEventId aEventId,
                          uint64_t aData)
     : mDeviceAddress(aDeviceAddress)
     , mEventId(aEventId)
     , mData(aData)
   {
     MOZ_ASSERT(!mDeviceAddress.IsCleared());
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
     MOZ_ASSERT(sDBusConnection);
     MOZ_ASSERT(!sAdapterPath.IsEmpty());
 
     const nsCString objectPath = NS_ConvertUTF16toUTF8(
       GetObjectPathFromAddress(sAdapterPath, mDeviceAddress));
 
@@ -4252,17 +4286,19 @@ public:
     bool success = sDBusConnection->SendWithReply(
       ControlCallback, nullptr, -1,
       BLUEZ_DBUS_BASE_IFC,
       objectPath.get(),
       DBUS_CTL_IFACE, "UpdateNotification",
       DBUS_TYPE_UINT16, &eventId,
       DBUS_TYPE_UINT64, &mData,
       DBUS_TYPE_INVALID);
-    NS_ENSURE_TRUE_VOID(success);
+    NS_ENSURE_TRUE(success, NS_OK);
+
+    return NS_OK;
   }
 
 private:
   const BluetoothAddress mDeviceAddress;
   int16_t mEventId;
   int32_t mData;
 };
 
@@ -4276,18 +4312,18 @@ BluetoothDBusService::UpdateNotification
   BluetoothAvrcpManager* avrcp = BluetoothAvrcpManager::Get();
   NS_ENSURE_TRUE_VOID(avrcp);
   MOZ_ASSERT(avrcp->IsConnected());
   MOZ_ASSERT(!sAdapterPath.IsEmpty());
 
   BluetoothAddress deviceAddress;
   avrcp->GetAddress(deviceAddress);
 
-  Task* task = new UpdateNotificationTask(deviceAddress, aEventId, aData);
-  DispatchToDBusThread(task);
+  DispatchToDBusThread(
+    MakeAndAddRef<UpdateNotificationTask>(deviceAddress, aEventId, aData));
 }
 
 void
 BluetoothDBusService::StartLeScanInternal(
   const nsTArray<BluetoothUuid>& aServiceUuids,
   BluetoothReplyRunnable* aRunnable)
 {
 }
--- a/dom/bluetooth/bluez/BluetoothHfpManager.cpp
+++ b/dom/bluetooth/bluez/BluetoothHfpManager.cpp
@@ -237,85 +237,88 @@ BluetoothHfpManager::Notify(const hal::B
   int level = round(aBatteryInfo.level() * 5.0);
   if (level != sCINDItems[CINDType::BATTCHG].value) {
     sCINDItems[CINDType::BATTCHG].value = level;
     SendCommand(RESPONSE_CIEV, CINDType::BATTCHG);
   }
 }
 
 #ifdef MOZ_B2G_RIL
-class BluetoothHfpManager::RespondToBLDNTask : public Task
+class BluetoothHfpManager::RespondToBLDNTask : public Runnable
 {
 private:
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(sBluetoothHfpManager);
 
     if (!sBluetoothHfpManager->mDialingRequestProcessed) {
       sBluetoothHfpManager->mDialingRequestProcessed = true;
       sBluetoothHfpManager->SendLine("ERROR");
     }
+    return NS_OK;
   }
 };
 
-class BluetoothHfpManager::SendRingIndicatorTask : public Task
+class BluetoothHfpManager::SendRingIndicatorTask : public Runnable
 {
 public:
   SendRingIndicatorTask(const nsAString& aNumber, int aType)
     : mNumber(aNumber)
     , mType(aType)
   {
     MOZ_ASSERT(NS_IsMainThread());
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     // Stop sending RING indicator
     if (sStopSendingRingFlag) {
-      return;
+      return NS_OK;
     }
 
     if (!sBluetoothHfpManager) {
       BT_WARNING("BluetoothHfpManager no longer exists, cannot send ring!");
-      return;
+      return NS_OK;
     }
 
     nsAutoCString ringMsg("RING");
     sBluetoothHfpManager->SendLine(ringMsg.get());
 
     if (!mNumber.IsEmpty()) {
       nsAutoCString clipMsg("+CLIP: \"");
       clipMsg.Append(NS_ConvertUTF16toUTF8(mNumber).get());
       clipMsg.AppendLiteral("\",");
       clipMsg.AppendInt(mType);
       sBluetoothHfpManager->SendLine(clipMsg.get());
     }
 
-    MessageLoop::current()->
-      PostDelayedTask(FROM_HERE,
-                      new SendRingIndicatorTask(mNumber, mType),
-                      sRingInterval);
+    MessageLoop::current()->PostDelayedTask(
+      MakeAndAddRef<SendRingIndicatorTask>(mNumber, mType), sRingInterval);
+
+    return NS_OK;
   }
 
 private:
   nsString mNumber;
   int mType;
 };
 #endif // MOZ_B2G_RIL
 
-class BluetoothHfpManager::CloseScoTask : public Task
+class BluetoothHfpManager::CloseScoTask : public Runnable
 {
 private:
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(sBluetoothHfpManager);
 
     sBluetoothHfpManager->DisconnectSco();
+
+    return NS_OK;
   }
 };
 
 #ifdef MOZ_B2G_RIL
 static bool
 IsValidDtmf(const char aChar) {
   // Valid DTMF: [*#0-9ABCD]
   if (aChar == '*' || aChar == '#') {
@@ -980,17 +983,17 @@ BluetoothHfpManager::ReceiveSocketData(B
 
     if (msg.Find("AT+BLDN") != -1) {
       NotifyDialer(NS_LITERAL_STRING("BLDN"));
     } else {
       NotifyDialer(NS_ConvertUTF8toUTF16(msg));
     }
 
     MessageLoop::current()->
-      PostDelayedTask(FROM_HERE, new RespondToBLDNTask(),
+      PostDelayedTask(MakeAndAddRef<RespondToBLDNTask>(),
                       sWaitingForDialingInterval);
 
     // Don't send response 'OK' here because we'll respond later in either
     // RespondToBLDNTask or HandleCallStateChanged()
     return;
   } else if (msg.Find("ATA") != -1) {
     NotifyDialer(NS_LITERAL_STRING("ATA"));
   } else if (msg.Find("AT+CHUP") != -1) {
@@ -1571,19 +1574,18 @@ BluetoothHfpManager::HandleCallStateChan
         }
 
         nsAutoString number(aNumber);
         if (!mCLIP) {
           number.Truncate();
         }
 
         MessageLoop::current()->PostDelayedTask(
-          FROM_HERE,
-          new SendRingIndicatorTask(number,
-                                    mCurrentCallArray[aCallIndex].mType),
+          MakeAndAddRef<SendRingIndicatorTask>(
+            number, mCurrentCallArray[aCallIndex].mType),
           sRingInterval);
       }
       break;
     case nsITelephonyService::CALL_STATE_DIALING:
       if (!mDialingRequestProcessed) {
         SendLine("OK");
         mDialingRequestProcessed = true;
       }
@@ -1681,18 +1683,17 @@ BluetoothHfpManager::HandleCallStateChan
       if (mCurrentCallArray.Length() - 1 ==
           GetNumberOfCalls(nsITelephonyService::CALL_STATE_DISCONNECTED)) {
         // In order to let user hear busy tone via connected Bluetooth headset,
         // we postpone the timing of dropping SCO.
         if (!(aError.Equals(NS_LITERAL_STRING("BusyError")))) {
           DisconnectSco();
         } else {
           // Close Sco later since Dialer is still playing busy tone via HF.
-          MessageLoop::current()->PostDelayedTask(FROM_HERE,
-                                                  new CloseScoTask(),
+          MessageLoop::current()->PostDelayedTask(MakeAndAddRef<CloseScoTask>(),
                                                   sBusyToneInterval);
         }
 
         ResetCallArray();
       }
       break;
     default:
       BT_WARNING("Not handling state changed");
--- a/dom/bluetooth/bluez/BluetoothOppManager.cpp
+++ b/dom/bluetooth/bluez/BluetoothOppManager.cpp
@@ -162,32 +162,33 @@ public:
     return NS_OK;
   };
 
 private:
   nsCOMPtr<nsIInputStream> mInputStream;
   uint32_t mAvailablePacketSize;
 };
 
-class CloseSocketTask : public Task
+class CloseSocketTask : public Runnable
 {
 public:
   CloseSocketTask(BluetoothSocket* aSocket) : mSocket(aSocket)
   {
     MOZ_ASSERT(aSocket);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     if (mSocket->GetConnectionStatus() ==
         SocketConnectionStatus::SOCKET_CONNECTED) {
       mSocket->Close();
     }
+    return NS_OK;
   }
 
 private:
   RefPtr<BluetoothSocket> mSocket;
 };
 
 BluetoothOppManager::BluetoothOppManager()
   : mConnected(false)
@@ -1071,17 +1072,17 @@ BluetoothOppManager::ClientDataHandler(U
     FileTransferComplete();
   } else if (mLastCommand == ObexRequestCode::Disconnect) {
     AfterOppDisconnected();
     // Most devices will directly terminate connection after receiving
     // Disconnect request, so we make a delay here. If the socket hasn't been
     // disconnected, we will close it.
     if (mSocket) {
       MessageLoop::current()->
-        PostDelayedTask(FROM_HERE, new CloseSocketTask(mSocket), 1000);
+        PostDelayedTask(MakeAndAddRef<CloseSocketTask>(mSocket), 1000);
     }
   } else if (mLastCommand == ObexRequestCode::Connect) {
     MOZ_ASSERT(!mFileName.IsEmpty());
     MOZ_ASSERT(mBlob);
 
     AfterOppConnected();
 
     // Ensure valid access to remote information
--- a/dom/bluetooth/bluez/BluetoothSocket.cpp
+++ b/dom/bluetooth/bluez/BluetoothSocket.cpp
@@ -38,17 +38,17 @@ public:
   void GetSocketAddr(BluetoothAddress& aAddress) const;
 
   BluetoothSocket* GetBluetoothSocket();
   DataSocket* GetDataSocket();
 
   // Delayed-task handling
   //
 
-  void SetDelayedConnectTask(CancelableTask* aTask);
+  void SetDelayedConnectTask(CancelableRunnable* aTask);
   void ClearDelayedConnectTask();
   void CancelDelayedConnectTask();
 
   // Task callback methods
   //
 
   /**
    * Run bind/listen to prepare for further runs of accept()
@@ -121,17 +121,17 @@ private:
    * Address structure of the socket currently in use
    */
   struct sockaddr_storage mAddress;
 
   /**
    * Task member for delayed connect task. Should only be access on consumer
    * thread.
    */
-  CancelableTask* mDelayedConnectTask;
+  CancelableRunnable* mDelayedConnectTask;
 
   /**
    * I/O buffer for received data
    */
   UniquePtr<UnixSocketRawData> mBuffer;
 };
 
 BluetoothSocket::BluetoothSocketIO::BluetoothSocketIO(
@@ -188,17 +188,17 @@ BluetoothSocket::BluetoothSocketIO::GetB
 
 DataSocket*
 BluetoothSocket::BluetoothSocketIO::GetDataSocket()
 {
   return GetBluetoothSocket();
 }
 
 void
-BluetoothSocket::BluetoothSocketIO::SetDelayedConnectTask(CancelableTask* aTask)
+BluetoothSocket::BluetoothSocketIO::SetDelayedConnectTask(CancelableRunnable* aTask)
 {
   MOZ_ASSERT(IsConsumerThread());
 
   mDelayedConnectTask = aTask;
 }
 
 void
 BluetoothSocket::BluetoothSocketIO::ClearDelayedConnectTask()
@@ -280,17 +280,17 @@ BluetoothSocket::BluetoothSocketIO::Send
 
 void
 BluetoothSocket::BluetoothSocketIO::OnConnected()
 {
   MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
   MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_CONNECTED);
 
   GetConsumerThread()->PostTask(
-    FROM_HERE, new SocketEventTask(this, SocketEventTask::CONNECT_SUCCESS));
+    MakeAndAddRef<SocketEventTask>(this, SocketEventTask::CONNECT_SUCCESS));
 
   AddWatchers(READ_WATCHER, true);
   if (HasPendingData()) {
     AddWatchers(WRITE_WATCHER, false);
   }
 }
 
 void
@@ -329,17 +329,17 @@ BluetoothSocket::BluetoothSocketIO::OnSo
     FireSocketError();
     return;
   }
 
   Close();
   SetSocket(fd, SOCKET_IS_CONNECTED);
 
   GetConsumerThread()->PostTask(
-    FROM_HERE, new SocketEventTask(this, SocketEventTask::CONNECT_SUCCESS));
+    MakeAndAddRef<SocketEventTask>(this, SocketEventTask::CONNECT_SUCCESS));
 
   AddWatchers(READ_WATCHER, true);
   if (HasPendingData()) {
     AddWatchers(WRITE_WATCHER, false);
   }
 }
 
 void
@@ -379,17 +379,17 @@ BluetoothSocket::BluetoothSocketIO::Fire
 {
   MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
 
   // Clean up watchers, statuses, fds
   Close();
 
   // Tell the consumer thread we've errored
   GetConsumerThread()->PostTask(
-    FROM_HERE, new SocketEventTask(this, SocketEventTask::CONNECT_ERROR));
+    MakeAndAddRef<SocketEventTask>(this, SocketEventTask::CONNECT_ERROR));
 }
 
 // |DataSocketIO|
 
 nsresult
 BluetoothSocket::BluetoothSocketIO::QueryReceiveBuffer(
   UnixSocketIOBuffer** aBuffer)
 {
@@ -411,43 +411,45 @@ class BluetoothSocket::BluetoothSocketIO
   : public SocketTask<BluetoothSocketIO>
 {
 public:
   ReceiveTask(BluetoothSocketIO* aIO, UnixSocketBuffer* aBuffer)
     : SocketTask<BluetoothSocketIO>(aIO)
     , mBuffer(aBuffer)
   { }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     BluetoothSocketIO* io = SocketTask<BluetoothSocketIO>::GetIO();
 
     MOZ_ASSERT(io->IsConsumerThread());
 
     if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
       // Since we've already explicitly closed and the close
       // happened before this, this isn't really an error.
-      return;
+      return NS_OK;
     }
 
     BluetoothSocket* bluetoothSocket = io->GetBluetoothSocket();
     MOZ_ASSERT(bluetoothSocket);
 
     bluetoothSocket->ReceiveSocketData(mBuffer);
+
+    return NS_OK;
   }
 
 private:
   UniquePtr<UnixSocketBuffer> mBuffer;
 };
 
 void
 BluetoothSocket::BluetoothSocketIO::ConsumeBuffer()
 {
-  GetConsumerThread()->PostTask(FROM_HERE,
-                                new ReceiveTask(this, mBuffer.release()));
+  GetConsumerThread()->PostTask(
+    MakeAndAddRef<ReceiveTask>(this, mBuffer.release()));
 }
 
 void
 BluetoothSocket::BluetoothSocketIO::DiscardBuffer()
 {
   // Nothing to do.
 }
 
@@ -500,66 +502,71 @@ BluetoothSocket::BluetoothSocketIO::Shut
 class BluetoothSocket::ListenTask final
   : public SocketIOTask<BluetoothSocketIO>
 {
 public:
   ListenTask(BluetoothSocketIO* aIO)
     : SocketIOTask<BluetoothSocketIO>(aIO)
   { }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!GetIO()->IsConsumerThread());
 
     if (!IsCanceled()) {
       GetIO()->Listen();
     }
+    return NS_OK;
   }
 };
 
 class BluetoothSocket::ConnectTask final
   : public SocketIOTask<BluetoothSocketIO>
 {
 public:
   ConnectTask(BluetoothSocketIO* aIO)
     : SocketIOTask<BluetoothSocketIO>(aIO)
   { }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!GetIO()->IsConsumerThread());
     MOZ_ASSERT(!IsCanceled());
 
     GetIO()->Connect();
+
+    return NS_OK;
   }
 };
 
 class BluetoothSocket::DelayedConnectTask final
   : public SocketIOTask<BluetoothSocketIO>
 {
 public:
   DelayedConnectTask(BluetoothSocketIO* aIO)
     : SocketIOTask<BluetoothSocketIO>(aIO)
   { }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(GetIO()->IsConsumerThread());
 
     if (IsCanceled()) {
-      return;
+      return NS_OK;
     }
 
     BluetoothSocketIO* io = GetIO();
     if (io->IsShutdownOnConsumerThread()) {
-      return;
+      return NS_OK;
     }
 
     io->ClearDelayedConnectTask();
-    io->GetIOLoop()->PostTask(FROM_HERE, new ConnectTask(io));
+    io->GetIOLoop()->PostTask(MakeAndAddRef<ConnectTask>(io));
+
+    return NS_OK;
   }
 };
 
 //
 // BluetoothSocket
 //
 
 BluetoothSocket::BluetoothSocket(BluetoothSocketObserver* aObserver)
@@ -665,21 +672,22 @@ BluetoothSocket::Connect(BluetoothUnixSo
   MOZ_ASSERT(aConsumerLoop);
   MOZ_ASSERT(aIOLoop);
   MOZ_ASSERT(!mIO);
 
   mIO = new BluetoothSocketIO(aConsumerLoop, aIOLoop, this, aConnector);
   SetConnectionStatus(SOCKET_CONNECTING);
 
   if (aDelayMs > 0) {
-    DelayedConnectTask* connectTask = new DelayedConnectTask(mIO);
+    RefPtr<DelayedConnectTask> connectTask =
+      MakeAndAddRef<DelayedConnectTask>(mIO);
     mIO->SetDelayedConnectTask(connectTask);
-    MessageLoop::current()->PostDelayedTask(FROM_HERE, connectTask, aDelayMs);
+    MessageLoop::current()->PostDelayedTask(connectTask.forget(), aDelayMs);
   } else {
-    aIOLoop->PostTask(FROM_HERE, new ConnectTask(mIO));
+    aIOLoop->PostTask(MakeAndAddRef<ConnectTask>(mIO));
   }
 
   return NS_OK;
 }
 
 nsresult
 BluetoothSocket::Connect(BluetoothUnixSocketConnector* aConnector,
                          int aDelayMs)
@@ -695,17 +703,17 @@ BluetoothSocket::Listen(BluetoothUnixSoc
   MOZ_ASSERT(aConnector);
   MOZ_ASSERT(aConsumerLoop);
   MOZ_ASSERT(aIOLoop);
   MOZ_ASSERT(!mIO);
 
   mIO = new BluetoothSocketIO(aConsumerLoop, aIOLoop, this, aConnector);
   SetConnectionStatus(SOCKET_LISTENING);
 
-  aIOLoop->PostTask(FROM_HERE, new ListenTask(mIO));
+  aIOLoop->PostTask(MakeAndAddRef<ListenTask>(mIO));
 
   return NS_OK;
 }
 
 nsresult
 BluetoothSocket::Listen(BluetoothUnixSocketConnector* aConnector)
 {
   return Listen(aConnector, MessageLoop::current(), XRE_GetIOMessageLoop());
@@ -728,18 +736,17 @@ BluetoothSocket::GetAddress(BluetoothAdd
 void
 BluetoothSocket::SendSocketData(UnixSocketIOBuffer* aBuffer)
 {
   MOZ_ASSERT(mIO);
   MOZ_ASSERT(mIO->IsConsumerThread());
   MOZ_ASSERT(!mIO->IsShutdownOnConsumerThread());
 
   mIO->GetIOLoop()->PostTask(
-    FROM_HERE,
-    new SocketIOSendTask<BluetoothSocketIO, UnixSocketIOBuffer>(mIO, aBuffer));
+    MakeAndAddRef<SocketIOSendTask<BluetoothSocketIO, UnixSocketIOBuffer>>(mIO, aBuffer));
 }
 
 // |SocketBase|
 
 void
 BluetoothSocket::Close()
 {
   if (!mIO) {
@@ -749,17 +756,17 @@ BluetoothSocket::Close()
   MOZ_ASSERT(mIO->IsConsumerThread());
 
   mIO->CancelDelayedConnectTask();
 
   // From this point on, we consider mIO as being deleted.
   // We sever the relationship here so any future calls to listen or connect
   // will create a new implementation.
   mIO->ShutdownOnConsumerThread();
-  mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
+  mIO->GetIOLoop()->PostTask(MakeAndAddRef<SocketIOShutdownTask>(mIO));
   mIO = nullptr;
 
   NotifyDisconnect();
 }
 
 void
 BluetoothSocket::OnConnectSuccess()
 {
--- a/dom/ipc/NuwaChild.cpp
+++ b/dom/ipc/NuwaChild.cpp
@@ -89,17 +89,17 @@ void
 NuwaFork()
 {
   if (sNuwaForking) {           // No reentry.
       return;
   }
   sNuwaForking = true;
 
   MessageLoop* ioloop = XRE_GetIOMessageLoop();
-  ioloop->PostTask(FROM_HERE, NewRunnableFunction(RunNuwaFork));
+  ioloop->PostTask(NewRunnableFunction(RunNuwaFork));
 }
 
 } // Anonymous namespace.
 
 #endif
 
 NuwaChild* NuwaChild::sSingleton;
 
--- a/dom/ipc/PreallocatedProcessManager.cpp
+++ b/dom/ipc/PreallocatedProcessManager.cpp
@@ -63,17 +63,17 @@ public:
   void OnNuwaReady();
   bool PreallocatedProcessReady();
   already_AddRefed<ContentParent> GetSpareProcess();
 
 private:
   void NuwaFork();
 
   // initialization off the critical path of app startup.
-  CancelableTask* mPreallocateAppProcessTask;
+  CancelableRunnable* mPreallocateAppProcessTask;
 
   // The array containing the preallocated processes. 4 as the inline storage size
   // should be enough so we don't need to grow the AutoTArray.
   AutoTArray<RefPtr<ContentParent>, 4> mSpareProcesses;
 
   // Nuwa process is ready for creating new process.
   bool mIsNuwaReady;
 #endif
@@ -238,17 +238,17 @@ PreallocatedProcessManagerImpl::Schedule
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (mPreallocateAppProcessTask) {
     // Make sure there is only one request running.
     return;
   }
 
-  RefPtr<CancelableTask> task = NewRunnableMethod(
+  RefPtr<CancelableRunnable> task = NewRunnableMethod(
     this, &PreallocatedProcessManagerImpl::DelayedNuwaFork);
   mPreallocateAppProcessTask = task;
   MessageLoop::current()->PostDelayedTask(task.forget(),
     Preferences::GetUint("dom.ipc.processPrelaunch.delayMs",
                          DEFAULT_ALLOCATE_DELAY));
 }
 
 void
--- a/dom/system/gonk/AudioManager.cpp
+++ b/dom/system/gonk/AudioManager.cpp
@@ -169,25 +169,25 @@ struct VolumeData {
 static const VolumeData gVolumeData[] = {
   {"audio.volume.content",      AUDIO_STREAM_MUSIC},
   {"audio.volume.notification", AUDIO_STREAM_NOTIFICATION},
   {"audio.volume.alarm",        AUDIO_STREAM_ALARM},
   {"audio.volume.telephony",    AUDIO_STREAM_VOICE_CALL},
   {"audio.volume.bt_sco",       AUDIO_STREAM_BLUETOOTH_SCO}
 };
 
-class RunnableCallTask : public Task
+class RunnableCallTask : public Runnable
 {
 public:
   explicit RunnableCallTask(nsIRunnable* aRunnable)
     : mRunnable(aRunnable) {}
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
-    mRunnable->Run();
+    return mRunnable->Run();
   }
 protected:
   nsCOMPtr<nsIRunnable> mRunnable;
 };
 
 nsCOMPtr<nsISettingsServiceLock>
 GetSettingServiceLock()
 {
@@ -499,17 +499,17 @@ AudioManager::HandleBluetoothStatusChang
 
           String8 cmd("bluetooth_enabled=false");
           AudioSystem::setParameters(0, cmd);
           cmd.setTo("A2dpSuspended=true");
           AudioSystem::setParameters(0, cmd);
           self->mA2dpSwitchDone = true;
         });
       MessageLoop::current()->PostDelayedTask(
-        FROM_HERE, new RunnableCallTask(runnable), 1000);
+        MakeAndAddRef<RunnableCallTask>(runnable), 1000);
 
       mA2dpSwitchDone = false;
     } else {
       UpdateDeviceConnectionState(isConnected,
                                   AUDIO_DEVICE_OUT_BLUETOOTH_A2DP,
                                   aAddress);
       String8 cmd("bluetooth_enabled=true");
       AudioSystem::setParameters(0, cmd);
@@ -658,17 +658,18 @@ AudioManager::HandleHeadphoneSwitchEvent
     nsCOMPtr<nsIRunnable> runnable =
       NS_NewRunnableFunction([self]() {
         if (self->mSwitchDone) {
           return;
         }
         self->UpdateHeadsetConnectionState(hal::SWITCH_STATE_OFF);
         self->mSwitchDone = true;
     });
-    MessageLoop::current()->PostDelayedTask(FROM_HERE, new RunnableCallTask(runnable), 1000);
+    MessageLoop::current()->PostDelayedTask(
+      MakeAndAddRef<RunnableCallTask>(runnable), 1000);
     mSwitchDone = false;
   } else if (aEvent.status() != hal::SWITCH_STATE_OFF) {
     UpdateHeadsetConnectionState(aEvent.status());
     mSwitchDone = true;
   }
   // Handle the coexistence of a2dp / headset device, latest one wins.
 #if ANDROID_VERSION >= 17
   int32_t forceUse = 0;
@@ -1413,17 +1414,17 @@ AudioManager::VolumeStreamState::SetVolu
     rv = SetVolumeIndex(aIndex, AUDIO_DEVICE_OUT_EARPIECE);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   } else {
     // No alias device
     rv = SetVolumeIndex(aIndex, aDevice);
   }
-  return rv;  
+  return rv;
 }
 
 nsresult
 AudioManager::VolumeStreamState::SetVolumeIndex(uint32_t aIndex,
                                                 uint32_t aDevice,
                                                 bool aUpdateCache)
 {
   status_t rv;
--- a/dom/system/gonk/AutoMounter.cpp
+++ b/dom/system/gonk/AutoMounter.cpp
@@ -957,18 +957,17 @@ AutoMounter::UpdateState()
         ERR("statfs failed for '%s': errno = %d (%s)", vol->NameStr(), errno, strerror(errno));
         continue;
       }
       static int delay = 250;
       if (fsbuf.f_blocks == 0) {
         if (delay <= 4000) {
           LOG("UpdateState: Volume '%s' is inaccessible, checking again in %d msec", vol->NameStr(), delay);
           MessageLoopForIO::current()->
-            PostDelayedTask(FROM_HERE,
-                            NewRunnableMethod(this, &AutoMounter::UpdateState),
+            PostDelayedTask(NewRunnableMethod(this, &AutoMounter::UpdateState),
                             delay);
           delay *= 2;
         } else {
           LOG("UpdateState: Volume '%s' is inaccessible, giving up", vol->NameStr());
         }
         continue;
       } else {
         delay = 250;
@@ -1032,18 +1031,17 @@ AutoMounter::UpdateState()
             // the sharing more responsive. If after a few seconds, the apps
             // haven't closed their files, then we back off.
 
             int delay = 1000;
             if (filesOpenDelayCount > 10) {
               delay = 5000;
             }
             MessageLoopForIO::current()->
-              PostDelayedTask(FROM_HERE,
-                              NewRunnableMethod(this, &AutoMounter::UpdateState),
+              PostDelayedTask(NewRunnableMethod(this, &AutoMounter::UpdateState),
                               delay);
             filesOpen = true;
             break;
           }
 
           // Volume is mounted, we need to unmount before
           // we can share.
           LOG("UpdateState: Unmounting %s", vol->NameStr());
@@ -1385,32 +1383,30 @@ public:
     hal::RegisterSwitchObserver(hal::SWITCH_USB, this);
   }
 
   virtual void Notify(const hal::SwitchEvent& aEvent)
   {
     DBG("UsbCable switch device: %d state: %s\n",
         aEvent.device(), SwitchStateStr(aEvent));
     XRE_GetIOMessageLoop()->PostTask(
-        FROM_HERE,
         NewRunnableFunction(UsbCableEventIOThread));
   }
 };
 
 static StaticRefPtr<UsbCableObserver> sUsbCableObserver;
 static StaticRefPtr<AutoMounterSetting> sAutoMounterSetting;
 
 void
 InitAutoMounter()
 {
   InitVolumeManager();
   sAutoMounterSetting = new AutoMounterSetting();
 
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(InitAutoMounterIOThread));
 
   // Switch Observers need to run on the main thread, so we need to
   // start it here and have it send events to the AutoMounter running
   // on the IO Thread.
   sUsbCableObserver = new UsbCableObserver();
 
   // Register status reporter into reporter manager
@@ -1437,52 +1433,47 @@ SetAutoMounterStatus(int32_t aStatus)
     sAutoMounterSetting->SetStatus(aStatus);
   }
 }
 
 void
 SetAutoMounterMode(int32_t aMode)
 {
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(SetAutoMounterModeIOThread, aMode));
 }
 
 void
 SetAutoMounterSharingMode(const nsCString& aVolumeName, bool aAllowSharing)
 {
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(SetAutoMounterSharingModeIOThread,
                           aVolumeName, aAllowSharing));
 }
 
 void
 AutoMounterFormatVolume(const nsCString& aVolumeName)
 {
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(AutoMounterFormatVolumeIOThread,
                           aVolumeName));
 }
 
 void
 AutoMounterMountVolume(const nsCString& aVolumeName)
 {
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(AutoMounterMountVolumeIOThread,
                           aVolumeName));
 }
 
 void
 AutoMounterUnmountVolume(const nsCString& aVolumeName)
 {
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(AutoMounterUnmountVolumeIOThread,
                           aVolumeName));
 }
 
 void
 ShutdownAutoMounter()
 {
   if (sAutoMounter) {
@@ -1493,14 +1484,13 @@ ShutdownAutoMounter()
       NS_UnregisterStatusReporter(new NS_STATUS_REPORTER_NAME(AutoMounter));
     }
     status_reporter_progress = REPORTER_UNREGISTERED;
   }
   sAutoMounterSetting = nullptr;
   sUsbCableObserver = nullptr;
 
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(ShutdownAutoMounterIOThread));
 }
 
 } // system
 } // mozilla
--- a/dom/system/gonk/VolumeManager.cpp
+++ b/dom/system/gonk/VolumeManager.cpp
@@ -523,18 +523,17 @@ VolumeManager::Start()
 
   if (!sVolumeManager) {
     return;
   }
   SetState(STARTING);
   if (!sVolumeManager->OpenSocket()) {
     // Socket open failed, try again in a second.
     MessageLoopForIO::current()->
-      PostDelayedTask(FROM_HERE,
-                      NewRunnableFunction(VolumeManager::Start),
+      PostDelayedTask(NewRunnableFunction(VolumeManager::Start),
                       1000);
   }
 }
 
 void
 VolumeManager::OnError()
 {
   Restart();
@@ -570,24 +569,22 @@ ShutdownVolumeManagerIOThread()
 *   to IOThread context before we can do anything.
 *
 **************************************************************************/
 
 void
 InitVolumeManager()
 {
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(InitVolumeManagerIOThread));
 }
 
 void
 ShutdownVolumeManager()
 {
   ShutdownVolumeServiceTest();
 
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(ShutdownVolumeManagerIOThread));
 }
 
 } // system
 } // mozilla
--- a/dom/system/gonk/nsVolume.cpp
+++ b/dom/system/gonk/nsVolume.cpp
@@ -260,17 +260,16 @@ NS_IMETHODIMP nsVolume::GetIsHotSwappabl
   return NS_OK;
 }
 
 NS_IMETHODIMP nsVolume::Format()
 {
   MOZ_ASSERT(XRE_IsParentProcess());
 
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(FormatVolumeIOThread, NameStr()));
 
   return NS_OK;
 }
 
 /* static */
 void nsVolume::FormatVolumeIOThread(const nsCString& aVolume)
 {
@@ -284,17 +283,16 @@ void nsVolume::FormatVolumeIOThread(cons
   AutoMounterFormatVolume(aVolume);
 }
 
 NS_IMETHODIMP nsVolume::Mount()
 {
   MOZ_ASSERT(XRE_IsParentProcess());
 
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(MountVolumeIOThread, NameStr()));
 
   return NS_OK;
 }
 
 /* static */
 void nsVolume::MountVolumeIOThread(const nsCString& aVolume)
 {
@@ -308,17 +306,16 @@ void nsVolume::MountVolumeIOThread(const
   AutoMounterMountVolume(aVolume);
 }
 
 NS_IMETHODIMP nsVolume::Unmount()
 {
   MOZ_ASSERT(XRE_IsParentProcess());
 
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(UnmountVolumeIOThread, NameStr()));
 
   return NS_OK;
 }
 
 /* static */
 void nsVolume::UnmountVolumeIOThread(const nsCString& aVolume)
 {
@@ -406,17 +403,16 @@ nsVolume::UpdateMountLock(bool aMountLoc
 
   if (aMountLocked == mMountLocked) {
     return;
   }
   // The locked/unlocked state changed. Tell IOThread about it.
   mMountLocked = aMountLocked;
   LogState();
   XRE_GetIOMessageLoop()->PostTask(
-     FROM_HERE,
      NewRunnableFunction(Volume::UpdateMountLock,
                          NS_LossyConvertUTF16toASCII(Name()),
                          MountGeneration(), aMountLocked));
 }
 
 void
 nsVolume::SetIsFake(bool aIsFake)
 {
--- a/dom/system/gonk/nsVolumeService.cpp
+++ b/dom/system/gonk/nsVolumeService.cpp
@@ -75,17 +75,16 @@ nsVolumeService::Shutdown()
 
   nsCOMPtr<nsIPowerManagerService> pmService =
     do_GetService(POWERMANAGERSERVICE_CONTRACTID);
   if (pmService) {
     pmService->RemoveWakeLockListener(sSingleton.get());
   }
 
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(ShutdownVolumeServiceIOThread));
 
   sSingleton = nullptr;
 }
 
 nsVolumeService::nsVolumeService()
   : mArrayMonitor("nsVolumeServiceArray"),
     mGotVolumesFromParent(false)
@@ -96,17 +95,16 @@ nsVolumeService::nsVolumeService()
     // VolumeServiceIOThread and the WakeLock listener should only run in the
     // parent, so we return early.
     return;
   }
 
   // Startup the IOThread side of things. The actual volume changes
   // are captured by the IOThread and forwarded to main thread.
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(InitVolumeServiceIOThread, this));
 
   nsCOMPtr<nsIPowerManagerService> pmService =
     do_GetService(POWERMANAGERSERVICE_CONTRACTID);
   if (!pmService) {
     return;
   }
   pmService->AddWakeLockListener(this);
--- a/hal/gonk/GonkDiskSpaceWatcher.cpp
+++ b/hal/gonk/GonkDiskSpaceWatcher.cpp
@@ -306,27 +306,25 @@ StartDiskSpaceWatcher()
   // Bail out if called several times.
   if (gHalDiskSpaceWatcher != nullptr) {
     return;
   }
 
   gHalDiskSpaceWatcher = new GonkDiskSpaceWatcher();
 
   XRE_GetIOMessageLoop()->PostTask(
-    FROM_HERE,
     NewRunnableMethod(gHalDiskSpaceWatcher, &GonkDiskSpaceWatcher::DoStart));
 }
 
 void
 StopDiskSpaceWatcher()
 {
   MOZ_ASSERT(NS_IsMainThread());
   if (!gHalDiskSpaceWatcher) {
     return;
   }
 
   XRE_GetIOMessageLoop()->PostTask(
-    FROM_HERE,
     NewRunnableMethod(gHalDiskSpaceWatcher, &GonkDiskSpaceWatcher::DoStop));
 }
 
 } // namespace hal_impl
 } // namespace mozilla
--- a/hal/gonk/GonkHal.cpp
+++ b/hal/gonk/GonkHal.cpp
@@ -520,17 +520,16 @@ RegisterBatteryObserverIOThread()
   sBatteryObserver = new BatteryObserver();
   RegisterUeventListener(sBatteryObserver);
 }
 
 void
 EnableBatteryNotifications()
 {
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(RegisterBatteryObserverIOThread));
 }
 
 static void
 UnregisterBatteryObserverIOThread()
 {
   MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
   MOZ_ASSERT(sBatteryObserver);
@@ -538,17 +537,16 @@ UnregisterBatteryObserverIOThread()
   UnregisterUeventListener(sBatteryObserver);
   sBatteryObserver = nullptr;
 }
 
 void
 DisableBatteryNotifications()
 {
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(UnregisterBatteryObserverIOThread));
 }
 
 static bool
 GetCurrentBatteryCharge(int* aCharge)
 {
   bool success = ReadSysFile("/sys/class/power_supply/battery/capacity",
                              aCharge);
--- a/hal/gonk/GonkSensor.cpp
+++ b/hal/gonk/GonkSensor.cpp
@@ -318,18 +318,18 @@ EnableSensorNotificationsInternal(Sensor
     }
   }
 
   if (!sPollingThread) {
     sPollingThread = new base::Thread("GonkSensors");
     MOZ_ASSERT(sPollingThread);
     // sPollingThread never terminates because poll may never return
     sPollingThread->Start();
-    sPollingThread->message_loop()->PostTask(FROM_HERE,
-                                     NewRunnableFunction(PollSensors));
+    sPollingThread->message_loop()->PostTask(
+      NewRunnableFunction(PollSensors));
   }
 
   SetSensorState(aSensor, true);
 }
 
 static void
 DisableSensorNotificationsInternal(SensorType aSensor)
 {
--- a/hal/gonk/GonkSwitch.cpp
+++ b/hal/gonk/GonkSwitch.cpp
@@ -62,23 +62,23 @@ public:
   }
 
   bool CheckEvent(NetlinkEvent* aEvent)
   {
     if (strcmp(GetSubsystem(), aEvent->getSubsystem()) ||
         strcmp(mDevPath, aEvent->findParam("DEVPATH"))) {
         return false;
     }
-    
+
     mState = ConvertState(GetStateString(aEvent));
     return mState != SWITCH_STATE_UNKNOWN;
   }
 
   SwitchState GetState()
-  { 
+  {
     return mState;
   }
 
   SwitchDevice GetType()
   {
     return mDevice;
   }
 protected:
@@ -110,17 +110,17 @@ protected:
     if (bytesRead < 0) {
       HAL_ERR("Read data from %s fails", statePath.get());
       return;
     }
 
     if (state[bytesRead - 1] == '\n') {
       bytesRead--;
     }
-    
+
     state[bytesRead] = '\0';
     mState = ConvertState(state);
   }
 
   virtual SwitchState ConvertState(const char* aState)
   {
     MOZ_ASSERT(aState);
     return aState[0] == '0' ? SWITCH_STATE_OFF : SWITCH_STATE_ON;
@@ -259,20 +259,20 @@ public:
   {
     mEventInfo[aDevice].mEnabled = false;
     mEnableCount--;
   }
 
   void Notify(const NetlinkEvent& aEvent)
   {
     SwitchState currState;
-    
+
     SwitchDevice device = GetEventInfo(aEvent, currState);
     if (device == SWITCH_DEVICE_UNKNOWN) {
-      return; 
+      return;
     }
 
     EventInfo& info = mEventInfo[device];
     if (currState == info.mEvent.status()) {
       return;
     }
 
     info.mEvent.status() = currState;
@@ -367,17 +367,17 @@ private:
       mEventInfo[device].mEvent.status() = state;
     }
   }
 
   SwitchDevice GetEventInfo(const NetlinkEvent& aEvent, SwitchState& aState)
   {
     //working around the android code not being const-correct
     NetlinkEvent *e = const_cast<NetlinkEvent*>(&aEvent);
-    
+
     for (size_t i = 0; i < mHandler.Length(); i++) {
       if (mHandler[i]->CheckEvent(e)) {
         aState = mHandler[i]->GetState();
         return mHandler[i]->GetType();
       }
     }
     return SWITCH_DEVICE_UNKNOWN;
   }
@@ -408,30 +408,29 @@ EnableSwitchNotificationsIOThread(Switch
 {
   InitializeResourceIfNeed();
   sSwitchObserver->EnableSwitch(aDevice);
   {
     MonitorAutoLock lock(*aMonitor);
     lock.Notify();
   }
 
-  // Notify the latest state if IO thread has the information. 
+  // Notify the latest state if IO thread has the information.
   if (sSwitchObserver->GetEnableCount() > 1) {
     sSwitchObserver->NotifyAnEvent(aDevice);
   }
 }
 
 void
 EnableSwitchNotifications(SwitchDevice aDevice)
 {
   Monitor monitor("EnableSwitch.monitor");
   {
     MonitorAutoLock lock(monitor);
     XRE_GetIOMessageLoop()->PostTask(
-        FROM_HERE,
         NewRunnableFunction(EnableSwitchNotificationsIOThread, aDevice, &monitor));
     lock.Wait();
   }
 }
 
 static void
 DisableSwitchNotificationsIOThread(SwitchDevice aDevice)
 {
@@ -439,17 +438,16 @@ DisableSwitchNotificationsIOThread(Switc
   sSwitchObserver->DisableSwitch(aDevice);
   ReleaseResourceIfNeed();
 }
 
 void
 DisableSwitchNotifications(SwitchDevice aDevice)
 {
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(DisableSwitchNotificationsIOThread, aDevice));
 }
 
 SwitchState
 GetCurrentSwitchState(SwitchDevice aDevice)
 {
   MOZ_ASSERT(sSwitchObserver && sSwitchObserver->GetEnableCount());
   return sSwitchObserver->GetCurrentInformation(aDevice);
@@ -460,17 +458,16 @@ NotifySwitchStateIOThread(SwitchDevice a
 {
   InitializeResourceIfNeed();
   sSwitchObserver->Notify(aDevice, aState);
 }
 
 void NotifySwitchStateFromInputDevice(SwitchDevice aDevice, SwitchState aState)
 {
   XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
       NewRunnableFunction(NotifySwitchStateIOThread, aDevice, aState));
 }
 
 bool IsHeadphoneEventFromInputDev()
 {
   // Instead of calling InitializeResourceIfNeed, create new SwitchEventObserver
   // to prevent calling RegisterUeventListener in main thread.
   RefPtr<SwitchEventObserver> switchObserver = new SwitchEventObserver();
--- a/hal/gonk/UeventPoller.cpp
+++ b/hal/gonk/UeventPoller.cpp
@@ -156,27 +156,29 @@ NetlinkPoller::OpenSocket()
       return false;
   }
 
   return true;
 }
 
 static StaticAutoPtr<NetlinkPoller> sPoller;
 
-class UeventInitTask : public Task
+class UeventInitTask : public Runnable
 {
-  virtual void Run()
+  NS_IMETHOD Run() override
   {
     if (!sPoller) {
-      return;
+      return NS_OK;
     }
     if (sPoller->OpenSocket()) {
-      return;
+      return NS_OK;
     }
-    sPoller->GetIOLoop()->PostDelayedTask(FROM_HERE, new UeventInitTask(), 1000);
+    sPoller->GetIOLoop()->PostDelayedTask(MakeAndAddRef<UeventInitTask>(),
+                                          1000);
+    return NS_OK;
   }
 };
 
 void
 NetlinkPoller::OnFileCanReadWithoutBlocking(int fd)
 {
   MOZ_ASSERT(fd == mSocket.get());
   while (true) {
@@ -212,17 +214,16 @@ public:
     // This is called from KillClearOnShutdown() on the main thread.
     MOZ_ASSERT(NS_IsMainThread());
     MOZ_ASSERT(XRE_GetIOMessageLoop());
 
     {
       MonitorAutoLock lock(*sMonitor);
 
       XRE_GetIOMessageLoop()->PostTask(
-          FROM_HERE,
           NewRunnableFunction(ShutdownUeventIOThread));
 
       while (!sShutdown) {
         lock.Wait();
       }
     }
 
     sShutdown = true;
@@ -262,17 +263,17 @@ private:
   }
 };
 
 static void
 InitializeUevent()
 {
   MOZ_ASSERT(!sPoller);
   sPoller = new NetlinkPoller();
-  sPoller->GetIOLoop()->PostTask(FROM_HERE, new UeventInitTask());
+  sPoller->GetIOLoop()->PostTask(MakeAndAddRef<UeventInitTask>());
 
   ShutdownNetlinkPoller::MaybeInit();
 }
 
 static void
 ShutdownUevent()
 {
   sPoller = nullptr;
--- a/ipc/glue/ProcessUtils_linux.cpp
+++ b/ipc/glue/ProcessUtils_linux.cpp
@@ -245,18 +245,17 @@ ProcLoaderClientDeinit()
   sProcLoaderClientOnDeinit = true;
 
   MOZ_ASSERT(sProcLoaderParent != nullptr);
   PProcLoaderParent *procLoaderParent = sProcLoaderParent;
   sProcLoaderParent = nullptr;
   sProcLoaderLoop = nullptr;
 
   MessageLoop::current()->
-    PostTask(FROM_HERE,
-             NewRunnableFunction(&_ProcLoaderParentDestroy,
+    PostTask(NewRunnableFunction(&_ProcLoaderParentDestroy,
                                  procLoaderParent));
 }
 
 struct AsyncSendLoadData
 {
   nsTArray<nsCString> mArgv;
   nsTArray<nsCString> mEnv;
   nsTArray<FDRemap> mFdsremap;
@@ -309,18 +308,17 @@ ProcLoaderLoad(const char *aArgv[],
     fdsremap.AppendElement(FDRemap(FileDescriptor(fdmap->first), fdmap->second));
   }
   load->mPrivs = aPrivs;
   load->mCookie = cookie++;
 
   *aProcessHandle = sProcLoaderPid;
   sProcLoaderPid = 0;
 
-  sProcLoaderLoop->PostTask(FROM_HERE,
-                            NewRunnableFunction(AsyncSendLoad, load));
+  sProcLoaderLoop->PostTask(NewRunnableFunction(AsyncSendLoad, load));
   return true;
 }
 
 
 class ProcLoaderRunnerBase;
 
 static bool sProcLoaderServing = false;
 static ProcLoaderRunnerBase *sProcLoaderDispatchedTask = nullptr;
@@ -486,38 +484,36 @@ ProcLoaderChild::RecvLoad(InfallibleTArr
 
   MOZ_ASSERT(sProcLoaderDispatchedTask == nullptr);
   ChildPrivileges privs = static_cast<ChildPrivileges>(aPrivs);
   sProcLoaderDispatchedTask =
     new ProcLoaderLoadRunner(aArgv, aEnv, aFdsRemap, privs);
 
   SendLoadComplete(mPeerPid, aCookie);
 
-  MessageLoop::current()->PostTask(FROM_HERE,
-                                   NewRunnableFunction(_ProcLoaderChildDestroy,
-                                                       this));
+  MessageLoop::current()->PostTask(
+    NewRunnableFunction(_ProcLoaderChildDestroy, this));
   return true;
 }
 
 void
 ProcLoaderChild::OnChannelError()
 {
   if (!sProcLoaderServing) {
     return;
   }
   sProcLoaderServing = false;
 
   PProcLoaderChild::OnChannelError();
 
   MOZ_ASSERT(sProcLoaderDispatchedTask == nullptr);
   sProcLoaderDispatchedTask = new ProcLoaderNoopRunner();
 
-  MessageLoop::current()->PostTask(FROM_HERE,
-                                   NewRunnableFunction(_ProcLoaderChildDestroy,
-                                                       this));
+  MessageLoop::current()->PostTask(
+    NewRunnableFunction(_ProcLoaderChildDestroy, this));
 }
 
 /**
  * A helper class which calls NS_LogInit/NS_LogTerm in its scope.
  */
 class ScopedLogging
 {
 public:
--- a/ipc/hal/DaemonSocket.cpp
+++ b/ipc/hal/DaemonSocket.cpp
@@ -213,34 +213,34 @@ DaemonSocket::PrepareAccept(UnixSocketCo
 
 void
 DaemonSocket::SendSocketData(UnixSocketIOBuffer* aBuffer)
 {
   MOZ_ASSERT(mIO);
   MOZ_ASSERT(mIO->IsConsumerThread());
 
   mIO->GetIOLoop()->PostTask(
-    FROM_HERE,
-    new SocketIOSendTask<DaemonSocketIO, UnixSocketIOBuffer>(mIO, aBuffer));
+    MakeAndAddRef<SocketIOSendTask<DaemonSocketIO, UnixSocketIOBuffer>>(
+      mIO, aBuffer));
 }
 
 // |SocketBase|
 
 void
 DaemonSocket::Close()
 {
   if (!mIO) {
     CHROMIUM_LOG("HAL daemon already disconnected!");
     return;
   }
 
   MOZ_ASSERT(mIO->IsConsumerThread());
 
   mIO->ShutdownOnConsumerThread();
-  mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
+  mIO->GetIOLoop()->PostTask(MakeAndAddRef<SocketIOShutdownTask>(mIO));
   mIO = nullptr;
 
   NotifyDisconnect();
 }
 
 void
 DaemonSocket::OnConnectSuccess()
 {
--- a/ipc/netd/Netd.cpp
+++ b/ipc/netd/Netd.cpp
@@ -212,18 +212,17 @@ NetdClient::Start()
     // Socket open failed, try again in a second.
     NETD_LOG("Fail to connect to Netd");
     if (++gNetdClient->mReConnectTimes > MAX_RECONNECT_TIMES) {
       NETD_LOG("Fail to connect to Netd after retry %d times", MAX_RECONNECT_TIMES);
       return;
     }
 
     MessageLoopForIO::current()->
-      PostDelayedTask(FROM_HERE,
-                      NewRunnableFunction(NetdClient::Start),
+      PostDelayedTask(NewRunnableFunction(NetdClient::Start),
                       1000);
     return;
   }
   gNetdClient->mReConnectTimes = 0;
 }
 
 // static
 void
@@ -329,30 +328,28 @@ void
 StartNetd(NetdConsumer* aNetdConsumer)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aNetdConsumer);
   MOZ_ASSERT(gNetdConsumer == nullptr);
 
   gNetdConsumer = aNetdConsumer;
   XRE_GetIOMessageLoop()->PostTask(
-    FROM_HERE,
     NewRunnableFunction(InitNetdIOThread));
 }
 
 void
 StopNetd()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   nsIThread* currentThread = NS_GetCurrentThread();
   NS_ASSERTION(currentThread, "This should never be null!");
 
   XRE_GetIOMessageLoop()->PostTask(
-    FROM_HERE,
     NewRunnableFunction(ShutdownNetdIOThread));
 
   while (gNetdConsumer) {
     if (!NS_ProcessNextEvent(currentThread)) {
       NS_WARNING("Something bad happened!");
       break;
     }
   }
@@ -365,14 +362,13 @@ StopNetd()
 *
 **************************************************************************/
 void
 SendNetdCommand(NetdCommand* aMessage)
 {
   MOZ_ASSERT(aMessage);
 
   XRE_GetIOMessageLoop()->PostTask(
-    FROM_HERE,
     NewRunnableFunction(NetdClient::SendNetdCommandIOThread, aMessage));
 }
 
 } // namespace ipc
 } // namespace mozilla
--- a/ipc/netd/Netd.h
+++ b/ipc/netd/Netd.h
@@ -32,19 +32,19 @@ protected:
   virtual ~NetdConsumer() { }
 
 public:
   NS_INLINE_DECL_REFCOUNTING(NetdConsumer)
 
   virtual void MessageReceived(NetdCommand* aMessage) = 0;
 };
 
-class NetdWriteTask : public Task
+class NetdWriteTask : public Runnable
 {
-  virtual void Run();
+  NS_IMETHOD Run();
 };
 
 class NetdClient : public MessageLoopForIO::LineWatcher
 {
   virtual ~NetdClient();
 
 public:
   NS_INLINE_DECL_REFCOUNTING(NetdClient)
--- a/ipc/ril/RilSocket.cpp
+++ b/ipc/ril/RilSocket.cpp
@@ -39,17 +39,17 @@ public:
   ~RilSocketIO();
 
   RilSocket* GetRilSocket();
   DataSocket* GetDataSocket();
 
   // Delayed-task handling
   //
 
-  void SetDelayedConnectTask(CancelableTask* aTask);
+  void SetDelayedConnectTask(CancelableRunnable* aTask);
   void ClearDelayedConnectTask();
   void CancelDelayedConnectTask();
 
   // Methods for |DataSocket|
   //
 
   nsresult QueryReceiveBuffer(UnixSocketIOBuffer** aBuffer) override;
   void ConsumeBuffer() override;
@@ -83,17 +83,17 @@ private:
    * If true, do not requeue whatever task we're running
    */
   bool mShuttingDownOnIOThread;
 
   /**
    * Task member for delayed connect task. Should only be access on consumer
    * thread.
    */
-  CancelableTask* mDelayedConnectTask;
+  CancelableRunnable* mDelayedConnectTask;
 
   /**
    * I/O buffer for received data
    */
   UniquePtr<UnixSocketRawData> mBuffer;
 };
 
 RilSocketIO::RilSocketIO(WorkerCrossThreadDispatcher* aDispatcher,
@@ -129,17 +129,17 @@ RilSocketIO::GetRilSocket()
 
 DataSocket*
 RilSocketIO::GetDataSocket()
 {
   return mRilSocket.get();
 }
 
 void
-RilSocketIO::SetDelayedConnectTask(CancelableTask* aTask)
+RilSocketIO::SetDelayedConnectTask(CancelableRunnable* aTask)
 {
   MOZ_ASSERT(IsConsumerThread());
 
   mDelayedConnectTask = aTask;
 }
 
 void
 RilSocketIO::ClearDelayedConnectTask()
@@ -276,48 +276,52 @@ RilSocketIO::ShutdownOnIOThread()
 class RilSocketIO::ConnectTask final
   : public SocketIOTask<RilSocketIO>
 {
 public:
   ConnectTask(RilSocketIO* aIO)
     : SocketIOTask<RilSocketIO>(aIO)
   { }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!GetIO()->IsConsumerThread());
     MOZ_ASSERT(!IsCanceled());
 
     GetIO()->Connect();
+
+    return NS_OK;
   }
 };
 
 class RilSocketIO::DelayedConnectTask final
   : public SocketIOTask<RilSocketIO>
 {
 public:
   DelayedConnectTask(RilSocketIO* aIO)
     : SocketIOTask<RilSocketIO>(aIO)
   { }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(GetIO()->IsConsumerThread());
 
     if (IsCanceled()) {
-      return;
+      return NS_OK;
     }
 
     RilSocketIO* io = GetIO();
     if (io->IsShutdownOnConsumerThread()) {
-      return;
+      return NS_OK;
     }
 
     io->ClearDelayedConnectTask();
-    io->GetIOLoop()->PostTask(FROM_HERE, new ConnectTask(io));
+    io->GetIOLoop()->PostTask(MakeAndAddRef<ConnectTask>(io));
+
+    return NS_OK;
   }
 };
 
 //
 // RilSocket
 //
 
 RilSocket::RilSocket(WorkerCrossThreadDispatcher* aDispatcher,
@@ -352,22 +356,22 @@ RilSocket::Connect(UnixSocketConnector* 
                    MessageLoop* aConsumerLoop, MessageLoop* aIOLoop)
 {
   MOZ_ASSERT(!mIO);
 
   mIO = new RilSocketIO(mDispatcher, aConsumerLoop, aIOLoop, this, aConnector);
   SetConnectionStatus(SOCKET_CONNECTING);
 
   if (aDelayMs > 0) {
-    RilSocketIO::DelayedConnectTask* connectTask =
-      new RilSocketIO::DelayedConnectTask(mIO);
+    RefPtr<RilSocketIO::DelayedConnectTask> connectTask =
+      MakeAndAddRef<RilSocketIO::DelayedConnectTask>(mIO);
     mIO->SetDelayedConnectTask(connectTask);
-    MessageLoop::current()->PostDelayedTask(FROM_HERE, connectTask, aDelayMs);
+    MessageLoop::current()->PostDelayedTask(connectTask.forget(), aDelayMs);
   } else {
-    aIOLoop->PostTask(FROM_HERE, new RilSocketIO::ConnectTask(mIO));
+    aIOLoop->PostTask(MakeAndAddRef<RilSocketIO::ConnectTask>(mIO));
   }
 
   return NS_OK;
 }
 
 nsresult
 RilSocket::Connect(UnixSocketConnector* aConnector, int aDelayMs)
 {
@@ -391,35 +395,34 @@ RilSocket::PrepareAccept(UnixSocketConne
 void
 RilSocket::SendSocketData(UnixSocketIOBuffer* aBuffer)
 {
   MOZ_ASSERT(mIO);
   MOZ_ASSERT(mIO->IsConsumerThread());
   MOZ_ASSERT(!mIO->IsShutdownOnConsumerThread());
 
   mIO->GetIOLoop()->PostTask(
-    FROM_HERE,
-    new SocketIOSendTask<RilSocketIO, UnixSocketIOBuffer>(mIO, aBuffer));
+    MakeAndAddRef<SocketIOSendTask<RilSocketIO, UnixSocketIOBuffer>>(mIO, aBuffer));
 }
 
 // |SocketBase|
 
 void
 RilSocket::Close()
 {
   MOZ_ASSERT(mIO);
   MOZ_ASSERT(mIO->IsConsumerThread());
 
   mIO->CancelDelayedConnectTask();
 
   // From this point on, we consider |mIO| as being deleted. We sever
   // the relationship here so any future calls to |Connect| will create
   // a new I/O object.
   mIO->ShutdownOnConsumerThread();
-  mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
+  mIO->GetIOLoop()->PostTask(MakeAndAddRef<SocketIOShutdownTask>(mIO));
   mIO = nullptr;
 
   NotifyDisconnect();
 }
 
 void
 RilSocket::OnConnectSuccess()
 {
--- a/ipc/unixsocket/ConnectionOrientedSocket.cpp
+++ b/ipc/unixsocket/ConnectionOrientedSocket.cpp
@@ -81,17 +81,17 @@ ConnectionOrientedSocketIO::Connect()
 
   int fd;
   nsresult rv = mConnector->CreateStreamSocket(peerAddress,
                                                &mPeerAddressLength,
                                                fd);
   if (NS_FAILED(rv)) {
     // Tell the consumer thread we've errored
     GetConsumerThread()->PostTask(
-      FROM_HERE, new SocketEventTask(this, SocketEventTask::CONNECT_ERROR));
+      MakeAndAddRef<SocketEventTask>(this, SocketEventTask::CONNECT_ERROR));
     return NS_ERROR_FAILURE;
   }
 
   SetFd(fd);
 
   // calls OnConnected() on success, or OnError() otherwise
   rv = UnixSocketWatcher::Connect(peerAddress, mPeerAddressLength);
 
@@ -148,17 +148,17 @@ ConnectionOrientedSocketIO::OnSocketCanS
 
 void
 ConnectionOrientedSocketIO::OnConnected()
 {
   MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
   MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_CONNECTED);
 
   GetConsumerThread()->PostTask(
-    FROM_HERE, new SocketEventTask(this, SocketEventTask::CONNECT_SUCCESS));
+    MakeAndAddRef<SocketEventTask>(this, SocketEventTask::CONNECT_SUCCESS));
 
   AddWatchers(READ_WATCHER, true);
   if (HasPendingData()) {
     AddWatchers(WRITE_WATCHER, false);
   }
 }
 
 void
@@ -176,17 +176,17 @@ ConnectionOrientedSocketIO::OnError(cons
 
   UnixFdWatcher::OnError(aFunction, aErrno);
 
   // Clean up watchers, status, fd
   Close();
 
   // Tell the consumer thread we've errored
   GetConsumerThread()->PostTask(
-    FROM_HERE, new SocketEventTask(this, SocketEventTask::CONNECT_ERROR));
+    MakeAndAddRef<SocketEventTask>(this, SocketEventTask::CONNECT_ERROR));
 }
 
 //
 // ConnectionOrientedSocket
 //
 
 ConnectionOrientedSocket::ConnectionOrientedSocket()
 {
--- a/ipc/unixsocket/DataSocket.cpp
+++ b/ipc/unixsocket/DataSocket.cpp
@@ -48,33 +48,33 @@ ssize_t
 DataSocketIO::ReceiveData(int aFd)
 {
   MOZ_ASSERT(aFd >= 0);
 
   UnixSocketIOBuffer* incoming;
   nsresult rv = QueryReceiveBuffer(&incoming);
   if (NS_FAILED(rv)) {
     /* an error occured */
-    GetConsumerThread()->PostTask(FROM_HERE,
-                                  new SocketRequestClosingTask(this));
+    GetConsumerThread()->PostTask(
+      MakeAndAddRef<SocketRequestClosingTask>(this));
     return -1;
   }
 
   ssize_t res = incoming->Receive(aFd);
   if (res < 0) {
     /* an I/O error occured */
     DiscardBuffer();
-    GetConsumerThread()->PostTask(FROM_HERE,
-                                  new SocketRequestClosingTask(this));
+    GetConsumerThread()->PostTask(
+      MakeAndAddRef<SocketRequestClosingTask>(this));
     return -1;
   } else if (!res) {
     /* EOF or peer shut down sending */
     DiscardBuffer();
-    GetConsumerThread()->PostTask(FROM_HERE,
-                                  new SocketRequestClosingTask(this));
+    GetConsumerThread()->PostTask(
+      MakeAndAddRef<SocketRequestClosingTask>(this));
     return 0;
   }
 
 #ifdef MOZ_TASK_TRACER
   /* Make unix socket creation events to be the source events of TaskTracer,
    * and originate the rest correlation tasks from here.
    */
   AutoSourceEvent taskTracerEvent(SourceEventType::Unixsocket);
@@ -91,18 +91,18 @@ DataSocketIO::SendPendingData(int aFd)
   MOZ_ASSERT(aFd >= 0);
 
   while (HasPendingData()) {
     UnixSocketIOBuffer* outgoing = mOutgoingQ.ElementAt(0);
 
     ssize_t res = outgoing->Send(aFd);
     if (res < 0) {
       /* an I/O error occured */
-      GetConsumerThread()->PostTask(FROM_HERE,
-                                    new SocketRequestClosingTask(this));
+      GetConsumerThread()->PostTask(
+        MakeAndAddRef<SocketRequestClosingTask>(this));
       return NS_ERROR_FAILURE;
     } else if (!res && outgoing->GetSize()) {
       /* I/O is currently blocked; try again later */
       return NS_OK;
     }
     if (!outgoing->GetSize()) {
       mOutgoingQ.RemoveElementAt(0);
       delete outgoing;
--- a/ipc/unixsocket/DataSocket.h
+++ b/ipc/unixsocket/DataSocket.h
@@ -117,25 +117,27 @@ class SocketIOSendTask final : public So
 public:
   SocketIOSendTask(Tio* aIO, Tdata* aData)
   : SocketIOTask<Tio>(aIO)
   , mData(aData)
   {
     MOZ_ASSERT(aData);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!SocketIOTask<Tio>::IsCanceled());
 
     Tio* io = SocketIOTask<Tio>::GetIO();
     MOZ_ASSERT(!io->IsConsumerThread());
     MOZ_ASSERT(!io->IsShutdownOnIOThread());
 
     io->Send(mData);
+
+    return NS_OK;
   }
 
 private:
   Tdata* mData;
 };
 
 }
 }
--- a/ipc/unixsocket/ListenSocket.cpp
+++ b/ipc/unixsocket/ListenSocket.cpp
@@ -170,17 +170,17 @@ ListenSocketIO::OnListening()
 {
   MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
   MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_LISTENING);
 
   AddWatchers(READ_WATCHER, true);
 
   /* We signal a successful 'connection' to a local address for listening. */
   GetConsumerThread()->PostTask(
-    FROM_HERE, new SocketEventTask(this, SocketEventTask::CONNECT_SUCCESS));
+    MakeAndAddRef<SocketEventTask>(this, SocketEventTask::CONNECT_SUCCESS));
 }
 
 void
 ListenSocketIO::OnError(const char* aFunction, int aErrno)
 {
   MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
 
   UnixFdWatcher::OnError(aFunction, aErrno);
@@ -192,17 +192,17 @@ ListenSocketIO::FireSocketError()
 {
   MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
 
   // Clean up watchers, statuses, fds
   Close();
 
   // Tell the consumer thread we've errored
   GetConsumerThread()->PostTask(
-    FROM_HERE, new SocketEventTask(this, SocketEventTask::CONNECT_ERROR));
+    MakeAndAddRef<SocketEventTask>(this, SocketEventTask::CONNECT_ERROR));
 }
 
 void
 ListenSocketIO::OnSocketCanAcceptWithoutBlocking()
 {
   MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
   MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_LISTENING);
   MOZ_ASSERT(mCOSocketIO);
@@ -284,23 +284,24 @@ public:
     MOZ_COUNT_CTOR(ListenTask);
   }
 
   ~ListenTask()
   {
     MOZ_COUNT_DTOR(ListenTask);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!GetIO()->IsConsumerThread());
 
     if (!IsCanceled()) {
       GetIO()->Listen(mCOSocketIO);
     }
+    return NS_OK;
   }
 
 private:
   ConnectionOrientedSocketIO* mCOSocketIO;
 };
 
 //
 // ListenSocket
@@ -377,17 +378,17 @@ ListenSocket::Listen(ConnectionOrientedS
 
   Unused << connector.release(); // now owned by |io|
 
   // Then we start listening for connection requests.
 
   SetConnectionStatus(SOCKET_LISTENING);
 
   mIO->GetIOLoop()->PostTask(
-    FROM_HERE, new ListenSocketIO::ListenTask(mIO, io));
+    MakeAndAddRef<ListenSocketIO::ListenTask>(mIO, io));
 
   return NS_OK;
 }
 
 // |SocketBase|
 
 void
 ListenSocket::Close()
@@ -397,17 +398,17 @@ ListenSocket::Close()
   }
 
   MOZ_ASSERT(mIO->IsConsumerThread());
 
   // From this point on, we consider mIO as being deleted. We sever
   // the relationship here so any future calls to listen or connect
   // will create a new implementation.
   mIO->ShutdownOnConsumerThread();
-  mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
+  mIO->GetIOLoop()->PostTask(MakeAndAddRef<SocketIOShutdownTask>(mIO));
   mIO = nullptr;
 
   NotifyDisconnect();
 }
 
 void
 ListenSocket::OnConnectSuccess()
 {
--- a/ipc/unixsocket/SocketBase.cpp
+++ b/ipc/unixsocket/SocketBase.cpp
@@ -321,39 +321,41 @@ SocketEventTask::SocketEventTask(SocketI
   MOZ_COUNT_CTOR(SocketEventTask);
 }
 
 SocketEventTask::~SocketEventTask()
 {
   MOZ_COUNT_DTOR(SocketEventTask);
 }
 
-void
+NS_IMETHODIMP
 SocketEventTask::Run()
 {
   SocketIOBase* io = SocketTask<SocketIOBase>::GetIO();
 
   MOZ_ASSERT(io->IsConsumerThread());
 
   if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
     // Since we've already explicitly closed and the close
     // happened before this, this isn't really an error.
-    return;
+    return NS_OK;
   }
 
   SocketBase* socketBase = io->GetSocketBase();
   MOZ_ASSERT(socketBase);
 
   if (mEvent == CONNECT_SUCCESS) {
     socketBase->NotifySuccess();
   } else if (mEvent == CONNECT_ERROR) {
     socketBase->NotifyError();
   } else if (mEvent == DISCONNECT) {
     socketBase->NotifyDisconnect();
   }
+
+  return NS_OK;
 }
 
 //
 // SocketRequestClosingTask
 //
 
 SocketRequestClosingTask::SocketRequestClosingTask(SocketIOBase* aIO)
   : SocketTask<SocketIOBase>(aIO)
@@ -361,33 +363,35 @@ SocketRequestClosingTask::SocketRequestC
   MOZ_COUNT_CTOR(SocketRequestClosingTask);
 }
 
 SocketRequestClosingTask::~SocketRequestClosingTask()
 {
   MOZ_COUNT_DTOR(SocketRequestClosingTask);
 }
 
-void
+NS_IMETHODIMP
 SocketRequestClosingTask::Run()
 {
   SocketIOBase* io = SocketTask<SocketIOBase>::GetIO();
 
   MOZ_ASSERT(io->IsConsumerThread());
 
   if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
     // Since we've already explicitly closed and the close
     // happened before this, this isn't really an error.
-    return;
+    return NS_OK;
   }
 
   SocketBase* socketBase = io->GetSocketBase();
   MOZ_ASSERT(socketBase);
 
   socketBase->Close();
+
+  return NS_OK;
 }
 
 //
 // SocketDeleteInstanceTask
 //
 
 SocketDeleteInstanceTask::SocketDeleteInstanceTask(SocketIOBase* aIO)
   : mIO(aIO)
@@ -395,20 +399,21 @@ SocketDeleteInstanceTask::SocketDeleteIn
   MOZ_COUNT_CTOR(SocketDeleteInstanceTask);
 }
 
 SocketDeleteInstanceTask::~SocketDeleteInstanceTask()
 {
   MOZ_COUNT_DTOR(SocketDeleteInstanceTask);
 }
 
-void
+NS_IMETHODIMP
 SocketDeleteInstanceTask::Run()
 {
   mIO.reset(); // delete instance
+  return NS_OK;
 }
 
 //
 // SocketIOShutdownTask
 //
 
 SocketIOShutdownTask::SocketIOShutdownTask(SocketIOBase* aIO)
   : SocketIOTask<SocketIOBase>(aIO)
@@ -416,28 +421,29 @@ SocketIOShutdownTask::SocketIOShutdownTa
   MOZ_COUNT_CTOR(SocketIOShutdownTask);
 }
 
 SocketIOShutdownTask::~SocketIOShutdownTask()
 {
   MOZ_COUNT_DTOR(SocketIOShutdownTask);
 }
 
-void
+NS_IMETHODIMP
 SocketIOShutdownTask::Run()
 {
   SocketIOBase* io = SocketIOTask<SocketIOBase>::GetIO();
 
   MOZ_ASSERT(!io->IsConsumerThread());
   MOZ_ASSERT(!io->IsShutdownOnIOThread());
 
   // At this point, there should be no new events on the I/O thread
   // after this one with the possible exception of an accept task,
   // which ShutdownOnIOThread will cancel for us. We are now fully
   // shut down, so we can send a message to the consumer thread to
   // delete |io| safely knowing that it's not reference any longer.
   io->ShutdownOnIOThread();
-  io->GetConsumerThread()->PostTask(FROM_HERE,
-                                    new SocketDeleteInstanceTask(io));
+  io->GetConsumerThread()->PostTask(
+    MakeAndAddRef<SocketDeleteInstanceTask>(io));
+  return NS_OK;
 }
 
 }
 }
--- a/ipc/unixsocket/SocketBase.h
+++ b/ipc/unixsocket/SocketBase.h
@@ -448,17 +448,17 @@ private:
 //
 // Socket tasks
 //
 
 /* |SocketTask| is a task for sending a message from
  * the I/O thread to the consumer thread.
  */
 template <typename T>
-class SocketTask : public Task
+class SocketTask : public Runnable
 {
 public:
   virtual ~SocketTask()
   { }
 
   T* GetIO() const
   {
     return mIO;
@@ -486,72 +486,73 @@ public:
     CONNECT_SUCCESS,
     CONNECT_ERROR,
     DISCONNECT
   };
 
   SocketEventTask(SocketIOBase* aIO, SocketEvent aEvent);
   ~SocketEventTask();
 
-  void Run() override;
+  NS_IMETHOD Run() override;
 
 private:
   SocketEvent mEvent;
 };
 
 /**
  * |SocketRequestClosingTask| closes an instance of |SocketBase|
  * on the consumer thread.
  */
 class SocketRequestClosingTask final : public SocketTask<SocketIOBase>
 {
 public:
   SocketRequestClosingTask(SocketIOBase* aIO);
   ~SocketRequestClosingTask();
 
-  void Run() override;
+  NS_IMETHOD Run() override;
 };
 
 /**
  * |SocketDeleteInstanceTask| deletes an object on the consumer thread.
  */
-class SocketDeleteInstanceTask final : public Task
+class SocketDeleteInstanceTask final : public Runnable
 {
 public:
   SocketDeleteInstanceTask(SocketIOBase* aIO);
   ~SocketDeleteInstanceTask();
 
-  void Run() override;
+  NS_IMETHOD Run() override;
 
 private:
   UniquePtr<SocketIOBase> mIO;
 };
 
 //
 // Socket I/O tasks
 //
 
 /* |SocketIOTask| holds a reference to a Socket I/O object. It's
  * supposed to run on the I/O thread.
  */
 template<typename Tio>
-class SocketIOTask : public CancelableTask
+class SocketIOTask : public CancelableRunnable
 {
 public:
   virtual ~SocketIOTask()
   { }
 
   Tio* GetIO() const
   {
     return mIO;
   }
 
-  void Cancel() override
+  nsresult Cancel() override
   {
     mIO = nullptr;
+    return NS_OK;
   }
 
   bool IsCanceled() const
   {
     return !mIO;
   }
 
 protected:
@@ -570,15 +571,15 @@ private:
  * the I/O thread and sends it to the consumer thread for destruction.
  */
 class SocketIOShutdownTask final : public SocketIOTask<SocketIOBase>
 {
 public:
   SocketIOShutdownTask(SocketIOBase* aIO);
   ~SocketIOShutdownTask();
 
-  void Run() override;
+  NS_IMETHOD Run() override;
 };
 
 }
 }
 
 #endif
--- a/ipc/unixsocket/StreamSocket.cpp
+++ b/ipc/unixsocket/StreamSocket.cpp
@@ -40,17 +40,17 @@ public:
   ~StreamSocketIO();
 
   StreamSocket* GetStreamSocket();
   DataSocket* GetDataSocket();
 
   // Delayed-task handling
   //
 
-  void SetDelayedConnectTask(CancelableTask* aTask);
+  void SetDelayedConnectTask(CancelableRunnable* aTask);
   void ClearDelayedConnectTask();
   void CancelDelayedConnectTask();
 
   // Methods for |DataSocket|
   //
 
   nsresult QueryReceiveBuffer(UnixSocketIOBuffer** aBuffer) override;
   void ConsumeBuffer() override;
@@ -79,17 +79,17 @@ private:
    * If true, do not requeue whatever task we're running
    */
   bool mShuttingDownOnIOThread;
 
   /**
    * Task member for delayed connect task. Should only be access on consumer
    * thread.
    */
-  CancelableTask* mDelayedConnectTask;
+  CancelableRunnable* mDelayedConnectTask;
 
   /**
    * I/O buffer for received data
    */
   UniquePtr<UnixSocketRawData> mBuffer;
 };
 
 StreamSocketIO::StreamSocketIO(MessageLoop* aConsumerLoop,
@@ -141,17 +141,17 @@ StreamSocketIO::GetStreamSocket()
 
 DataSocket*
 StreamSocketIO::GetDataSocket()
 {
   return GetStreamSocket();
 }
 
 void
-StreamSocketIO::SetDelayedConnectTask(CancelableTask* aTask)
+StreamSocketIO::SetDelayedConnectTask(CancelableRunnable* aTask)
 {
   MOZ_ASSERT(IsConsumerThread());
 
   mDelayedConnectTask = aTask;
 }
 
 void
 StreamSocketIO::ClearDelayedConnectTask()
@@ -203,43 +203,45 @@ public:
     MOZ_COUNT_CTOR(ReceiveTask);
   }
 
   ~ReceiveTask()
   {
     MOZ_COUNT_DTOR(ReceiveTask);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     StreamSocketIO* io = SocketTask<StreamSocketIO>::GetIO();
 
     MOZ_ASSERT(io->IsConsumerThread());
 
     if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
       // Since we've already explicitly closed and the close
       // happened before this, this isn't really an error.
-      return;
+      return NS_OK;
     }
 
     StreamSocket* streamSocket = io->GetStreamSocket();
     MOZ_ASSERT(streamSocket);
 
     streamSocket->ReceiveSocketData(mBuffer);
+
+    return NS_OK;
   }
 
 private:
   UniquePtr<UnixSocketBuffer> mBuffer;
 };
 
 void
 StreamSocketIO::ConsumeBuffer()
 {
-  GetConsumerThread()->PostTask(FROM_HERE,
-                                new ReceiveTask(this, mBuffer.release()));
+  GetConsumerThread()->PostTask(
+    MakeAndAddRef<ReceiveTask>(this, mBuffer.release()));
 }
 
 void
 StreamSocketIO::DiscardBuffer()
 {
   // Nothing to do.
 }
 
@@ -297,22 +299,24 @@ public:
     MOZ_COUNT_CTOR(ReceiveTask);
   }
 
   ~ConnectTask()
   {
     MOZ_COUNT_DTOR(ReceiveTask);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(!GetIO()->IsConsumerThread());
     MOZ_ASSERT(!IsCanceled());
 
     GetIO()->Connect();
+
+    return NS_OK;
   }
 };
 
 class StreamSocketIO::DelayedConnectTask final
   : public SocketIOTask<StreamSocketIO>
 {
 public:
   DelayedConnectTask(StreamSocketIO* aIO)
@@ -321,31 +325,33 @@ public:
     MOZ_COUNT_CTOR(DelayedConnectTask);
   }
 
   ~DelayedConnectTask()
   {
     MOZ_COUNT_DTOR(DelayedConnectTask);
   }
 
-  void Run() override
+  NS_IMETHOD Run() override
   {
     MOZ_ASSERT(GetIO()->IsConsumerThread());
 
     if (IsCanceled()) {
-      return;
+      return NS_OK;
     }
 
     StreamSocketIO* io = GetIO();
     if (io->IsShutdownOnConsumerThread()) {
-      return;
+      return NS_OK;
     }
 
     io->ClearDelayedConnectTask();
-    io->GetIOLoop()->PostTask(FROM_HERE, new ConnectTask(io));
+    io->GetIOLoop()->PostTask(MakeAndAddRef<ConnectTask>(io));
+
+    return NS_OK;
   }
 };
 
 //
 // StreamSocket
 //
 
 StreamSocket::StreamSocket(StreamSocketConsumer* aConsumer, int aIndex)
@@ -376,22 +382,22 @@ StreamSocket::Connect(UnixSocketConnecto
                       MessageLoop* aConsumerLoop, MessageLoop* aIOLoop)
 {
   MOZ_ASSERT(!mIO);
 
   mIO = new StreamSocketIO(aConsumerLoop, aIOLoop, this, aConnector);
   SetConnectionStatus(SOCKET_CONNECTING);
 
   if (aDelayMs > 0) {
-    StreamSocketIO::DelayedConnectTask* connectTask =
-      new StreamSocketIO::DelayedConnectTask(mIO);
+    RefPtr<StreamSocketIO::DelayedConnectTask> connectTask =
+      MakeAndAddRef<StreamSocketIO::DelayedConnectTask>(mIO);
     mIO->SetDelayedConnectTask(connectTask);
-    MessageLoop::current()->PostDelayedTask(FROM_HERE, connectTask, aDelayMs);
+    MessageLoop::current()->PostDelayedTask(connectTask.forget(), aDelayMs);
   } else {
-    aIOLoop->PostTask(FROM_HERE, new StreamSocketIO::ConnectTask(mIO));
+    aIOLoop->PostTask(MakeAndAddRef<StreamSocketIO::ConnectTask>(mIO));
   }
 
   return NS_OK;
 }
 
 nsresult
 StreamSocket::Connect(UnixSocketConnector* aConnector, int aDelayMs)
 {
@@ -425,35 +431,35 @@ StreamSocket::PrepareAccept(UnixSocketCo
 void
 StreamSocket::SendSocketData(UnixSocketIOBuffer* aBuffer)
 {
   MOZ_ASSERT(mIO);
   MOZ_ASSERT(mIO->IsConsumerThread());
   MOZ_ASSERT(!mIO->IsShutdownOnConsumerThread());
 
   mIO->GetIOLoop()->PostTask(
-    FROM_HERE,
-    new SocketIOSendTask<StreamSocketIO, UnixSocketIOBuffer>(mIO, aBuffer));
+    MakeAndAddRef<SocketIOSendTask<StreamSocketIO, UnixSocketIOBuffer>>(
+      mIO, aBuffer));
 }
 
 // |SocketBase|
 
 void
 StreamSocket::Close()
 {
   MOZ_ASSERT(mIO);
   MOZ_ASSERT(mIO->IsConsumerThread());
 
   mIO->CancelDelayedConnectTask();
 
   // From this point on, we consider |mIO| as being deleted. We sever
   // the relationship here so any future calls to |Connect| will create
   // a new I/O object.
   mIO->ShutdownOnConsumerThread();
-  mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
+  mIO->GetIOLoop()->PostTask(MakeAndAddRef<SocketIOShutdownTask>(mIO));
   mIO = nullptr;
 
   NotifyDisconnect();
 }
 
 void
 StreamSocket::OnConnectSuccess()
 {
--- a/widget/gonk/nativewindow/FakeSurfaceComposer.cpp
+++ b/widget/gonk/nativewindow/FakeSurfaceComposer.cpp
@@ -438,24 +438,25 @@ FakeSurfaceComposer::captureScreen(const
         });
     NS_DispatchToMainThread(runnable);
 
     status_t result = wrapper->waitForResponse();
 
     return result;
 }
 
-class RunnableCallTask : public Task {
+class RunnableCallTask final : public Runnable
+{
 public:
     explicit RunnableCallTask(nsIRunnable* aRunnable)
         : mRunnable(aRunnable) {}
 
-    void Run() override
+    NS_IMETHOD Run() override
     {
-        mRunnable->Run();
+        return mRunnable->Run();
     }
 protected:
     nsCOMPtr<nsIRunnable> mRunnable;
 };
 
 void
 FakeSurfaceComposer::captureScreenImp(const sp<IGraphicBufferProducer>& producer,
                                       uint32_t reqWidth,
@@ -520,17 +521,17 @@ FakeSurfaceComposer::captureScreenImp(co
                 result = BAD_VALUE;
             }
             native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
             static_cast<GraphicProducerWrapper*>(producer->asBinder().get())->exit(result);
             NS_ReleaseOnMainThread(screenAlias.forget());
         });
 
     mozilla::layers::CompositorBridgeParent::CompositorLoop()->PostTask(
-        FROM_HERE, new RunnableCallTask(runnable));
+        MakeAndAddRef<RunnableCallTask>(runnable));
 }
 
 #if ANDROID_VERSION >= 21
 void
 FakeSurfaceComposer::setPowerMode(const sp<IBinder>& display, int mode)
 {
 }
 
--- a/widget/gonk/nativewindow/GonkBufferQueueJB.cpp
+++ b/widget/gonk/nativewindow/GonkBufferQueueJB.cpp
@@ -403,19 +403,20 @@ status_t GonkBufferQueue::dequeueBuffer(
         {
             mSlots[buf].mAcquireCalled = false;
             mSlots[buf].mGraphicBuffer = NULL;
             mSlots[buf].mRequestBufferCalled = false;
             mSlots[buf].mFence = Fence::NO_FENCE;
             if (mSlots[buf].mTextureClient) {
               mSlots[buf].mTextureClient->ClearRecycleCallback();
               // release TextureClient in ImageBridge thread
-              TextureClientReleaseTask* task = new TextureClientReleaseTask(mSlots[buf].mTextureClient);
+              RefPtr<TextureClientReleaseTask> task =
+                MakeAndAddRef<TextureClientReleaseTask>(mSlots[buf].mTextureClient);
               mSlots[buf].mTextureClient = NULL;
-              ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(FROM_HERE, task);
+              ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(task.forget());
             }
             returnFlags |= IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION;
         }
 
         *outFence = mSlots[buf].mFence;
         mSlots[buf].mFence = Fence::NO_FENCE;
     }  // end lock scope
 
@@ -777,19 +778,20 @@ void GonkBufferQueue::freeAllBuffersLock
             "freeAllBuffersLocked called but mQueue is not empty");
     mQueue.clear();
     mBufferHasBeenQueued = false;
     for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
         mSlots[i].mGraphicBuffer = 0;
         if (mSlots[i].mTextureClient) {
           mSlots[i].mTextureClient->ClearRecycleCallback();
           // release TextureClient in ImageBridge thread
-          TextureClientReleaseTask* task = new TextureClientReleaseTask(mSlots[i].mTextureClient);
+          RefPtr<TextureClientReleaseTask> task =
+            MakeAndAddRef<TextureClientReleaseTask>(mSlots[i].mTextureClient);
           mSlots[i].mTextureClient = NULL;
-          ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(FROM_HERE, task);
+          ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(task.forget());
         }
         if (mSlots[i].mBufferState == BufferSlot::ACQUIRED) {
             mSlots[i].mNeedsCleanupOnRelease = true;
         }
         mSlots[i].mBufferState = BufferSlot::FREE;
         mSlots[i].mFrameNumber = 0;
         mSlots[i].mAcquireCalled = false;
         // destroy fence as GonkBufferQueue now takes ownership
--- a/widget/gonk/nativewindow/GonkBufferQueueKK.cpp
+++ b/widget/gonk/nativewindow/GonkBufferQueueKK.cpp
@@ -418,19 +418,20 @@ status_t GonkBufferQueue::dequeueBuffer(
         {
             mSlots[buf].mAcquireCalled = false;
             mSlots[buf].mGraphicBuffer = NULL;
             mSlots[buf].mRequestBufferCalled = false;
             mSlots[buf].mFence = Fence::NO_FENCE;
             if (mSlots[buf].mTextureClient) {
               mSlots[buf].mTextureClient->ClearRecycleCallback();
               // release TextureClient in ImageBridge thread
-              TextureClientReleaseTask* task = new TextureClientReleaseTask(mSlots[buf].mTextureClient);
+              RefPtr<TextureClientReleaseTask> task =
+                MakeAndAddRef<TextureClientReleaseTask>(mSlots[buf].mTextureClient);
               mSlots[buf].mTextureClient = NULL;
-              ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(FROM_HERE, task);
+              ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(task.forget());
             }
             returnFlags |= IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION;
         }
 
 
         if (CC_UNLIKELY(mSlots[buf].mFence == NULL)) {
             ALOGE("dequeueBuffer: about to return a NULL fence from mSlot. "
                     "buf=%d, w=%d, h=%d, format=%d",
@@ -864,19 +865,20 @@ void GonkBufferQueue::freeAllBuffersLock
             "freeAllBuffersLocked called but mQueue is not empty");
     mQueue.clear();
     mBufferHasBeenQueued = false;
     for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
         mSlots[i].mGraphicBuffer = 0;
         if (mSlots[i].mTextureClient) {
           mSlots[i].mTextureClient->ClearRecycleCallback();
           // release TextureClient in ImageBridge thread
-          TextureClientReleaseTask* task = new TextureClientReleaseTask(mSlots[i].mTextureClient);
+          RefPtr<TextureClientReleaseTask> task =
+            MakeAndAddRef<TextureClientReleaseTask>(mSlots[i].mTextureClient);
           mSlots[i].mTextureClient = NULL;
-          ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(FROM_HERE, task);
+          ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(task.forget());
         }
         if (mSlots[i].mBufferState == BufferSlot::ACQUIRED) {
             mSlots[i].mNeedsCleanupOnRelease = true;
         }
         mSlots[i].mBufferState = BufferSlot::FREE;
         mSlots[i].mFrameNumber = 0;
         mSlots[i].mAcquireCalled = false;
         // destroy fence as GonkBufferQueue now takes ownership
--- a/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueCore.cpp
+++ b/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueCore.cpp
@@ -185,19 +185,20 @@ status_t GonkBufferQueueCore::setDefault
 }
 
 void GonkBufferQueueCore::freeBufferLocked(int slot) {
     ALOGV("freeBufferLocked: slot %d", slot);
 
     if (mSlots[slot].mTextureClient) {
         mSlots[slot].mTextureClient->ClearRecycleCallback();
         // release TextureClient in ImageBridge thread
-        TextureClientReleaseTask* task = new TextureClientReleaseTask(mSlots[slot].mTextureClient);
+        RefPtr<TextureClientReleaseTask> task =
+          MakeAndAddRef<TextureClientReleaseTask>(mSlots[slot].mTextureClient);
         mSlots[slot].mTextureClient = NULL;
-        ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(FROM_HERE, task);
+        ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(task.forget());
     }
     mSlots[slot].mGraphicBuffer.clear();
     if (mSlots[slot].mBufferState == GonkBufferSlot::ACQUIRED) {
         mSlots[slot].mNeedsCleanupOnRelease = true;
     }
     mSlots[slot].mBufferState = GonkBufferSlot::FREE;
     mSlots[slot].mFrameNumber = UINT32_MAX;
     mSlots[slot].mAcquireCalled = false;
--- a/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueProducer.cpp
+++ b/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueProducer.cpp
@@ -317,19 +317,20 @@ status_t GonkBufferQueueProducer::dequeu
             mSlots[found].mAcquireCalled = false;
             mSlots[found].mGraphicBuffer = NULL;
             mSlots[found].mRequestBufferCalled = false;
             mSlots[found].mFence = Fence::NO_FENCE;
 
             if (mSlots[found].mTextureClient) {
                 mSlots[found].mTextureClient->ClearRecycleCallback();
                 // release TextureClient in ImageBridge thread
-                TextureClientReleaseTask* task = new TextureClientReleaseTask(mSlots[found].mTextureClient);
+                RefPtr<TextureClientReleaseTask> task =
+                  MakeAndAddRef<TextureClientReleaseTask>(mSlots[found].mTextureClient);
                 mSlots[found].mTextureClient = NULL;
-                ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(FROM_HERE, task);
+                ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(task.forget());
             }
 
             returnFlags |= BUFFER_NEEDS_REALLOCATION;
         }
 
         if (CC_UNLIKELY(mSlots[found].mFence == NULL)) {
             ALOGE("dequeueBuffer: about to return a NULL fence - "
                     "slot=%d w=%d h=%d format=%u",
--- a/widget/gonk/nativewindow/GonkNativeWindowICS.cpp
+++ b/widget/gonk/nativewindow/GonkNativeWindowICS.cpp
@@ -67,19 +67,20 @@ void GonkNativeWindow::freeAllBuffersLoc
 {
     CNW_LOGD("freeAllBuffersLocked");
 
     for (int i = 0; i < NUM_BUFFER_SLOTS; ++i) {
         if (mSlots[i].mGraphicBuffer != NULL) {
             if (mSlots[i].mTextureClient) {
               mSlots[i].mTextureClient->ClearRecycleCallback();
               // release TextureClient in ImageBridge thread
-              TextureClientReleaseTask* task = new TextureClientReleaseTask(mSlots[i].mTextureClient);
+              RefPtr<TextureClientReleaseTask> task =
+                MakeAndAddRef<TextureClientReleaseTask>(mSlots[i].mTextureClient);
               mSlots[i].mTextureClient = NULL;
-              ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(FROM_HERE, task);
+              ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(task.forget());
             }
             mSlots[i].mGraphicBuffer = NULL;
             mSlots[i].mBufferState = BufferSlot::FREE;
             mSlots[i].mFrameNumber = 0;
         }
     }
 }
 
@@ -89,19 +90,20 @@ void GonkNativeWindow::clearRenderingSta
 
     for (int i = 0; i < NUM_BUFFER_SLOTS; ++i) {
         if (mSlots[i].mGraphicBuffer != NULL) {
             // Clear RENDERING state buffer
             if (mSlots[i].mBufferState == BufferSlot::RENDERING) {
                 if (mSlots[i].mTextureClient) {
                   mSlots[i].mTextureClient->ClearRecycleCallback();
                   // release TextureClient in ImageBridge thread
-                  TextureClientReleaseTask* task = new TextureClientReleaseTask(mSlots[i].mTextureClient);
+                  RefPtr<TextureClientReleaseTask> task =
+                    MakeAndAddRef<TextureClientReleaseTask>(mSlots[i].mTextureClient);
                   mSlots[i].mTextureClient = NULL;
-                  ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(FROM_HERE, task);
+                  ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(task.forget());
                 }
                 mSlots[i].mGraphicBuffer = NULL;
                 mSlots[i].mBufferState = BufferSlot::FREE;
                 mSlots[i].mFrameNumber = 0;
             }
         }
     }
 }
@@ -305,19 +307,20 @@ status_t GonkNativeWindow::dequeueBuffer
             (uint32_t(gbuf->height) != h) ||
             (uint32_t(gbuf->format) != format) ||
             ((uint32_t(gbuf->usage) & usage) != usage))) {
             mSlots[buf].mGraphicBuffer = NULL;
             mSlots[buf].mRequestBufferCalled = false;
             if (mSlots[buf].mTextureClient) {
                 mSlots[buf].mTextureClient->ClearRecycleCallback();
                 // release TextureClient in ImageBridge thread
-                TextureClientReleaseTask* task = new TextureClientReleaseTask(mSlots[buf].mTextureClient);
+                RefPtr<TextureClientReleaseTask> task =
+                  MakeAndAddRef<TextureClientReleaseTask>(mSlots[buf].mTextureClient);
                 mSlots[buf].mTextureClient = NULL;
-                ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(FROM_HERE, task);
+                ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(task.forget());
             }
             alloc = true;
         }
     }  // end lock scope
 
     if (alloc) {
         ClientIPCAllocator* allocator = ImageBridgeChild::GetSingleton();
         usage |= GraphicBuffer::USAGE_HW_TEXTURE;
--- a/widget/gonk/nsScreenManagerGonk.cpp
+++ b/widget/gonk/nsScreenManagerGonk.cpp
@@ -157,17 +157,16 @@ ReleaseGLContextSync(mozilla::gl::GLCont
     aGLContext->Release();
 }
 
 nsScreenGonk::~nsScreenGonk()
 {
     // Release GLContext on compositor thread
     if (mGLContext) {
         CompositorBridgeParent::CompositorLoop()->PostTask(
-            FROM_HERE,
             NewRunnableFunction(&ReleaseGLContextSync,
                                 mGLContext.forget().take()));
         mGLContext = nullptr;
     }
 }
 
 bool
 nsScreenGonk::IsPrimaryScreen()
@@ -664,17 +663,16 @@ nsScreenGonk::EnableMirroring()
     RefPtr<nsWindow> window = new nsWindow();
     window->Create(nullptr, nullptr, mNaturalBounds, &initData);
     MOZ_ASSERT(static_cast<nsWindow*>(window)->GetScreen() == this);
 
     // Update mMirroringWidget on compositor thread
     nsMainThreadPtrHandle<nsScreenGonk> primary =
       nsMainThreadPtrHandle<nsScreenGonk>(new nsMainThreadPtrHolder<nsScreenGonk>(primaryScreen, false));
     CompositorBridgeParent::CompositorLoop()->PostTask(
-        FROM_HERE,
         NewRunnableFunction(&UpdateMirroringWidgetSync,
                             primary,
                             window.forget().take()));
 
     mIsMirroring = true;
     return true;
 }
 
@@ -690,17 +688,16 @@ nsScreenGonk::DisableMirroring()
 
     bool ret = primaryScreen->ClearMirroringScreen(this);
     NS_ENSURE_TRUE(ret, false);
 
     // Update mMirroringWidget on compositor thread
     nsMainThreadPtrHandle<nsScreenGonk> primary =
       nsMainThreadPtrHandle<nsScreenGonk>(new nsMainThreadPtrHolder<nsScreenGonk>(primaryScreen, false));
     CompositorBridgeParent::CompositorLoop()->PostTask(
-        FROM_HERE,
         NewRunnableFunction(&UpdateMirroringWidgetSync,
                             primary,
                             nullptr));
     return true;
 }
 
 bool
 nsScreenGonk::SetMirroringScreen(nsScreenGonk* aScreen)
--- a/widget/gonk/nsWindow.cpp
+++ b/widget/gonk/nsWindow.cpp
@@ -230,28 +230,28 @@ nsWindow::DispatchTouchEventForAPZ(const
 
     // Dispatch the event into the gecko root process for "normal" flow.
     // The event might get sent to a child process,
     // but if it doesn't we need to notify the APZ of various things.
     // All of that happens in ProcessUntransformedAPZEvent
     ProcessUntransformedAPZEvent(&event, aGuid, aInputBlockId, aApzResponse);
 }
 
-class DispatchTouchInputOnControllerThread : public Task
+class DispatchTouchInputOnControllerThread : public Runnable
 {
 public:
     DispatchTouchInputOnControllerThread(const MultiTouchInput& aInput)
-      : Task()
-      , mInput(aInput)
+      : mInput(aInput)
     {}
 
-    virtual void Run() override {
+    NS_IMETHOD Run() override {
         if (gFocusedWindow) {
             gFocusedWindow->DispatchTouchInputViaAPZ(mInput);
         }
+        return NS_OK;
     }
 
 private:
     MultiTouchInput mInput;
 };
 
 nsresult
 nsWindow::SynthesizeNativeTouchPoint(uint32_t aPointerId,
@@ -320,17 +320,18 @@ nsWindow::SynthesizeNativeTouchPoint(uin
     }
 
     // Can't use NewRunnableMethod here because that will pass a const-ref
     // argument to DispatchTouchInputViaAPZ whereas that function takes a
     // non-const ref. At this callsite we don't care about the mutations that
     // the function performs so this is fine. Also we can't pass |this| to the
     // task because nsWindow refcounting is not threadsafe. Instead we just use
     // the gFocusedWindow static ptr instead the task.
-    APZThreadUtils::RunOnControllerThread(new DispatchTouchInputOnControllerThread(inputToDispatch));
+    APZThreadUtils::RunOnControllerThread(
+      MakeAndAddRef<DispatchTouchInputOnControllerThread>(inputToDispatch));
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindow::Create(nsIWidget* aParent,
                  void* aNativeParent,
                  const LayoutDeviceIntRect& aRect,