| 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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 CBPeripheral* peripheral, | 523 CBPeripheral* peripheral, |
| 524 NSDictionary* advertisement_data, | 524 NSDictionary* advertisement_data, |
| 525 int rssi) { | 525 int rssi) { |
| 526 BluetoothLowEnergyDeviceMac* device_mac = | 526 BluetoothLowEnergyDeviceMac* device_mac = |
| 527 GetBluetoothLowEnergyDeviceMac(peripheral); | 527 GetBluetoothLowEnergyDeviceMac(peripheral); |
| 528 // If has no entry in the map, create new device and insert into |devices_|, | 528 // If has no entry in the map, create new device and insert into |devices_|, |
| 529 // otherwise update the existing device. | 529 // otherwise update the existing device. |
| 530 const bool is_new_device = device_mac == nullptr; | 530 const bool is_new_device = device_mac == nullptr; |
| 531 if (is_new_device) { | 531 if (is_new_device) { |
| 532 // A new device has been found. | 532 // A new device has been found. |
| 533 device_mac = new BluetoothLowEnergyDeviceMac(this, peripheral); | 533 bool connectable = |
| 534 [advertisement_data[CBAdvertisementDataIsConnectable] boolValue]; |
| 535 device_mac = new BluetoothLowEnergyDeviceMac(this, peripheral, connectable); |
| 534 VLOG(1) << *device_mac << ": New Device."; | 536 VLOG(1) << *device_mac << ": New Device."; |
| 535 } else if (DoesCollideWithKnownDevice(peripheral, device_mac)) { | 537 } else if (DoesCollideWithKnownDevice(peripheral, device_mac)) { |
| 536 return; | 538 return; |
| 537 } | 539 } |
| 538 | 540 |
| 539 DCHECK(device_mac); | 541 DCHECK(device_mac); |
| 540 VLOG(3) << *device_mac << ": Device updated with " | 542 VLOG(3) << *device_mac << ": Device updated with " |
| 541 << base::SysNSStringToUTF8([advertisement_data description]); | 543 << base::SysNSStringToUTF8([advertisement_data description]); |
| 542 | 544 |
| 543 // Get Advertised UUIDs | 545 // Get Advertised UUIDs |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 std::vector<BluetoothDevice*> connected_devices; | 630 std::vector<BluetoothDevice*> connected_devices; |
| 629 for (CBPeripheral* peripheral in peripherals) { | 631 for (CBPeripheral* peripheral in peripherals) { |
| 630 BluetoothLowEnergyDeviceMac* device_mac = | 632 BluetoothLowEnergyDeviceMac* device_mac = |
| 631 GetBluetoothLowEnergyDeviceMac(peripheral); | 633 GetBluetoothLowEnergyDeviceMac(peripheral); |
| 632 const bool is_new_device = device_mac == nullptr; | 634 const bool is_new_device = device_mac == nullptr; |
| 633 | 635 |
| 634 if (!is_new_device && DoesCollideWithKnownDevice(peripheral, device_mac)) { | 636 if (!is_new_device && DoesCollideWithKnownDevice(peripheral, device_mac)) { |
| 635 continue; | 637 continue; |
| 636 } | 638 } |
| 637 if (is_new_device) { | 639 if (is_new_device) { |
| 638 device_mac = new BluetoothLowEnergyDeviceMac(this, peripheral); | 640 device_mac = new BluetoothLowEnergyDeviceMac(this, peripheral, true); |
| 639 std::string device_address = | 641 std::string device_address = |
| 640 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); | 642 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); |
| 641 devices_[device_address] = base::WrapUnique(device_mac); | 643 devices_[device_address] = base::WrapUnique(device_mac); |
| 642 for (auto& observer : observers_) { | 644 for (auto& observer : observers_) { |
| 643 observer.DeviceAdded(this, device_mac); | 645 observer.DeviceAdded(this, device_mac); |
| 644 } | 646 } |
| 645 } | 647 } |
| 646 connected_devices.push_back(device_mac); | 648 connected_devices.push_back(device_mac); |
| 647 VLOG(1) << *device_mac << ": New connected device."; | 649 VLOG(1) << *device_mac << ": New connected device."; |
| 648 } | 650 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 // hash the probability of this occuring with 10,000 devices | 733 // hash the probability of this occuring with 10,000 devices |
| 732 // simultaneously present is 1e-6 (see | 734 // simultaneously present is 1e-6 (see |
| 733 // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We | 735 // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We |
| 734 // ignore the second device by returning. | 736 // ignore the second device by returning. |
| 735 return true; | 737 return true; |
| 736 } | 738 } |
| 737 return false; | 739 return false; |
| 738 } | 740 } |
| 739 | 741 |
| 740 } // namespace device | 742 } // namespace device |
| OLD | NEW |