diff --git a/dom/bluetooth/bluedroid/BluetoothSocket.cpp b/dom/bluetooth/bluedroid/BluetoothSocket.cpp index cbc16f578fe2..745d3e652a93 100644 --- a/dom/bluetooth/bluedroid/BluetoothSocket.cpp +++ b/dom/bluetooth/bluedroid/BluetoothSocket.cpp @@ -136,6 +136,11 @@ public: AddWatchers(WRITE_WATCHER, false); } + SocketConsumerBase* GetConsumer() + { + return mConsumer.get(); + } + /** * Consumer pointer. Non-thread safe RefPtr, so should only be manipulated * directly from main thread. All non-main-thread accesses should happen with @@ -198,48 +203,6 @@ private: T* mInstance; }; -class OnSocketEventRunnable : public SocketIORunnable -{ -public: - enum SocketEvent { - CONNECT_SUCCESS, - CONNECT_ERROR, - DISCONNECT - }; - - OnSocketEventRunnable(DroidSocketImpl* aImpl, SocketEvent e) - : SocketIORunnable(aImpl) - , mEvent(e) - { - MOZ_ASSERT(!NS_IsMainThread()); - } - - NS_IMETHOD Run() MOZ_OVERRIDE - { - MOZ_ASSERT(NS_IsMainThread()); - - DroidSocketImpl* impl = GetIO(); - - if (impl->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; - } - if (mEvent == CONNECT_SUCCESS) { - impl->mConsumer->NotifySuccess(); - } else if (mEvent == CONNECT_ERROR) { - impl->mConsumer->NotifyError(); - } else if (mEvent == DISCONNECT) { - impl->mConsumer->NotifyDisconnect(); - } - return NS_OK; - } - -private: - SocketEvent mEvent; -}; - class RequestClosingSocketTask : public SocketIORunnable { public: @@ -483,8 +446,9 @@ DroidSocketImpl::Accept(int aFd) SetFd(aFd); mConnectionStatus = SOCKET_IS_CONNECTED; - nsRefPtr r = - new OnSocketEventRunnable(this, OnSocketEventRunnable::CONNECT_SUCCESS); + nsRefPtr r = + new SocketIOEventRunnable( + this, SocketIOEventRunnable::CONNECT_SUCCESS); NS_DispatchToMainThread(r); AddWatchers(READ_WATCHER, true); @@ -710,8 +674,9 @@ DroidSocketImpl::OnSocketCanConnectWithoutBlocking(int aFd) mConnectionStatus = SOCKET_IS_CONNECTED; - nsRefPtr r = - new OnSocketEventRunnable(this, OnSocketEventRunnable::CONNECT_SUCCESS); + nsRefPtr r = + new SocketIOEventRunnable( + this, SocketIOEventRunnable::CONNECT_SUCCESS); NS_DispatchToMainThread(r); AddWatchers(READ_WATCHER, true);