Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1350)

Unified Diff: device/bluetooth/adapter.cc

Issue 2448713002: bluetooth: Add Device connection logic and accompanying user interface. (Closed)
Patch Set: Remove binding variable in Device.Create Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/adapter.h ('k') | device/bluetooth/device.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/adapter.cc
diff --git a/device/bluetooth/adapter.cc b/device/bluetooth/adapter.cc
index 639e7a2fd501b984dcbe1fc63486200e7523ef1c..62eb9a54b08f777951034e123ef7c9a7405921c5 100644
--- a/device/bluetooth/adapter.cc
+++ b/device/bluetooth/adapter.cc
@@ -6,9 +6,10 @@
#include <utility>
#include <vector>
+#include "base/memory/ptr_util.h"
#include "device/bluetooth/adapter.h"
#include "device/bluetooth/device.h"
-#include "mojo/public/cpp/bindings/strong_binding.h"
+#include "device/bluetooth/public/interfaces/connect_result_type_converter.h"
namespace bluetooth {
@@ -34,12 +35,21 @@ void Adapter::GetInfo(const GetInfoCallback& callback) {
callback.Run(std::move(adapter_info));
}
-void Adapter::GetDevice(const std::string& address,
- const GetDeviceCallback& callback) {
- mojom::DevicePtr device_ptr;
- mojo::MakeStrongBinding(base::MakeUnique<Device>(address, adapter_),
- mojo::GetProxy(&device_ptr));
- callback.Run(std::move(device_ptr));
+void Adapter::ConnectToDevice(const std::string& address,
+ const ConnectToDeviceCallback& callback) {
+ device::BluetoothDevice* device = adapter_->GetDevice(address);
+
+ if (!device) {
+ callback.Run(mojom::ConnectResult::DEVICE_NO_LONGER_IN_RANGE,
+ nullptr /* device */);
+ return;
+ }
+
+ device->CreateGattConnection(
+ base::Bind(&Adapter::OnGattConnected, weak_ptr_factory_.GetWeakPtr(),
+ callback),
+ base::Bind(&Adapter::OnConnectError, weak_ptr_factory_.GetWeakPtr(),
+ callback));
}
void Adapter::GetDevices(const GetDevicesCallback& callback) {
@@ -82,4 +92,18 @@ void Adapter::DeviceChanged(device::BluetoothAdapter* adapter,
}
}
+void Adapter::OnGattConnected(
+ const ConnectToDeviceCallback& callback,
+ std::unique_ptr<device::BluetoothGattConnection> connection) {
+ mojom::DevicePtr device_ptr;
+ Device::Create(adapter_, std::move(connection), mojo::GetProxy(&device_ptr));
+ callback.Run(mojom::ConnectResult::SUCCESS, std::move(device_ptr));
+}
+
+void Adapter::OnConnectError(
+ const ConnectToDeviceCallback& callback,
+ device::BluetoothDevice::ConnectErrorCode error_code) {
+ callback.Run(mojo::ConvertTo<mojom::ConnectResult>(error_code),
+ nullptr /* Device */);
+}
} // namespace bluetooth
« no previous file with comments | « device/bluetooth/adapter.h ('k') | device/bluetooth/device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698