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|.
This commit is contained in:
Thomas Zimmermann 2015-03-09 03:27:00 -04:00
parent 4365986c1d
commit 3f04f600c1
4 changed files with 46 additions and 3 deletions

View File

@ -371,6 +371,24 @@ NfcService::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aData)
mThread->Dispatch(runnable, nsIEventTarget::DISPATCH_NORMAL); 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, NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(NfcService,
NfcService::FactoryCreate) NfcService::FactoryCreate)

View File

@ -29,8 +29,12 @@ public:
void DispatchNfcEvent(const mozilla::dom::NfcEventOptions& aOptions); void DispatchNfcEvent(const mozilla::dom::NfcEventOptions& aOptions);
virtual void virtual void ReceiveSocketData(
ReceiveSocketData(nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aData) MOZ_OVERRIDE; 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() { nsCOMPtr<nsIThread> GetThread() {
return mThread; return mThread;

View File

@ -209,14 +209,23 @@ NfcConsumer::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aData)
void void
NfcConsumer::OnConnectSuccess() NfcConsumer::OnConnectSuccess()
{ {
// Nothing to do here.
CHROMIUM_LOG("NFC: %s\n", __FUNCTION__); CHROMIUM_LOG("NFC: %s\n", __FUNCTION__);
if (mListener) {
mListener->OnConnectSuccess(NfcSocketListener::STREAM_SOCKET);
}
// Nothing to do here.
} }
void void
NfcConsumer::OnConnectError() NfcConsumer::OnConnectError()
{ {
CHROMIUM_LOG("NFC: %s\n", __FUNCTION__); CHROMIUM_LOG("NFC: %s\n", __FUNCTION__);
if (mListener) {
mListener->OnConnectError(NfcSocketListener::STREAM_SOCKET);
}
Close(); Close();
} }
@ -224,6 +233,10 @@ void
NfcConsumer::OnDisconnect() NfcConsumer::OnDisconnect()
{ {
CHROMIUM_LOG("NFC: %s\n", __FUNCTION__); CHROMIUM_LOG("NFC: %s\n", __FUNCTION__);
if (mListener) {
mListener->OnDisconnect(NfcSocketListener::STREAM_SOCKET);
}
if (!mShutdown) { if (!mShutdown) {
Connect(new NfcConnector(), mAddress.get(), GetSuggestedConnectDelayMs()); Connect(new NfcConnector(), mAddress.get(), GetSuggestedConnectDelayMs());
} }

View File

@ -17,7 +17,15 @@ namespace ipc {
class NfcSocketListener class NfcSocketListener
{ {
public: public:
enum SocketType {
STREAM_SOCKET
};
virtual void ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aData) = 0; 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 class NfcConsumer MOZ_FINAL : public mozilla::ipc::StreamSocket