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 | 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 1388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1399 } | 1399 } |
| 1400 if (type == mojom::BluetoothPropertyType::ALL || | 1400 if (type == mojom::BluetoothPropertyType::ALL || |
| 1401 type == mojom::BluetoothPropertyType::BDADDR) { | 1401 type == mojom::BluetoothPropertyType::BDADDR) { |
| 1402 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1402 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 1403 btp->set_bdaddr(mojom::BluetoothAddress::From(device->GetAddress())); | 1403 btp->set_bdaddr(mojom::BluetoothAddress::From(device->GetAddress())); |
| 1404 properties.push_back(std::move(btp)); | 1404 properties.push_back(std::move(btp)); |
| 1405 } | 1405 } |
| 1406 if (type == mojom::BluetoothPropertyType::ALL || | 1406 if (type == mojom::BluetoothPropertyType::ALL || |
| 1407 type == mojom::BluetoothPropertyType::UUIDS) { | 1407 type == mojom::BluetoothPropertyType::UUIDS) { |
| 1408 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1408 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 1409 std::vector<BluetoothUUID> uuids = device->GetUUIDs(); | 1409 BluetoothDevice::UUIDSet uuids = device->GetUUIDs(); |
| 1410 mojo::Array<mojom::BluetoothUUIDPtr> uuid_results = | 1410 mojo::Array<mojom::BluetoothUUIDPtr> uuid_results = |
| 1411 mojo::Array<mojom::BluetoothUUIDPtr>::New(0); | 1411 mojo::Array<mojom::BluetoothUUIDPtr>::New(uuids.size()); |
| 1412 | 1412 |
| 1413 for (auto& uuid : uuids) { | 1413 size_t i = 0; |
| 1414 uuid_results.push_back(mojom::BluetoothUUID::From(uuid)); | 1414 for (const auto& uuid : uuids) { |
| 1415 uuid_results[i] = mojom::BluetoothUUID::From(uuid); | |
|
Jeffrey Yasskin
2016/08/18 16:04:32
Too bad they don't have tests. You need to i++ in
ortuno
2016/08/19 20:50:32
Done.
| |
| 1415 } | 1416 } |
| 1416 | 1417 |
| 1417 btp->set_uuids(std::move(uuid_results)); | 1418 btp->set_uuids(std::move(uuid_results)); |
| 1418 properties.push_back(std::move(btp)); | 1419 properties.push_back(std::move(btp)); |
| 1419 } | 1420 } |
| 1420 if (type == mojom::BluetoothPropertyType::ALL || | 1421 if (type == mojom::BluetoothPropertyType::ALL || |
| 1421 type == mojom::BluetoothPropertyType::CLASS_OF_DEVICE) { | 1422 type == mojom::BluetoothPropertyType::CLASS_OF_DEVICE) { |
| 1422 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1423 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 1423 btp->set_device_class(device->GetBluetoothClass()); | 1424 btp->set_device_class(device->GetBluetoothClass()); |
| 1424 properties.push_back(std::move(btp)); | 1425 properties.push_back(std::move(btp)); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1535 mojo::Array<mojom::BluetoothAdvertisingDataPtr> advertising_data; | 1536 mojo::Array<mojom::BluetoothAdvertisingDataPtr> advertising_data; |
| 1536 | 1537 |
| 1537 // LocalName | 1538 // LocalName |
| 1538 mojom::BluetoothAdvertisingDataPtr local_name = | 1539 mojom::BluetoothAdvertisingDataPtr local_name = |
| 1539 mojom::BluetoothAdvertisingData::New(); | 1540 mojom::BluetoothAdvertisingData::New(); |
| 1540 local_name->set_local_name(device->GetName() ? device->GetName().value() | 1541 local_name->set_local_name(device->GetName() ? device->GetName().value() |
| 1541 : nullptr); | 1542 : nullptr); |
| 1542 advertising_data.push_back(std::move(local_name)); | 1543 advertising_data.push_back(std::move(local_name)); |
| 1543 | 1544 |
| 1544 // ServiceUuid | 1545 // ServiceUuid |
| 1545 BluetoothDevice::UUIDList uuid_list = device->GetUUIDs(); | 1546 BluetoothDevice::UUIDSet uuid_set = device->GetUUIDs(); |
|
Jeffrey Yasskin
2016/08/18 16:04:32
This indentation's wrong.
ortuno
2016/08/19 20:50:32
Done.
| |
| 1546 if (uuid_list.size() > 0) { | 1547 if (uuid_set.size() > 0) { |
| 1547 mojom::BluetoothAdvertisingDataPtr service_uuids = | 1548 mojom::BluetoothAdvertisingDataPtr service_uuids = |
| 1548 mojom::BluetoothAdvertisingData::New(); | 1549 mojom::BluetoothAdvertisingData::New(); |
| 1549 service_uuids->set_service_uuids( | 1550 mojo::Array<mojom::BluetoothUUIDPtr> advertised_uuids(uuid_set.size()); |
| 1550 mojo::Array<mojom::BluetoothUUIDPtr>::From(uuid_list)); | 1551 size_t i = 0; |
| 1552 for (const auto& uuid : uuid_set) { | |
| 1553 advertised_uuids[i] = mojom::BluetoothUUID::From(uuid); | |
|
Jeffrey Yasskin
2016/08/18 16:04:32
Another missing i++.
ortuno
2016/08/19 20:50:32
Done.
| |
| 1554 } | |
| 1555 service_uuids->set_service_uuids(std::move(advertised_uuids)); | |
| 1551 advertising_data.push_back(std::move(service_uuids)); | 1556 advertising_data.push_back(std::move(service_uuids)); |
| 1552 } | 1557 } |
| 1553 | 1558 |
| 1554 // Service data | 1559 // Service data |
| 1555 for (auto& uuid : device->GetServiceDataUUIDs()) { | 1560 for (auto& uuid : device->GetServiceDataUUIDs()) { |
|
Jeffrey Yasskin
2016/08/18 16:04:32
Not from this change, but can this be a 'const aut
ortuno
2016/08/19 20:50:32
Done.
| |
| 1556 base::BinaryValue* data = device->GetServiceData(uuid); | |
| 1557 if (data->GetSize() == 0) | |
| 1558 continue; | |
| 1559 std::string data_str; | |
| 1560 if (!data->GetAsString(&data_str)) | |
| 1561 continue; | |
| 1562 | |
| 1563 mojom::BluetoothAdvertisingDataPtr service_data_element = | 1561 mojom::BluetoothAdvertisingDataPtr service_data_element = |
| 1564 mojom::BluetoothAdvertisingData::New(); | 1562 mojom::BluetoothAdvertisingData::New(); |
| 1565 mojom::BluetoothServiceDataPtr service_data = | 1563 mojom::BluetoothServiceDataPtr service_data = |
| 1566 mojom::BluetoothServiceData::New(); | 1564 mojom::BluetoothServiceData::New(); |
| 1567 | 1565 |
| 1568 std::string uuid_str = uuid.canonical_value(); | 1566 std::string uuid_str = uuid.canonical_value(); |
| 1569 // Convert xxxxyyyy-xxxx-xxxx-xxxx-xxxxxxxxxxxx to int16 yyyy | 1567 // Convert xxxxyyyy-xxxx-xxxx-xxxx-xxxxxxxxxxxx to int16 yyyy |
| 1570 service_data->uuid_16bit = std::stoi(uuid_str.substr(4, 4), nullptr, 16); | 1568 service_data->uuid_16bit = std::stoi(uuid_str.substr(4, 4), nullptr, 16); |
| 1571 for (auto& c : data_str) { | 1569 |
| 1572 service_data->data.push_back(c); | 1570 const std::vector<uint8_t>* data = device->GetServiceDataForUUID(uuid); |
| 1571 DCHECK(data != nullptr); | |
| 1572 | |
| 1573 for (const uint8_t& byte : *data) { | |
|
Jeffrey Yasskin
2016/08/18 16:04:32
I think you can use "service_data->data.assign(dat
ortuno
2016/08/19 20:50:32
Close. service_data->data is a mojo::Array and tha
| |
| 1574 service_data->data.push_back(byte); | |
| 1573 } | 1575 } |
| 1574 service_data_element->set_service_data(std::move(service_data)); | 1576 service_data_element->set_service_data(std::move(service_data)); |
| 1575 advertising_data.push_back(std::move(service_data_element)); | 1577 advertising_data.push_back(std::move(service_data_element)); |
| 1576 } | 1578 } |
| 1577 | 1579 |
| 1578 return advertising_data; | 1580 return advertising_data; |
| 1579 } | 1581 } |
| 1580 | 1582 |
| 1581 void ArcBluetoothBridge::SendCachedDevicesFound() const { | 1583 void ArcBluetoothBridge::SendCachedDevicesFound() const { |
| 1582 // Send devices that have already been discovered, but aren't connected. | 1584 // Send devices that have already been discovered, but aren't connected. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1662 LOG(WARNING) << "Bluetooth instance is too old (version " << version | 1664 LOG(WARNING) << "Bluetooth instance is too old (version " << version |
| 1663 << ") need version " << version_need; | 1665 << ") need version " << version_need; |
| 1664 return false; | 1666 return false; |
| 1665 } | 1667 } |
| 1666 | 1668 |
| 1667 bool ArcBluetoothBridge::CalledOnValidThread() { | 1669 bool ArcBluetoothBridge::CalledOnValidThread() { |
| 1668 return thread_checker_.CalledOnValidThread(); | 1670 return thread_checker_.CalledOnValidThread(); |
| 1669 } | 1671 } |
| 1670 | 1672 |
| 1671 } // namespace arc | 1673 } // namespace arc |
| OLD | NEW |