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()); |
107 DCHECK(device); | |
108 | |
109 if (!uuid.IsValid()) { | |
110 error_callback.Run(kInvalidUUID); | |
111 return; | |
112 } | |
113 | |
114 const BluetoothServiceRecord* service_record = device->GetServiceRecord(uuid); | |
keybuk
2014/06/05 22:03:03
If this returned BluetoothServiceRecordWin* direct
| |
115 if (!service_record) { | |
116 error_callback.Run(kInvalidUUID); | |
117 return; | |
118 } | |
109 | 119 |
110 const BluetoothServiceRecordWin* service_record_win = | 120 const BluetoothServiceRecordWin* service_record_win = |
111 static_cast<const BluetoothServiceRecordWin*>(&service_record); | 121 static_cast<const BluetoothServiceRecordWin*>(service_record); |
keybuk
2014/06/05 22:03:03
...then you wouldn't need to cast it here.
xiyuan
2014/06/06 00:29:13
Done.
| |
112 device_address_ = service_record_win->address(); | 122 device_address_ = service_record_win->address(); |
113 if (service_record.SupportsRfcomm()) { | 123 if (service_record_win->SupportsRfcomm()) { |
114 supports_rfcomm_ = true; | 124 supports_rfcomm_ = true; |
115 rfcomm_channel_ = service_record_win->rfcomm_channel(); | 125 rfcomm_channel_ = service_record_win->rfcomm_channel(); |
116 bth_addr_ = service_record_win->bth_addr(); | 126 bth_addr_ = service_record_win->bth_addr(); |
117 } | 127 } |
118 | 128 |
119 socket_thread()->task_runner()->PostTask( | 129 socket_thread()->task_runner()->PostTask( |
120 FROM_HERE, | 130 FROM_HERE, |
121 base::Bind( | 131 base::Bind( |
122 &BluetoothSocketWin::DoConnect, | 132 &BluetoothSocketWin::DoConnect, |
123 this, | 133 this, |
124 base::Bind(&BluetoothSocketWin::PostSuccess, this, success_callback), | 134 base::Bind(&BluetoothSocketWin::PostSuccess, this, success_callback), |
125 base::Bind( | 135 base::Bind( |
126 &BluetoothSocketWin::PostErrorCompletion, this, error_callback))); | 136 &BluetoothSocketWin::PostErrorCompletion, this, error_callback))); |
127 } | 137 } |
128 | 138 |
139 void BluetoothSocketWin::Listen(scoped_refptr<BluetoothAdapter> adapter, | |
140 const BluetoothUUID& uuid, | |
141 int rfcomm_channel, | |
142 const base::Closure& success_callback, | |
143 const ErrorCompletionCallback& error_callback) { | |
144 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | |
145 | |
146 adapter_ = adapter; | |
147 | |
148 socket_thread()->task_runner()->PostTask( | |
149 FROM_HERE, | |
150 base::Bind(&BluetoothSocketWin::DoListen, | |
151 this, | |
152 uuid, | |
153 rfcomm_channel, | |
154 success_callback, | |
155 error_callback)); | |
156 } | |
129 | 157 |
130 void BluetoothSocketWin::ResetData() { | 158 void BluetoothSocketWin::ResetData() { |
131 if (service_reg_data_) { | 159 if (service_reg_data_) { |
132 if (WSASetService(&service_reg_data_->service,RNRSERVICE_DELETE, 0) == | 160 if (WSASetService(&service_reg_data_->service,RNRSERVICE_DELETE, 0) == |
133 SOCKET_ERROR) { | 161 SOCKET_ERROR) { |
134 LOG(WARNING) << "Failed to unregister service."; | 162 LOG(WARNING) << "Failed to unregister service."; |
135 } | 163 } |
136 service_reg_data_.reset(); | 164 service_reg_data_.reset(); |
137 } | 165 } |
138 } | 166 } |
139 | 167 |
140 void BluetoothSocketWin::Accept( | 168 void BluetoothSocketWin::Accept( |
141 const AcceptCompletionCallback& success_callback, | 169 const AcceptCompletionCallback& success_callback, |
142 const ErrorCompletionCallback& error_callback) { | 170 const ErrorCompletionCallback& error_callback) { |
143 NOTIMPLEMENTED(); | 171 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
172 | |
173 socket_thread()->task_runner()->PostTask( | |
174 FROM_HERE, | |
175 base::Bind(&BluetoothSocketWin::DoAccept, | |
176 this, | |
177 success_callback, | |
178 error_callback)); | |
144 } | 179 } |
145 | 180 |
146 void BluetoothSocketWin::DoConnect( | 181 void BluetoothSocketWin::DoConnect( |
147 const base::Closure& success_callback, | 182 const base::Closure& success_callback, |
148 const ErrorCompletionCallback& error_callback) { | 183 const ErrorCompletionCallback& error_callback) { |
149 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); | 184 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); |
150 base::ThreadRestrictions::AssertIOAllowed(); | 185 base::ThreadRestrictions::AssertIOAllowed(); |
151 | 186 |
152 if (tcp_socket()) { | 187 if (tcp_socket()) { |
153 error_callback.Run(kSocketAlreadyConnected); | 188 error_callback.Run(kSocketAlreadyConnected); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 if (net_result != net::OK) { | 224 if (net_result != net::OK) { |
190 error_callback.Run("Error connecting to socket: " + | 225 error_callback.Run("Error connecting to socket: " + |
191 std::string(net::ErrorToString(net_result))); | 226 std::string(net::ErrorToString(net_result))); |
192 closesocket(socket_fd); | 227 closesocket(socket_fd); |
193 return; | 228 return; |
194 } | 229 } |
195 | 230 |
196 success_callback.Run(); | 231 success_callback.Run(); |
197 } | 232 } |
198 | 233 |
199 void BluetoothSocketWin::DoStartService( | 234 void BluetoothSocketWin::DoListen( |
200 const BluetoothUUID& uuid, | 235 const BluetoothUUID& uuid, |
201 const std::string& name, | |
202 int rfcomm_channel, | 236 int rfcomm_channel, |
203 const base::Closure& success_callback, | 237 const base::Closure& success_callback, |
204 const ErrorCompletionCallback& error_callback, | 238 const ErrorCompletionCallback& error_callback) { |
205 const OnNewConnectionCallback& new_connection_callback) { | |
206 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); | 239 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); |
207 DCHECK(!tcp_socket() && | 240 DCHECK(!tcp_socket() && !service_reg_data_); |
208 !service_reg_data_ && | |
209 on_new_connection_callback_.is_null()); | |
210 | 241 |
211 // The valid range is 0-30. 0 means BT_PORT_ANY and 1-30 are the | 242 // The valid range is 0-30. 0 means BT_PORT_ANY and 1-30 are the |
212 // valid RFCOMM port numbers of SOCKADDR_BTH. | 243 // valid RFCOMM port numbers of SOCKADDR_BTH. |
213 if (rfcomm_channel < 0 || rfcomm_channel > 30) { | 244 if (rfcomm_channel < 0 || rfcomm_channel > 30) { |
214 LOG(WARNING) << "Failed to start service: " | 245 LOG(WARNING) << "Failed to start service: " |
215 << "Invalid RFCCOMM port " << rfcomm_channel | 246 << "Invalid RFCCOMM port " << rfcomm_channel |
216 << ", uuid=" << uuid.value(); | 247 << ", uuid=" << uuid.value(); |
217 PostErrorCompletion(error_callback, kInvalidRfcommPort); | 248 PostErrorCompletion(error_callback, kInvalidRfcommPort); |
218 return; | 249 return; |
219 } | 250 } |
(...skipping 28 matching lines...) Expand all Loading... | |
248 | 279 |
249 const int kListenBacklog = 5; | 280 const int kListenBacklog = 5; |
250 if (scoped_socket->Listen(kListenBacklog) < 0) { | 281 if (scoped_socket->Listen(kListenBacklog) < 0) { |
251 LOG(WARNING) << "Failed to start service: Listen" | 282 LOG(WARNING) << "Failed to start service: Listen" |
252 << "winsock err=" << WSAGetLastError(); | 283 << "winsock err=" << WSAGetLastError(); |
253 PostErrorCompletion(error_callback, kFailedToListenOnSocket); | 284 PostErrorCompletion(error_callback, kFailedToListenOnSocket); |
254 return; | 285 return; |
255 } | 286 } |
256 | 287 |
257 scoped_ptr<ServiceRegData> reg_data(new ServiceRegData); | 288 scoped_ptr<ServiceRegData> reg_data(new ServiceRegData); |
258 reg_data->name = base::UTF8ToUTF16(name); | 289 reg_data->name = base::UTF8ToUTF16(uuid.canonical_value()); |
259 | 290 |
260 if (getsockname(socket_fd, sock_addr, &sock_addr_len)) { | 291 if (getsockname(socket_fd, sock_addr, &sock_addr_len)) { |
261 LOG(WARNING) << "Failed to start service: getsockname, " | 292 LOG(WARNING) << "Failed to start service: getsockname, " |
262 << "winsock err=" << WSAGetLastError(); | 293 << "winsock err=" << WSAGetLastError(); |
263 PostErrorCompletion(error_callback, kFailedToGetSockNameForSocket); | 294 PostErrorCompletion(error_callback, kFailedToGetSockNameForSocket); |
264 return; | 295 return; |
265 } | 296 } |
266 reg_data->address = sa; | 297 reg_data->address = sa; |
267 | 298 |
268 reg_data->address_info.LocalAddr.iSockaddrLength = sizeof(sa); | 299 reg_data->address_info.LocalAddr.iSockaddrLength = sizeof(sa); |
269 reg_data->address_info.LocalAddr.lpSockaddr = | 300 reg_data->address_info.LocalAddr.lpSockaddr = |
270 reinterpret_cast<struct sockaddr*>(®_data->address); | 301 reinterpret_cast<struct sockaddr*>(®_data->address); |
271 reg_data->address_info.iSocketType = SOCK_STREAM; | 302 reg_data->address_info.iSocketType = SOCK_STREAM; |
272 reg_data->address_info.iProtocol = BTHPROTO_RFCOMM; | 303 reg_data->address_info.iProtocol = BTHPROTO_RFCOMM; |
273 | 304 |
274 base::string16 cannonical_uuid = L"{" + base::ASCIIToUTF16( | 305 base::string16 cannonical_uuid = L"{" + base::ASCIIToUTF16( |
275 uuid.canonical_value()) + L"}"; | 306 uuid.canonical_value()) + L"}"; |
276 if (!SUCCEEDED(CLSIDFromString(cannonical_uuid.c_str(), ®_data->uuid))) { | 307 if (!SUCCEEDED(CLSIDFromString(cannonical_uuid.c_str(), ®_data->uuid))) { |
277 LOG(WARNING) << "Failed to start service: " | 308 LOG(WARNING) << "Failed to start service: " |
278 << ", bad uuid=" << cannonical_uuid; | 309 << ", invalid uuid=" << cannonical_uuid; |
279 PostErrorCompletion(error_callback, kBadUuid); | 310 PostErrorCompletion(error_callback, kInvalidUUID); |
280 return; | 311 return; |
281 } | 312 } |
282 | 313 |
283 reg_data->service.dwSize = sizeof(WSAQUERYSET); | 314 reg_data->service.dwSize = sizeof(WSAQUERYSET); |
284 reg_data->service.lpszServiceInstanceName = | 315 reg_data->service.lpszServiceInstanceName = |
285 const_cast<LPWSTR>(reg_data->name.c_str()); | 316 const_cast<LPWSTR>(reg_data->name.c_str()); |
286 reg_data->service.lpServiceClassId = ®_data->uuid; | 317 reg_data->service.lpServiceClassId = ®_data->uuid; |
287 reg_data->service.dwNameSpace = NS_BTH; | 318 reg_data->service.dwNameSpace = NS_BTH; |
288 reg_data->service.dwNumberOfCsAddrs = 1; | 319 reg_data->service.dwNumberOfCsAddrs = 1; |
289 reg_data->service.lpcsaBuffer = ®_data->address_info; | 320 reg_data->service.lpcsaBuffer = ®_data->address_info; |
290 | 321 |
291 if (WSASetService(®_data->service, | 322 if (WSASetService(®_data->service, |
292 RNRSERVICE_REGISTER, 0) == SOCKET_ERROR) { | 323 RNRSERVICE_REGISTER, 0) == SOCKET_ERROR) { |
293 LOG(WARNING) << "Failed to register profile: WSASetService" | 324 LOG(WARNING) << "Failed to register profile: WSASetService" |
294 << "winsock err=" << WSAGetLastError(); | 325 << "winsock err=" << WSAGetLastError(); |
295 PostErrorCompletion(error_callback, kWsaSetServiceError); | 326 PostErrorCompletion(error_callback, kWsaSetServiceError); |
296 return; | 327 return; |
297 } | 328 } |
298 | 329 |
299 SetTCPSocket(scoped_socket.Pass()); | 330 SetTCPSocket(scoped_socket.Pass()); |
300 service_reg_data_ = reg_data.Pass(); | 331 service_reg_data_ = reg_data.Pass(); |
301 on_new_connection_callback_ = new_connection_callback; | |
302 DoAccept(); | |
303 | 332 |
304 PostSuccess(success_callback); | 333 PostSuccess(success_callback); |
305 } | 334 } |
306 | 335 |
307 void BluetoothSocketWin::DoAccept() { | 336 void BluetoothSocketWin::DoAccept( |
337 const AcceptCompletionCallback& success_callback, | |
338 const ErrorCompletionCallback& error_callback) { | |
308 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); | 339 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); |
309 int result = tcp_socket()->Accept( | 340 int result = tcp_socket()->Accept( |
310 &accept_socket_, | 341 &accept_socket_, |
311 &accept_address_, | 342 &accept_address_, |
312 base::Bind(&BluetoothSocketWin::OnAcceptOnSocketThread, this)); | 343 base::Bind(&BluetoothSocketWin::OnAcceptOnSocketThread, |
313 if (result != net::OK && result != net::ERR_IO_PENDING) | 344 this, |
345 success_callback, | |
346 error_callback)); | |
347 if (result != net::OK && result != net::ERR_IO_PENDING) { | |
314 LOG(WARNING) << "Failed to accept, net err=" << result; | 348 LOG(WARNING) << "Failed to accept, net err=" << result; |
349 PostErrorCompletion(error_callback, kFailedToAccept); | |
350 } | |
315 } | 351 } |
316 | 352 |
317 void BluetoothSocketWin::OnAcceptOnSocketThread(int accept_result) { | 353 void BluetoothSocketWin::OnAcceptOnSocketThread( |
354 const AcceptCompletionCallback& success_callback, | |
355 const ErrorCompletionCallback& error_callback, | |
356 int accept_result) { | |
318 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); | 357 DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); |
319 if (accept_result != net::OK) { | 358 if (accept_result != net::OK) { |
320 LOG(WARNING) << "OnAccept error, net err=" << accept_result; | 359 LOG(WARNING) << "OnAccept error, net err=" << accept_result; |
360 PostErrorCompletion(error_callback, kFailedToAccept); | |
321 return; | 361 return; |
322 } | 362 } |
323 | 363 |
324 ui_task_runner()->PostTask( | 364 ui_task_runner()->PostTask( |
325 FROM_HERE, | 365 FROM_HERE, |
326 base::Bind(&BluetoothSocketWin::OnAcceptOnUI, | 366 base::Bind(&BluetoothSocketWin::OnAcceptOnUI, |
327 this, | 367 this, |
328 base::Passed(&accept_socket_), | 368 base::Passed(&accept_socket_), |
329 accept_address_)); | 369 accept_address_, |
330 DoAccept(); | 370 success_callback, |
371 error_callback)); | |
331 } | 372 } |
332 | 373 |
333 void BluetoothSocketWin::OnAcceptOnUI( | 374 void BluetoothSocketWin::OnAcceptOnUI( |
334 scoped_ptr<net::TCPSocket> accept_socket, | 375 scoped_ptr<net::TCPSocket> accept_socket, |
335 const net::IPEndPoint& peer_address) { | 376 const net::IPEndPoint& peer_address, |
377 const AcceptCompletionCallback& success_callback, | |
378 const ErrorCompletionCallback& error_callback) { | |
336 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 379 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
337 | 380 |
338 scoped_refptr<BluetoothSocketWin> peer = CreateBluetoothSocket( | 381 const std::string peer_device_address = |
382 IPEndPointToBluetoothAddress(peer_address); | |
383 const BluetoothDevice* peer_device = adapter_->GetDevice(peer_device_address); | |
384 if (!peer_device) { | |
385 LOG(WARNING) << "OnAccept failed with unknown device, addr=" | |
386 << peer_device_address; | |
387 error_callback.Run(kFailedToAccept); | |
388 return; | |
389 } | |
390 | |
391 scoped_refptr<BluetoothSocketWin> peer_socket = CreateBluetoothSocket( | |
339 ui_task_runner(), | 392 ui_task_runner(), |
340 socket_thread(), | 393 socket_thread(), |
341 net_log(), | 394 net_log(), |
342 source()); | 395 source()); |
343 peer->SetTCPSocket(accept_socket.Pass()); | 396 peer_socket->SetTCPSocket(accept_socket.Pass()); |
344 | 397 success_callback.Run(peer_device, peer_socket); |
345 on_new_connection_callback_.Run(peer, peer_address); | |
346 } | 398 } |
347 | 399 |
348 } // namespace device | 400 } // namespace device |
OLD | NEW |