| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } | 148 } |
| 149 | 149 |
| 150 bool BluetoothAdapterMac::IsInitialized() const { | 150 bool BluetoothAdapterMac::IsInitialized() const { |
| 151 return true; | 151 return true; |
| 152 } | 152 } |
| 153 | 153 |
| 154 bool BluetoothAdapterMac::IsPresent() const { | 154 bool BluetoothAdapterMac::IsPresent() const { |
| 155 bool is_present = !address_.empty(); | 155 bool is_present = !address_.empty(); |
| 156 if (IsLowEnergyAvailable()) { | 156 if (IsLowEnergyAvailable()) { |
| 157 is_present = is_present || ([low_energy_central_manager_ state] != | 157 is_present = is_present || ([low_energy_central_manager_ state] != |
| 158 CBCentralManagerStateUnsupported); | 158 CBManagerStateUnsupported); |
| 159 } | 159 } |
| 160 return is_present; | 160 return is_present; |
| 161 } | 161 } |
| 162 | 162 |
| 163 bool BluetoothAdapterMac::IsPowered() const { | 163 bool BluetoothAdapterMac::IsPowered() const { |
| 164 bool is_powered = classic_powered_; | 164 bool is_powered = classic_powered_; |
| 165 if (IsLowEnergyAvailable()) { | 165 if (IsLowEnergyAvailable()) { |
| 166 is_powered = is_powered || ([low_energy_central_manager_ state] == | 166 is_powered = is_powered || ([low_energy_central_manager_ state] == |
| 167 CBCentralManagerStatePoweredOn); | 167 CBManagerStatePoweredOn); |
| 168 } | 168 } |
| 169 return is_powered; | 169 return is_powered; |
| 170 } | 170 } |
| 171 | 171 |
| 172 void BluetoothAdapterMac::SetPowered(bool powered, | 172 void BluetoothAdapterMac::SetPowered(bool powered, |
| 173 const base::Closure& callback, | 173 const base::Closure& callback, |
| 174 const ErrorCallback& error_callback) { | 174 const ErrorCallback& error_callback) { |
| 175 NOTIMPLEMENTED(); | 175 NOTIMPLEMENTED(); |
| 176 } | 176 } |
| 177 | 177 |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); | 581 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); |
| 582 devices_[device_address] = base::WrapUnique(device_mac); | 582 devices_[device_address] = base::WrapUnique(device_mac); |
| 583 for (auto& observer : observers_) | 583 for (auto& observer : observers_) |
| 584 observer.DeviceAdded(this, device_mac); | 584 observer.DeviceAdded(this, device_mac); |
| 585 } else { | 585 } else { |
| 586 for (auto& observer : observers_) | 586 for (auto& observer : observers_) |
| 587 observer.DeviceChanged(this, device_mac); | 587 observer.DeviceChanged(this, device_mac); |
| 588 } | 588 } |
| 589 } | 589 } |
| 590 | 590 |
| 591 // TODO(crbug.com/511025): Handle state < CBCentralManagerStatePoweredOff. | 591 // TODO(crbug.com/511025): Handle state < CBManagerStatePoweredOff. |
| 592 void BluetoothAdapterMac::LowEnergyCentralManagerUpdatedState() { | 592 void BluetoothAdapterMac::LowEnergyCentralManagerUpdatedState() { |
| 593 VLOG(1) << "Central manager state updated: " | 593 VLOG(1) << "Central manager state updated: " |
| 594 << [low_energy_central_manager_ state]; | 594 << [low_energy_central_manager_ state]; |
| 595 // A state with a value lower than CBCentralManagerStatePoweredOn implies that | 595 // A state with a value lower than CBManagerStatePoweredOn implies that |
| 596 // scanning has stopped and that any connected peripherals have been | 596 // scanning has stopped and that any connected peripherals have been |
| 597 // disconnected. Call DidDisconnectPeripheral manually to update the devices' | 597 // disconnected. Call DidDisconnectPeripheral manually to update the devices' |
| 598 // states since macOS doesn't call it. | 598 // states since macOS doesn't call it. |
| 599 // See | 599 // See |
| 600 // https://developer.apple.com/reference/corebluetooth/cbcentralmanagerdelegat
e/1518888-centralmanagerdidupdatestate?language=objc | 600 // https://developer.apple.com/reference/corebluetooth/cbcentralmanagerdelegat
e/1518888-centralmanagerdidupdatestate?language=objc |
| 601 if ([low_energy_central_manager_ state] < CBCentralManagerStatePoweredOn) { | 601 if ([low_energy_central_manager_ state] < CBManagerStatePoweredOn) { |
| 602 VLOG(1) | 602 VLOG(1) |
| 603 << "Central no longer powered on. Notifying of device disconnection."; | 603 << "Central no longer powered on. Notifying of device disconnection."; |
| 604 for (BluetoothDevice* device : GetDevices()) { | 604 for (BluetoothDevice* device : GetDevices()) { |
| 605 BluetoothLowEnergyDeviceMac* device_mac = | 605 BluetoothLowEnergyDeviceMac* device_mac = |
| 606 static_cast<BluetoothLowEnergyDeviceMac*>(device); | 606 static_cast<BluetoothLowEnergyDeviceMac*>(device); |
| 607 if (device_mac->IsGattConnected()) { | 607 if (device_mac->IsGattConnected()) { |
| 608 device_mac->DidDisconnectPeripheral(nullptr); | 608 device_mac->DidDisconnectPeripheral(nullptr); |
| 609 } | 609 } |
| 610 } | 610 } |
| 611 } | 611 } |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 // hash the probability of this occuring with 10,000 devices | 748 // hash the probability of this occuring with 10,000 devices |
| 749 // simultaneously present is 1e-6 (see | 749 // simultaneously present is 1e-6 (see |
| 750 // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We | 750 // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We |
| 751 // ignore the second device by returning. | 751 // ignore the second device by returning. |
| 752 return true; | 752 return true; |
| 753 } | 753 } |
| 754 return false; | 754 return false; |
| 755 } | 755 } |
| 756 | 756 |
| 757 } // namespace device | 757 } // namespace device |
| OLD | NEW |