OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_mac.h" | 5 #include "device/bluetooth/bluetooth_adapter_mac.h" |
6 | 6 |
7 #import <IOBluetooth/objc/IOBluetoothDevice.h> | 7 #import <IOBluetooth/objc/IOBluetoothDevice.h> |
8 #import <IOBluetooth/objc/IOBluetoothHostController.h> | 8 #import <IOBluetooth/objc/IOBluetoothHostController.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 FROM_HERE, | 462 FROM_HERE, |
463 base::Bind(&BluetoothAdapterMac::PollAdapter, | 463 base::Bind(&BluetoothAdapterMac::PollAdapter, |
464 weak_ptr_factory_.GetWeakPtr()), | 464 weak_ptr_factory_.GetWeakPtr()), |
465 base::TimeDelta::FromMilliseconds(kPollIntervalMs)); | 465 base::TimeDelta::FromMilliseconds(kPollIntervalMs)); |
466 } | 466 } |
467 | 467 |
468 void BluetoothAdapterMac::ClassicDeviceAdded(IOBluetoothDevice* device) { | 468 void BluetoothAdapterMac::ClassicDeviceAdded(IOBluetoothDevice* device) { |
469 std::string device_address = | 469 std::string device_address = |
470 BluetoothClassicDeviceMac::GetDeviceAddress(device); | 470 BluetoothClassicDeviceMac::GetDeviceAddress(device); |
471 | 471 |
| 472 BluetoothDevice* device_classic = GetDevice(device_address); |
| 473 |
472 // Only notify observers once per device. | 474 // Only notify observers once per device. |
473 if (devices_.count(device_address)) | 475 if (device_classic != nullptr) { |
| 476 VLOG(3) << "Updating classic device: " << device_classic->GetAddress(); |
| 477 device_classic->UpdateTimestamp(); |
474 return; | 478 return; |
| 479 } |
475 | 480 |
476 BluetoothDevice* device_classic = new BluetoothClassicDeviceMac(this, device); | 481 device_classic = new BluetoothClassicDeviceMac(this, device); |
477 devices_.set(device_address, base::WrapUnique(device_classic)); | 482 devices_.set(device_address, base::WrapUnique(device_classic)); |
| 483 VLOG(1) << "Adding new classic device: " << device_classic->GetAddress(); |
| 484 |
478 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 485 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
479 DeviceAdded(this, device_classic)); | 486 DeviceAdded(this, device_classic)); |
480 } | 487 } |
481 | 488 |
482 void BluetoothAdapterMac::LowEnergyDeviceUpdated( | 489 void BluetoothAdapterMac::LowEnergyDeviceUpdated( |
483 CBPeripheral* peripheral, | 490 CBPeripheral* peripheral, |
484 NSDictionary* advertisement_data, | 491 NSDictionary* advertisement_data, |
485 int rssi) { | 492 int rssi) { |
486 BluetoothLowEnergyDeviceMac* device_mac = | 493 BluetoothLowEnergyDeviceMac* device_mac = |
487 GetBluetoothLowEnergyDeviceMac(peripheral); | 494 GetBluetoothLowEnergyDeviceMac(peripheral); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 DeviceChanged(this, device_mac)); | 567 DeviceChanged(this, device_mac)); |
561 } | 568 } |
562 } | 569 } |
563 | 570 |
564 // TODO(krstnmnlsn): Implement. crbug.com/511025 | 571 // TODO(krstnmnlsn): Implement. crbug.com/511025 |
565 void BluetoothAdapterMac::LowEnergyCentralManagerUpdatedState() {} | 572 void BluetoothAdapterMac::LowEnergyCentralManagerUpdatedState() {} |
566 | 573 |
567 void BluetoothAdapterMac::AddPairedDevices() { | 574 void BluetoothAdapterMac::AddPairedDevices() { |
568 // Add any new paired devices. | 575 // Add any new paired devices. |
569 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { | 576 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { |
570 ClassicDeviceAdded(device); | 577 // pairedDevices sometimes includes unknown devices that are not paired. |
| 578 // Radar issue with id 2282763004 has been filed about it. |
| 579 if ([device isPaired]) { |
| 580 ClassicDeviceAdded(device); |
| 581 } |
571 } | 582 } |
572 } | 583 } |
573 | 584 |
574 void BluetoothAdapterMac::CreateGattConnection( | 585 void BluetoothAdapterMac::CreateGattConnection( |
575 BluetoothLowEnergyDeviceMac* device_mac) { | 586 BluetoothLowEnergyDeviceMac* device_mac) { |
576 [low_energy_central_manager_ connectPeripheral:device_mac->peripheral_ | 587 [low_energy_central_manager_ connectPeripheral:device_mac->peripheral_ |
577 options:nil]; | 588 options:nil]; |
578 } | 589 } |
579 | 590 |
580 void BluetoothAdapterMac::DisconnectGatt( | 591 void BluetoothAdapterMac::DisconnectGatt( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 std::string device_address = | 646 std::string device_address = |
636 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); | 647 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); |
637 DevicesMap::const_iterator iter = devices_.find(device_address); | 648 DevicesMap::const_iterator iter = devices_.find(device_address); |
638 if (iter == devices_.end()) { | 649 if (iter == devices_.end()) { |
639 return nil; | 650 return nil; |
640 } | 651 } |
641 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); | 652 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); |
642 } | 653 } |
643 | 654 |
644 } // namespace device | 655 } // namespace device |
OLD | NEW |