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 | 6 |
7 #include <bluetooth/bluetooth.h> | 7 #include <bluetooth/bluetooth.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 return; | 936 return; |
937 | 937 |
938 DCHECK(addr); | 938 DCHECK(addr); |
939 | 939 |
940 arc_bridge_service()->bluetooth()->instance()->OnLEConnectionStateChange( | 940 arc_bridge_service()->bluetooth()->instance()->OnLEConnectionStateChange( |
941 std::move(addr), connected); | 941 std::move(addr), connected); |
942 } | 942 } |
943 | 943 |
944 void ArcBluetoothBridge::OnGattConnected( | 944 void ArcBluetoothBridge::OnGattConnected( |
945 mojom::BluetoothAddressPtr addr, | 945 mojom::BluetoothAddressPtr addr, |
946 std::unique_ptr<BluetoothGattConnection> connection) const { | 946 std::unique_ptr<BluetoothGattConnection> connection) { |
| 947 DCHECK(CalledOnValidThread()); |
| 948 gatt_connections_[addr->To<std::string>()] = std::move(connection); |
947 OnGattConnectStateChanged(std::move(addr), true); | 949 OnGattConnectStateChanged(std::move(addr), true); |
948 } | 950 } |
949 | 951 |
950 void ArcBluetoothBridge::OnGattConnectError( | 952 void ArcBluetoothBridge::OnGattConnectError( |
951 mojom::BluetoothAddressPtr addr, | 953 mojom::BluetoothAddressPtr addr, |
952 BluetoothDevice::ConnectErrorCode error_code) const { | 954 BluetoothDevice::ConnectErrorCode error_code) const { |
953 OnGattConnectStateChanged(std::move(addr), false); | 955 OnGattConnectStateChanged(std::move(addr), false); |
954 } | 956 } |
955 | 957 |
956 void ArcBluetoothBridge::OnGattDisconnected( | 958 void ArcBluetoothBridge::OnGattDisconnected( |
957 mojom::BluetoothAddressPtr addr) const { | 959 mojom::BluetoothAddressPtr addr) { |
| 960 DCHECK(CalledOnValidThread()); |
| 961 auto it = gatt_connections_.find(addr->To<std::string>()); |
| 962 if (it == gatt_connections_.end()) { |
| 963 LOG(WARNING) << "OnGattDisconnected called, " |
| 964 << "but no gatt connection was found"; |
| 965 } else { |
| 966 gatt_connections_.erase(it); |
| 967 } |
| 968 |
958 OnGattConnectStateChanged(std::move(addr), false); | 969 OnGattConnectStateChanged(std::move(addr), false); |
959 } | 970 } |
960 | 971 |
961 void ArcBluetoothBridge::ConnectLEDevice( | 972 void ArcBluetoothBridge::ConnectLEDevice( |
962 mojom::BluetoothAddressPtr remote_addr) { | 973 mojom::BluetoothAddressPtr remote_addr) { |
963 if (!HasBluetoothInstance()) | 974 if (!HasBluetoothInstance()) |
964 return; | 975 return; |
965 | 976 |
966 BluetoothDevice* device = | 977 BluetoothDevice* device = |
967 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 978 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1832 LOG(WARNING) << "Bluetooth instance is too old (version " << version | 1843 LOG(WARNING) << "Bluetooth instance is too old (version " << version |
1833 << ") need version " << version_need; | 1844 << ") need version " << version_need; |
1834 return false; | 1845 return false; |
1835 } | 1846 } |
1836 | 1847 |
1837 bool ArcBluetoothBridge::CalledOnValidThread() { | 1848 bool ArcBluetoothBridge::CalledOnValidThread() { |
1838 return thread_checker_.CalledOnValidThread(); | 1849 return thread_checker_.CalledOnValidThread(); |
1839 } | 1850 } |
1840 | 1851 |
1841 } // namespace arc | 1852 } // namespace arc |
OLD | NEW |