Bug 1268313: Part 2 - Replace some NewRunnableMethods with NS_NewNonOwningRunnableMethod. r=froydnj
authorKyle Huey <khuey@kylehuey.com>
Thu, 05 May 2016 01:44:59 -0700
changeset 296215 c8b8d67ee83372c56a761821f5eb63e98abdf679
parent 296214 bf5001ed992f96517e6d35409f3d07c0351d4986
child 296216 9f23832812fd28d3a1d817247c875a149349017a
push id30233
push userryanvm@gmail.com
push dateThu, 05 May 2016 18:57:26 +0000
treeherdermozilla-central@0177462aac74 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1268313
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1268313: Part 2 - Replace some NewRunnableMethods with NS_NewNonOwningRunnableMethod. r=froydnj
dom/ipc/ProcessHangMonitor.cpp
dom/media/gmp/GMPProcessParent.cpp
dom/media/webaudio/blink/ReverbConvolver.cpp
dom/plugins/ipc/PluginModuleChild.cpp
dom/plugins/ipc/PluginModuleParent.cpp
dom/plugins/ipc/PluginProcessParent.cpp
ipc/glue/GeckoChildProcessHost.cpp
ipc/glue/MessageChannel.cpp
ipc/glue/MessageLink.cpp
toolkit/xre/nsEmbedFunctions.cpp
--- a/dom/ipc/ProcessHangMonitor.cpp
+++ b/dom/ipc/ProcessHangMonitor.cpp
@@ -225,32 +225,16 @@ public:
   bool mShutdownDone;
   // Map from plugin ID to crash dump ID. Protected by mBrowserCrashDumpHashLock.
   nsDataHashtable<nsUint32HashKey, nsString> mBrowserCrashDumpIds;
   Mutex mBrowserCrashDumpHashLock;
 };
 
 } // namespace
 
-template<>
-struct RunnableMethodTraits<HangMonitorChild>
-{
-  typedef HangMonitorChild Class;
-  static void RetainCallee(Class* obj) { }
-  static void ReleaseCallee(Class* obj) { }
-};
-
-template<>
-struct RunnableMethodTraits<HangMonitorParent>
-{
-  typedef HangMonitorParent Class;
-  static void RetainCallee(Class* obj) { }
-  static void ReleaseCallee(Class* obj) { }
-};
-
 /* HangMonitorChild implementation */
 
 HangMonitorChild::HangMonitorChild(ProcessHangMonitor* aMonitor)
  : mHangMonitor(aMonitor),
    mMonitor("HangMonitorChild lock"),
    mSentReport(false),
    mTerminateScript(false),
    mStartDebugger(false),
@@ -298,18 +282,18 @@ void
 HangMonitorChild::ActorDestroy(ActorDestroyReason aWhy)
 {
   MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
 
   mIPCOpen = false;
 
   // We use a task here to ensure that IPDL is finished with this
   // HangMonitorChild before it gets deleted on the main thread.
-  MonitorLoop()->PostTask(
-    NewRunnableMethod(this, &HangMonitorChild::ShutdownOnThread));
+  RefPtr<Runnable> runnable = NS_NewNonOwningRunnableMethod(this, &HangMonitorChild::ShutdownOnThread);
+  MonitorLoop()->PostTask(runnable.forget());
 }
 
 bool
 HangMonitorChild::RecvTerminateScript()
 {
   MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
 
   MonitorAutoLock lock(mMonitor);
@@ -385,19 +369,24 @@ HangMonitorChild::NotifySlowScript(nsITa
 
   TabId id;
   if (aTabChild) {
     RefPtr<TabChild> tabChild = static_cast<TabChild*>(aTabChild);
     id = tabChild->GetTabId();
   }
   nsAutoCString filename(aFileName);
 
-  MonitorLoop()->PostTask(
-    NewRunnableMethod(this, &HangMonitorChild::NotifySlowScriptAsync,
-                      id, filename, aLineNo));
+  RefPtr<Runnable> runnable =
+    NS_NewNonOwningRunnableMethodWithArgs<TabId,
+                                          nsCString,
+                                          unsigned>(this,
+                                                    &HangMonitorChild::NotifySlowScriptAsync,
+                                                    id, filename, aLineNo);
+  MonitorLoop()->PostTask(runnable.forget());
+
   return SlowScriptAction::Continue;
 }
 
 bool
 HangMonitorChild::IsDebuggerStartupComplete()
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
 
@@ -415,20 +404,21 @@ void
 HangMonitorChild::NotifyPluginHang(uint32_t aPluginId)
 {
   // main thread in the child
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
 
   mSentReport = true;
 
   // bounce to background thread
-  MonitorLoop()->PostTask(
-    NewRunnableMethod(this,
-                      &HangMonitorChild::NotifyPluginHangAsync,
-                      aPluginId));
+  RefPtr<Runnable> runnable =
+    NS_NewNonOwningRunnableMethodWithArgs<uint32_t>(this,
+                                                    &HangMonitorChild::NotifyPluginHangAsync,
+                                                    aPluginId);
+  MonitorLoop()->PostTask(runnable.forget());
 }
 
 void
 HangMonitorChild::NotifyPluginHangAsync(uint32_t aPluginId)
 {
   MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
 
   // bounce back to parent on background thread
@@ -440,18 +430,18 @@ HangMonitorChild::NotifyPluginHangAsync(
 
 void
 HangMonitorChild::ClearHang()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (mSentReport) {
     // bounce to background thread
-    MonitorLoop()->PostTask(
-      NewRunnableMethod(this, &HangMonitorChild::ClearHangAsync));
+    RefPtr<Runnable> runnable = NS_NewNonOwningRunnableMethod(this, &HangMonitorChild::ClearHangAsync);
+    MonitorLoop()->PostTask(runnable.forget());
 
     MonitorAutoLock lock(mMonitor);
     mSentReport = false;
     mTerminateScript = false;
     mStartDebugger = false;
     mFinishedStartingDebugger = false;
   }
 }
@@ -506,18 +496,18 @@ HangMonitorParent::Shutdown()
 
   MonitorAutoLock lock(mMonitor);
 
   if (mProcess) {
     mProcess->Clear();
     mProcess = nullptr;
   }
 
-  MonitorLoop()->PostTask(
-    NewRunnableMethod(this, &HangMonitorParent::ShutdownOnThread));
+  RefPtr<Runnable> runnable = NS_NewNonOwningRunnableMethod(this, &HangMonitorParent::ShutdownOnThread);
+  MonitorLoop()->PostTask(runnable.forget());
 
   while (!mShutdownDone) {
     mMonitor.Wait();
   }
 }
 
 void
 HangMonitorParent::ShutdownOnThread()
@@ -827,52 +817,52 @@ HangMonitoredProcess::TerminateScript()
   if (mHangData.type() != HangData::TSlowScriptData) {
     return NS_ERROR_UNEXPECTED;
   }
 
   if (!mActor) {
     return NS_ERROR_UNEXPECTED;
   }
 
-  ProcessHangMonitor::Get()->MonitorLoop()->PostTask(
-    NewRunnableMethod(mActor, &HangMonitorParent::TerminateScript));
+  RefPtr<Runnable> runnable = NS_NewNonOwningRunnableMethod(mActor, &HangMonitorParent::TerminateScript);
+  ProcessHangMonitor::Get()->MonitorLoop()->PostTask(runnable.forget());
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HangMonitoredProcess::BeginStartingDebugger()
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   if (mHangData.type() != HangData::TSlowScriptData) {
     return NS_ERROR_UNEXPECTED;
   }
 
   if (!mActor) {
     return NS_ERROR_UNEXPECTED;
   }
 
-  ProcessHangMonitor::Get()->MonitorLoop()->PostTask(
-    NewRunnableMethod(mActor, &HangMonitorParent::BeginStartingDebugger));
+  RefPtr<Runnable> runnable = NS_NewNonOwningRunnableMethod(mActor, &HangMonitorParent::BeginStartingDebugger);
+  ProcessHangMonitor::Get()->MonitorLoop()->PostTask(runnable.forget());
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HangMonitoredProcess::EndStartingDebugger()
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   if (mHangData.type() != HangData::TSlowScriptData) {
     return NS_ERROR_UNEXPECTED;
   }
 
   if (!mActor) {
     return NS_ERROR_UNEXPECTED;
   }
 
-  ProcessHangMonitor::Get()->MonitorLoop()->PostTask(
-    NewRunnableMethod(mActor, &HangMonitorParent::EndStartingDebugger));
+  RefPtr<Runnable> runnable = NS_NewNonOwningRunnableMethod(mActor, &HangMonitorParent::EndStartingDebugger);
+  ProcessHangMonitor::Get()->MonitorLoop()->PostTask(runnable.forget());
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HangMonitoredProcess::TerminatePlugin()
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   if (mHangData.type() != HangData::TPluginHangData) {
@@ -1040,35 +1030,45 @@ mozilla::CreateHangMonitorParent(Content
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
 
   ProcessHangMonitor* monitor = ProcessHangMonitor::GetOrCreate();
   HangMonitorParent* parent = new HangMonitorParent(monitor);
 
   HangMonitoredProcess* process = new HangMonitoredProcess(parent, aContentParent);
   parent->SetProcess(process);
 
-  monitor->MonitorLoop()->PostTask(
-    NewRunnableMethod(parent, &HangMonitorParent::Open,
-                      aTransport, aOtherPid, XRE_GetIOMessageLoop()));
+  RefPtr<Runnable> runnable =
+    NS_NewNonOwningRunnableMethodWithArgs<mozilla::ipc::Transport*,
+                                          base::ProcessId,
+                                          MessageLoop*>(parent,
+                                                        &HangMonitorParent::Open,
+                                                        aTransport, aOtherPid,
+                                                        XRE_GetIOMessageLoop());
+  monitor->MonitorLoop()->PostTask(runnable.forget());
 
   return parent;
 }
 
 PProcessHangMonitorChild*
 mozilla::CreateHangMonitorChild(mozilla::ipc::Transport* aTransport,
                                 base::ProcessId aOtherPid)
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
 
   ProcessHangMonitor* monitor = ProcessHangMonitor::GetOrCreate();
   HangMonitorChild* child = new HangMonitorChild(monitor);
 
-  monitor->MonitorLoop()->PostTask(
-    NewRunnableMethod(child, &HangMonitorChild::Open,
-                      aTransport, aOtherPid, XRE_GetIOMessageLoop()));
+  RefPtr<Runnable> runnable =
+    NS_NewNonOwningRunnableMethodWithArgs<mozilla::ipc::Transport*,
+                                          base::ProcessId,
+                                          MessageLoop*>(child,
+                                                        &HangMonitorChild::Open,
+                                                        aTransport, aOtherPid,
+                                                        XRE_GetIOMessageLoop());
+  monitor->MonitorLoop()->PostTask(runnable.forget());
 
   return child;
 }
 
 MessageLoop*
 ProcessHangMonitor::MonitorLoop()
 {
   return mThread->message_loop();
--- a/dom/media/gmp/GMPProcessParent.cpp
+++ b/dom/media/gmp/GMPProcessParent.cpp
@@ -19,23 +19,16 @@
 
 using std::vector;
 using std::string;
 
 using mozilla::gmp::GMPProcessParent;
 using mozilla::ipc::GeckoChildProcessHost;
 using base::ProcessArchitecture;
 
-template<>
-struct RunnableMethodTraits<GMPProcessParent>
-{
-  static void RetainCallee(GMPProcessParent* obj) { }
-  static void ReleaseCallee(GMPProcessParent* obj) { }
-};
-
 namespace mozilla {
 namespace gmp {
 
 GMPProcessParent::GMPProcessParent(const std::string& aGMPPath)
 : GeckoChildProcessHost(GeckoProcessType_GMPlugin),
   mGMPPath(aGMPPath)
 {
   MOZ_COUNT_CTOR(GMPProcessParent);
@@ -80,17 +73,18 @@ GMPProcessParent::Launch(int32_t aTimeou
 
   return SyncLaunch(args, aTimeoutMs, base::GetCurrentProcessArchitecture());
 }
 
 void
 GMPProcessParent::Delete(nsCOMPtr<nsIRunnable> aCallback)
 {
   mDeletedCallback = aCallback;
-  XRE_GetIOMessageLoop()->PostTask(NewRunnableMethod(this, &GMPProcessParent::DoDelete));
+  RefPtr<mozilla::Runnable> task = NS_NewNonOwningRunnableMethod(this, &GMPProcessParent::DoDelete);
+  XRE_GetIOMessageLoop()->PostTask(task.forget());
 }
 
 void
 GMPProcessParent::DoDelete()
 {
   MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
   Join();
 
--- a/dom/media/webaudio/blink/ReverbConvolver.cpp
+++ b/dom/media/webaudio/blink/ReverbConvolver.cpp
@@ -26,23 +26,16 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include "ReverbConvolver.h"
 #include "ReverbConvolverStage.h"
 
 using namespace mozilla;
 
-template<>
-struct RunnableMethodTraits<WebCore::ReverbConvolver>
-{
-  static void RetainCallee(WebCore::ReverbConvolver* obj) {}
-  static void ReleaseCallee(WebCore::ReverbConvolver* obj) {}
-};
-
 namespace WebCore {
 
 const int InputBufferSize = 8 * 16384;
 
 // We only process the leading portion of the impulse response in the real-time thread.  We don't exceed this length.
 // It turns out then, that the background thread has about 278msec of scheduling slop.
 // Empirically, this has been found to be a good compromise between giving enough time for scheduling slop,
 // while still minimizing the amount of processing done in the primary (high-priority) thread.
@@ -153,18 +146,18 @@ ReverbConvolver::ReverbConvolver(const f
 
     // Start up background thread
     // FIXME: would be better to up the thread priority here.  It doesn't need to be real-time, but higher than the default...
     if (this->useBackgroundThreads() && m_backgroundStages.Length() > 0) {
         if (!m_backgroundThread.Start()) {
           NS_WARNING("Cannot start convolver thread.");
           return;
         }
-        m_backgroundThread.message_loop()->PostTask(
-	  NewRunnableMethod(this, &ReverbConvolver::backgroundThreadEntry));
+	RefPtr<Runnable> runnable = NS_NewNonOwningRunnableMethod(this, &ReverbConvolver::backgroundThreadEntry);
+        m_backgroundThread.message_loop()->PostTask(runnable.forget());
     }
 }
 
 ReverbConvolver::~ReverbConvolver()
 {
     // Wait for background thread to stop
     if (useBackgroundThreads() && m_backgroundThread.IsRunning()) {
         m_wantsToExit = true;
--- a/dom/plugins/ipc/PluginModuleChild.cpp
+++ b/dom/plugins/ipc/PluginModuleChild.cpp
@@ -99,23 +99,16 @@ static CreateFileAPtr sCreateFileAStub =
 static bool gDelayFlashFocusReplyUntilEval = false;
 // Used to fix GetWindowInfo problems with internal flash settings dialogs
 static WindowsDllInterceptor sUser32Intercept;
 typedef BOOL (WINAPI *GetWindowInfoPtr)(HWND hwnd, PWINDOWINFO pwi);
 static GetWindowInfoPtr sGetWindowInfoPtrStub = nullptr;
 static HWND sBrowserHwnd = nullptr;
 #endif
 
-template<>
-struct RunnableMethodTraits<PluginModuleChild>
-{
-    static void RetainCallee(PluginModuleChild* obj) { }
-    static void ReleaseCallee(PluginModuleChild* obj) { }
-};
-
 /* static */
 PluginModuleChild*
 PluginModuleChild::CreateForContentProcess(mozilla::ipc::Transport* aTransport,
                                            base::ProcessId aOtherPid)
 {
     PluginModuleChild* child = new PluginModuleChild(false);
 
     if (!child->InitForContent(aOtherPid, XRE_GetIOMessageLoop(), aTransport)) {
--- a/dom/plugins/ipc/PluginModuleParent.cpp
+++ b/dom/plugins/ipc/PluginModuleParent.cpp
@@ -91,24 +91,16 @@ static const char kAsyncInitPref[] = "do
 #ifdef XP_WIN
 static const char kHangUITimeoutPref[] = "dom.ipc.plugins.hangUITimeoutSecs";
 static const char kHangUIMinDisplayPref[] = "dom.ipc.plugins.hangUIMinDisplaySecs";
 #define CHILD_TIMEOUT_PREF kHangUITimeoutPref
 #else
 #define CHILD_TIMEOUT_PREF kChildTimeoutPref
 #endif
 
-template<>
-struct RunnableMethodTraits<mozilla::plugins::PluginModuleParent>
-{
-    typedef mozilla::plugins::PluginModuleParent Class;
-    static void RetainCallee(Class* obj) { }
-    static void ReleaseCallee(Class* obj) { }
-};
-
 bool
 mozilla::plugins::SetupBridge(uint32_t aPluginId,
                               dom::ContentParent* aContentParent,
                               bool aForceBridgeNow,
                               nsresult* rv,
                               uint32_t* runID)
 {
     PROFILER_LABEL_FUNC(js::ProfileEntry::Category::OTHER);
--- a/dom/plugins/ipc/PluginProcessParent.cpp
+++ b/dom/plugins/ipc/PluginProcessParent.cpp
@@ -22,23 +22,16 @@ using std::vector;
 using std::string;
 
 using mozilla::ipc::BrowserProcessSubThread;
 using mozilla::ipc::GeckoChildProcessHost;
 using mozilla::plugins::LaunchCompleteTask;
 using mozilla::plugins::PluginProcessParent;
 using base::ProcessArchitecture;
 
-template<>
-struct RunnableMethodTraits<PluginProcessParent>
-{
-    static void RetainCallee(PluginProcessParent* obj) { }
-    static void ReleaseCallee(PluginProcessParent* obj) { }
-};
-
 PluginProcessParent::PluginProcessParent(const std::string& aPluginFilePath) :
     GeckoChildProcessHost(GeckoProcessType_Plugin),
     mPluginFilePath(aPluginFilePath),
     mTaskFactory(this),
     mMainMsgLoop(MessageLoop::current()),
     mRunCompleteTaskImmediately(false)
 {
 }
@@ -197,17 +190,18 @@ PluginProcessParent::Delete()
   MessageLoop* currentLoop = MessageLoop::current();
   MessageLoop* ioLoop = XRE_GetIOMessageLoop();
 
   if (currentLoop == ioLoop) {
       delete this;
       return;
   }
 
-  ioLoop->PostTask(NewRunnableMethod(this, &PluginProcessParent::Delete));
+  RefPtr<Runnable> runnable = NS_NewNonOwningRunnableMethod(this, &PluginProcessParent::Delete);
+  ioLoop->PostTask(runnable.forget());
 }
 
 void
 PluginProcessParent::SetCallRunnableImmediately(bool aCallImmediately)
 {
     mRunCompleteTaskImmediately = aCallImmediately;
 }
 
--- a/ipc/glue/GeckoChildProcessHost.cpp
+++ b/ipc/glue/GeckoChildProcessHost.cpp
@@ -76,23 +76,16 @@ static const bool kLowRightsSubprocesses
   ;
 
 static bool
 ShouldHaveDirectoryService()
 {
   return GeckoProcessType_Default == XRE_GetProcessType();
 }
 
-template<>
-struct RunnableMethodTraits<GeckoChildProcessHost>
-{
-    static void RetainCallee(GeckoChildProcessHost* obj) { }
-    static void ReleaseCallee(GeckoChildProcessHost* obj) { }
-};
-
 /*static*/
 base::ChildPrivileges
 GeckoChildProcessHost::DefaultChildPrivileges()
 {
   return (kLowRightsSubprocesses ?
           base::PRIVILEGES_UNPRIVILEGED : base::PRIVILEGES_INHERIT);
 }
 
@@ -346,33 +339,40 @@ void GeckoChildProcessHost::InitWindowsG
 bool
 GeckoChildProcessHost::SyncLaunch(std::vector<std::string> aExtraOpts, int aTimeoutMs, base::ProcessArchitecture arch)
 {
   PrepareLaunch();
 
   MessageLoop* ioLoop = XRE_GetIOMessageLoop();
   NS_ASSERTION(MessageLoop::current() != ioLoop, "sync launch from the IO thread NYI");
 
-  ioLoop->PostTask(NewRunnableMethod(this,
-                                     &GeckoChildProcessHost::RunPerformAsyncLaunch,
-                                     aExtraOpts, arch));
+  RefPtr<Runnable> runnable =
+    NS_NewNonOwningRunnableMethodWithArgs<std::vector<std::string>,
+                                          base::ProcessArchitecture>(this,
+                                                                     &GeckoChildProcessHost::RunPerformAsyncLaunch,
+                                                                     aExtraOpts, arch);
+  ioLoop->PostTask(runnable.forget());
 
   return WaitUntilConnected(aTimeoutMs);
 }
 
 bool
 GeckoChildProcessHost::AsyncLaunch(std::vector<std::string> aExtraOpts,
                                    base::ProcessArchitecture arch)
 {
   PrepareLaunch();
 
   MessageLoop* ioLoop = XRE_GetIOMessageLoop();
-  ioLoop->PostTask(NewRunnableMethod(this,
-                                     &GeckoChildProcessHost::RunPerformAsyncLaunch,
-                                     aExtraOpts, arch));
+
+  RefPtr<Runnable> runnable =
+    NS_NewNonOwningRunnableMethodWithArgs<std::vector<std::string>,
+                                          base::ProcessArchitecture>(this,
+                                                                     &GeckoChildProcessHost::RunPerformAsyncLaunch,
+                                                                     aExtraOpts, arch);
+  ioLoop->PostTask(runnable.forget());
 
   // This may look like the sync launch wait, but we only delay as
   // long as it takes to create the channel.
   MonitorAutoLock lock(mMonitor);
   while (mProcessState < CHANNEL_INITIALIZED) {
     lock.Wait();
   }
 
@@ -418,19 +418,23 @@ GeckoChildProcessHost::WaitUntilConnecte
 }
 
 bool
 GeckoChildProcessHost::LaunchAndWaitForProcessHandle(StringVector aExtraOpts)
 {
   PrepareLaunch();
 
   MessageLoop* ioLoop = XRE_GetIOMessageLoop();
-  ioLoop->PostTask(NewRunnableMethod(this,
-                                     &GeckoChildProcessHost::RunPerformAsyncLaunch,
-                                     aExtraOpts, base::GetCurrentProcessArchitecture()));
+  RefPtr<Runnable> runnable =
+    NS_NewNonOwningRunnableMethodWithArgs<std::vector<std::string>,
+                                          base::ProcessArchitecture>(this,
+                                                                     &GeckoChildProcessHost::RunPerformAsyncLaunch,
+                                                                     aExtraOpts,
+                                                                     base::GetCurrentProcessArchitecture());
+  ioLoop->PostTask(runnable.forget());
 
   MonitorAutoLock lock(mMonitor);
   while (mProcessState < PROCESS_CREATED) {
     lock.Wait();
   }
   MOZ_ASSERT(mProcessState == PROCESS_ERROR || mChildProcessHandle);
 
   return mProcessState < PROCESS_ERROR;
--- a/ipc/glue/MessageChannel.cpp
+++ b/ipc/glue/MessageChannel.cpp
@@ -695,18 +695,21 @@ MessageChannel::Open(MessageChannel *aTa
       case ParentSide: oppSide = ChildSide; break;
       case UnknownSide: break;
     }
 
     mMonitor = new RefCountedMonitor();
 
     MonitorAutoLock lock(*mMonitor);
     mChannelState = ChannelOpening;
-    aTargetLoop->PostTask(
-        NewRunnableMethod(aTargetChan, &MessageChannel::OnOpenAsSlave, this, oppSide));
+    RefPtr<Runnable> runnable =
+        NS_NewNonOwningRunnableMethodWithArgs<MessageChannel*, Side>(aTargetChan,
+                                                                     &MessageChannel::OnOpenAsSlave,
+                                                                     this, oppSide);
+    aTargetLoop->PostTask(runnable.forget());
 
     while (ChannelOpening == mChannelState)
         mMonitor->Wait();
     MOZ_RELEASE_ASSERT(ChannelConnected == mChannelState, "not connected when awoken");
     return (ChannelConnected == mChannelState);
 }
 
 void
--- a/ipc/glue/MessageLink.cpp
+++ b/ipc/glue/MessageLink.cpp
@@ -26,41 +26,28 @@ extern "C" char* PrintJSStack();
 #include "mozilla/DebugOnly.h"
 #include "nsDebug.h"
 #include "nsISupportsImpl.h"
 #include "nsXULAppAPI.h"
 
 using namespace mozilla;
 using namespace std;
 
-template<>
-struct RunnableMethodTraits<mozilla::ipc::ProcessLink>
-{
-    static void RetainCallee(mozilla::ipc::ProcessLink* obj) { }
-    static void ReleaseCallee(mozilla::ipc::ProcessLink* obj) { }
-};
-
 // We rely on invariants about the lifetime of the transport:
 //
 //  - outlives this MessageChannel
 //  - deleted on the IO thread
 //
 // These invariants allow us to send messages directly through the
 // transport without having to worry about orphaned Send() tasks on
 // the IO thread touching MessageChannel memory after it's been deleted
 // on the worker thread.  We also don't need to refcount the
 // Transport, because whatever task triggers its deletion only runs on
 // the IO thread, and only runs after this MessageChannel is done with
 // the Transport.
-template<>
-struct RunnableMethodTraits<mozilla::ipc::MessageChannel::Transport>
-{
-    static void RetainCallee(mozilla::ipc::MessageChannel::Transport* obj) { }
-    static void ReleaseCallee(mozilla::ipc::MessageChannel::Transport* obj) { }
-};
 
 namespace mozilla {
 namespace ipc {
 
 MessageLink::MessageLink(MessageChannel *aChan)
   : mChan(aChan)
 {
 }
@@ -126,24 +113,24 @@ ProcessLink::Open(mozilla::ipc::Transpor
 
     {
         MonitorAutoLock lock(*mChan->mMonitor);
 
         if (needOpen) {
             // Transport::Connect() has not been called.  Call it so
             // we start polling our pipe and processing outgoing
             // messages.
-            mIOLoop->PostTask(
-                NewRunnableMethod(this, &ProcessLink::OnChannelOpened));
+            RefPtr<Runnable> runnable = NS_NewNonOwningRunnableMethod(this, &ProcessLink::OnChannelOpened);
+            mIOLoop->PostTask(runnable.forget());
         } else {
             // Transport::Connect() has already been called.  Take
             // over the channel from the previous listener and process
             // any queued messages.
-            mIOLoop->PostTask(
-                NewRunnableMethod(this, &ProcessLink::OnTakeConnectedChannel));
+            RefPtr<Runnable> runnable = NS_NewNonOwningRunnableMethod(this, &ProcessLink::OnTakeConnectedChannel);
+            mIOLoop->PostTask(runnable.forget());
         }
 
 #ifdef MOZ_NUWA_PROCESS
         if (IsNuwaProcess() && NS_IsMainThread() &&
             Preferences::GetBool("dom.ipc.processPrelaunch.testMode")) {
             // The pref value is turned on in a deadlock test against the Nuwa
             // process. The sleep here makes it easy to trigger the deadlock
             // that an IPC channel is still opening but the worker loop is
@@ -160,18 +147,19 @@ ProcessLink::Open(mozilla::ipc::Transpor
 }
 
 void
 ProcessLink::EchoMessage(Message *msg)
 {
     mChan->AssertWorkerThread();
     mChan->mMonitor->AssertCurrentThreadOwns();
 
-    mIOLoop->PostTask(
-        NewRunnableMethod(this, &ProcessLink::OnEchoMessage, msg));
+    RefPtr<Runnable> runnable =
+        NS_NewNonOwningRunnableMethodWithArgs<Message*>(this, &ProcessLink::OnEchoMessage, msg);
+    mIOLoop->PostTask(runnable.forget());
     // OnEchoMessage takes ownership of |msg|
 }
 
 void
 ProcessLink::SendMessage(Message *msg)
 {
     mChan->AssertWorkerThread();
     mChan->mMonitor->AssertCurrentThreadOwns();
@@ -207,27 +195,29 @@ ProcessLink::SendMessage(Message *msg)
                       "with a blocked IPC channel from \n%s",
                       jsstack ? jsstack : "<no JS stack>");
         JS_smprintf_free(jsstack);
         MOZ_CRASH();
     }
 #endif
 #endif
 
-    mIOLoop->PostTask(
-        NewRunnableMethod(mTransport, &Transport::Send, msg));
+    RefPtr<Runnable> runnable =
+        NS_NewNonOwningRunnableMethodWithArgs<Message*>(mTransport, &Transport::Send, msg);
+    mIOLoop->PostTask(runnable.forget());
 }
 
 void
 ProcessLink::SendClose()
 {
     mChan->AssertWorkerThread();
     mChan->mMonitor->AssertCurrentThreadOwns();
 
-    mIOLoop->PostTask(NewRunnableMethod(this, &ProcessLink::OnCloseChannel));
+    RefPtr<Runnable> runnable = NS_NewNonOwningRunnableMethod(this, &ProcessLink::OnCloseChannel);
+    mIOLoop->PostTask(runnable.forget());
 }
 
 ThreadLink::ThreadLink(MessageChannel *aChan, MessageChannel *aTargetChan)
   : MessageLink(aChan),
     mTargetChan(aTargetChan)
 {
 }
 
--- a/toolkit/xre/nsEmbedFunctions.cpp
+++ b/toolkit/xre/nsEmbedFunctions.cpp
@@ -797,23 +797,16 @@ XRE_RunAppShell()
       loop->Run();
 
       loop->SetNestableTasksAllowed(couldNest);
     }
 #endif  // XP_MACOSX
     return appShell->Run();
 }
 
-template<>
-struct RunnableMethodTraits<ContentChild>
-{
-    static void RetainCallee(ContentChild* obj) { }
-    static void ReleaseCallee(ContentChild* obj) { }
-};
-
 void
 XRE_ShutdownChildProcess()
 {
   MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
 #if defined(XP_MACOSX)
   mozilla::ipc::SharedMemoryBasic::Shutdown();
 #endif