diff --git a/ipc/glue/MessageChannel.cpp b/ipc/glue/MessageChannel.cpp index 9008eeda1410..e16fa387d2c5 100644 --- a/ipc/glue/MessageChannel.cpp +++ b/ipc/glue/MessageChannel.cpp @@ -746,23 +746,6 @@ MessageChannel::Clear() } } -class AbstractThreadWrapperCleanup : public MessageLoop::DestructionObserver -{ -public: - AbstractThreadWrapperCleanup(already_AddRefed aWrapper) - : mWrapper(aWrapper) - {} - virtual ~AbstractThreadWrapperCleanup() override {} - virtual void WillDestroyCurrentMessageLoop() override - { - mWrapper = nullptr; - MessageLoop::current()->RemoveDestructionObserver(this); - delete this; - } -private: - RefPtr mWrapper; -}; - bool MessageChannel::Open(Transport* aTransport, MessageLoop* aIOLoop, Side aSide) { @@ -774,9 +757,7 @@ MessageChannel::Open(Transport* aTransport, MessageLoop* aIOLoop, Side aSide) mWorkerLoop->AddDestructionObserver(this); if (!AbstractThread::GetCurrent()) { - mWorkerLoop->AddDestructionObserver( - new AbstractThreadWrapperCleanup( - MessageLoopAbstractThreadWrapper::Create(mWorkerLoop))); + mAbstractThread = MessageLoopAbstractThreadWrapper::Create(mWorkerLoop); } @@ -859,9 +840,7 @@ MessageChannel::CommonThreadOpenInit(MessageChannel *aTargetChan, Side aSide) mWorkerLoop->AddDestructionObserver(this); if (!AbstractThread::GetCurrent()) { - mWorkerLoop->AddDestructionObserver( - new AbstractThreadWrapperCleanup( - MessageLoopAbstractThreadWrapper::Create(mWorkerLoop))); + mAbstractThread = MessageLoopAbstractThreadWrapper::Create(mWorkerLoop); } mLink = new ThreadLink(this, aTargetChan); diff --git a/ipc/glue/MessageChannel.h b/ipc/glue/MessageChannel.h index a8e71117d8e8..38b17cdb03c9 100644 --- a/ipc/glue/MessageChannel.h +++ b/ipc/glue/MessageChannel.h @@ -34,6 +34,8 @@ #include namespace mozilla { +class AbstractThread; + namespace ipc { class MessageChannel; @@ -556,6 +558,7 @@ class MessageChannel : HasResultCodes, MessageLoop::DestructionObserver Side mSide; MessageLink* mLink; MessageLoop* mWorkerLoop; // thread where work is done + RefPtr mAbstractThread; RefPtr mChannelErrorTask; // NotifyMaybeChannelError runnable // id() of mWorkerLoop. This persists even after mWorkerLoop is cleared