Bug 1050174: Use |SocketIOReceiveRunnable| for Bluetooth sockets (under bluetooth2/), r=btian
authorThomas Zimmermann <tdz@users.sourceforge.net>
Thu, 21 Aug 2014 09:30:35 +0200
changeset 200786 8e834c42337716a2baf59857e74d26e31f4f31a5
parent 200785 d18894e0c89ba08b42a294d60d9719e56dafa866
child 200787 364c67cefa5e2da6acb121bbb238d8551b25c141
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbtian
bugs1050174
milestone34.0a1
Bug 1050174: Use |SocketIOReceiveRunnable| for Bluetooth sockets (under bluetooth2/), r=btian
dom/bluetooth2/bluedroid/BluetoothSocket.cpp
--- a/dom/bluetooth2/bluedroid/BluetoothSocket.cpp
+++ b/dom/bluetooth2/bluedroid/BluetoothSocket.cpp
@@ -249,48 +249,16 @@ class ShutdownSocketTask : public Task {
   }
 
   DroidSocketImpl* mImpl;
 
 public:
   ShutdownSocketTask(DroidSocketImpl* aImpl) : mImpl(aImpl) { }
 };
 
-class SocketReceiveTask : public SocketIORunnable<DroidSocketImpl>
-{
-public:
-  SocketReceiveTask(DroidSocketImpl* aImpl, UnixSocketRawData* aData)
-  : SocketIORunnable<DroidSocketImpl>(aImpl)
-  , mRawData(aData)
-  {
-    MOZ_ASSERT(aData);
-  }
-
-  NS_IMETHOD Run()
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    DroidSocketImpl* impl = GetIO();
-
-    if (impl->IsShutdownOnMainThread()) {
-      NS_WARNING("mConsumer is null, aborting receive!");
-      // 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;
-    }
-
-    MOZ_ASSERT(impl->mConsumer);
-    impl->mConsumer->ReceiveSocketData(mRawData);
-    return NS_OK;
-  }
-
-private:
-  nsAutoPtr<UnixSocketRawData> mRawData;
-};
-
 class SocketSendTask : public Task
 {
 public:
   SocketSendTask(BluetoothSocket* aConsumer, DroidSocketImpl* aImpl,
                  UnixSocketRawData* aData)
     : mConsumer(aConsumer),
       mImpl(aImpl),
       mData(aData)
@@ -498,19 +466,19 @@ DroidSocketImpl::OnSocketCanReceiveWitho
       // cause us to end up back here.
       RemoveWatchers(READ_WATCHER | WRITE_WATCHER);
       nsRefPtr<RequestClosingSocketTask> t = new RequestClosingSocketTask(this);
       NS_DispatchToMainThread(t);
       return;
     }
 
     incoming->mSize = ret;
-    nsRefPtr<SocketReceiveTask> t =
-      new SocketReceiveTask(this, incoming.forget());
-    NS_DispatchToMainThread(t);
+    nsRefPtr<nsRunnable> r =
+      new SocketIOReceiveRunnable<DroidSocketImpl>(this, incoming.forget());
+    NS_DispatchToMainThread(r);
 
     // If ret is less than MAX_READ_SIZE, there's no
     // more data in the socket for us to read now.
     if (ret < ssize_t(MAX_READ_SIZE)) {
       return;
     }
   }