diff --git a/ipc/unixsocket/SocketBase.h b/ipc/unixsocket/SocketBase.h index 510148d2a51b..dd2404bc6362 100644 --- a/ipc/unixsocket/SocketBase.h +++ b/ipc/unixsocket/SocketBase.h @@ -246,7 +246,35 @@ 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 0b29de066aaa..131cc04ca2b5 100644 --- a/ipc/unixsocket/UnixSocket.cpp +++ b/ipc/unixsocket/UnixSocket.cpp @@ -201,32 +201,6 @@ 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: @@ -594,8 +568,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 RequestClosingSocketRunnable(this); + nsRefPtr r = + new SocketIORequestClosingRunnable(this); NS_DispatchToMainThread(r); return; }