diff --git a/ipc/unixsocket/SocketBase.h b/ipc/unixsocket/SocketBase.h index dd2404bc636..510148d2a51 100644 --- a/ipc/unixsocket/SocketBase.h +++ b/ipc/unixsocket/SocketBase.h @@ -246,35 +246,7 @@ private: nsAutoPtr mData; }; -template -class SocketIORequestClosingRunnable MOZ_FINAL : public SocketIORunnable -{ -public: - SocketIORequestClosingRunnable(T* aImpl) - : SocketIORunnable(aImpl) - { } - NS_IMETHOD Run() MOZ_OVERRIDE - { - MOZ_ASSERT(NS_IsMainThread()); - - T* io = SocketIORunnable::GetIO(); - - if (io->IsShutdownOnMainThread()) { - NS_WARNING("CloseSocket has already been called!"); - // Since we've already explicitly closed and the close happened before - // this, this isn't really an error. Since we've warned, return OK. - return NS_OK; - } - - SocketConsumerBase* consumer = io->GetConsumer(); - MOZ_ASSERT(consumer); - - consumer->CloseSocket(); - - return NS_OK; - } -}; } } diff --git a/ipc/unixsocket/UnixSocket.cpp b/ipc/unixsocket/UnixSocket.cpp index 131cc04ca2b..0b29de066aa 100644 --- a/ipc/unixsocket/UnixSocket.cpp +++ b/ipc/unixsocket/UnixSocket.cpp @@ -201,6 +201,32 @@ private: T* mInstance; }; +class RequestClosingSocketRunnable : public SocketIORunnable +{ +public: + RequestClosingSocketRunnable(UnixSocketImpl* aImpl) + : SocketIORunnable(aImpl) + { } + + NS_IMETHOD Run() MOZ_OVERRIDE + { + MOZ_ASSERT(NS_IsMainThread()); + + UnixSocketImpl* impl = GetIO(); + if (impl->IsShutdownOnMainThread()) { + NS_WARNING("CloseSocket has already been called!"); + // Since we've already explicitly closed and the close happened before + // this, this isn't really an error. Since we've warned, return OK. + return NS_OK; + } + + // Start from here, same handling flow as calling CloseSocket() from + // upper layer + impl->mConsumer->CloseSocket(); + return NS_OK; + } +}; + class UnixSocketImplTask : public CancelableTask { public: @@ -568,8 +594,8 @@ UnixSocketImpl::OnSocketCanReceiveWithoutBlocking() // We're done with our descriptors. Ensure that spurious events don't // cause us to end up back here. RemoveWatchers(READ_WATCHER|WRITE_WATCHER); - nsRefPtr r = - new SocketIORequestClosingRunnable(this); + nsRefPtr r = + new RequestClosingSocketRunnable(this); NS_DispatchToMainThread(r); return; }