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

Unified Diff: device/bluetooth/device.cc

Issue 2643393002: bluetooth: Remove queuing of GetCharacteristicsCallbacks (Closed)
Patch Set: Add comment explaining null/empty difference Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/device.h ('k') | device/bluetooth/device_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/device.cc
diff --git a/device/bluetooth/device.cc b/device/bluetooth/device.cc
index ca1e6149dbf2370efbbb3caea1dd7d202d18fb56..0e018a2ee93790e3cf15053fd2f93ede4befaa52 100644
--- a/device/bluetooth/device.cc
+++ b/device/bluetooth/device.cc
@@ -100,16 +100,27 @@ void Device::GetCharacteristics(const std::string& service_id,
device::BluetoothDevice* device = adapter_->GetDevice(GetAddress());
DCHECK(device);
- if (device->IsGattServicesDiscoveryComplete()) {
- GetCharacteristicsImpl(service_id, callback);
+ device::BluetoothRemoteGattService* service =
+ device->GetGattService(service_id);
+ if (service == nullptr) {
+ callback.Run(base::nullopt);
return;
}
- // pending_services_requests_ is owned by Device, so base::Unretained is
- // safe.
- pending_services_requests_.push_back(
- base::Bind(&Device::GetCharacteristicsImpl, base::Unretained(this),
- service_id, callback));
+ std::vector<mojom::CharacteristicInfoPtr> characteristics;
+
+ for (const auto* characteristic : service->GetCharacteristics()) {
+ mojom::CharacteristicInfoPtr characteristic_info =
+ mojom::CharacteristicInfo::New();
+
+ characteristic_info->id = characteristic->GetIdentifier();
+ characteristic_info->uuid = characteristic->GetUUID();
+ characteristic_info->properties = characteristic->GetProperties();
+
+ characteristics.push_back(std::move(characteristic_info));
+ }
+
+ callback.Run(std::move(characteristics));
}
Device::Device(scoped_refptr<device::BluetoothAdapter> adapter,
@@ -143,31 +154,6 @@ mojom::ServiceInfoPtr Device::ConstructServiceInfoStruct(
return service_info;
}
-void Device::GetCharacteristicsImpl(
- const std::string& service_id,
- const GetCharacteristicsCallback& callback) {
- device::BluetoothDevice* device = adapter_->GetDevice(GetAddress());
- DCHECK(device);
- device::BluetoothRemoteGattService* service =
- device->GetGattService(service_id);
- DCHECK(service);
-
- std::vector<mojom::CharacteristicInfoPtr> characteristics;
-
- for (const auto* characteristic : service->GetCharacteristics()) {
- mojom::CharacteristicInfoPtr characteristic_info =
- mojom::CharacteristicInfo::New();
-
- characteristic_info->id = characteristic->GetIdentifier();
- characteristic_info->uuid = characteristic->GetUUID();
- characteristic_info->properties = characteristic->GetProperties();
-
- characteristics.push_back(std::move(characteristic_info));
- }
-
- callback.Run(std::move(characteristics));
-}
-
const std::string& Device::GetAddress() {
return connection_->GetDeviceAddress();
}
« no previous file with comments | « device/bluetooth/device.h ('k') | device/bluetooth/device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698