| 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 <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <iomanip> | 10 #include <iomanip> |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 ArcBluetoothBridge::~ArcBluetoothBridge() { | 76 ArcBluetoothBridge::~ArcBluetoothBridge() { |
| 77 arc_bridge_service()->RemoveObserver(this); | 77 arc_bridge_service()->RemoveObserver(this); |
| 78 | 78 |
| 79 if (bluetooth_adapter_) | 79 if (bluetooth_adapter_) |
| 80 bluetooth_adapter_->RemoveObserver(this); | 80 bluetooth_adapter_->RemoveObserver(this); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void ArcBluetoothBridge::OnAdapterInitialized( | 83 void ArcBluetoothBridge::OnAdapterInitialized( |
| 84 scoped_refptr<BluetoothAdapter> adapter) { | 84 scoped_refptr<BluetoothAdapter> adapter) { |
| 85 bluetooth_adapter_ = adapter; | 85 // We can downcast here because we are always running on Chrome OS, and |
| 86 // so our adapter uses BlueZ. |
| 87 bluetooth_adapter_ = |
| 88 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter.get()); |
| 86 bluetooth_adapter_->AddObserver(this); | 89 bluetooth_adapter_->AddObserver(this); |
| 87 } | 90 } |
| 88 | 91 |
| 89 void ArcBluetoothBridge::OnBluetoothInstanceReady() { | 92 void ArcBluetoothBridge::OnBluetoothInstanceReady() { |
| 90 mojom::BluetoothInstance* bluetooth_instance = | 93 mojom::BluetoothInstance* bluetooth_instance = |
| 91 arc_bridge_service()->bluetooth_instance(); | 94 arc_bridge_service()->bluetooth_instance(); |
| 92 if (!bluetooth_instance) { | 95 if (!bluetooth_instance) { |
| 93 LOG(ERROR) << "OnBluetoothInstanceReady called, " | 96 LOG(ERROR) << "OnBluetoothInstanceReady called, " |
| 94 << "but no bluetooth instance found"; | 97 << "but no bluetooth instance found"; |
| 95 return; | 98 return; |
| (...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1178 mojom::BluetoothAddress::From(device->GetAddress()); | 1181 mojom::BluetoothAddress::From(device->GetAddress()); |
| 1179 bonded_devices.push_back(std::move(addr)); | 1182 bonded_devices.push_back(std::move(addr)); |
| 1180 } | 1183 } |
| 1181 | 1184 |
| 1182 btp->set_bonded_devices(std::move(bonded_devices)); | 1185 btp->set_bonded_devices(std::move(bonded_devices)); |
| 1183 properties.push_back(std::move(btp)); | 1186 properties.push_back(std::move(btp)); |
| 1184 } | 1187 } |
| 1185 if (type == mojom::BluetoothPropertyType::ALL || | 1188 if (type == mojom::BluetoothPropertyType::ALL || |
| 1186 type == mojom::BluetoothPropertyType::ADAPTER_DISCOVERY_TIMEOUT) { | 1189 type == mojom::BluetoothPropertyType::ADAPTER_DISCOVERY_TIMEOUT) { |
| 1187 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1190 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 1188 btp->set_discovery_timeout(120); | 1191 btp->set_discovery_timeout(bluetooth_adapter_->GetDiscoverableTimeout()); |
| 1189 properties.push_back(std::move(btp)); | 1192 properties.push_back(std::move(btp)); |
| 1190 } | 1193 } |
| 1191 | 1194 |
| 1192 return properties; | 1195 return properties; |
| 1193 } | 1196 } |
| 1194 | 1197 |
| 1195 // Android support 5 types of Advertising Data. | 1198 // Android support 5 types of Advertising Data. |
| 1196 // However Chrome didn't expose AdvertiseFlag and ManufacturerData. | 1199 // However Chrome didn't expose AdvertiseFlag and ManufacturerData. |
| 1197 // So we will only expose local_name, service_uuids and service_data. | 1200 // So we will only expose local_name, service_uuids and service_data. |
| 1198 // TODO(crbug.com/618442) Make Chrome expose missing data. | 1201 // TODO(crbug.com/618442) Make Chrome expose missing data. |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 // to | 1314 // to |
| 1312 // make sure the bond state machine on Android is ready to take the | 1315 // make sure the bond state machine on Android is ready to take the |
| 1313 // pair-done event. Otherwise the pair-done event will be dropped as an | 1316 // pair-done event. Otherwise the pair-done event will be dropped as an |
| 1314 // invalid change of paired status. | 1317 // invalid change of paired status. |
| 1315 OnPairing(addr->Clone()); | 1318 OnPairing(addr->Clone()); |
| 1316 OnPairedDone(std::move(addr)); | 1319 OnPairedDone(std::move(addr)); |
| 1317 } | 1320 } |
| 1318 } | 1321 } |
| 1319 | 1322 |
| 1320 } // namespace arc | 1323 } // namespace arc |
| OLD | NEW |