| Index: components/arc/bluetooth/arc_bluetooth_bridge.cc
|
| diff --git a/components/arc/bluetooth/arc_bluetooth_bridge.cc b/components/arc/bluetooth/arc_bluetooth_bridge.cc
|
| index 5042636b7465a062c41a05f768b4253c6e6f05a4..06b4ea7d372c5e0664796bb21b6d2f495989aa55 100644
|
| --- a/components/arc/bluetooth/arc_bluetooth_bridge.cc
|
| +++ b/components/arc/bluetooth/arc_bluetooth_bridge.cc
|
| @@ -4,8 +4,10 @@
|
|
|
| #include "components/arc/bluetooth/arc_bluetooth_bridge.h"
|
|
|
| +#include <bluetooth/bluetooth.h>
|
| #include <fcntl.h>
|
| #include <stddef.h>
|
| +#include <sys/socket.h>
|
|
|
| #include <iomanip>
|
| #include <string>
|
| @@ -28,6 +30,8 @@
|
| #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
|
| #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h"
|
| #include "device/bluetooth/bluetooth_remote_gatt_service.h"
|
| +#include "mojo/edk/embedder/embedder.h"
|
| +#include "mojo/edk/embedder/scoped_platform_handle.h"
|
|
|
| using device::BluetoothAdapter;
|
| using device::BluetoothAdapterFactory;
|
| @@ -1023,6 +1027,29 @@ void ArcBluetoothBridge::ReadRemoteRssi(
|
| callback.Run(rssi);
|
| }
|
|
|
| +void ArcBluetoothBridge::OpenBluetoothSocket(
|
| + const OpenBluetoothSocketCallback& callback) {
|
| + base::ScopedFD sock(socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM));
|
| + if (!sock.is_valid()) {
|
| + LOG(ERROR) << "Failed to open socket.";
|
| + callback.Run(mojo::ScopedHandle());
|
| + return;
|
| + }
|
| + mojo::edk::ScopedPlatformHandle platform_handle{
|
| + mojo::edk::PlatformHandle(sock.release())};
|
| + MojoHandle wrapped_handle;
|
| + MojoResult wrap_result = mojo::edk::CreatePlatformHandleWrapper(
|
| + std::move(platform_handle), &wrapped_handle);
|
| + if (wrap_result != MOJO_RESULT_OK) {
|
| + LOG(ERROR) << "Failed to wrap handles. Closing: " << wrap_result;
|
| + callback.Run(mojo::ScopedHandle());
|
| + return;
|
| + }
|
| + mojo::ScopedHandle scoped_handle{mojo::Handle(wrapped_handle)};
|
| +
|
| + callback.Run(std::move(scoped_handle));
|
| +}
|
| +
|
| void ArcBluetoothBridge::OnDiscoveryError() {
|
| LOG(WARNING) << "failed to change discovery state";
|
| }
|
|
|