Bug 1159209: Remove template parameters from |SocketIOShutdownTask|, r=kmachulis
authorThomas Zimmermann <tdz@users.sourceforge.net>
Wed, 29 Apr 2015 11:19:28 +0200
changeset 273038 3d372dd3a14486cfaf163a0b2bc222614b30b7c2
parent 273037 a2fe03686c0d53e76f44647b06500b068f999e56
child 273039 4a53afc1acbf05e525c3da3b4d9cc7897cea2c3c
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmachulis
bugs1159209
milestone40.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 1159209: Remove template parameters from |SocketIOShutdownTask|, r=kmachulis This patch removes the template parameters from |SocketIOShutdownTask| and moves its methods into the C++ source file. All users have been adapted.
dom/bluetooth/bluedroid/BluetoothSocket.cpp
dom/bluetooth/bluez/BluetoothSocket.cpp
ipc/bluetooth/BluetoothDaemonConnection.cpp
ipc/unixsocket/ListenSocket.cpp
ipc/unixsocket/SocketBase.cpp
ipc/unixsocket/SocketBase.h
ipc/unixsocket/StreamSocket.cpp
--- a/dom/bluetooth/bluedroid/BluetoothSocket.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothSocket.cpp
@@ -92,29 +92,29 @@ public:
   }
 
   bool IsShutdownOnMainThread() const override
   {
     MOZ_ASSERT(NS_IsMainThread());
     return mConsumer == nullptr;
   }
 
-  bool IsShutdownOnIOThread() const
+  bool IsShutdownOnIOThread() const override
   {
     return mShuttingDownOnIOThread;
   }
 
-  void ShutdownOnMainThread()
+  void ShutdownOnMainThread() override
   {
     MOZ_ASSERT(NS_IsMainThread());
     MOZ_ASSERT(!IsShutdownOnMainThread());
     mConsumer = nullptr;
   }
 
-  void ShutdownOnIOThread()
+  void ShutdownOnIOThread() override
   {
     MOZ_ASSERT(!NS_IsMainThread());
     MOZ_ASSERT(!mShuttingDownOnIOThread);
 
     Close(); // will also remove fd from I/O loop
     mShuttingDownOnIOThread = true;
   }
 
@@ -720,18 +720,18 @@ BluetoothSocket::CloseSocket()
   if (mCurrentRes) {
     sBluetoothSocketInterface->Close(mCurrentRes);
   }
 
   // From this point on, we consider mImpl as being deleted.
   // We sever the relationship here so any future calls to listen or connect
   // will create a new implementation.
   mImpl->ShutdownOnMainThread();
-  XRE_GetIOMessageLoop()->PostTask(
-    FROM_HERE, new SocketIOShutdownTask<DroidSocketImpl>(mImpl));
+
+  XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mImpl));
 
   mImpl = nullptr;
 
   NotifyDisconnect();
 }
 
 void
 BluetoothSocket::SendSocketData(UnixSocketIOBuffer* aBuffer)
--- a/dom/bluetooth/bluez/BluetoothSocket.cpp
+++ b/dom/bluetooth/bluez/BluetoothSocket.cpp
@@ -39,20 +39,20 @@ public:
   BluetoothSocket* GetBluetoothSocket();
   DataSocket* GetDataSocket();
   SocketBase* GetSocketBase() override;
 
   // Shutdown state
   //
 
   bool IsShutdownOnMainThread() const override;
-  void ShutdownOnMainThread();
+  void ShutdownOnMainThread() override;
 
-  bool IsShutdownOnIOThread() const;
-  void ShutdownOnIOThread();
+  bool IsShutdownOnIOThread() const override;
+  void ShutdownOnIOThread() override;
 
   // Delayed-task handling
   //
 
   void SetDelayedConnectTask(CancelableTask* aTask);
   void ClearDelayedConnectTask();
   void CancelDelayedConnectTask();
 
@@ -751,18 +751,17 @@ BluetoothSocket::CloseSocket()
 
   mIO->CancelDelayedConnectTask();
 
   // From this point on, we consider mIO as being deleted.
   // We sever the relationship here so any future calls to listen or connect
   // will create a new implementation.
   mIO->ShutdownOnMainThread();
 
-  XRE_GetIOMessageLoop()->PostTask(
-    FROM_HERE, new SocketIOShutdownTask<BluetoothSocketIO>(mIO));
+  XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
 
   mIO = nullptr;
 
   NotifyDisconnect();
 }
 
 void
 BluetoothSocket::GetSocketAddr(nsAString& aAddrStr)
--- a/ipc/bluetooth/BluetoothDaemonConnection.cpp
+++ b/ipc/bluetooth/BluetoothDaemonConnection.cpp
@@ -556,18 +556,17 @@ BluetoothDaemonConnection::CloseSocket()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!mIO) {
     CHROMIUM_LOG("Bluetooth daemon already disconnected!");
     return;
   }
 
-  XRE_GetIOMessageLoop()->PostTask(
-    FROM_HERE, new SocketIOShutdownTask<BluetoothDaemonConnectionIO>(mIO));
+  XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
 
   mIO = nullptr;
 
   NotifyDisconnect();
 }
 
 nsresult
 BluetoothDaemonConnection::Send(BluetoothDaemonPDU* aPDU)
--- a/ipc/unixsocket/ListenSocket.cpp
+++ b/ipc/unixsocket/ListenSocket.cpp
@@ -34,20 +34,20 @@ public:
   void        GetSocketAddr(nsAString& aAddrStr) const;
   DataSocket* GetDataSocket();
   SocketBase* GetSocketBase() override;
 
   // Shutdown state
   //
 
   bool IsShutdownOnMainThread() const override;
-  void ShutdownOnMainThread();
+  void ShutdownOnMainThread() override;
 
-  bool IsShutdownOnIOThread() const;
-  void ShutdownOnIOThread();
+  bool IsShutdownOnIOThread() const override;
+  void ShutdownOnIOThread() override;
 
   // Task callback methods
   //
 
   /**
    * Run bind/listen to prepare for further runs of accept()
    */
   void Listen(ConnectionOrientedSocketIO* aCOSocketIO);
@@ -369,18 +369,17 @@ ListenSocket::Close()
     return;
   }
 
   // From this point on, we consider mIO as being deleted. We sever
   // the relationship here so any future calls to listen or connect
   // will create a new implementation.
   mIO->ShutdownOnMainThread();
 
-  XRE_GetIOMessageLoop()->PostTask(
-    FROM_HERE, new SocketIOShutdownTask<ListenSocketIO>(mIO));
+  XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
 
   mIO = nullptr;
 
   NotifyDisconnect();
 }
 
 bool
 ListenSocket::Listen(UnixSocketConnector* aConnector,
--- a/ipc/unixsocket/SocketBase.cpp
+++ b/ipc/unixsocket/SocketBase.cpp
@@ -357,10 +357,36 @@ SocketIODeleteInstanceRunnable::SocketIO
 NS_METHOD
 SocketIODeleteInstanceRunnable::Run()
 {
   mIO = nullptr; // delete instance
 
   return NS_OK;
 }
 
+//
+// SocketIOShutdownTask
+//
+
+SocketIOShutdownTask::SocketIOShutdownTask(SocketIOBase* aIO)
+  : SocketIOTask<SocketIOBase>(aIO)
+{ }
+
+void
+SocketIOShutdownTask::Run()
+{
+  MOZ_ASSERT(!NS_IsMainThread());
+
+  SocketIOBase* io = SocketIOTask<SocketIOBase>::GetIO();
+
+  // At this point, there should be no new events on the I/O thread
+  // after this one with the possible exception of an accept task,
+  // which ShutdownOnIOThread will cancel for us. We are now fully
+  // shut down, so we can send a message to the main thread to delete
+  // |io| safely knowing that it's not reference any longer.
+  MOZ_ASSERT(!io->IsShutdownOnIOThread());
+  io->ShutdownOnIOThread();
+
+  NS_DispatchToMainThread(new SocketIODeleteInstanceRunnable(io));
+}
+
 }
 }
--- a/ipc/unixsocket/SocketBase.h
+++ b/ipc/unixsocket/SocketBase.h
@@ -327,23 +327,42 @@ public:
    * Implemented by socket I/O classes to return the current instance of
    * |SocketBase|.
    *
    * @return The current instance of |SocketBase|
    */
   virtual SocketBase* GetSocketBase() = 0;
 
   /**
+   * Implemented by socket I/O classes to signal that the socket I/O class has
+   * been shut down.
+   *
+   * @return True if the socket I/O class has been shut down, false otherwise.
+   */
+  virtual bool IsShutdownOnIOThread() const = 0;
+
+  /**
    * Implemented by socket I/O classes to signal that socket class has
    * been shut down.
    *
    * @return True if the socket class has been shut down, false otherwise.
    */
   virtual bool IsShutdownOnMainThread() const = 0;
 
+  /**
+   * Signals to the socket I/O classes that it has been shut down.
+   */
+  virtual void ShutdownOnIOThread() = 0;
+
+  /**
+   * Signals to the socket I/O classes that the socket class has been
+   * shut down.
+   */
+  virtual void ShutdownOnMainThread() = 0;
+
 protected:
   SocketIOBase();
 };
 
 //
 // Socket I/O runnables
 //
 
@@ -447,49 +466,33 @@ public:
 
   bool IsCanceled() const
   {
     return !mIO;
   }
 
 protected:
   SocketIOTask(Tio* aIO)
-  : mIO(aIO)
+    : mIO(aIO)
   {
     MOZ_ASSERT(mIO);
   }
 
 private:
   Tio* mIO;
 };
 
-/* |SocketIOShutdownTask| signals shutdown to the Socket I/O object on
+/**
+ * |SocketIOShutdownTask| signals shutdown to the socket I/O class on
  * the I/O thread and sends it to the main thread for destruction.
  */
-template<typename Tio>
-class SocketIOShutdownTask final : public SocketIOTask<Tio>
+class SocketIOShutdownTask final : public SocketIOTask<SocketIOBase>
 {
 public:
-  SocketIOShutdownTask(Tio* aIO)
-  : SocketIOTask<Tio>(aIO)
-  { }
-
-  void Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread());
-
-    Tio* io = SocketIOTask<Tio>::GetIO();
+  SocketIOShutdownTask(SocketIOBase* aIO);
 
-    // At this point, there should be no new events on the I/O thread
-    // after this one with the possible exception of an accept task,
-    // which ShutdownOnIOThread will cancel for us. We are now fully
-    // shut down, so we can send a message to the main thread to delete
-    // |io| safely knowing that it's not reference any longer.
-    io->ShutdownOnIOThread();
-
-    NS_DispatchToMainThread(new SocketIODeleteInstanceRunnable(io));
-  }
+  void Run() override;
 };
 
 }
 }
 
 #endif
--- a/ipc/unixsocket/StreamSocket.cpp
+++ b/ipc/unixsocket/StreamSocket.cpp
@@ -51,20 +51,20 @@ public:
 
   nsresult Accept(int aFd,
                   const union sockaddr_any* aAddr, socklen_t aAddrLen);
 
   // Shutdown state
   //
 
   bool IsShutdownOnMainThread() const override;
-  void ShutdownOnMainThread();
+  void ShutdownOnMainThread() override;
 
-  bool IsShutdownOnIOThread() const;
-  void ShutdownOnIOThread();
+  bool IsShutdownOnIOThread() const override;
+  void ShutdownOnIOThread() override;
 
   // Delayed-task handling
   //
 
   void SetDelayedConnectTask(CancelableTask* aTask);
   void ClearDelayedConnectTask();
   void CancelDelayedConnectTask();
 
@@ -664,18 +664,17 @@ StreamSocket::Close()
 
   mIO->CancelDelayedConnectTask();
 
   // From this point on, we consider mIO as being deleted.
   // We sever the relationship here so any future calls to listen or connect
   // will create a new implementation.
   mIO->ShutdownOnMainThread();
 
-  XRE_GetIOMessageLoop()->PostTask(
-    FROM_HERE, new SocketIOShutdownTask<StreamSocketIO>(mIO));
+  XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
 
   mIO = nullptr;
 
   NotifyDisconnect();
 }
 
 void
 StreamSocket::GetSocketAddr(nsAString& aAddrStr)