Bug 1109592 - Forward socket state from |NfcSocketListener|. r=allstars.chh
authorThomas Zimmermann <tdz@users.sourceforge.net>
Mon, 09 Mar 2015 03:27:00 -0400
changeset 233508 226052175769bb2d401835741e45f10cf11bbed4
parent 233507 6c311023dcabbea2d89401f9a11dce3c1e4e8fd0
child 233509 fb83f94efd3ce55ccc52c7d045f50338927f4ff4
push id28414
push userryanvm@gmail.com
push dateFri, 13 Mar 2015 16:15:53 +0000
treeherdermozilla-central@1722c4635fac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersallstars.chh
bugs1109592
milestone39.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 1109592 - Forward socket state from |NfcSocketListener|. r=allstars.chh This patch allows to handle changes to the socket state at a higher level than |NfcSocketListener|.
dom/nfc/gonk/NfcService.cpp
dom/nfc/gonk/NfcService.h
ipc/nfc/Nfc.cpp
ipc/nfc/Nfc.h
--- a/dom/nfc/gonk/NfcService.cpp
+++ b/dom/nfc/gonk/NfcService.cpp
@@ -366,16 +366,34 @@ NfcService::DispatchNfcEvent(const mozil
 void
 NfcService::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aData)
 {
   MOZ_ASSERT(mHandler);
   nsCOMPtr<nsIRunnable> runnable = new NfcEventRunnable(mHandler, aData.forget());
   mThread->Dispatch(runnable, nsIEventTarget::DISPATCH_NORMAL);
 }
 
+void
+NfcService::OnConnectSuccess(enum SocketType aSocketType)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+}
+
+void
+NfcService::OnConnectError(enum SocketType aSocketType)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+}
+
+void
+NfcService::OnDisconnect(enum SocketType aSocketType)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+}
+
 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
@@ -24,18 +24,22 @@ class NfcService MOZ_FINAL : public nsIN
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSINFCSERVICE
 
   static already_AddRefed<NfcService> FactoryCreate();
 
   void DispatchNfcEvent(const mozilla::dom::NfcEventOptions& aOptions);
 
-  virtual void
-  ReceiveSocketData(nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aData) MOZ_OVERRIDE;
+  virtual void ReceiveSocketData(
+    nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aData) MOZ_OVERRIDE;
+
+  virtual void OnConnectSuccess(enum SocketType aSocketType) MOZ_OVERRIDE;
+  virtual void OnConnectError(enum SocketType aSocketType) MOZ_OVERRIDE;
+  virtual void OnDisconnect(enum SocketType aSocketType) MOZ_OVERRIDE;
 
   nsCOMPtr<nsIThread> GetThread() {
     return mThread;
   }
 
 private:
   NfcService();
   ~NfcService();
--- a/ipc/nfc/Nfc.cpp
+++ b/ipc/nfc/Nfc.cpp
@@ -204,31 +204,44 @@ NfcConsumer::ReceiveSocketData(nsAutoPtr
   if (mListener) {
     mListener->ReceiveSocketData(aData);
   }
 }
 
 void
 NfcConsumer::OnConnectSuccess()
 {
+  CHROMIUM_LOG("NFC: %s\n", __FUNCTION__);
+
+  if (mListener) {
+    mListener->OnConnectSuccess(NfcSocketListener::STREAM_SOCKET);
+  }
   // Nothing to do here.
-  CHROMIUM_LOG("NFC: %s\n", __FUNCTION__);
 }
 
 void
 NfcConsumer::OnConnectError()
 {
   CHROMIUM_LOG("NFC: %s\n", __FUNCTION__);
+
+  if (mListener) {
+    mListener->OnConnectError(NfcSocketListener::STREAM_SOCKET);
+  }
+
   Close();
 }
 
 void
 NfcConsumer::OnDisconnect()
 {
   CHROMIUM_LOG("NFC: %s\n", __FUNCTION__);
+
+  if (mListener) {
+    mListener->OnDisconnect(NfcSocketListener::STREAM_SOCKET);
+  }
   if (!mShutdown) {
     Connect(new NfcConnector(), mAddress.get(), GetSuggestedConnectDelayMs());
   }
 }
 
 ConnectionOrientedSocketIO*
 NfcConsumer::GetIO()
 {
--- a/ipc/nfc/Nfc.h
+++ b/ipc/nfc/Nfc.h
@@ -12,17 +12,25 @@
 #include <mozilla/ipc/StreamSocket.h>
 
 namespace mozilla {
 namespace ipc {
 
 class NfcSocketListener
 {
 public:
+  enum SocketType {
+    STREAM_SOCKET
+  };
+
   virtual void ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aData) = 0;
+
+  virtual void OnConnectSuccess(enum SocketType aSocketType) = 0;
+  virtual void OnConnectError(enum SocketType aSocketType) = 0;
+  virtual void OnDisconnect(enum SocketType aSocketType) = 0;
 };
 
 class NfcConsumer MOZ_FINAL : public mozilla::ipc::StreamSocket
 {
 public:
   NfcConsumer(NfcSocketListener* aListener);
 
   void Shutdown();