| 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 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ |
| 7 | 7 |
| 8 #include <IOKit/IOReturn.h> | 8 #include <IOKit/IOReturn.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 // Registers that a new |device| has connected to the local host. | 91 // Registers that a new |device| has connected to the local host. |
| 92 void DeviceConnected(IOBluetoothDevice* device); | 92 void DeviceConnected(IOBluetoothDevice* device); |
| 93 | 93 |
| 94 // We only use CoreBluetooth when OS X >= 10.10. This because the | 94 // We only use CoreBluetooth when OS X >= 10.10. This because the |
| 95 // CBCentralManager destructor was found to crash on the mac_chromium_rel_ng | 95 // CBCentralManager destructor was found to crash on the mac_chromium_rel_ng |
| 96 // builder running 10.9.5. May also cause blued to crash on OS X 10.9.5 | 96 // builder running 10.9.5. May also cause blued to crash on OS X 10.9.5 |
| 97 // (crbug.com/506287). | 97 // (crbug.com/506287). |
| 98 static bool IsLowEnergyAvailable(); | 98 static bool IsLowEnergyAvailable(); |
| 99 | 99 |
| 100 // Resets |low_energy_central_manager_| to |central_manager| and sets | 100 // Creates a GATT connection by calling CoreBluetooth APIs. |
| 101 // |low_energy_central_manager_delegate_| as the manager's delegate. Should | 101 void CreateGattConnection(BluetoothLowEnergyDeviceMac* device_mac); |
| 102 // be called only when |IsLowEnergyAvailable()|. | 102 |
| 103 void SetCentralManagerForTesting(CBCentralManager* central_manager); | 103 // Closes the GATT connection by calling CoreBluetooth APIs. |
| 104 void DisconnectGatt(BluetoothLowEnergyDeviceMac* device_mac); |
| 105 |
| 106 // Methods called from CBCentralManager delegate. |
| 107 void DidConnectPeripheral(CBPeripheral* peripheral); |
| 108 void DidFailToConnectPeripheral(CBPeripheral* peripheral, NSError* error); |
| 109 void DidDisconnectPeripheral(CBPeripheral* peripheral, NSError* error); |
| 104 | 110 |
| 105 protected: | 111 protected: |
| 106 // BluetoothAdapter override: | 112 // BluetoothAdapter override: |
| 107 void RemovePairingDelegateInternal( | 113 void RemovePairingDelegateInternal( |
| 108 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; | 114 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; |
| 109 | 115 |
| 110 private: | 116 private: |
| 117 // Resets |low_energy_central_manager_| to |central_manager| and sets |
| 118 // |low_energy_central_manager_delegate_| as the manager's delegate. Should |
| 119 // be called only when |IsLowEnergyAvailable()|. |
| 120 void SetCentralManagerForTesting(CBCentralManager* central_manager); |
| 121 CBCentralManager* GetCentralManagerForTesting(); |
| 122 |
| 111 // The length of time that must elapse since the last Inquiry response (on | 123 // The length of time that must elapse since the last Inquiry response (on |
| 112 // Classic devices) or call to BluetoothLowEnergyDevice::Update() (on Low | 124 // Classic devices) or call to BluetoothLowEnergyDevice::Update() (on Low |
| 113 // Energy) before a discovered device is considered to be no longer available. | 125 // Energy) before a discovered device is considered to be no longer available. |
| 114 const static NSTimeInterval kDiscoveryTimeoutSec; | 126 const static NSTimeInterval kDiscoveryTimeoutSec; |
| 115 | 127 |
| 116 friend class BluetoothTestMac; | 128 friend class BluetoothTestMac; |
| 117 friend class BluetoothAdapterMacTest; | 129 friend class BluetoothAdapterMacTest; |
| 118 friend class BluetoothLowEnergyCentralManagerBridge; | 130 friend class BluetoothLowEnergyCentralManagerBridge; |
| 119 | 131 |
| 120 BluetoothAdapterMac(); | 132 BluetoothAdapterMac(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 void LowEnergyCentralManagerUpdatedState(); | 167 void LowEnergyCentralManagerUpdatedState(); |
| 156 | 168 |
| 157 // Removes from |devices_| any previously paired, connected or seen devices | 169 // Removes from |devices_| any previously paired, connected or seen devices |
| 158 // which are no longer present. Notifies observers. | 170 // which are no longer present. Notifies observers. |
| 159 void RemoveTimedOutDevices(); | 171 void RemoveTimedOutDevices(); |
| 160 | 172 |
| 161 // Updates |devices_| to include the currently paired devices and notifies | 173 // Updates |devices_| to include the currently paired devices and notifies |
| 162 // observers. | 174 // observers. |
| 163 void AddPairedDevices(); | 175 void AddPairedDevices(); |
| 164 | 176 |
| 177 // Returns the BLE device associated with the CoreBluetooth peripheral. |
| 178 BluetoothLowEnergyDeviceMac* GetBluetoothLowEnergyDeviceMac( |
| 179 CBPeripheral* peripheral); |
| 180 |
| 165 std::string address_; | 181 std::string address_; |
| 166 std::string name_; | 182 std::string name_; |
| 167 bool classic_powered_; | 183 bool classic_powered_; |
| 168 int num_discovery_sessions_; | 184 int num_discovery_sessions_; |
| 169 | 185 |
| 170 // Discovery manager for Bluetooth Classic. | 186 // Discovery manager for Bluetooth Classic. |
| 171 scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_; | 187 scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_; |
| 172 | 188 |
| 173 // Discovery manager for Bluetooth Low Energy. | 189 // Discovery manager for Bluetooth Low Energy. |
| 174 scoped_ptr<BluetoothLowEnergyDiscoveryManagerMac> | 190 scoped_ptr<BluetoothLowEnergyDiscoveryManagerMac> |
| 175 low_energy_discovery_manager_; | 191 low_energy_discovery_manager_; |
| 176 | 192 |
| 177 // Underlying CoreBluetooth CBCentralManager and its delegate. | 193 // Underlying CoreBluetooth CBCentralManager and its delegate. |
| 178 base::scoped_nsobject<CBCentralManager> low_energy_central_manager_; | 194 base::scoped_nsobject<CBCentralManager> low_energy_central_manager_; |
| 179 base::scoped_nsobject<BluetoothLowEnergyCentralManagerDelegate> | 195 base::scoped_nsobject<BluetoothLowEnergyCentralManagerDelegate> |
| 180 low_energy_central_manager_delegate_; | 196 low_energy_central_manager_delegate_; |
| 181 | 197 |
| 182 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 198 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 183 | 199 |
| 184 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; | 200 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; |
| 185 | 201 |
| 186 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); | 202 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); |
| 187 }; | 203 }; |
| 188 | 204 |
| 189 } // namespace device | 205 } // namespace device |
| 190 | 206 |
| 191 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 207 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ |
| OLD | NEW |