From f1e1ede770b48501470d1ba89c30b7faffff5743 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Wed, 29 Apr 2015 11:19:28 +0200 Subject: [PATCH] Bug 1159209: Remove template parameters from |SocketIORequestClosingRunnable|, r=kmachulis This patch removes the template parameters from |SocketIORequestClosingRunnable| and moves its methods into the C++ source file. All users have been adapted. --- dom/bluetooth/bluedroid/BluetoothSocket.cpp | 2 +- dom/bluetooth/bluez/BluetoothSocket.cpp | 2 +- ipc/bluetooth/BluetoothDaemonConnection.cpp | 8 ++--- ipc/unixsocket/DataSocket.h | 12 +++----- ipc/unixsocket/SocketBase.cpp | 30 +++++++++++++++++++ ipc/unixsocket/SocketBase.h | 33 +++++---------------- ipc/unixsocket/StreamSocket.cpp | 2 +- 7 files changed, 47 insertions(+), 42 deletions(-) diff --git a/dom/bluetooth/bluedroid/BluetoothSocket.cpp b/dom/bluetooth/bluedroid/BluetoothSocket.cpp index 339d98d08785..3acba7f39b80 100644 --- a/dom/bluetooth/bluedroid/BluetoothSocket.cpp +++ b/dom/bluetooth/bluedroid/BluetoothSocket.cpp @@ -43,7 +43,7 @@ EnsureBluetoothSocketHalLoad() } class mozilla::dom::bluetooth::DroidSocketImpl : public ipc::UnixFdWatcher - , protected DataSocketIO + , public DataSocketIO { public: /* The connection status in DroidSocketImpl indicates the current diff --git a/dom/bluetooth/bluez/BluetoothSocket.cpp b/dom/bluetooth/bluez/BluetoothSocket.cpp index 2ccdff7b274c..04f5a425dc39 100644 --- a/dom/bluetooth/bluez/BluetoothSocket.cpp +++ b/dom/bluetooth/bluez/BluetoothSocket.cpp @@ -25,7 +25,7 @@ static const size_t MAX_READ_SIZE = 1 << 16; class BluetoothSocket::BluetoothSocketIO final : public UnixSocketWatcher - , protected DataSocketIO + , public DataSocketIO { public: BluetoothSocketIO(MessageLoop* mIOLoop, diff --git a/ipc/bluetooth/BluetoothDaemonConnection.cpp b/ipc/bluetooth/BluetoothDaemonConnection.cpp index 3151383aa7b8..bad34b76ecb8 100644 --- a/ipc/bluetooth/BluetoothDaemonConnection.cpp +++ b/ipc/bluetooth/BluetoothDaemonConnection.cpp @@ -403,15 +403,11 @@ BluetoothDaemonConnectionIO::ReceiveData(int aFd) ssize_t res = mPDU->Receive(aFd); if (res < 0) { /* an I/O error occured */ - nsRefPtr r = - new SocketIORequestClosingRunnable(this); - NS_DispatchToMainThread(r); + NS_DispatchToMainThread(new SocketIORequestClosingRunnable(this)); return -1; } else if (!res) { /* EOF or peer shut down sending */ - nsRefPtr r = - new SocketIORequestClosingRunnable(this); - NS_DispatchToMainThread(r); + NS_DispatchToMainThread(new SocketIORequestClosingRunnable(this)); return 0; } diff --git a/ipc/unixsocket/DataSocket.h b/ipc/unixsocket/DataSocket.h index 705d51ee2429..47fd34f88960 100644 --- a/ipc/unixsocket/DataSocket.h +++ b/ipc/unixsocket/DataSocket.h @@ -95,8 +95,7 @@ public: nsresult rv = QueryReceiveBuffer(&incoming); if (NS_FAILED(rv)) { /* an error occured */ - nsRefPtr r = new SocketIORequestClosingRunnable(aIO); - NS_DispatchToMainThread(r); + NS_DispatchToMainThread(new SocketIORequestClosingRunnable(aIO)); return -1; } @@ -104,14 +103,12 @@ public: if (res < 0) { /* an I/O error occured */ DiscardBuffer(); - nsRefPtr r = new SocketIORequestClosingRunnable(aIO); - NS_DispatchToMainThread(r); + NS_DispatchToMainThread(new SocketIORequestClosingRunnable(aIO)); return -1; } else if (!res) { /* EOF or peer shut down sending */ DiscardBuffer(); - nsRefPtr r = new SocketIORequestClosingRunnable(aIO); - NS_DispatchToMainThread(r); + NS_DispatchToMainThread(new SocketIORequestClosingRunnable(aIO)); return 0; } @@ -138,8 +135,7 @@ public: ssize_t res = outgoing->Send(aFd); if (res < 0) { /* an I/O error occured */ - nsRefPtr r = new SocketIORequestClosingRunnable(aIO); - NS_DispatchToMainThread(r); + NS_DispatchToMainThread(new SocketIORequestClosingRunnable(aIO)); return NS_ERROR_FAILURE; } else if (!res && outgoing->GetSize()) { /* I/O is currently blocked; try again later */ diff --git a/ipc/unixsocket/SocketBase.cpp b/ipc/unixsocket/SocketBase.cpp index 0859fcfdd0dc..90bd90690fad 100644 --- a/ipc/unixsocket/SocketBase.cpp +++ b/ipc/unixsocket/SocketBase.cpp @@ -315,5 +315,35 @@ SocketIOEventRunnable::Run() return NS_OK; } +// +// SocketIORequestClosingRunnable +// + +SocketIORequestClosingRunnable::SocketIORequestClosingRunnable( + SocketIOBase* aIO) + : SocketIORunnable(aIO) +{ } + +NS_METHOD +SocketIORequestClosingRunnable::Run() +{ + MOZ_ASSERT(NS_IsMainThread()); + + SocketIOBase* io = SocketIORunnable::GetIO(); + + if (NS_WARN_IF(io->IsShutdownOnMainThread())) { + // Since we've already explicitly closed and the close + // happened before this, this isn't really an error. + return NS_OK; + } + + SocketBase* socketBase = io->GetSocketBase(); + MOZ_ASSERT(socketBase); + + socketBase->CloseSocket(); + + return NS_OK; +} + } } diff --git a/ipc/unixsocket/SocketBase.h b/ipc/unixsocket/SocketBase.h index ec234d809812..f4d23d856da0 100644 --- a/ipc/unixsocket/SocketBase.h +++ b/ipc/unixsocket/SocketBase.h @@ -394,34 +394,17 @@ private: SocketEvent mEvent; }; -template -class SocketIORequestClosingRunnable final : public SocketIORunnable +/** + * |SocketIORequestClosingRunnable| closes an instance of |SocketBase| + * to the main thread. + */ +class SocketIORequestClosingRunnable final + : public SocketIORunnable { public: - SocketIORequestClosingRunnable(T* aImpl) - : SocketIORunnable(aImpl) - { } + SocketIORequestClosingRunnable(SocketIOBase* aIO); - NS_IMETHOD Run() 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; - } - - SocketBase* base = io->GetSocketBase(); - MOZ_ASSERT(base); - - base->CloseSocket(); - - return NS_OK; - } + NS_IMETHOD Run() override; }; /* |SocketIODeleteInstanceRunnable| deletes an object on the main thread. diff --git a/ipc/unixsocket/StreamSocket.cpp b/ipc/unixsocket/StreamSocket.cpp index c8284f4c6da7..82e111421bd3 100644 --- a/ipc/unixsocket/StreamSocket.cpp +++ b/ipc/unixsocket/StreamSocket.cpp @@ -21,7 +21,7 @@ namespace ipc { class StreamSocketIO final : public UnixSocketWatcher - , protected DataSocketIO + , public DataSocketIO , public ConnectionOrientedSocketIO { public: