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

Side by Side Diff: device/bluetooth/device.cc

Issue 2640073004: bluetooth: Add descriptor list to DeviceDetailsPage on internals page. (Closed)
Patch Set: Add comment to differentiate descriptor return value 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 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 <utility> 5 #include <utility>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "device/bluetooth/device.h" 10 #include "device/bluetooth/device.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 return; 105 return;
106 } 106 }
107 107
108 // pending_services_requests_ is owned by Device, so base::Unretained is 108 // pending_services_requests_ is owned by Device, so base::Unretained is
109 // safe. 109 // safe.
110 pending_services_requests_.push_back( 110 pending_services_requests_.push_back(
111 base::Bind(&Device::GetCharacteristicsImpl, base::Unretained(this), 111 base::Bind(&Device::GetCharacteristicsImpl, base::Unretained(this),
112 service_id, callback)); 112 service_id, callback));
113 } 113 }
114 114
115 void Device::GetDescriptors(const std::string& service_id,
116 const std::string& characteristic_id,
117 const GetDescriptorsCallback& callback) {
118 device::BluetoothDevice* device = adapter_->GetDevice(GetAddress());
119 if (device == nullptr) {
Dan Beam 2017/01/24 06:07:29 is this preferable to just if (!device) { ?
mbrunson 2017/01/24 21:29:46 I've seen it both ways, but the other files here u
120 callback.Run(base::nullopt);
121 return;
122 }
123
124 device::BluetoothRemoteGattService* service =
125 device->GetGattService(service_id);
126 if (service == nullptr) {
127 callback.Run(base::nullopt);
128 return;
129 }
130
131 device::BluetoothRemoteGattCharacteristic* characteristic =
132 service->GetCharacteristic(characteristic_id);
133 if (characteristic == nullptr) {
134 callback.Run(base::nullopt);
135 return;
136 }
137
138 std::vector<mojom::DescriptorInfoPtr> descriptors;
139
140 for (const auto* descriptor : characteristic->GetDescriptors()) {
141 mojom::DescriptorInfoPtr descriptor_info = mojom::DescriptorInfo::New();
142
143 descriptor_info->id = descriptor->GetIdentifier();
144 descriptor_info->uuid = descriptor->GetUUID();
145 descriptors.push_back(std::move(descriptor_info));
146 }
147
148 callback.Run(std::move(descriptors));
149 }
150
115 Device::Device(scoped_refptr<device::BluetoothAdapter> adapter, 151 Device::Device(scoped_refptr<device::BluetoothAdapter> adapter,
116 std::unique_ptr<device::BluetoothGattConnection> connection) 152 std::unique_ptr<device::BluetoothGattConnection> connection)
117 : adapter_(std::move(adapter)), connection_(std::move(connection)) { 153 : adapter_(std::move(adapter)), connection_(std::move(connection)) {
118 adapter_->AddObserver(this); 154 adapter_->AddObserver(this);
119 } 155 }
120 156
121 void Device::GetServicesImpl(const GetServicesCallback& callback) { 157 void Device::GetServicesImpl(const GetServicesCallback& callback) {
122 device::BluetoothDevice* device = adapter_->GetDevice(GetAddress()); 158 device::BluetoothDevice* device = adapter_->GetDevice(GetAddress());
123 DCHECK(device); 159 DCHECK(device);
124 160
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 202 }
167 203
168 callback.Run(std::move(characteristics)); 204 callback.Run(std::move(characteristics));
169 } 205 }
170 206
171 const std::string& Device::GetAddress() { 207 const std::string& Device::GetAddress() {
172 return connection_->GetDeviceAddress(); 208 return connection_->GetDeviceAddress();
173 } 209 }
174 210
175 } // namespace bluetooth 211 } // namespace bluetooth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698