Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/bluetooth/bluetooth_socket_win.h" | 5 #include "device/bluetooth/bluetooth_socket_win.h" |
| 6 | 6 |
| 7 #include <objbase.h> | 7 #include <objbase.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "base/strings/stringprintf.h" | |
| 14 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
| 18 #include "device/bluetooth/bluetooth_device_win.h" | |
| 17 #include "device/bluetooth/bluetooth_init_win.h" | 19 #include "device/bluetooth/bluetooth_init_win.h" |
| 18 #include "device/bluetooth/bluetooth_service_record_win.h" | 20 #include "device/bluetooth/bluetooth_service_record_win.h" |
| 19 #include "device/bluetooth/bluetooth_socket_thread.h" | 21 #include "device/bluetooth/bluetooth_socket_thread.h" |
| 20 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
| 21 #include "net/base/ip_endpoint.h" | 23 #include "net/base/ip_endpoint.h" |
| 22 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 23 #include "net/base/winsock_init.h" | 25 #include "net/base/winsock_init.h" |
| 24 | 26 |
| 25 namespace { | 27 namespace { |
| 26 | 28 |
| 27 const char kL2CAPNotSupported[] = "Bluetooth L2CAP protocal is not supported"; | 29 const char kL2CAPNotSupported[] = "Bluetooth L2CAP protocal is not supported"; |
| 28 const char kSocketAlreadyConnected[] = "Socket is already connected."; | 30 const char kSocketAlreadyConnected[] = "Socket is already connected."; |
| 29 const char kInvalidRfcommPort[] = "Invalid RFCCOMM port."; | 31 const char kInvalidRfcommPort[] = "Invalid RFCCOMM port."; |
| 30 const char kFailedToCreateSocket[] = "Failed to create socket."; | 32 const char kFailedToCreateSocket[] = "Failed to create socket."; |
| 31 const char kFailedToBindSocket[] = "Failed to bind socket."; | 33 const char kFailedToBindSocket[] = "Failed to bind socket."; |
| 32 const char kFailedToListenOnSocket[] = "Failed to listen on socket."; | 34 const char kFailedToListenOnSocket[] = "Failed to listen on socket."; |
| 33 const char kFailedToGetSockNameForSocket[] = "Failed to getsockname."; | 35 const char kFailedToGetSockNameForSocket[] = "Failed to getsockname."; |
| 34 const char kBadUuid[] = "Bad uuid."; | 36 const char kFailedToAccept[] = "Failed to accept."; |
| 37 const char kInvalidUUID[] = "Invalid UUID"; | |
| 35 const char kWsaSetServiceError[] = "WSASetService error."; | 38 const char kWsaSetServiceError[] = "WSASetService error."; |
| 36 | 39 |
| 40 std::string IPEndPointToBluetoothAddress(const net::IPEndPoint& end_point) { | |
| 41 if (end_point.address().size() != net::kBluetoothAddressSize) | |
| 42 return std::string(); | |
| 43 // The address is copied from BTH_ADDR field of SOCKADDR_BTH, which is a | |
| 44 // 64-bit ULONGLONG that stores Bluetooth address in little-endian. Print in | |
| 45 // reverse order to preserve the correct ordering. | |
| 46 return base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X", | |
| 47 end_point.address()[5], | |
| 48 end_point.address()[4], | |
| 49 end_point.address()[3], | |
| 50 end_point.address()[2], | |
| 51 end_point.address()[1], | |
| 52 end_point.address()[0]); | |
| 53 } | |
| 54 | |
| 37 } // namespace | 55 } // namespace |
| 38 | 56 |
| 39 namespace device { | 57 namespace device { |
| 40 | 58 |
| 41 struct BluetoothSocketWin::ServiceRegData { | 59 struct BluetoothSocketWin::ServiceRegData { |
| 42 ServiceRegData() { | 60 ServiceRegData() { |
| 43 ZeroMemory(&address, sizeof(address)); | 61 ZeroMemory(&address, sizeof(address)); |
| 44 ZeroMemory(&address_info, sizeof(address_info)); | 62 ZeroMemory(&address_info, sizeof(address_info)); |
| 45 ZeroMemory(&uuid, sizeof(uuid)); | 63 ZeroMemory(&uuid, sizeof(uuid)); |
| 46 ZeroMemory(&service, sizeof(service)); | 64 ZeroMemory(&service, sizeof(service)); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 73 const net::NetLog::Source& source) | 91 const net::NetLog::Source& source) |
| 74 : BluetoothSocketNet(ui_task_runner, socket_thread, net_log, source), | 92 : BluetoothSocketNet(ui_task_runner, socket_thread, net_log, source), |
| 75 supports_rfcomm_(false), | 93 supports_rfcomm_(false), |
| 76 rfcomm_channel_(-1), | 94 rfcomm_channel_(-1), |
| 77 bth_addr_(BTH_ADDR_NULL) { | 95 bth_addr_(BTH_ADDR_NULL) { |
| 78 } | 96 } |
| 79 | 97 |
| 80 BluetoothSocketWin::~BluetoothSocketWin() { | 98 BluetoothSocketWin::~BluetoothSocketWin() { |
| 81 } | 99 } |
| 82 | 100 |
| 83 void BluetoothSocketWin::StartService( | 101 void BluetoothSocketWin::Connect( |
| 102 const BluetoothDeviceWin* device, | |
| 84 const BluetoothUUID& uuid, | 103 const BluetoothUUID& uuid, |
| 85 const std::string& name, | |
| 86 int rfcomm_channel, | |
| 87 const base::Closure& success_callback, | |
| 88 const ErrorCompletionCallback& error_callback, | |
| 89 const OnNewConnectionCallback& new_connection_callback) { | |
| 90 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | |
| 91 | |
| 92 socket_thread()->task_runner()->PostTask( | |
| 93 FROM_HERE, | |
| 94 base::Bind(&BluetoothSocketWin::DoStartService, | |
| 95 this, | |
| 96 uuid, | |
| 97 name, | |
| 98 rfcomm_channel, | |
| 99 success_callback, | |
| 100 error_callback, | |
| 101 new_connection_callback)); | |
| 102 } | |
| 103 | |
| 104 void BluetoothSocketWin::Connect( | |
| 105 const BluetoothServiceRecord& service_record, | |
| 106 const base::Closure& success_callback, | 104 const base::Closure& success_callback, |
| 107 const ErrorCompletionCallback& error_callback) { | 105 const ErrorCompletionCallback& error_callback) { |
| 108 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 106 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 109 | 107 |
| 108 if (!uuid.IsValid()) { | |
| 109 error_callback.Run(kInvalidUUID); | |
| 110 return; | |
| 111 } | |
| 112 | |
| 110 const BluetoothServiceRecordWin* service_record_win = | 113 const BluetoothServiceRecordWin* service_record_win = |
| 111 static_cast<const BluetoothServiceRecordWin*>(&service_record); | 114 static_cast<const BluetoothServiceRecordWin*>( |
| 115 device->GetServiceRecord(uuid)); | |
|
rpaquay
2014/06/05 20:40:36
Don't we need to check to NULL here? Or, if we are
xiyuan
2014/06/05 20:57:22
Absolutely needed, missed that. Handled as an inva
| |
| 112 device_address_ = service_record_win->address(); | 116 device_address_ = service_record_win->address(); |
| 113 if (service_record.SupportsRfcomm()) { | 117 if (service_record_win->SupportsRfcomm()) { |
| 114 supports_rfcomm_ = true; | 118 supports_rfcomm_ = true; |
| 115 rfcomm_channel_ = service_record_win->rfcomm_channel(); | 119 rfcomm_channel_ = service_record_win->rfcomm_channel(); |
| 116 bth_addr_ = service_record_win->bth_addr(); | 120 bth_addr_ = service_record_win->bth_addr(); |
| 117 } | 121 } |
| 118 | 122 |
| 119 socket_thread()->task_runner()->PostTask( | 123 socket_thread()->task_runner()->PostTask( |
| 120 FROM_HERE, | 124 FROM_HERE, |
| 121 base::Bind( | 125 base::Bind( |
| 122 &BluetoothSocketWin::DoConnect, | 126 &BluetoothSocketWin::DoConnect, |
| 123 this, | 127 this, |
| 124 base::Bind(&BluetoothSocketWin::PostSuccess, this, success_callback), | 128 base::Bind(&BluetoothSocketWin::PostSuccess, this, success_callback), |
| 125 base::Bind( | 129 base::Bind( |
| 126 &BluetoothSocketWin::PostErrorCompletion, this, error_callback))); | 130 &BluetoothSocketWin::PostErrorCompletion, this, error_callback))); |
| 127 } | 131 } |
| 128 | 132 |
| 133 void BluetoothSocketWin::Listen(scoped_refptr<BluetoothAdapter> adapter, | |
| 134 const BluetoothUUID& uuid, | |
| 135 int rfcomm_channel, | |
| 136 const base::Closure& success_callback, | |
| 137 const ErrorCompletionCallback& error_callback) { | |
| 138 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | |
| 139 | |
| 140 adapter_ = adapter; | |
| 141 | |
| 142 socket_thread()->task_runner()->PostTask( | |
| 143 FROM_HERE, | |
| 144 base::Bind(&BluetoothSocketWin::DoListen, | |
| 145 this, | |
| 146 uuid, | |
| 147 rfcomm_channel, | |
| 148 success_callback, | |
| 149 error_callback)); | |
| 150 } | |
| 129 | 151 |
| 130 void BluetoothSocketWin::ResetData() { | 152 void BluetoothSocketWin::ResetData() { |
| 131 if (service_reg_data_) { | 153 if (service_reg_data_) { |
| 132 if (WSASetService(&service_reg_data_->service,RNRSERVICE_DELETE, 0) == | 154 if (WSASetService(&service_reg_data_->service,RNRSERVICE_DELETE, 0) == |
| 133 SOCKET_ERROR) { | 155 SOCKET_ERROR) { |
| 134 LOG(WARNING) << "Failed to unregister service."; | 156 LOG(WARNING) << "Failed to unregister service."; |
| 135 } | 157 } |
| 136 service_reg_data_.reset(); | 158 service_reg_data_.reset(); |
| 137 } | 159 } |
| 138 } | 160 } |
| 139 | 161 |
| 140 void BluetoothSocketWin::Accept( | 162 void BluetoothSocketWin::Accept( |
| 141 const AcceptCompletionCallback& success_callback, | 163 const AcceptCompletionCallback& success_callback, |
| 142 const ErrorCompletionCallback& error_callback) { | 164 const ErrorCompletionCallback& error_callback) { |
| 143 NOTIMPLEMENTED(); | 165 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 166 | |
| 167 socket_thread()->task_runner()->PostTask( | |
| 168 FROM_HERE, | |
| 169 base::Bind(&BluetoothSocketWin::DoAccept, | |
| 170 this, | |
| 171 success_callback, | |
| 172 error_callback)); | |
| 144 } | 173 } |
| 145 | 174 |
| 146 void BluetoothSocketWin::DoConnect( | 175 void BluetoothSocketWin::DoConnect( |
| 147 const base::Closure& success_callback, | 176 const base::Closure& success_callback, |
| 148 const ErrorCompletionCallback& error_callback) { | 177 const ErrorCompletionCallback& error_callback) { |
| 149 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); | 178 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); |
| 150 base::ThreadRestrictions::AssertIOAllowed(); | 179 base::ThreadRestrictions::AssertIOAllowed(); |
| 151 | 180 |
| 152 if (tcp_socket()) { | 181 if (tcp_socket()) { |
| 153 error_callback.Run(kSocketAlreadyConnected); | 182 error_callback.Run(kSocketAlreadyConnected); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 if (net_result != net::OK) { | 218 if (net_result != net::OK) { |
| 190 error_callback.Run("Error connecting to socket: " + | 219 error_callback.Run("Error connecting to socket: " + |
| 191 std::string(net::ErrorToString(net_result))); | 220 std::string(net::ErrorToString(net_result))); |
| 192 closesocket(socket_fd); | 221 closesocket(socket_fd); |
| 193 return; | 222 return; |
| 194 } | 223 } |
| 195 | 224 |
| 196 success_callback.Run(); | 225 success_callback.Run(); |
| 197 } | 226 } |
| 198 | 227 |
| 199 void BluetoothSocketWin::DoStartService( | 228 void BluetoothSocketWin::DoListen( |
| 200 const BluetoothUUID& uuid, | 229 const BluetoothUUID& uuid, |
| 201 const std::string& name, | |
| 202 int rfcomm_channel, | 230 int rfcomm_channel, |
| 203 const base::Closure& success_callback, | 231 const base::Closure& success_callback, |
| 204 const ErrorCompletionCallback& error_callback, | 232 const ErrorCompletionCallback& error_callback) { |
| 205 const OnNewConnectionCallback& new_connection_callback) { | |
| 206 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); | 233 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); |
| 207 DCHECK(!tcp_socket() && | 234 DCHECK(!tcp_socket() && !service_reg_data_); |
| 208 !service_reg_data_ && | |
| 209 on_new_connection_callback_.is_null()); | |
| 210 | 235 |
| 211 // The valid range is 0-30. 0 means BT_PORT_ANY and 1-30 are the | 236 // The valid range is 0-30. 0 means BT_PORT_ANY and 1-30 are the |
| 212 // valid RFCOMM port numbers of SOCKADDR_BTH. | 237 // valid RFCOMM port numbers of SOCKADDR_BTH. |
| 213 if (rfcomm_channel < 0 || rfcomm_channel > 30) { | 238 if (rfcomm_channel < 0 || rfcomm_channel > 30) { |
| 214 LOG(WARNING) << "Failed to start service: " | 239 LOG(WARNING) << "Failed to start service: " |
| 215 << "Invalid RFCCOMM port " << rfcomm_channel | 240 << "Invalid RFCCOMM port " << rfcomm_channel |
| 216 << ", uuid=" << uuid.value(); | 241 << ", uuid=" << uuid.value(); |
| 217 PostErrorCompletion(error_callback, kInvalidRfcommPort); | 242 PostErrorCompletion(error_callback, kInvalidRfcommPort); |
| 218 return; | 243 return; |
| 219 } | 244 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 248 | 273 |
| 249 const int kListenBacklog = 5; | 274 const int kListenBacklog = 5; |
| 250 if (scoped_socket->Listen(kListenBacklog) < 0) { | 275 if (scoped_socket->Listen(kListenBacklog) < 0) { |
| 251 LOG(WARNING) << "Failed to start service: Listen" | 276 LOG(WARNING) << "Failed to start service: Listen" |
| 252 << "winsock err=" << WSAGetLastError(); | 277 << "winsock err=" << WSAGetLastError(); |
| 253 PostErrorCompletion(error_callback, kFailedToListenOnSocket); | 278 PostErrorCompletion(error_callback, kFailedToListenOnSocket); |
| 254 return; | 279 return; |
| 255 } | 280 } |
| 256 | 281 |
| 257 scoped_ptr<ServiceRegData> reg_data(new ServiceRegData); | 282 scoped_ptr<ServiceRegData> reg_data(new ServiceRegData); |
| 258 reg_data->name = base::UTF8ToUTF16(name); | 283 reg_data->name = base::UTF8ToUTF16(uuid.canonical_value()); |
| 259 | 284 |
| 260 if (getsockname(socket_fd, sock_addr, &sock_addr_len)) { | 285 if (getsockname(socket_fd, sock_addr, &sock_addr_len)) { |
| 261 LOG(WARNING) << "Failed to start service: getsockname, " | 286 LOG(WARNING) << "Failed to start service: getsockname, " |
| 262 << "winsock err=" << WSAGetLastError(); | 287 << "winsock err=" << WSAGetLastError(); |
| 263 PostErrorCompletion(error_callback, kFailedToGetSockNameForSocket); | 288 PostErrorCompletion(error_callback, kFailedToGetSockNameForSocket); |
| 264 return; | 289 return; |
| 265 } | 290 } |
| 266 reg_data->address = sa; | 291 reg_data->address = sa; |
| 267 | 292 |
| 268 reg_data->address_info.LocalAddr.iSockaddrLength = sizeof(sa); | 293 reg_data->address_info.LocalAddr.iSockaddrLength = sizeof(sa); |
| 269 reg_data->address_info.LocalAddr.lpSockaddr = | 294 reg_data->address_info.LocalAddr.lpSockaddr = |
| 270 reinterpret_cast<struct sockaddr*>(®_data->address); | 295 reinterpret_cast<struct sockaddr*>(®_data->address); |
| 271 reg_data->address_info.iSocketType = SOCK_STREAM; | 296 reg_data->address_info.iSocketType = SOCK_STREAM; |
| 272 reg_data->address_info.iProtocol = BTHPROTO_RFCOMM; | 297 reg_data->address_info.iProtocol = BTHPROTO_RFCOMM; |
| 273 | 298 |
| 274 base::string16 cannonical_uuid = L"{" + base::ASCIIToUTF16( | 299 base::string16 cannonical_uuid = L"{" + base::ASCIIToUTF16( |
| 275 uuid.canonical_value()) + L"}"; | 300 uuid.canonical_value()) + L"}"; |
| 276 if (!SUCCEEDED(CLSIDFromString(cannonical_uuid.c_str(), ®_data->uuid))) { | 301 if (!SUCCEEDED(CLSIDFromString(cannonical_uuid.c_str(), ®_data->uuid))) { |
| 277 LOG(WARNING) << "Failed to start service: " | 302 LOG(WARNING) << "Failed to start service: " |
| 278 << ", bad uuid=" << cannonical_uuid; | 303 << ", invalid uuid=" << cannonical_uuid; |
| 279 PostErrorCompletion(error_callback, kBadUuid); | 304 PostErrorCompletion(error_callback, kInvalidUUID); |
| 280 return; | 305 return; |
| 281 } | 306 } |
| 282 | 307 |
| 283 reg_data->service.dwSize = sizeof(WSAQUERYSET); | 308 reg_data->service.dwSize = sizeof(WSAQUERYSET); |
| 284 reg_data->service.lpszServiceInstanceName = | 309 reg_data->service.lpszServiceInstanceName = |
| 285 const_cast<LPWSTR>(reg_data->name.c_str()); | 310 const_cast<LPWSTR>(reg_data->name.c_str()); |
| 286 reg_data->service.lpServiceClassId = ®_data->uuid; | 311 reg_data->service.lpServiceClassId = ®_data->uuid; |
| 287 reg_data->service.dwNameSpace = NS_BTH; | 312 reg_data->service.dwNameSpace = NS_BTH; |
| 288 reg_data->service.dwNumberOfCsAddrs = 1; | 313 reg_data->service.dwNumberOfCsAddrs = 1; |
| 289 reg_data->service.lpcsaBuffer = ®_data->address_info; | 314 reg_data->service.lpcsaBuffer = ®_data->address_info; |
| 290 | 315 |
| 291 if (WSASetService(®_data->service, | 316 if (WSASetService(®_data->service, |
| 292 RNRSERVICE_REGISTER, 0) == SOCKET_ERROR) { | 317 RNRSERVICE_REGISTER, 0) == SOCKET_ERROR) { |
| 293 LOG(WARNING) << "Failed to register profile: WSASetService" | 318 LOG(WARNING) << "Failed to register profile: WSASetService" |
| 294 << "winsock err=" << WSAGetLastError(); | 319 << "winsock err=" << WSAGetLastError(); |
| 295 PostErrorCompletion(error_callback, kWsaSetServiceError); | 320 PostErrorCompletion(error_callback, kWsaSetServiceError); |
| 296 return; | 321 return; |
| 297 } | 322 } |
| 298 | 323 |
| 299 SetTCPSocket(scoped_socket.Pass()); | 324 SetTCPSocket(scoped_socket.Pass()); |
| 300 service_reg_data_ = reg_data.Pass(); | 325 service_reg_data_ = reg_data.Pass(); |
| 301 on_new_connection_callback_ = new_connection_callback; | |
| 302 DoAccept(); | |
| 303 | 326 |
| 304 PostSuccess(success_callback); | 327 PostSuccess(success_callback); |
| 305 } | 328 } |
| 306 | 329 |
| 307 void BluetoothSocketWin::DoAccept() { | 330 void BluetoothSocketWin::DoAccept( |
| 331 const AcceptCompletionCallback& success_callback, | |
| 332 const ErrorCompletionCallback& error_callback) { | |
| 308 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); | 333 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); |
| 309 int result = tcp_socket()->Accept( | 334 int result = tcp_socket()->Accept( |
| 310 &accept_socket_, | 335 &accept_socket_, |
| 311 &accept_address_, | 336 &accept_address_, |
| 312 base::Bind(&BluetoothSocketWin::OnAcceptOnSocketThread, this)); | 337 base::Bind(&BluetoothSocketWin::OnAcceptOnSocketThread, |
| 313 if (result != net::OK && result != net::ERR_IO_PENDING) | 338 this, |
| 339 success_callback, | |
| 340 error_callback)); | |
| 341 if (result != net::OK && result != net::ERR_IO_PENDING) { | |
| 314 LOG(WARNING) << "Failed to accept, net err=" << result; | 342 LOG(WARNING) << "Failed to accept, net err=" << result; |
| 343 PostErrorCompletion(error_callback, kFailedToAccept); | |
| 344 } | |
| 315 } | 345 } |
| 316 | 346 |
| 317 void BluetoothSocketWin::OnAcceptOnSocketThread(int accept_result) { | 347 void BluetoothSocketWin::OnAcceptOnSocketThread( |
| 348 const AcceptCompletionCallback& success_callback, | |
| 349 const ErrorCompletionCallback& error_callback, | |
| 350 int accept_result) { | |
| 318 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); | 351 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); |
| 319 if (accept_result != net::OK) { | 352 if (accept_result != net::OK) { |
| 320 LOG(WARNING) << "OnAccept error, net err=" << accept_result; | 353 LOG(WARNING) << "OnAccept error, net err=" << accept_result; |
| 354 PostErrorCompletion(error_callback, kFailedToAccept); | |
| 321 return; | 355 return; |
| 322 } | 356 } |
| 323 | 357 |
| 324 ui_task_runner()->PostTask( | 358 ui_task_runner()->PostTask( |
| 325 FROM_HERE, | 359 FROM_HERE, |
| 326 base::Bind(&BluetoothSocketWin::OnAcceptOnUI, | 360 base::Bind(&BluetoothSocketWin::OnAcceptOnUI, |
| 327 this, | 361 this, |
| 328 base::Passed(&accept_socket_), | 362 base::Passed(&accept_socket_), |
| 329 accept_address_)); | 363 accept_address_, |
| 330 DoAccept(); | 364 success_callback, |
| 365 error_callback)); | |
| 331 } | 366 } |
| 332 | 367 |
| 333 void BluetoothSocketWin::OnAcceptOnUI( | 368 void BluetoothSocketWin::OnAcceptOnUI( |
| 334 scoped_ptr<net::TCPSocket> accept_socket, | 369 scoped_ptr<net::TCPSocket> accept_socket, |
| 335 const net::IPEndPoint& peer_address) { | 370 const net::IPEndPoint& peer_address, |
| 371 const AcceptCompletionCallback& success_callback, | |
| 372 const ErrorCompletionCallback& error_callback) { | |
| 336 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 373 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 337 | 374 |
| 338 scoped_refptr<BluetoothSocketWin> peer = CreateBluetoothSocket( | 375 const std::string peer_device_address = |
| 376 IPEndPointToBluetoothAddress(peer_address); | |
| 377 const BluetoothDevice* peer_device = adapter_->GetDevice(peer_device_address); | |
| 378 if (!peer_device) { | |
| 379 LOG(WARNING) << "OnAccept failed with unknown device, addr=" | |
| 380 << peer_device_address; | |
| 381 error_callback.Run(kFailedToAccept); | |
| 382 return; | |
| 383 } | |
| 384 | |
| 385 scoped_refptr<BluetoothSocketWin> peer_socket = CreateBluetoothSocket( | |
| 339 ui_task_runner(), | 386 ui_task_runner(), |
| 340 socket_thread(), | 387 socket_thread(), |
| 341 net_log(), | 388 net_log(), |
| 342 source()); | 389 source()); |
| 343 peer->SetTCPSocket(accept_socket.Pass()); | 390 peer_socket->SetTCPSocket(accept_socket.Pass()); |
| 344 | 391 success_callback.Run(peer_device, peer_socket); |
| 345 on_new_connection_callback_.Run(peer, peer_address); | |
| 346 } | 392 } |
| 347 | 393 |
| 348 } // namespace device | 394 } // namespace device |
| OLD | NEW |