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

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

Issue 2244693002: bluetooth: Refactor how we update based on Advertising Data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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
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 <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 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 } 1465 }
1466 if (type == mojom::BluetoothPropertyType::ALL || 1466 if (type == mojom::BluetoothPropertyType::ALL ||
1467 type == mojom::BluetoothPropertyType::BDADDR) { 1467 type == mojom::BluetoothPropertyType::BDADDR) {
1468 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); 1468 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New();
1469 btp->set_bdaddr(mojom::BluetoothAddress::From(device->GetAddress())); 1469 btp->set_bdaddr(mojom::BluetoothAddress::From(device->GetAddress()));
1470 properties.push_back(std::move(btp)); 1470 properties.push_back(std::move(btp));
1471 } 1471 }
1472 if (type == mojom::BluetoothPropertyType::ALL || 1472 if (type == mojom::BluetoothPropertyType::ALL ||
1473 type == mojom::BluetoothPropertyType::UUIDS) { 1473 type == mojom::BluetoothPropertyType::UUIDS) {
1474 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); 1474 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New();
1475 std::vector<BluetoothUUID> uuids = device->GetUUIDs(); 1475 BluetoothDevice::UUIDSet uuids = device->GetUUIDs();
1476 mojo::Array<mojom::BluetoothUUIDPtr> uuid_results = 1476 mojo::Array<mojom::BluetoothUUIDPtr> uuid_results =
1477 mojo::Array<mojom::BluetoothUUIDPtr>::New(0); 1477 mojo::Array<mojom::BluetoothUUIDPtr>::New(uuids.size());
1478 1478
1479 for (auto& uuid : uuids) { 1479 size_t i = 0;
1480 uuid_results.push_back(mojom::BluetoothUUID::From(uuid)); 1480 for (const auto& uuid : uuids) {
Luis Héctor Chávez 2016/08/23 15:49:27 nit: can this be for (size_t i = 0; i < uuids.siz
ortuno 2016/08/23 17:40:19 We can't do that because uuids is not a vector, it
Luis Héctor Chávez 2016/08/23 17:44:28 Fine then :(
1481 uuid_results[i] = mojom::BluetoothUUID::From(uuid);
1482 i++;
1481 } 1483 }
1482 1484
1483 btp->set_uuids(std::move(uuid_results)); 1485 btp->set_uuids(std::move(uuid_results));
1484 properties.push_back(std::move(btp)); 1486 properties.push_back(std::move(btp));
1485 } 1487 }
1486 if (type == mojom::BluetoothPropertyType::ALL || 1488 if (type == mojom::BluetoothPropertyType::ALL ||
1487 type == mojom::BluetoothPropertyType::CLASS_OF_DEVICE) { 1489 type == mojom::BluetoothPropertyType::CLASS_OF_DEVICE) {
1488 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); 1490 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New();
1489 btp->set_device_class(device->GetBluetoothClass()); 1491 btp->set_device_class(device->GetBluetoothClass());
1490 properties.push_back(std::move(btp)); 1492 properties.push_back(std::move(btp));
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 mojo::Array<mojom::BluetoothAdvertisingDataPtr> advertising_data; 1625 mojo::Array<mojom::BluetoothAdvertisingDataPtr> advertising_data;
1624 1626
1625 // LocalName 1627 // LocalName
1626 mojom::BluetoothAdvertisingDataPtr local_name = 1628 mojom::BluetoothAdvertisingDataPtr local_name =
1627 mojom::BluetoothAdvertisingData::New(); 1629 mojom::BluetoothAdvertisingData::New();
1628 local_name->set_local_name(device->GetName() ? device->GetName().value() 1630 local_name->set_local_name(device->GetName() ? device->GetName().value()
1629 : nullptr); 1631 : nullptr);
1630 advertising_data.push_back(std::move(local_name)); 1632 advertising_data.push_back(std::move(local_name));
1631 1633
1632 // ServiceUuid 1634 // ServiceUuid
1633 BluetoothDevice::UUIDList uuid_list = device->GetUUIDs(); 1635 BluetoothDevice::UUIDSet uuid_set = device->GetUUIDs();
1634 if (uuid_list.size() > 0) { 1636 if (uuid_set.size() > 0) {
1635 mojom::BluetoothAdvertisingDataPtr service_uuids_16 = 1637 mojom::BluetoothAdvertisingDataPtr service_uuids_16 =
1636 mojom::BluetoothAdvertisingData::New(); 1638 mojom::BluetoothAdvertisingData::New();
1637 mojo::Array<uint16_t> uuid16s; 1639 mojo::Array<uint16_t> uuid16s(uuid_set.size());
1638 for (auto& uuid : uuid_list) { 1640 size_t i = 0;
1639 uuid16s.push_back(GetUUID16(uuid)); 1641 for (const auto& uuid : uuid_set) {
1642 uuid16s[i] = GetUUID16(uuid);
1643 i++;
1640 } 1644 }
1641 service_uuids_16->set_service_uuids_16(std::move(uuid16s)); 1645 service_uuids_16->set_service_uuids_16(std::move(uuid16s));
1642 advertising_data.push_back(std::move(service_uuids_16)); 1646 advertising_data.push_back(std::move(service_uuids_16));
1643 } 1647 }
1644 1648
1645 // Service data 1649 // Service data
1646 for (auto& uuid : device->GetServiceDataUUIDs()) { 1650 for (const BluetoothUUID& uuid : device->GetServiceDataUUIDs()) {
1647 base::BinaryValue* data = device->GetServiceData(uuid);
1648 if (data->GetSize() == 0)
1649 continue;
1650 std::string data_str;
1651 if (!data->GetAsString(&data_str))
1652 continue;
1653
1654 mojom::BluetoothAdvertisingDataPtr service_data_element = 1651 mojom::BluetoothAdvertisingDataPtr service_data_element =
1655 mojom::BluetoothAdvertisingData::New(); 1652 mojom::BluetoothAdvertisingData::New();
1656 mojom::BluetoothServiceDataPtr service_data = 1653 mojom::BluetoothServiceDataPtr service_data =
1657 mojom::BluetoothServiceData::New(); 1654 mojom::BluetoothServiceData::New();
1658 1655
1659 service_data->uuid_16bit = GetUUID16(uuid); 1656 service_data->uuid_16bit = GetUUID16(uuid);
1660 for (auto& c : data_str) { 1657
1661 service_data->data.push_back(c); 1658 const std::vector<uint8_t>* data = device->GetServiceDataForUUID(uuid);
1662 } 1659 DCHECK(data != nullptr);
1660
1661 std::vector<uint8_t> data_copy = *data;
1662 service_data->data.Swap(&data_copy);
1663
1663 service_data_element->set_service_data(std::move(service_data)); 1664 service_data_element->set_service_data(std::move(service_data));
1664 advertising_data.push_back(std::move(service_data_element)); 1665 advertising_data.push_back(std::move(service_data_element));
1665 } 1666 }
1666 1667
1667 return advertising_data; 1668 return advertising_data;
1668 } 1669 }
1669 1670
1670 void ArcBluetoothBridge::SendCachedDevicesFound() const { 1671 void ArcBluetoothBridge::SendCachedDevicesFound() const {
1671 // Send devices that have already been discovered, but aren't connected. 1672 // Send devices that have already been discovered, but aren't connected.
1672 if (!HasBluetoothInstance()) 1673 if (!HasBluetoothInstance())
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 LOG(WARNING) << "Bluetooth instance is too old (version " << version 1752 LOG(WARNING) << "Bluetooth instance is too old (version " << version
1752 << ") need version " << version_need; 1753 << ") need version " << version_need;
1753 return false; 1754 return false;
1754 } 1755 }
1755 1756
1756 bool ArcBluetoothBridge::CalledOnValidThread() { 1757 bool ArcBluetoothBridge::CalledOnValidThread() {
1757 return thread_checker_.CalledOnValidThread(); 1758 return thread_checker_.CalledOnValidThread();
1758 } 1759 }
1759 1760
1760 } // namespace arc 1761 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698