Index: device/bluetooth/bluetooth_socket_win.cc |
diff --git a/device/bluetooth/bluetooth_socket_win.cc b/device/bluetooth/bluetooth_socket_win.cc |
index 9b1e953fb6ddb709705726698625c3232bccd08a..41bae5a3f20450da8bcae813fdaa0a1dcf289282 100644 |
--- a/device/bluetooth/bluetooth_socket_win.cc |
+++ b/device/bluetooth/bluetooth_socket_win.cc |
@@ -71,6 +71,22 @@ scoped_refptr<BluetoothSocketWin> BluetoothSocketWin::CreateBluetoothSocket( |
return result; |
} |
+// static |
+scoped_refptr<BluetoothSocketWin> BluetoothSocketWin::CreateBluetoothSocket( |
+ scoped_ptr<net::TCPSocket> existing, |
+ scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
+ scoped_refptr<BluetoothSocketThreadWin> socket_thread, |
+ net::NetLog* net_log, |
+ const net::NetLog::Source& source) { |
+ DCHECK(ui_task_runner->RunsTasksOnCurrentThread()); |
+ |
+ scoped_refptr<BluetoothSocketWin> result( |
+ new BluetoothSocketWin(ui_task_runner, socket_thread, net_log, source)); |
+ result->tcp_socket_ = existing.Pass(); |
+ |
+ return result; |
+} |
+ |
BluetoothSocketWin::BluetoothSocketWin( |
scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
scoped_refptr<BluetoothSocketThreadWin> socket_thread, |
@@ -159,6 +175,15 @@ void BluetoothSocketWin::Send(scoped_refptr<net::IOBuffer> buffer, |
&BluetoothSocketWin::PostErrorCompletion, this, error_callback))); |
} |
+void BluetoothSocketWin::Accept( |
+ const BluetoothSocketWin::OnAcceptCallback& on_accept_callback) { |
+ DCHECK(on_accept_callback_.is_null()); |
+ on_accept_callback_ = on_accept_callback; |
+ socket_thread_->task_runner()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&BluetoothSocketWin::DoAccept, this)); |
+} |
+ |
void BluetoothSocketWin::DoClose() { |
DCHECK(socket_thread_->task_runner()->RunsTasksOnCurrentThread()); |
base::ThreadRestrictions::AssertIOAllowed(); |
@@ -399,4 +424,45 @@ void BluetoothSocketWin::PostSendCompletion( |
ui_task_runner_->PostTask(FROM_HERE, base::Bind(callback, bytes_written)); |
} |
+void BluetoothSocketWin::DoAccept() { |
+ DCHECK(socket_thread_->task_runner()->RunsTasksOnCurrentThread()); |
+ int result = tcp_socket_->Accept( |
+ &accept_socket_, |
+ &accept_address_, |
+ base::Bind(&BluetoothSocketWin::OnAcceptOnSocketThread, this)); |
+ if (result != net::OK && result != net::ERR_IO_PENDING) |
+ LOG(WARNING) << "Failed to accept, net err=" << result; |
+} |
+ |
+void BluetoothSocketWin::OnAcceptOnSocketThread(int accept_result) { |
+ DCHECK(socket_thread_->task_runner()->RunsTasksOnCurrentThread()); |
+ if (accept_result != net::OK) { |
+ LOG(WARNING) << "OnAccept error, net err=" << accept_result; |
+ return; |
+ } |
+ |
+ ui_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&BluetoothSocketWin::OnAcceptOnUI, |
+ this, |
+ base::Passed(&accept_socket_), |
+ accept_address_)); |
+ DoAccept(); |
+} |
+ |
+void BluetoothSocketWin::OnAcceptOnUI( |
+ scoped_ptr<net::TCPSocket> accept_socket, |
+ const net::IPEndPoint& peer_address) { |
+ DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
+ |
+ on_accept_callback_.Run( |
+ CreateBluetoothSocket( |
+ accept_socket.Pass(), |
+ ui_task_runner_, |
+ socket_thread_, |
+ net_log_, |
+ source_), |
+ peer_address); |
+} |
+ |
} // namespace device |