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

Side by Side Diff: components/arc/bluetooth/arc_bluetooth_bridge.cc

Issue 2319953002: arc: bluetooth: Implement socket opening (Closed)
Patch Set: Created 4 years, 3 months 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 unified diff | Download patch
« no previous file with comments | « components/arc/bluetooth/arc_bluetooth_bridge.h ('k') | components/arc/common/bluetooth.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/arc/bluetooth/arc_bluetooth_bridge.h" 5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h"
6 6
7 #include <bluetooth/bluetooth.h>
7 #include <fcntl.h> 8 #include <fcntl.h>
8 #include <stddef.h> 9 #include <stddef.h>
10 #include <sys/socket.h>
9 11
10 #include <iomanip> 12 #include <iomanip>
11 #include <string> 13 #include <string>
12 14
13 #include "base/bind.h" 15 #include "base/bind.h"
14 #include "base/logging.h" 16 #include "base/logging.h"
15 #include "base/posix/eintr_wrapper.h" 17 #include "base/posix/eintr_wrapper.h"
16 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
18 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
19 #include "base/time/time.h" 21 #include "base/time/time.h"
20 #include "components/arc/arc_bridge_service.h" 22 #include "components/arc/arc_bridge_service.h"
21 #include "components/arc/bluetooth/bluetooth_type_converters.h" 23 #include "components/arc/bluetooth/bluetooth_type_converters.h"
22 #include "device/bluetooth/bluetooth_common.h" 24 #include "device/bluetooth/bluetooth_common.h"
23 #include "device/bluetooth/bluetooth_device.h" 25 #include "device/bluetooth/bluetooth_device.h"
24 #include "device/bluetooth/bluetooth_gatt_connection.h" 26 #include "device/bluetooth/bluetooth_gatt_connection.h"
25 #include "device/bluetooth/bluetooth_gatt_notify_session.h" 27 #include "device/bluetooth/bluetooth_gatt_notify_session.h"
26 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h" 28 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h"
27 #include "device/bluetooth/bluetooth_local_gatt_descriptor.h" 29 #include "device/bluetooth/bluetooth_local_gatt_descriptor.h"
30 #include "mojo/edk/embedder/embedder.h"
31 #include "mojo/edk/embedder/scoped_platform_handle.h"
28 32
29 using device::BluetoothAdapter; 33 using device::BluetoothAdapter;
30 using device::BluetoothAdapterFactory; 34 using device::BluetoothAdapterFactory;
31 using device::BluetoothAdvertisement; 35 using device::BluetoothAdvertisement;
32 using device::BluetoothDevice; 36 using device::BluetoothDevice;
33 using device::BluetoothDiscoveryFilter; 37 using device::BluetoothDiscoveryFilter;
34 using device::BluetoothDiscoverySession; 38 using device::BluetoothDiscoverySession;
35 using device::BluetoothGattConnection; 39 using device::BluetoothGattConnection;
36 using device::BluetoothGattNotifySession; 40 using device::BluetoothGattNotifySession;
37 using device::BluetoothGattCharacteristic; 41 using device::BluetoothGattCharacteristic;
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 OnGattOperationDone(callback); 1338 OnGattOperationDone(callback);
1335 } 1339 }
1336 1340
1337 void ArcBluetoothBridge::SendIndication( 1341 void ArcBluetoothBridge::SendIndication(
1338 int32_t attribute_handle, 1342 int32_t attribute_handle,
1339 mojom::BluetoothAddressPtr address, 1343 mojom::BluetoothAddressPtr address,
1340 bool confirm, 1344 bool confirm,
1341 mojo::Array<uint8_t> value, 1345 mojo::Array<uint8_t> value,
1342 const SendIndicationCallback& callback) {} 1346 const SendIndicationCallback& callback) {}
1343 1347
1348 void ArcBluetoothBridge::OpenBluetoothSocket(
1349 const OpenBluetoothSocketCallback& callback) {
1350 base::ScopedFD sock(socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM));
1351 if (!sock.is_valid()) {
1352 LOG(ERROR) << "Failed to open socket.";
1353 callback.Run(mojo::ScopedHandle());
1354 return;
1355 }
1356 mojo::edk::ScopedPlatformHandle platform_handle{
1357 mojo::edk::PlatformHandle(sock.release())};
1358 MojoHandle wrapped_handle;
1359 MojoResult wrap_result = mojo::edk::CreatePlatformHandleWrapper(
1360 std::move(platform_handle), &wrapped_handle);
1361 if (wrap_result != MOJO_RESULT_OK) {
1362 LOG(ERROR) << "Failed to wrap handles. Closing: " << wrap_result;
1363 callback.Run(mojo::ScopedHandle());
1364 return;
1365 }
1366 mojo::ScopedHandle scoped_handle{mojo::Handle(wrapped_handle)};
1367
1368 callback.Run(std::move(scoped_handle));
1369 }
1370
1344 void ArcBluetoothBridge::OnDiscoveryError() { 1371 void ArcBluetoothBridge::OnDiscoveryError() {
1345 LOG(WARNING) << "failed to change discovery state"; 1372 LOG(WARNING) << "failed to change discovery state";
1346 } 1373 }
1347 1374
1348 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { 1375 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const {
1349 if (!HasBluetoothInstance()) 1376 if (!HasBluetoothInstance())
1350 return; 1377 return;
1351 1378
1352 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged( 1379 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged(
1353 mojom::BluetoothStatus::SUCCESS, std::move(addr), 1380 mojom::BluetoothStatus::SUCCESS, std::move(addr),
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 LOG(WARNING) << "Bluetooth instance is too old (version " << version 1706 LOG(WARNING) << "Bluetooth instance is too old (version " << version
1680 << ") need version " << version_need; 1707 << ") need version " << version_need;
1681 return false; 1708 return false;
1682 } 1709 }
1683 1710
1684 bool ArcBluetoothBridge::CalledOnValidThread() { 1711 bool ArcBluetoothBridge::CalledOnValidThread() {
1685 return thread_checker_.CalledOnValidThread(); 1712 return thread_checker_.CalledOnValidThread();
1686 } 1713 }
1687 1714
1688 } // namespace arc 1715 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/bluetooth/arc_bluetooth_bridge.h ('k') | components/arc/common/bluetooth.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698