Index: device/bluetooth/bluetooth_profile_win.cc |
diff --git a/device/bluetooth/bluetooth_profile_win.cc b/device/bluetooth/bluetooth_profile_win.cc |
index 707afeb023624193e3900d9cc282c2e09330bb8d..79848caf074fc2a931b307695e946dca9f8bde09 100644 |
--- a/device/bluetooth/bluetooth_profile_win.cc |
+++ b/device/bluetooth/bluetooth_profile_win.cc |
@@ -4,11 +4,66 @@ |
#include "device/bluetooth/bluetooth_profile_win.h" |
+#include "base/bind.h" |
#include "base/memory/ref_counted.h" |
+#include "base/sequenced_task_runner.h" |
+#include "device/bluetooth/bluetooth_adapter_factory.h" |
#include "device/bluetooth/bluetooth_device_win.h" |
#include "device/bluetooth/bluetooth_service_record.h" |
+#include "device/bluetooth/bluetooth_socket_thread_win.h" |
#include "device/bluetooth/bluetooth_socket_win.h" |
+namespace { |
+ |
+using device::BluetoothAdapter; |
+using device::BluetoothDevice; |
+using device::BluetoothProfileWin; |
+using device::BluetoothSocket; |
+using device::BluetoothSocketWin; |
+ |
+const char kNoConnectionCallback[] = "Connection callback not set"; |
+const char kProfileNotFound[] = "Profile not found"; |
+ |
+void OnConnectSuccessUIWithAdapter( |
+ scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
+ const base::Closure& callback, |
+ const BluetoothProfileWin::ConnectionCallback& connection_callback, |
+ const std::string& device_address, |
+ scoped_refptr<BluetoothSocketWin> socket, |
+ scoped_refptr<BluetoothAdapter> adapter) { |
+ DCHECK(ui_task_runner->RunsTasksOnCurrentThread()); |
+ const BluetoothDevice* device = adapter->GetDevice(device_address); |
+ if (device) { |
+ connection_callback.Run(device, socket); |
+ callback.Run(); |
+ } |
+} |
+ |
+void OnConnectSuccessUI( |
+ scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
+ const base::Closure& callback, |
+ const BluetoothProfileWin::ConnectionCallback& connection_callback, |
+ const std::string& device_address, |
+ scoped_refptr<BluetoothSocketWin> socket) { |
+ DCHECK(ui_task_runner->RunsTasksOnCurrentThread()); |
+ device::BluetoothAdapterFactory::GetAdapter( |
+ base::Bind(&OnConnectSuccessUIWithAdapter, |
+ ui_task_runner, |
+ callback, |
+ connection_callback, |
+ device_address, |
+ socket)); |
+} |
+ |
+void OnConnectErrorUI(scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
+ const BluetoothProfileWin::ErrorCallback& error_callback, |
+ const std::string& error) { |
+ DCHECK(ui_task_runner->RunsTasksOnCurrentThread()); |
+ error_callback.Run(error); |
+} |
+ |
+} // namespace |
+ |
namespace device { |
BluetoothProfileWin::BluetoothProfileWin(const BluetoothUUID& uuid, |
@@ -28,20 +83,37 @@ void BluetoothProfileWin::SetConnectionCallback( |
connection_callback_ = callback; |
} |
-bool BluetoothProfileWin::Connect(const BluetoothDeviceWin* device) { |
- if (connection_callback_.is_null()) |
- return false; |
+void BluetoothProfileWin::Connect( |
+ const BluetoothDeviceWin* device, |
+ scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
+ scoped_refptr<BluetoothSocketThreadWin> socket_thread, |
+ net::NetLog* net_log, |
+ const net::NetLog::Source& source, |
+ const base::Closure& success_callback, |
+ const ErrorCallback& error_callback) { |
+ DCHECK(ui_task_runner->RunsTasksOnCurrentThread()); |
+ if (connection_callback_.is_null()) { |
+ error_callback.Run(kNoConnectionCallback); |
+ return; |
+ } |
const BluetoothServiceRecord* record = device->GetServiceRecord(uuid_); |
- if (record) { |
- scoped_refptr<BluetoothSocket> socket( |
- BluetoothSocketWin::CreateBluetoothSocket(*record)); |
- if (socket.get() != NULL) { |
- connection_callback_.Run(device, socket); |
- return true; |
- } |
+ if (!record) { |
+ error_callback.Run(kProfileNotFound); |
+ return; |
} |
- return false; |
+ |
+ scoped_refptr<BluetoothSocketWin> socket( |
+ BluetoothSocketWin::CreateBluetoothSocket( |
+ *record, ui_task_runner, socket_thread, net_log, source)); |
+ |
+ socket->Connect(base::Bind(&OnConnectSuccessUI, |
+ ui_task_runner, |
+ success_callback, |
+ connection_callback_, |
+ device->GetAddress(), |
+ socket), |
+ error_callback); |
} |
} // namespace device |