Bug 1166638: Use |ListenSocketConsumer| in |ListenSocket|, r=kmachulis, dlee, chucklee, shuang
authorThomas Zimmermann <tdz@users.sourceforge.net>
Tue, 26 May 2015 13:24:20 +0200
changeset 245623 0e6c6674c6d33741d6048bb1c8a255c92809be4c
parent 245622 bc78f6fc3df51db8fc0119df798282eddd0c1ef1
child 245624 6296370a3b754ec909f520fc9403cc548d611e80
push id13177
push userkwierso@gmail.com
push dateTue, 26 May 2015 23:26:28 +0000
treeherderfx-team@b991cd5a0ad1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmachulis, dlee, chucklee, shuang
bugs1166638
milestone41.0a1
Bug 1166638: Use |ListenSocketConsumer| in |ListenSocket|, r=kmachulis, dlee, chucklee, shuang This patch converts |ListenSocket| to forward events to an instance of |ListenSocketConsumer|. All users are converted and the related listener and consumer classes are removed.
dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonInterface.h
dom/nfc/gonk/NfcService.cpp
dom/nfc/gonk/NfcService.h
ipc/keystore/KeyStore.cpp
ipc/keystore/KeyStore.h
ipc/nfc/Nfc.cpp
ipc/nfc/Nfc.h
ipc/nfc/moz.build
ipc/unixsocket/ListenSocket.cpp
ipc/unixsocket/ListenSocket.h
--- a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
@@ -1620,68 +1620,16 @@ BluetoothDaemonProtocol::FetchUserData(c
 
   void* userData = mUserDataQ.ElementAt(0);
   mUserDataQ.RemoveElementAt(0);
 
   return userData;
 }
 
 //
-// Listen socket
-//
-
-class BluetoothDaemonListenSocket final : public ipc::ListenSocket
-{
-public:
-  BluetoothDaemonListenSocket(BluetoothDaemonInterface* aInterface);
-
-  // Connection state
-  //
-
-  void OnConnectSuccess() override;
-  void OnConnectError() override;
-  void OnDisconnect() override;
-
-private:
-  BluetoothDaemonInterface* mInterface;
-};
-
-BluetoothDaemonListenSocket::BluetoothDaemonListenSocket(
-  BluetoothDaemonInterface* aInterface)
-  : mInterface(aInterface)
-{ }
-
-void
-BluetoothDaemonListenSocket::OnConnectSuccess()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(mInterface);
-
-  mInterface->OnConnectSuccess(BluetoothDaemonInterface::LISTEN_SOCKET);
-}
-
-void
-BluetoothDaemonListenSocket::OnConnectError()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(mInterface);
-
-  mInterface->OnConnectError(BluetoothDaemonInterface::LISTEN_SOCKET);
-}
-
-void
-BluetoothDaemonListenSocket::OnDisconnect()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(mInterface);
-
-  mInterface->OnDisconnect(BluetoothDaemonInterface::LISTEN_SOCKET);
-}
-
-//
 // Channels
 //
 
 class BluetoothDaemonChannel final : public BluetoothDaemonConnection
 {
 public:
   BluetoothDaemonChannel(BluetoothDaemonInterface* aInterface,
                          BluetoothDaemonInterface::Channel aChannel,
@@ -2093,17 +2041,17 @@ BluetoothDaemonInterface::Init(
 
   mResultHandlerQ.AppendElement(aRes);
 
   if (!mProtocol) {
     mProtocol = new BluetoothDaemonProtocol();
   }
 
   if (!mListenSocket) {
-    mListenSocket = new BluetoothDaemonListenSocket(this);
+    mListenSocket = new ListenSocket(this, LISTEN_SOCKET);
   }
 
   // Init, step 1: Listen for command channel... */
 
   if (!mCmdChannel) {
     mCmdChannel = new BluetoothDaemonChannel(this, CMD_CHANNEL, mProtocol);
   } else if (
     NS_WARN_IF(mCmdChannel->GetConnectionStatus() == SOCKET_CONNECTED)) {
@@ -2551,9 +2499,30 @@ BluetoothDaemonInterface::GetBluetoothAv
 }
 
 BluetoothGattInterface*
 BluetoothDaemonInterface::GetBluetoothGattInterface()
 {
   return nullptr;
 }
 
+// Methods for |ListenSocketConsumer|
+//
+
+void
+BluetoothDaemonInterface::OnConnectSuccess(int aIndex)
+{
+  OnConnectSuccess(static_cast<enum Channel>(aIndex));
+}
+
+void
+BluetoothDaemonInterface::OnConnectError(int aIndex)
+{
+  OnConnectError(static_cast<enum Channel>(aIndex));
+}
+
+void
+BluetoothDaemonInterface::OnDisconnect(int aIndex)
+{
+  OnDisconnect(static_cast<enum Channel>(aIndex));
+}
+
 END_BLUETOOTH_NAMESPACE
--- a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.h
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonInterface.h
@@ -3,28 +3,38 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_bluetooth_bluedroid_bluetoothdaemoninterface_h__
 #define mozilla_dom_bluetooth_bluedroid_bluetoothdaemoninterface_h__
 
 #include "BluetoothInterface.h"
+#include "mozilla/ipc/ListenSocketConsumer.h"
+
+namespace mozilla {
+namespace ipc {
+
+class ListenSocket;
+
+}
+}
 
 BEGIN_BLUETOOTH_NAMESPACE
 
-class BluetoothDaemonListenSocket;
 class BluetoothDaemonChannel;
 class BluetoothDaemonA2dpInterface;
 class BluetoothDaemonAvrcpInterface;
 class BluetoothDaemonHandsfreeInterface;
 class BluetoothDaemonProtocol;
 class BluetoothDaemonSocketInterface;
 
-class BluetoothDaemonInterface final : public BluetoothInterface
+class BluetoothDaemonInterface final
+  : public BluetoothInterface
+  , public mozilla::ipc::ListenSocketConsumer
 {
 public:
   class CleanupResultHandler;
   class InitResultHandler;
   class StartDaemonTask;
 
   friend class BluetoothDaemonListenSocket;
   friend class BluetoothDaemonChannel;
@@ -131,22 +141,29 @@ protected:
   void OnConnectSuccess(enum Channel aChannel);
   void OnConnectError(enum Channel aChannel);
   void OnDisconnect(enum Channel aChannel);
 
   nsresult CreateRandomAddressString(const nsACString& aPrefix,
                                      unsigned long aPostfixLength,
                                      nsACString& aAddress);
 
+  // Methods for |ListenSocketConsumer|
+  //
+
+  void OnConnectSuccess(int aIndex) override;
+  void OnConnectError(int aIndex) override;
+  void OnDisconnect(int aIndex) override;
+
 private:
   void DispatchError(BluetoothResultHandler* aRes, BluetoothStatus aStatus);
   void DispatchError(BluetoothResultHandler* aRes, nsresult aRv);
 
   nsCString mListenSocketName;
-  nsRefPtr<BluetoothDaemonListenSocket> mListenSocket;
+  nsRefPtr<mozilla::ipc::ListenSocket> mListenSocket;
   nsRefPtr<BluetoothDaemonChannel> mCmdChannel;
   nsRefPtr<BluetoothDaemonChannel> mNtfChannel;
   nsAutoPtr<BluetoothDaemonProtocol> mProtocol;
 
   nsTArray<nsRefPtr<BluetoothResultHandler> > mResultHandlerQ;
 
   nsAutoPtr<BluetoothDaemonSocketInterface> mSocketInterface;
   nsAutoPtr<BluetoothDaemonHandsfreeInterface> mHandsfreeInterface;
--- a/dom/nfc/gonk/NfcService.cpp
+++ b/dom/nfc/gonk/NfcService.cpp
@@ -336,21 +336,21 @@ NfcService::Start(nsINfcGonkEventListene
 
   // If we could not cleanup properly before and an old
   // instance of the daemon is still running, we kill it
   // here.
   unused << NS_WARN_IF(property_set("ctl.stop", "nfcd") < 0);
 
   mListener = aListener;
   mHandler = new NfcMessageHandler();
-  mStreamSocket = new StreamSocket(this, NfcSocketListener::STREAM_SOCKET);
+  mStreamSocket = new StreamSocket(this, STREAM_SOCKET);
 
   mListenSocketName = BASE_SOCKET_NAME;
 
-  mListenSocket = new NfcListenSocket(this);
+  mListenSocket = new ListenSocket(this, LISTEN_SOCKET);
   nsresult rv = mListenSocket->Listen(new NfcConnector(mListenSocketName),
                                       mStreamSocket);
   if (NS_FAILED(rv)) {
     mStreamSocket = nullptr;
     return rv;
   }
 
   rv = NS_NewNamedThread("NfcThread", getter_AddRefs(mThread));
@@ -426,86 +426,62 @@ NfcService::DispatchNfcEvent(const mozil
 
   if (!ToJSValue(cx, aOptions, &val)) {
     return;
   }
 
   mListener->OnEvent(val);
 }
 
+// |StreamSocketConsumer|, |ListenSocketConsumer|
+
 void
-NfcService::ReceiveSocketData(nsAutoPtr<UnixSocketBuffer>& aBuffer)
+NfcService::ReceiveSocketData(
+  int aIndex, nsAutoPtr<mozilla::ipc::UnixSocketBuffer>& aBuffer)
 {
   MOZ_ASSERT(mHandler);
   nsCOMPtr<nsIRunnable> runnable =
     new NfcEventRunnable(mHandler, aBuffer.forget());
   mThread->Dispatch(runnable, nsIEventTarget::DISPATCH_NORMAL);
 }
 
 void
-NfcService::OnConnectSuccess(enum SocketType aSocketType)
+NfcService::OnConnectSuccess(int aIndex)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  switch (aSocketType) {
+  switch (aIndex) {
     case LISTEN_SOCKET: {
         nsCString value("nfcd:-a ");
         value.Append(mListenSocketName);
         if (NS_WARN_IF(property_set("ctl.start", value.get()) < 0)) {
           OnConnectError(STREAM_SOCKET);
         }
       }
       break;
     case STREAM_SOCKET:
       /* nothing to do */
       break;
   }
 }
 
 void
-NfcService::OnConnectError(enum SocketType aSocketType)
+NfcService::OnConnectError(int aIndex)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   Shutdown();
 }
 
 void
-NfcService::OnDisconnect(enum SocketType aSocketType)
+NfcService::OnDisconnect(int aIndex)
 {
   MOZ_ASSERT(NS_IsMainThread());
 }
 
-// |StreamSocketConsumer|
-
-void
-NfcService::ReceiveSocketData(
-  int aIndex, nsAutoPtr<mozilla::ipc::UnixSocketBuffer>& aBuffer)
-{
-  ReceiveSocketData(aBuffer);
-}
-
-void
-NfcService::OnConnectSuccess(int aIndex)
-{
-  OnConnectSuccess(static_cast<enum SocketType>(aIndex));
-}
-
-void
-NfcService::OnConnectError(int aIndex)
-{
-  OnConnectSuccess(static_cast<enum SocketType>(aIndex));
-}
-
-void
-NfcService::OnDisconnect(int aIndex)
-{
-  OnConnectSuccess(static_cast<enum SocketType>(aIndex));
-}
-
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(NfcService,
                                          NfcService::FactoryCreate)
 
 NS_DEFINE_NAMED_CID(NS_NFCSERVICE_CID);
 
 static const mozilla::Module::CIDEntry kNfcServiceCIDs[] = {
   { &kNS_NFCSERVICE_CID, false, nullptr, NfcServiceConstructor },
   { nullptr }
--- a/dom/nfc/gonk/NfcService.h
+++ b/dom/nfc/gonk/NfcService.h
@@ -2,72 +2,71 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef NfcService_h
 #define NfcService_h
 
-#include "mozilla/ipc/Nfc.h"
-#include "mozilla/ipc/SocketBase.h"
+#include <mozilla/ipc/ListenSocket.h>
+#include "mozilla/ipc/ListenSocketConsumer.h"
+#include <mozilla/ipc/StreamSocket.h>
 #include "mozilla/ipc/StreamSocketConsumer.h"
 #include "nsCOMPtr.h"
 #include "nsINfcService.h"
 #include "NfcMessageHandler.h"
 
 class nsIThread;
 
 namespace mozilla {
 namespace dom {
 class NfcEventOptions;
 } // namespace dom
 
 class NfcService final
   : public nsINfcService
   , public mozilla::ipc::StreamSocketConsumer
-  , public mozilla::ipc::NfcSocketListener
+  , public mozilla::ipc::ListenSocketConsumer
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSINFCSERVICE
 
   static already_AddRefed<NfcService> FactoryCreate();
 
   void DispatchNfcEvent(const mozilla::dom::NfcEventOptions& aOptions);
 
   bool PostToNfcDaemon(const uint8_t* aData, size_t aSize);
 
-  virtual void ReceiveSocketData(
-    nsAutoPtr<mozilla::ipc::UnixSocketBuffer>& aBuffer) override;
-
-  virtual void OnConnectSuccess(enum SocketType aSocketType) override;
-  virtual void OnConnectError(enum SocketType aSocketType) override;
-  virtual void OnDisconnect(enum SocketType aSocketType) override;
-
   nsCOMPtr<nsIThread> GetThread() {
     return mThread;
   }
 
-  // Methods for |StreamSocketConsumer|
+  // Methods for |StreamSocketConsumer| and |ListenSocketConsumer|
   //
 
   void ReceiveSocketData(
     int aIndex, nsAutoPtr<mozilla::ipc::UnixSocketBuffer>& aBuffer) override;
   void OnConnectSuccess(int aIndex) override;
   void OnConnectError(int aIndex) override;
   void OnDisconnect(int aIndex) override;
 
 private:
+  enum SocketType {
+    LISTEN_SOCKET,
+    STREAM_SOCKET
+  };
+
   NfcService();
   ~NfcService();
 
   nsCOMPtr<nsIThread> mThread;
   nsCOMPtr<nsINfcGonkEventListener> mListener;
-  nsRefPtr<mozilla::ipc::NfcListenSocket> mListenSocket;
+  nsRefPtr<mozilla::ipc::ListenSocket> mListenSocket;
   nsRefPtr<mozilla::ipc::StreamSocket> mStreamSocket;
   nsAutoPtr<NfcMessageHandler> mHandler;
   nsCString mListenSocketName;
 };
 
 } // namespace mozilla
 
 #endif // NfcService_h
--- a/ipc/keystore/KeyStore.cpp
+++ b/ipc/keystore/KeyStore.cpp
@@ -668,48 +668,16 @@ checkPermission(uid_t uid)
       return true;
     }
   }
 
   return false;
 }
 
 //
-// KeyStore::ListenSocket
-//
-
-KeyStore::ListenSocket::ListenSocket(KeyStore* aKeyStore)
-: mKeyStore(aKeyStore)
-{
-  MOZ_ASSERT(mKeyStore);
-
-  MOZ_COUNT_CTOR(KeyStore::ListenSocket);
-}
-
-void
-KeyStore::ListenSocket::OnConnectSuccess()
-{
-  mKeyStore->OnConnectSuccess(LISTEN_SOCKET);
-
-  MOZ_COUNT_DTOR(KeyStore::ListenSocket);
-}
-
-void
-KeyStore::ListenSocket::OnConnectError()
-{
-  mKeyStore->OnConnectError(LISTEN_SOCKET);
-}
-
-void
-KeyStore::ListenSocket::OnDisconnect()
-{
-  mKeyStore->OnDisconnect(LISTEN_SOCKET);
-}
-
-//
 // KeyStore
 //
 
 KeyStore::KeyStore()
 : mShutdown(false)
 {
   MOZ_COUNT_CTOR(KeyStore);
   ::startKeyStoreService();
@@ -754,17 +722,17 @@ KeyStore::Listen()
   if (mStreamSocket) {
     mStreamSocket->Close();
   } else {
     mStreamSocket = new StreamSocket(this, STREAM_SOCKET);
   }
 
   if (!mListenSocket) {
     // We only ever allocate one |ListenSocket|...
-    mListenSocket = new ListenSocket(this);
+    mListenSocket = new ListenSocket(this, LISTEN_SOCKET);
     mListenSocket->Listen(new KeyStoreConnector(KEYSTORE_ALLOWED_USERS),
                           mStreamSocket);
   } else {
     // ... but keep it open.
     mListenSocket->Listen(mStreamSocket);
   }
 
   ResetHandlerInfo();
@@ -906,18 +874,20 @@ KeyStore::SendData(const uint8_t *aData,
 
   UnixSocketRawData* length = new UnixSocketRawData((const void *)&dataLength, 2);
   mStreamSocket->SendSocketData(length);
 
   UnixSocketRawData* data = new UnixSocketRawData((const void *)aData, aLength);
   mStreamSocket->SendSocketData(data);
 }
 
+// |StreamSocketConsumer|, |ListenSocketConsumer|
+
 void
-KeyStore::ReceiveSocketData(nsAutoPtr<UnixSocketBuffer>& aMessage)
+KeyStore::ReceiveSocketData(int aIndex, nsAutoPtr<UnixSocketBuffer>& aMessage)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // Handle request.
   ResponseCode result = SUCCESS;
   while (aMessage->GetSize() ||
          mHandlerInfo.state == STATE_PROCESSING) {
     switch (mHandlerInfo.state) {
@@ -967,76 +937,50 @@ KeyStore::ReceiveSocketData(nsAutoPtr<Un
       SendResponse(result);
       ResetHandlerInfo();
       return;
     }
   }
 }
 
 void
-KeyStore::OnConnectSuccess(SocketType aSocketType)
+KeyStore::OnConnectSuccess(int aIndex)
 {
-  if (aSocketType == STREAM_SOCKET) {
+  if (aIndex == STREAM_SOCKET) {
     mShutdown = false;
   }
 }
 
 void
-KeyStore::OnConnectError(SocketType aSocketType)
+KeyStore::OnConnectError(int aIndex)
 {
   if (mShutdown) {
     return;
   }
 
-  if (aSocketType == STREAM_SOCKET) {
+  if (aIndex == STREAM_SOCKET) {
     // Stream socket error; start listening again
     Listen();
   }
 }
 
 void
-KeyStore::OnDisconnect(SocketType aSocketType)
+KeyStore::OnDisconnect(int aIndex)
 {
   if (mShutdown) {
     return;
   }
 
-  switch (aSocketType) {
+  switch (aIndex) {
     case LISTEN_SOCKET:
       // Listen socket disconnected; start anew.
       mListenSocket = nullptr;
       Listen();
       break;
     case STREAM_SOCKET:
       // Stream socket disconnected; start listening again.
       Listen();
       break;
   }
 }
 
-// |StreamSocketConsumer|
-
-void
-KeyStore::ReceiveSocketData(int aIndex, nsAutoPtr<UnixSocketBuffer>& aMessage)
-{
-  ReceiveSocketData(aMessage);
-}
-
-void
-KeyStore::OnConnectSuccess(int aIndex)
-{
-  OnConnectSuccess(static_cast<SocketType>(aIndex));
-}
-
-void
-KeyStore::OnConnectError(int aIndex)
-{
-  OnConnectError(static_cast<SocketType>(aIndex));
-}
-
-void
-KeyStore::OnDisconnect(int aIndex)
-{
-  OnDisconnect(static_cast<SocketType>(aIndex));
-}
-
 } // namespace ipc
 } // namespace mozilla
--- a/ipc/keystore/KeyStore.h
+++ b/ipc/keystore/KeyStore.h
@@ -6,16 +6,17 @@
 
 #ifndef mozilla_ipc_KeyStore_h
 #define mozilla_ipc_KeyStore_h 1
 
 #include <sys/socket.h>
 #include <sys/un.h>
 #include "cert.h"
 #include "mozilla/ipc/ListenSocket.h"
+#include "mozilla/ipc/ListenSocketConsumer.h"
 #include "mozilla/ipc/StreamSocket.h"
 #include "mozilla/ipc/StreamSocketConsumer.h"
 #include "nsNSSShutDown.h"
 
 namespace mozilla {
 namespace ipc {
 
 enum ResponseCode {
@@ -76,16 +77,17 @@ typedef enum {
   STATE_IDLE,
   STATE_READ_PARAM_LEN,
   STATE_READ_PARAM_DATA,
   STATE_PROCESSING
 } ProtocolHandlerState;
 
 class KeyStore final
   : public StreamSocketConsumer
+  , public ListenSocketConsumer
   , public nsNSSShutDownObject
 {
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(KeyStore)
 
   KeyStore();
 
   void Shutdown();
@@ -94,41 +96,18 @@ protected:
   virtual void virtualDestroyNSSReference() {}
 
 private:
   enum SocketType {
     LISTEN_SOCKET,
     STREAM_SOCKET
   };
 
-  class ListenSocket final : public mozilla::ipc::ListenSocket
-  {
-  public:
-    ListenSocket(KeyStore* aKeyStore);
-    ListenSocket();
-
-    // SocketBase
-    //
-
-    void OnConnectSuccess() override;
-    void OnConnectError() override;
-    void OnDisconnect() override;
-
-  private:
-    KeyStore* mKeyStore;
-  };
-
   ~KeyStore();
 
-  void ReceiveSocketData(nsAutoPtr<UnixSocketBuffer>& aMessage);
-
-  void OnConnectSuccess(enum SocketType aSocketType);
-  void OnConnectError(enum SocketType aSocketType);
-  void OnDisconnect(enum SocketType aSocketType);
-
   struct {
     ProtocolHandlerState          state;
     uint8_t                       command;
     struct ProtocolParam          param[MAX_PARAM];
     int                           paramCount;
     const struct ProtocolCommand  *commandPattern;
   } mHandlerInfo;
   void ResetHandlerInfo();
deleted file mode 100644
--- a/ipc/nfc/Nfc.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* vim: set sw=2 ts=8 et ft=cpp: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/* Copyright © 2013, Deutsche Telekom, Inc. */
-
-#include "mozilla/ipc/Nfc.h"
-
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-
-#undef CHROMIUM_LOG
-#if (defined(MOZ_WIDGET_GONK) && defined(DEBUG))
-#include <android/log.h>
-#define CHROMIUM_LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "Gonk", args)
-#else
-#define CHROMIUM_LOG(args...)
-#endif
-
-#include "jsfriendapi.h"
-#include "mozilla/ArrayUtils.h"
-#include "mozilla/ipc/NfcConnector.h"
-#include "nsThreadUtils.h" // For NS_IsMainThread.
-
-using namespace mozilla::ipc;
-
-namespace mozilla {
-namespace ipc {
-
-//
-// NfcListenSocket
-//
-
-NfcListenSocket::NfcListenSocket(NfcSocketListener* aListener)
-  : mListener(aListener)
-{ }
-
-void
-NfcListenSocket::OnConnectSuccess()
-{
-  if (mListener) {
-    mListener->OnConnectSuccess(NfcSocketListener::LISTEN_SOCKET);
-  }
-}
-
-void
-NfcListenSocket::OnConnectError()
-{
-  if (mListener) {
-    mListener->OnConnectError(NfcSocketListener::LISTEN_SOCKET);
-  }
-}
-
-void
-NfcListenSocket::OnDisconnect()
-{
-  if (mListener) {
-    mListener->OnDisconnect(NfcSocketListener::LISTEN_SOCKET);
-  }
-}
-
-} // namespace ipc
-} // namespace mozilla
deleted file mode 100644
--- a/ipc/nfc/Nfc.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set sw=2 ts=8 et ft=cpp: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/* Copyright © 2013, Deutsche Telekom, Inc. */
-
-#ifndef mozilla_ipc_Nfc_h
-#define mozilla_ipc_Nfc_h 1
-
-#include <mozilla/ipc/ListenSocket.h>
-#include <mozilla/ipc/StreamSocket.h>
-
-namespace mozilla {
-namespace ipc {
-
-class NfcSocketListener
-{
-public:
-  enum SocketType {
-    LISTEN_SOCKET,
-    STREAM_SOCKET
-  };
-
-  virtual void ReceiveSocketData(nsAutoPtr<UnixSocketBuffer>& aData) = 0;
-
-  virtual void OnConnectSuccess(enum SocketType aSocketType) = 0;
-  virtual void OnConnectError(enum SocketType aSocketType) = 0;
-  virtual void OnDisconnect(enum SocketType aSocketType) = 0;
-};
-
-class NfcListenSocket final : public mozilla::ipc::ListenSocket
-{
-public:
-  NfcListenSocket(NfcSocketListener* aListener);
-
-  void OnConnectSuccess() override;
-  void OnConnectError() override;
-  void OnDisconnect() override;
-
-private:
-  NfcSocketListener* mListener;
-};
-
-} // namespace ipc
-} // namepsace mozilla
-
-#endif // mozilla_ipc_Nfc_h
--- a/ipc/nfc/moz.build
+++ b/ipc/nfc/moz.build
@@ -1,20 +1,18 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 if CONFIG['MOZ_NFC']:
     EXPORTS.mozilla.ipc += [
-        'Nfc.h',
         'NfcConnector.h',
     ]
     SOURCES += [
-        'Nfc.cpp',
         'NfcConnector.cpp',
     ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
 FAIL_ON_WARNINGS = True
--- a/ipc/unixsocket/ListenSocket.cpp
+++ b/ipc/unixsocket/ListenSocket.cpp
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ListenSocket.h"
 #include <fcntl.h>
 #include "ConnectionOrientedSocket.h"
 #include "DataSocket.h"
+#include "ListenSocketConsumer.h"
 #include "mozilla/RefPtr.h"
 #include "nsXULAppAPI.h"
 #include "UnixSocketConnector.h"
 
 namespace mozilla {
 namespace ipc {
 
 //
@@ -286,19 +287,23 @@ public:
 private:
   ConnectionOrientedSocketIO* mCOSocketIO;
 };
 
 //
 // UnixSocketConsumer
 //
 
-ListenSocket::ListenSocket()
-: mIO(nullptr)
-{ }
+ListenSocket::ListenSocket(ListenSocketConsumer* aConsumer, int aIndex)
+  : mConsumer(aConsumer)
+  , mIndex(aIndex)
+  , mIO(nullptr)
+{
+  MOZ_ASSERT(mConsumer);
+}
 
 ListenSocket::~ListenSocket()
 {
   MOZ_ASSERT(!mIO);
 }
 
 nsresult
 ListenSocket::Listen(UnixSocketConnector* aConnector,
@@ -371,10 +376,34 @@ ListenSocket::Close()
 
   XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
 
   mIO = nullptr;
 
   NotifyDisconnect();
 }
 
+void
+ListenSocket::OnConnectSuccess()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  mConsumer->OnConnectSuccess(mIndex);
+}
+
+void
+ListenSocket::OnConnectError()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  mConsumer->OnConnectError(mIndex);
+}
+
+void
+ListenSocket::OnDisconnect()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  mConsumer->OnDisconnect(mIndex);
+}
+
 } // namespace ipc
 } // namespace mozilla
--- a/ipc/unixsocket/ListenSocket.h
+++ b/ipc/unixsocket/ListenSocket.h
@@ -9,26 +9,27 @@
 
 #include "nsString.h"
 #include "mozilla/ipc/SocketBase.h"
 
 namespace mozilla {
 namespace ipc {
 
 class ConnectionOrientedSocket;
+class ListenSocketConsumer;
 class ListenSocketIO;
 class UnixSocketConnector;
 
-class ListenSocket : public SocketBase
+class ListenSocket final : public SocketBase
 {
 protected:
   virtual ~ListenSocket();
 
 public:
-  ListenSocket();
+  ListenSocket(ListenSocketConsumer* aConsumer, int aIndex);
 
   /**
    * Starts a task on the socket that will try to accept a new connection
    * in a non-blocking manner.
    *
    * @param aConnector Connector object for socket-type-specific functions
    * @param aCOSocket The connection-oriented socket for handling the
    *                  accepted connection.
@@ -47,17 +48,22 @@ public:
    * @return NS_OK on success, or an XPCOM error code otherwise.
    */
   nsresult Listen(ConnectionOrientedSocket* aCOSocket);
 
   // Methods for |SocketBase|
   //
 
   void Close() override;
+  void OnConnectSuccess() override;
+  void OnConnectError() override;
+  void OnDisconnect() override;
 
 private:
+  ListenSocketConsumer* mConsumer;
+  int mIndex;
   ListenSocketIO* mIO;
 };
 
 } // namespace ipc
 } // namepsace mozilla
 
 #endif // mozilla_ipc_listensocket_h