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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "device/bluetooth/bluetooth_device.h" | 13 #include "device/bluetooth/bluetooth_device.h" |
14 #include "device/bluetooth/bluetooth_discovery_session.h" | 14 #include "device/bluetooth/bluetooth_discovery_session.h" |
15 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" | 15 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" |
| 16 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
| 17 #include "device/bluetooth/bluetooth_gatt_descriptor.h" |
| 18 #include "device/bluetooth/bluetooth_gatt_service.h" |
16 | 19 |
17 namespace device { | 20 namespace device { |
18 | 21 |
19 BluetoothAdapter::ServiceOptions::ServiceOptions() { | 22 BluetoothAdapter::ServiceOptions::ServiceOptions() { |
20 } | 23 } |
21 BluetoothAdapter::ServiceOptions::~ServiceOptions() { | 24 BluetoothAdapter::ServiceOptions::~ServiceOptions() { |
22 } | 25 } |
23 | 26 |
24 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_MACOSX) && \ | 27 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_MACOSX) && \ |
25 !defined(OS_WIN) && !defined(OS_LINUX) | 28 !defined(OS_WIN) && !defined(OS_LINUX) |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 151 } |
149 } | 152 } |
150 | 153 |
151 BluetoothDevice::PairingDelegate* BluetoothAdapter::DefaultPairingDelegate() { | 154 BluetoothDevice::PairingDelegate* BluetoothAdapter::DefaultPairingDelegate() { |
152 if (pairing_delegates_.empty()) | 155 if (pairing_delegates_.empty()) |
153 return NULL; | 156 return NULL; |
154 | 157 |
155 return pairing_delegates_.front().first; | 158 return pairing_delegates_.front().first; |
156 } | 159 } |
157 | 160 |
| 161 void BluetoothAdapter::NotifyGattServiceAdded(BluetoothGattService* service) { |
| 162 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); |
| 163 |
| 164 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 165 GattServiceAdded(this, service->GetDevice(), service)); |
| 166 } |
| 167 |
| 168 void BluetoothAdapter::NotifyGattServiceRemoved(BluetoothGattService* service) { |
| 169 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); |
| 170 |
| 171 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 172 GattServiceRemoved(this, service->GetDevice(), service)); |
| 173 } |
| 174 |
| 175 void BluetoothAdapter::NotifyGattServiceChanged(BluetoothGattService* service) { |
| 176 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); |
| 177 |
| 178 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 179 GattServiceChanged(this, service)); |
| 180 } |
| 181 |
| 182 void BluetoothAdapter::NotifyGattServicesDiscovered(BluetoothDevice* device) { |
| 183 DCHECK(device->GetAdapter() == this); |
| 184 |
| 185 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 186 GattServicesDiscovered(this, device)); |
| 187 } |
| 188 |
| 189 void BluetoothAdapter::NotifyGattDiscoveryComplete( |
| 190 BluetoothGattService* service) { |
| 191 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); |
| 192 |
| 193 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 194 GattDiscoveryCompleteForService(this, service)); |
| 195 } |
| 196 |
| 197 void BluetoothAdapter::NotifyGattCharacteristicAdded( |
| 198 BluetoothGattCharacteristic* characteristic) { |
| 199 DCHECK_EQ(characteristic->GetService()->GetDevice()->GetAdapter(), this); |
| 200 |
| 201 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 202 GattCharacteristicAdded(this, characteristic)); |
| 203 } |
| 204 |
| 205 void BluetoothAdapter::NotifyGattCharacteristicRemoved( |
| 206 BluetoothGattCharacteristic* characteristic) { |
| 207 DCHECK_EQ(characteristic->GetService()->GetDevice()->GetAdapter(), this); |
| 208 |
| 209 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 210 GattCharacteristicRemoved(this, characteristic)); |
| 211 } |
| 212 |
| 213 void BluetoothAdapter::NotifyGattDescriptorAdded( |
| 214 BluetoothGattDescriptor* descriptor) { |
| 215 DCHECK_EQ( |
| 216 descriptor->GetCharacteristic()->GetService()->GetDevice()->GetAdapter(), |
| 217 this); |
| 218 |
| 219 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 220 GattDescriptorAdded(this, descriptor)); |
| 221 } |
| 222 |
| 223 void BluetoothAdapter::NotifyGattDescriptorRemoved( |
| 224 BluetoothGattDescriptor* descriptor) { |
| 225 DCHECK_EQ( |
| 226 descriptor->GetCharacteristic()->GetService()->GetDevice()->GetAdapter(), |
| 227 this); |
| 228 |
| 229 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 230 GattDescriptorRemoved(this, descriptor)); |
| 231 } |
| 232 |
| 233 void BluetoothAdapter::NotifyGattCharacteristicValueChanged( |
| 234 BluetoothGattCharacteristic* characteristic, |
| 235 const std::vector<uint8_t>& value) { |
| 236 DCHECK_EQ(characteristic->GetService()->GetDevice()->GetAdapter(), this); |
| 237 |
| 238 FOR_EACH_OBSERVER( |
| 239 BluetoothAdapter::Observer, observers_, |
| 240 GattCharacteristicValueChanged(this, characteristic, value)); |
| 241 } |
| 242 |
| 243 void BluetoothAdapter::NotifyGattDescriptorValueChanged( |
| 244 BluetoothGattDescriptor* descriptor, |
| 245 const std::vector<uint8_t>& value) { |
| 246 DCHECK_EQ( |
| 247 descriptor->GetCharacteristic()->GetService()->GetDevice()->GetAdapter(), |
| 248 this); |
| 249 |
| 250 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 251 GattDescriptorValueChanged(this, descriptor, value)); |
| 252 } |
| 253 |
158 BluetoothAdapter::BluetoothAdapter() : weak_ptr_factory_(this) { | 254 BluetoothAdapter::BluetoothAdapter() : weak_ptr_factory_(this) { |
159 } | 255 } |
160 | 256 |
161 BluetoothAdapter::~BluetoothAdapter() { | 257 BluetoothAdapter::~BluetoothAdapter() { |
162 } | 258 } |
163 | 259 |
164 void BluetoothAdapter::OnStartDiscoverySession( | 260 void BluetoothAdapter::OnStartDiscoverySession( |
165 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, | 261 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, |
166 const DiscoverySessionCallback& callback) { | 262 const DiscoverySessionCallback& callback) { |
167 VLOG(1) << "BluetoothAdapter::OnStartDiscoverySession"; | 263 VLOG(1) << "BluetoothAdapter::OnStartDiscoverySession"; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 350 |
255 // static | 351 // static |
256 void BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome( | 352 void BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome( |
257 UMABluetoothDiscoverySessionOutcome outcome) { | 353 UMABluetoothDiscoverySessionOutcome outcome) { |
258 UMA_HISTOGRAM_ENUMERATION( | 354 UMA_HISTOGRAM_ENUMERATION( |
259 "Bluetooth.DiscoverySession.Stop.Outcome", static_cast<int>(outcome), | 355 "Bluetooth.DiscoverySession.Stop.Outcome", static_cast<int>(outcome), |
260 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT)); | 356 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT)); |
261 } | 357 } |
262 | 358 |
263 } // namespace device | 359 } // namespace device |
OLD | NEW |