| 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" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 159 } |
| 160 | 160 |
| 161 BluetoothDevice::PairingDelegate* BluetoothAdapter::DefaultPairingDelegate() { | 161 BluetoothDevice::PairingDelegate* BluetoothAdapter::DefaultPairingDelegate() { |
| 162 if (pairing_delegates_.empty()) | 162 if (pairing_delegates_.empty()) |
| 163 return NULL; | 163 return NULL; |
| 164 | 164 |
| 165 return pairing_delegates_.front().first; | 165 return pairing_delegates_.front().first; |
| 166 } | 166 } |
| 167 | 167 |
| 168 void BluetoothAdapter::NotifyAdapterPoweredChanged(bool powered) { | 168 void BluetoothAdapter::NotifyAdapterPoweredChanged(bool powered) { |
| 169 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 169 for (auto& observer : observers_) |
| 170 AdapterPoweredChanged(this, powered)); | 170 observer.AdapterPoweredChanged(this, powered); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void BluetoothAdapter::NotifyDeviceChanged(BluetoothDevice* device) { | 173 void BluetoothAdapter::NotifyDeviceChanged(BluetoothDevice* device) { |
| 174 DCHECK(device); | 174 DCHECK(device); |
| 175 DCHECK_EQ(device->GetAdapter(), this); | 175 DCHECK_EQ(device->GetAdapter(), this); |
| 176 | 176 |
| 177 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 177 for (auto& observer : observers_) |
| 178 DeviceChanged(this, device)); | 178 observer.DeviceChanged(this, device); |
| 179 } | 179 } |
| 180 | 180 |
| 181 #if defined(OS_CHROMEOS) || defined(OS_LINUX) | 181 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 182 void BluetoothAdapter::NotifyDevicePairedChanged(BluetoothDevice* device, | 182 void BluetoothAdapter::NotifyDevicePairedChanged(BluetoothDevice* device, |
| 183 bool new_paired_status) { | 183 bool new_paired_status) { |
| 184 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 184 for (auto& observer : observers_) |
| 185 DevicePairedChanged(this, device, new_paired_status)); | 185 observer.DevicePairedChanged(this, device, new_paired_status); |
| 186 } | 186 } |
| 187 #endif | 187 #endif |
| 188 | 188 |
| 189 void BluetoothAdapter::NotifyGattServiceAdded( | 189 void BluetoothAdapter::NotifyGattServiceAdded( |
| 190 BluetoothRemoteGattService* service) { | 190 BluetoothRemoteGattService* service) { |
| 191 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); | 191 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); |
| 192 | 192 |
| 193 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 193 for (auto& observer : observers_) |
| 194 GattServiceAdded(this, service->GetDevice(), service)); | 194 observer.GattServiceAdded(this, service->GetDevice(), service); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void BluetoothAdapter::NotifyGattServiceRemoved( | 197 void BluetoothAdapter::NotifyGattServiceRemoved( |
| 198 BluetoothRemoteGattService* service) { | 198 BluetoothRemoteGattService* service) { |
| 199 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); | 199 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); |
| 200 | 200 |
| 201 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 201 for (auto& observer : observers_) |
| 202 GattServiceRemoved(this, service->GetDevice(), service)); | 202 observer.GattServiceRemoved(this, service->GetDevice(), service); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void BluetoothAdapter::NotifyGattServiceChanged( | 205 void BluetoothAdapter::NotifyGattServiceChanged( |
| 206 BluetoothRemoteGattService* service) { | 206 BluetoothRemoteGattService* service) { |
| 207 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); | 207 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); |
| 208 | 208 |
| 209 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 209 for (auto& observer : observers_) |
| 210 GattServiceChanged(this, service)); | 210 observer.GattServiceChanged(this, service); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void BluetoothAdapter::NotifyGattServicesDiscovered(BluetoothDevice* device) { | 213 void BluetoothAdapter::NotifyGattServicesDiscovered(BluetoothDevice* device) { |
| 214 DCHECK(device->GetAdapter() == this); | 214 DCHECK(device->GetAdapter() == this); |
| 215 | 215 |
| 216 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 216 for (auto& observer : observers_) |
| 217 GattServicesDiscovered(this, device)); | 217 observer.GattServicesDiscovered(this, device); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void BluetoothAdapter::NotifyGattDiscoveryComplete( | 220 void BluetoothAdapter::NotifyGattDiscoveryComplete( |
| 221 BluetoothRemoteGattService* service) { | 221 BluetoothRemoteGattService* service) { |
| 222 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); | 222 DCHECK_EQ(service->GetDevice()->GetAdapter(), this); |
| 223 | 223 |
| 224 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 224 for (auto& observer : observers_) |
| 225 GattDiscoveryCompleteForService(this, service)); | 225 observer.GattDiscoveryCompleteForService(this, service); |
| 226 } | 226 } |
| 227 | 227 |
| 228 void BluetoothAdapter::NotifyGattCharacteristicAdded( | 228 void BluetoothAdapter::NotifyGattCharacteristicAdded( |
| 229 BluetoothRemoteGattCharacteristic* characteristic) { | 229 BluetoothRemoteGattCharacteristic* characteristic) { |
| 230 DCHECK_EQ(characteristic->GetService()->GetDevice()->GetAdapter(), this); | 230 DCHECK_EQ(characteristic->GetService()->GetDevice()->GetAdapter(), this); |
| 231 | 231 |
| 232 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 232 for (auto& observer : observers_) |
| 233 GattCharacteristicAdded(this, characteristic)); | 233 observer.GattCharacteristicAdded(this, characteristic); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void BluetoothAdapter::NotifyGattCharacteristicRemoved( | 236 void BluetoothAdapter::NotifyGattCharacteristicRemoved( |
| 237 BluetoothRemoteGattCharacteristic* characteristic) { | 237 BluetoothRemoteGattCharacteristic* characteristic) { |
| 238 DCHECK_EQ(characteristic->GetService()->GetDevice()->GetAdapter(), this); | 238 DCHECK_EQ(characteristic->GetService()->GetDevice()->GetAdapter(), this); |
| 239 | 239 |
| 240 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 240 for (auto& observer : observers_) |
| 241 GattCharacteristicRemoved(this, characteristic)); | 241 observer.GattCharacteristicRemoved(this, characteristic); |
| 242 } | 242 } |
| 243 | 243 |
| 244 void BluetoothAdapter::NotifyGattDescriptorAdded( | 244 void BluetoothAdapter::NotifyGattDescriptorAdded( |
| 245 BluetoothRemoteGattDescriptor* descriptor) { | 245 BluetoothRemoteGattDescriptor* descriptor) { |
| 246 DCHECK_EQ( | 246 DCHECK_EQ( |
| 247 descriptor->GetCharacteristic()->GetService()->GetDevice()->GetAdapter(), | 247 descriptor->GetCharacteristic()->GetService()->GetDevice()->GetAdapter(), |
| 248 this); | 248 this); |
| 249 | 249 |
| 250 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 250 for (auto& observer : observers_) |
| 251 GattDescriptorAdded(this, descriptor)); | 251 observer.GattDescriptorAdded(this, descriptor); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void BluetoothAdapter::NotifyGattDescriptorRemoved( | 254 void BluetoothAdapter::NotifyGattDescriptorRemoved( |
| 255 BluetoothRemoteGattDescriptor* descriptor) { | 255 BluetoothRemoteGattDescriptor* descriptor) { |
| 256 DCHECK_EQ( | 256 DCHECK_EQ( |
| 257 descriptor->GetCharacteristic()->GetService()->GetDevice()->GetAdapter(), | 257 descriptor->GetCharacteristic()->GetService()->GetDevice()->GetAdapter(), |
| 258 this); | 258 this); |
| 259 | 259 |
| 260 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 260 for (auto& observer : observers_) |
| 261 GattDescriptorRemoved(this, descriptor)); | 261 observer.GattDescriptorRemoved(this, descriptor); |
| 262 } | 262 } |
| 263 | 263 |
| 264 void BluetoothAdapter::NotifyGattCharacteristicValueChanged( | 264 void BluetoothAdapter::NotifyGattCharacteristicValueChanged( |
| 265 BluetoothRemoteGattCharacteristic* characteristic, | 265 BluetoothRemoteGattCharacteristic* characteristic, |
| 266 const std::vector<uint8_t>& value) { | 266 const std::vector<uint8_t>& value) { |
| 267 DCHECK_EQ(characteristic->GetService()->GetDevice()->GetAdapter(), this); | 267 DCHECK_EQ(characteristic->GetService()->GetDevice()->GetAdapter(), this); |
| 268 | 268 |
| 269 FOR_EACH_OBSERVER( | 269 for (auto& observer : observers_) |
| 270 BluetoothAdapter::Observer, observers_, | 270 observer.GattCharacteristicValueChanged(this, characteristic, value); |
| 271 GattCharacteristicValueChanged(this, characteristic, value)); | |
| 272 } | 271 } |
| 273 | 272 |
| 274 void BluetoothAdapter::NotifyGattDescriptorValueChanged( | 273 void BluetoothAdapter::NotifyGattDescriptorValueChanged( |
| 275 BluetoothRemoteGattDescriptor* descriptor, | 274 BluetoothRemoteGattDescriptor* descriptor, |
| 276 const std::vector<uint8_t>& value) { | 275 const std::vector<uint8_t>& value) { |
| 277 DCHECK_EQ( | 276 DCHECK_EQ( |
| 278 descriptor->GetCharacteristic()->GetService()->GetDevice()->GetAdapter(), | 277 descriptor->GetCharacteristic()->GetService()->GetDevice()->GetAdapter(), |
| 279 this); | 278 this); |
| 280 | 279 |
| 281 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 280 for (auto& observer : observers_) |
| 282 GattDescriptorValueChanged(this, descriptor, value)); | 281 observer.GattDescriptorValueChanged(this, descriptor, value); |
| 283 } | 282 } |
| 284 | 283 |
| 285 BluetoothAdapter::BluetoothAdapter() : weak_ptr_factory_(this) { | 284 BluetoothAdapter::BluetoothAdapter() : weak_ptr_factory_(this) { |
| 286 } | 285 } |
| 287 | 286 |
| 288 BluetoothAdapter::~BluetoothAdapter() { | 287 BluetoothAdapter::~BluetoothAdapter() { |
| 289 } | 288 } |
| 290 | 289 |
| 291 void BluetoothAdapter::OnStartDiscoverySession( | 290 void BluetoothAdapter::OnStartDiscoverySession( |
| 292 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter, | 291 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 continue; | 391 continue; |
| 393 } | 392 } |
| 394 | 393 |
| 395 VLOG(1) << "Removing device: " << device->GetAddress(); | 394 VLOG(1) << "Removing device: " << device->GetAddress(); |
| 396 DevicesMap::iterator next = it; | 395 DevicesMap::iterator next = it; |
| 397 next++; | 396 next++; |
| 398 std::unique_ptr<BluetoothDevice> removed_device = | 397 std::unique_ptr<BluetoothDevice> removed_device = |
| 399 devices_.take_and_erase(it); | 398 devices_.take_and_erase(it); |
| 400 it = next; | 399 it = next; |
| 401 | 400 |
| 402 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 401 for (auto& observer : observers_) |
| 403 DeviceRemoved(this, removed_device.get())); | 402 observer.DeviceRemoved(this, removed_device.get()); |
| 404 } | 403 } |
| 405 } | 404 } |
| 406 | 405 |
| 407 // static | 406 // static |
| 408 void BluetoothAdapter::RecordBluetoothDiscoverySessionStartOutcome( | 407 void BluetoothAdapter::RecordBluetoothDiscoverySessionStartOutcome( |
| 409 UMABluetoothDiscoverySessionOutcome outcome) { | 408 UMABluetoothDiscoverySessionOutcome outcome) { |
| 410 UMA_HISTOGRAM_ENUMERATION( | 409 UMA_HISTOGRAM_ENUMERATION( |
| 411 "Bluetooth.DiscoverySession.Start.Outcome", static_cast<int>(outcome), | 410 "Bluetooth.DiscoverySession.Start.Outcome", static_cast<int>(outcome), |
| 412 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT)); | 411 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT)); |
| 413 } | 412 } |
| 414 | 413 |
| 415 // static | 414 // static |
| 416 void BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome( | 415 void BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome( |
| 417 UMABluetoothDiscoverySessionOutcome outcome) { | 416 UMABluetoothDiscoverySessionOutcome outcome) { |
| 418 UMA_HISTOGRAM_ENUMERATION( | 417 UMA_HISTOGRAM_ENUMERATION( |
| 419 "Bluetooth.DiscoverySession.Stop.Outcome", static_cast<int>(outcome), | 418 "Bluetooth.DiscoverySession.Stop.Outcome", static_cast<int>(outcome), |
| 420 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT)); | 419 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT)); |
| 421 } | 420 } |
| 422 | 421 |
| 423 // static | 422 // static |
| 424 const base::TimeDelta BluetoothAdapter::timeoutSec = | 423 const base::TimeDelta BluetoothAdapter::timeoutSec = |
| 425 base::TimeDelta::FromSeconds(180); | 424 base::TimeDelta::FromSeconds(180); |
| 426 | 425 |
| 427 } // namespace device | 426 } // namespace device |
| OLD | NEW |