Commit 20d09354 authored by Ovidio Henriquez's avatar Ovidio Henriquez Committed by Commit Bot

bluetooth: Use DeviceUUID in FakePeripheral

This change refactors FakePeripheral to use the built-in DeviceUUIDs
helper class in BluetoothDevice to handle the UUIDs for a device.

BUG=719826

Change-Id: I9c60f00912aca706f16f402031483711f6f3ae89
Reviewed-on: https://chromium-review.googlesource.com/958337
Commit-Queue: Ovidio Henriquez <odejesush@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarConley Owens <cco3@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544235}
parent 8befc322
......@@ -580,7 +580,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice {
// Helper class to easily update the sets of UUIDs and keep them in sync with
// the set of all the device's UUIDs.
class DeviceUUIDs {
class DEVICE_BLUETOOTH_EXPORT DeviceUUIDs {
public:
DeviceUUIDs();
~DeviceUUIDs();
......
......@@ -8,6 +8,7 @@
#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "device/bluetooth/bluetooth_uuid.h"
#include "device/bluetooth/test/fake_remote_gatt_service.h"
......@@ -35,7 +36,20 @@ void FakePeripheral::SetSystemConnected(bool connected) {
}
void FakePeripheral::SetServiceUUIDs(UUIDSet service_uuids) {
service_uuids_ = std::move(service_uuids);
device::BluetoothDevice::GattServiceMap services_map;
bool inserted;
// Create a temporary map of services, because ReplaceServiceUUids expects a
// GattServiceMap even though it only uses the UUIDs.
int count = 0;
for (const auto& uuid : service_uuids) {
std::string id = base::IntToString(count++);
std::tie(std::ignore, inserted) =
services_map.emplace(id, std::make_unique<FakeRemoteGattService>(
id, uuid, true /* is_primary */, this));
DCHECK(inserted);
}
device_uuids_.ReplaceServiceUUIDs(services_map);
}
void FakePeripheral::SetNextGATTConnectionResponse(uint16_t code) {
......@@ -66,6 +80,7 @@ void FakePeripheral::SimulateGATTDisconnection() {
// for more details.
system_connected_ = false;
gatt_connected_ = false;
device_uuids_.ClearServiceUUIDs();
SetGattServicesDiscoveryComplete(false);
DidDisconnectGatt();
}
......@@ -180,10 +195,6 @@ bool FakePeripheral::IsConnecting() const {
return false;
}
device::BluetoothDevice::UUIDSet FakePeripheral::GetUUIDs() const {
return service_uuids_;
}
bool FakePeripheral::ExpectingPinCode() const {
NOTREACHED();
return false;
......@@ -328,6 +339,7 @@ void FakePeripheral::DispatchDiscoveryResponse() {
pending_gatt_discovery_ = false;
if (code == mojom::kHCISuccess) {
device_uuids_.ReplaceServiceUUIDs(gatt_services_);
SetGattServicesDiscoveryComplete(true);
GetAdapter()->NotifyGattServicesDiscovered(this);
} else {
......
......@@ -81,7 +81,6 @@ class FakePeripheral : public device::BluetoothDevice {
bool IsGattConnected() const override;
bool IsConnectable() const override;
bool IsConnecting() const override;
UUIDSet GetUUIDs() const override;
bool ExpectingPinCode() const override;
bool ExpectingPasskey() const override;
bool ExpectingConfirmation() const override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment