OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "device/bluetooth/bluetooth_adapter.h" | 5 #include "device/bluetooth/bluetooth_adapter.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "device/bluetooth/bluetooth_device.h" | 14 #include "device/bluetooth/bluetooth_device.h" |
15 #include "device/bluetooth/bluetooth_discovery_session.h" | 15 #include "device/bluetooth/bluetooth_discovery_session.h" |
16 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" | 16 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" |
17 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 17 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
18 #include "device/bluetooth/bluetooth_gatt_descriptor.h" | 18 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" |
19 #include "device/bluetooth/bluetooth_gatt_service.h" | 19 #include "device/bluetooth/bluetooth_remote_gatt_service.h" |
20 | 20 |
21 namespace device { | 21 namespace device { |
22 | 22 |
23 BluetoothAdapter::ServiceOptions::ServiceOptions() { | 23 BluetoothAdapter::ServiceOptions::ServiceOptions() { |
24 } | 24 } |
25 BluetoothAdapter::ServiceOptions::~ServiceOptions() { | 25 BluetoothAdapter::ServiceOptions::~ServiceOptions() { |
26 } | 26 } |
27 | 27 |
28 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_MACOSX) && \ | 28 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_MACOSX) && \ |
29 !defined(OS_WIN) && !defined(OS_LINUX) | 29 !defined(OS_WIN) && !defined(OS_LINUX) |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 165 } |
166 | 166 |
167 #if defined(OS_CHROMEOS) || defined(OS_LINUX) | 167 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
168 void BluetoothAdapter::NotifyDevicePairedChanged(BluetoothDevice* device, | 168 void BluetoothAdapter::NotifyDevicePairedChanged(BluetoothDevice* device, |
169 bool new_paired_status) { | 169 bool new_paired_status) { |
170 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 170 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
171 DevicePairedChanged(this, device, new_paired_status)); | 171 DevicePairedChanged(this, device, new_paired_status)); |
172 } | 172 } |
173 #endif | 173 #endif |
174 | 174 |
175 void BluetoothAdapter::NotifyGattServiceAdded(BluetoothGattService* service) { | 175 void BluetoothAdapter::NotifyGattServiceAdded( |
| 176 BluetoothRemoteGattService* service) { |
176 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); | 177 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); |
177 | 178 |
178 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 179 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
179 GattServiceAdded(this, service->GetDevice(), service)); | 180 GattServiceAdded(this, service->GetDevice(), service)); |
180 } | 181 } |
181 | 182 |
182 void BluetoothAdapter::NotifyGattServiceRemoved(BluetoothGattService* service) { | 183 void BluetoothAdapter::NotifyGattServiceRemoved( |
| 184 BluetoothRemoteGattService* service) { |
183 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); | 185 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); |
184 | 186 |
185 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 187 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
186 GattServiceRemoved(this, service->GetDevice(), service)); | 188 GattServiceRemoved(this, service->GetDevice(), service)); |
187 } | 189 } |
188 | 190 |
189 void BluetoothAdapter::NotifyGattServiceChanged(BluetoothGattService* service) { | 191 void BluetoothAdapter::NotifyGattServiceChanged( |
| 192 BluetoothRemoteGattService* service) { |
190 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); | 193 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); |
191 | 194 |
192 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 195 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
193 GattServiceChanged(this, service)); | 196 GattServiceChanged(this, service)); |
194 } | 197 } |
195 | 198 |
196 void BluetoothAdapter::NotifyGattServicesDiscovered(BluetoothDevice* device) { | 199 void BluetoothAdapter::NotifyGattServicesDiscovered(BluetoothDevice* device) { |
197 DCHECK(device->GetAdapter() == this); | 200 DCHECK(device->GetAdapter() == this); |
198 | 201 |
199 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 202 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
200 GattServicesDiscovered(this, device)); | 203 GattServicesDiscovered(this, device)); |
201 } | 204 } |
202 | 205 |
203 void BluetoothAdapter::NotifyGattDiscoveryComplete( | 206 void BluetoothAdapter::NotifyGattDiscoveryComplete( |
204 BluetoothGattService* service) { | 207 BluetoothRemoteGattService* service) { |
205 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); | 208 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); |
206 | 209 |
207 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 210 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
208 GattDiscoveryCompleteForService(this, service)); | 211 GattDiscoveryCompleteForService(this, service)); |
209 } | 212 } |
210 | 213 |
211 void BluetoothAdapter::NotifyGattCharacteristicAdded( | 214 void BluetoothAdapter::NotifyGattCharacteristicAdded( |
212 BluetoothGattCharacteristic* characteristic) { | 215 BluetoothRemoteGattCharacteristic* characteristic) { |
213 DCHECK_EQ(characteristic->GetService()->GetDevice()->GetAdapter(), this); | 216 DCHECK_EQ(characteristic->GetService()->GetDevice()->GetAdapter(), this); |
214 | 217 |
215 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 218 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
216 GattCharacteristicAdded(this, characteristic)); | 219 GattCharacteristicAdded(this, characteristic)); |
217 } | 220 } |
218 | 221 |
219 void BluetoothAdapter::NotifyGattCharacteristicRemoved( | 222 void BluetoothAdapter::NotifyGattCharacteristicRemoved( |
220 BluetoothGattCharacteristic* characteristic) { | 223 BluetoothRemoteGattCharacteristic* characteristic) { |
221 DCHECK_EQ(characteristic->GetService()->GetDevice()->GetAdapter(), this); | 224 DCHECK_EQ(characteristic->GetService()->GetDevice()->GetAdapter(), this); |
222 | 225 |
223 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 226 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
224 GattCharacteristicRemoved(this, characteristic)); | 227 GattCharacteristicRemoved(this, characteristic)); |
225 } | 228 } |
226 | 229 |
227 void BluetoothAdapter::NotifyGattDescriptorAdded( | 230 void BluetoothAdapter::NotifyGattDescriptorAdded( |
228 BluetoothGattDescriptor* descriptor) { | 231 BluetoothRemoteGattDescriptor* descriptor) { |
229 DCHECK_EQ( | 232 DCHECK_EQ( |
230 descriptor->GetCharacteristic()->GetService()->GetDevice()->GetAdapter(), | 233 descriptor->GetCharacteristic()->GetService()->GetDevice()->GetAdapter(), |
231 this); | 234 this); |
232 | 235 |
233 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 236 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
234 GattDescriptorAdded(this, descriptor)); | 237 GattDescriptorAdded(this, descriptor)); |
235 } | 238 } |
236 | 239 |
237 void BluetoothAdapter::NotifyGattDescriptorRemoved( | 240 void BluetoothAdapter::NotifyGattDescriptorRemoved( |
238 BluetoothGattDescriptor* descriptor) { | 241 BluetoothRemoteGattDescriptor* descriptor) { |
239 DCHECK_EQ( | 242 DCHECK_EQ( |
240 descriptor->GetCharacteristic()->GetService()->GetDevice()->GetAdapter(), | 243 descriptor->GetCharacteristic()->GetService()->GetDevice()->GetAdapter(), |
241 this); | 244 this); |
242 | 245 |
243 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 246 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
244 GattDescriptorRemoved(this, descriptor)); | 247 GattDescriptorRemoved(this, descriptor)); |
245 } | 248 } |
246 | 249 |
247 void BluetoothAdapter::NotifyGattCharacteristicValueChanged( | 250 void BluetoothAdapter::NotifyGattCharacteristicValueChanged( |
248 BluetoothGattCharacteristic* characteristic, | 251 BluetoothRemoteGattCharacteristic* characteristic, |
249 const std::vector<uint8_t>& value) { | 252 const std::vector<uint8_t>& value) { |
250 DCHECK_EQ(characteristic->GetService()->GetDevice()->GetAdapter(), this); | 253 DCHECK_EQ(characteristic->GetService()->GetDevice()->GetAdapter(), this); |
251 | 254 |
252 FOR_EACH_OBSERVER( | 255 FOR_EACH_OBSERVER( |
253 BluetoothAdapter::Observer, observers_, | 256 BluetoothAdapter::Observer, observers_, |
254 GattCharacteristicValueChanged(this, characteristic, value)); | 257 GattCharacteristicValueChanged(this, characteristic, value)); |
255 } | 258 } |
256 | 259 |
257 void BluetoothAdapter::NotifyGattDescriptorValueChanged( | 260 void BluetoothAdapter::NotifyGattDescriptorValueChanged( |
258 BluetoothGattDescriptor* descriptor, | 261 BluetoothRemoteGattDescriptor* descriptor, |
259 const std::vector<uint8_t>& value) { | 262 const std::vector<uint8_t>& value) { |
260 DCHECK_EQ( | 263 DCHECK_EQ( |
261 descriptor->GetCharacteristic()->GetService()->GetDevice()->GetAdapter(), | 264 descriptor->GetCharacteristic()->GetService()->GetDevice()->GetAdapter(), |
262 this); | 265 this); |
263 | 266 |
264 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 267 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
265 GattDescriptorValueChanged(this, descriptor, value)); | 268 GattDescriptorValueChanged(this, descriptor, value)); |
266 } | 269 } |
267 | 270 |
268 BluetoothAdapter::BluetoothAdapter() : weak_ptr_factory_(this) { | 271 BluetoothAdapter::BluetoothAdapter() : weak_ptr_factory_(this) { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 | 367 |
365 // static | 368 // static |
366 void BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome( | 369 void BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome( |
367 UMABluetoothDiscoverySessionOutcome outcome) { | 370 UMABluetoothDiscoverySessionOutcome outcome) { |
368 UMA_HISTOGRAM_ENUMERATION( | 371 UMA_HISTOGRAM_ENUMERATION( |
369 "Bluetooth.DiscoverySession.Stop.Outcome", static_cast<int>(outcome), | 372 "Bluetooth.DiscoverySession.Stop.Outcome", static_cast<int>(outcome), |
370 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT)); | 373 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT)); |
371 } | 374 } |
372 | 375 |
373 } // namespace device | 376 } // namespace device |
OLD | NEW |