Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include <bluetooth/bluetooth.h> | |
| 7 #include <sys/socket.h> | |
|
Luis Héctor Chávez
2016/07/20 23:16:38
nit: these need to be together with the rest of th
| |
| 6 | 8 |
| 7 #include <fcntl.h> | 9 #include <fcntl.h> |
| 8 #include <stddef.h> | 10 #include <stddef.h> |
| 9 | 11 |
| 10 #include <iomanip> | 12 #include <iomanip> |
| 11 #include <string> | 13 #include <string> |
| 12 #include <utility> | 14 #include <utility> |
| 15 #include "mojo/edk/embedder/embedder.h" | |
| 16 #include "mojo/edk/embedder/scoped_platform_handle.h" | |
|
Luis Héctor Chávez
2016/07/20 23:16:38
nit: these need to be together with the rest of th
| |
| 13 | 17 |
| 14 #include "base/bind.h" | 18 #include "base/bind.h" |
| 15 #include "base/logging.h" | 19 #include "base/logging.h" |
| 16 #include "base/posix/eintr_wrapper.h" | 20 #include "base/posix/eintr_wrapper.h" |
| 17 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "base/time/time.h" | 24 #include "base/time/time.h" |
| 21 #include "components/arc/arc_bridge_service.h" | 25 #include "components/arc/arc_bridge_service.h" |
| 22 #include "components/arc/bluetooth/bluetooth_type_converters.h" | 26 #include "components/arc/bluetooth/bluetooth_type_converters.h" |
| (...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1016 | 1020 |
| 1017 void ArcBluetoothBridge::ReadRemoteRssi( | 1021 void ArcBluetoothBridge::ReadRemoteRssi( |
| 1018 mojom::BluetoothAddressPtr remote_addr, | 1022 mojom::BluetoothAddressPtr remote_addr, |
| 1019 const ReadRemoteRssiCallback& callback) { | 1023 const ReadRemoteRssiCallback& callback) { |
| 1020 BluetoothDevice* device = | 1024 BluetoothDevice* device = |
| 1021 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 1025 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
| 1022 int rssi = device->GetInquiryRSSI(); | 1026 int rssi = device->GetInquiryRSSI(); |
| 1023 callback.Run(rssi); | 1027 callback.Run(rssi); |
| 1024 } | 1028 } |
| 1025 | 1029 |
| 1030 void ArcBluetoothBridge::OpenBluetoothSocket( | |
| 1031 const OpenBluetoothSocketCallback& callback) { | |
| 1032 base::ScopedFD sock(socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)); | |
|
Luis Héctor Chávez
2016/07/20 23:16:38
nit: can you do
if (!sock.is_valid()) {
LOG(...
| |
| 1033 mojo::edk::ScopedPlatformHandle platform_handle{ | |
| 1034 mojo::edk::PlatformHandle(sock.release())}; | |
| 1035 MojoHandle wrapped_handle; | |
| 1036 MojoResult wrap_result = mojo::edk::CreatePlatformHandleWrapper( | |
| 1037 std::move(platform_handle), &wrapped_handle); | |
| 1038 if (wrap_result != MOJO_RESULT_OK) { | |
| 1039 LOG(ERROR) << "Failed to wrap handles. Closing: " << wrap_result; | |
| 1040 callback.Run(mojo::ScopedHandle()); | |
| 1041 return; | |
| 1042 } | |
| 1043 mojo::ScopedHandle scoped_handle{mojo::Handle(wrapped_handle)}; | |
| 1044 | |
| 1045 callback.Run(std::move(scoped_handle)); | |
| 1046 } | |
| 1047 | |
| 1026 void ArcBluetoothBridge::OnDiscoveryError() { | 1048 void ArcBluetoothBridge::OnDiscoveryError() { |
| 1027 LOG(WARNING) << "failed to change discovery state"; | 1049 LOG(WARNING) << "failed to change discovery state"; |
| 1028 } | 1050 } |
| 1029 | 1051 |
| 1030 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { | 1052 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { |
| 1031 if (!HasBluetoothInstance()) | 1053 if (!HasBluetoothInstance()) |
| 1032 return; | 1054 return; |
| 1033 | 1055 |
| 1034 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged( | 1056 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged( |
| 1035 mojom::BluetoothStatus::SUCCESS, std::move(addr), | 1057 mojom::BluetoothStatus::SUCCESS, std::move(addr), |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1354 uint32_t version_need) const { | 1376 uint32_t version_need) const { |
| 1355 uint32_t version = arc_bridge_service()->bluetooth()->version(); | 1377 uint32_t version = arc_bridge_service()->bluetooth()->version(); |
| 1356 if (version >= version_need) | 1378 if (version >= version_need) |
| 1357 return true; | 1379 return true; |
| 1358 LOG(WARNING) << "Bluetooth instance is too old (version " << version | 1380 LOG(WARNING) << "Bluetooth instance is too old (version " << version |
| 1359 << ") need version " << version_need; | 1381 << ") need version " << version_need; |
| 1360 return false; | 1382 return false; |
| 1361 } | 1383 } |
| 1362 | 1384 |
| 1363 } // namespace arc | 1385 } // namespace arc |
| OLD | NEW |