| 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 14 matching lines...) Expand all Loading... |
| 25 @class IOBluetoothDevice; | 25 @class IOBluetoothDevice; |
| 26 @class NSArray; | 26 @class NSArray; |
| 27 @class NSDate; | 27 @class NSDate; |
| 28 | 28 |
| 29 namespace base { | 29 namespace base { |
| 30 | 30 |
| 31 class SequencedTaskRunner; | 31 class SequencedTaskRunner; |
| 32 | 32 |
| 33 } // namespace base | 33 } // namespace base |
| 34 | 34 |
| 35 @class BluetoothLowEnergyCentralManagerDelegate; |
| 36 |
| 35 namespace device { | 37 namespace device { |
| 36 | 38 |
| 37 class BluetoothAdapterMacTest; | |
| 38 | |
| 39 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac | 39 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac |
| 40 : public BluetoothAdapter, | 40 : public BluetoothAdapter, |
| 41 public BluetoothDiscoveryManagerMac::Observer, | 41 public BluetoothDiscoveryManagerMac::Observer, |
| 42 public BluetoothLowEnergyDiscoveryManagerMac::Observer { | 42 public BluetoothLowEnergyDiscoveryManagerMac::Observer { |
| 43 public: | 43 public: |
| 44 static base::WeakPtr<BluetoothAdapter> CreateAdapter(); | 44 static base::WeakPtr<BluetoothAdapter> CreateAdapter(); |
| 45 | 45 |
| 46 // BluetoothAdapter overrides: | 46 // BluetoothAdapter overrides: |
| 47 std::string GetAddress() const override; | 47 std::string GetAddress() const override; |
| 48 std::string GetName() const override; | 48 std::string GetName() const override; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 void RemovePairingDelegateInternal( | 97 void RemovePairingDelegateInternal( |
| 98 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; | 98 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; |
| 99 | 99 |
| 100 private: | 100 private: |
| 101 // The length of time that must elapse since the last Inquiry response (on | 101 // The length of time that must elapse since the last Inquiry response (on |
| 102 // Classic devices) or call to BluetoothLowEnergyDevice::Update() (on Low | 102 // Classic devices) or call to BluetoothLowEnergyDevice::Update() (on Low |
| 103 // Energy) before a discovered device is considered to be no longer available. | 103 // Energy) before a discovered device is considered to be no longer available. |
| 104 const static NSTimeInterval kDiscoveryTimeoutSec; | 104 const static NSTimeInterval kDiscoveryTimeoutSec; |
| 105 | 105 |
| 106 friend class BluetoothAdapterMacTest; | 106 friend class BluetoothAdapterMacTest; |
| 107 friend class BluetoothLowEnergyCentralManagerBridge; |
| 107 | 108 |
| 108 BluetoothAdapterMac(); | 109 BluetoothAdapterMac(); |
| 109 ~BluetoothAdapterMac() override; | 110 ~BluetoothAdapterMac() override; |
| 110 | 111 |
| 111 // BluetoothAdapter overrides: | 112 // BluetoothAdapter overrides: |
| 112 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, | 113 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, |
| 113 const base::Closure& callback, | 114 const base::Closure& callback, |
| 114 const ErrorCallback& error_callback) override; | 115 const ErrorCallback& error_callback) override; |
| 115 void RemoveDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, | 116 void RemoveDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, |
| 116 const base::Closure& callback, | 117 const base::Closure& callback, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 129 | 130 |
| 130 // Registers that a new |device| has replied to an Inquiry, is paired, or has | 131 // Registers that a new |device| has replied to an Inquiry, is paired, or has |
| 131 // connected to the local host. | 132 // connected to the local host. |
| 132 void ClassicDeviceAdded(IOBluetoothDevice* device); | 133 void ClassicDeviceAdded(IOBluetoothDevice* device); |
| 133 | 134 |
| 134 // BluetoothLowEnergyDiscoveryManagerMac::Observer override: | 135 // BluetoothLowEnergyDiscoveryManagerMac::Observer override: |
| 135 void LowEnergyDeviceUpdated(CBPeripheral* peripheral, | 136 void LowEnergyDeviceUpdated(CBPeripheral* peripheral, |
| 136 NSDictionary* advertisement_data, | 137 NSDictionary* advertisement_data, |
| 137 int rssi) override; | 138 int rssi) override; |
| 138 | 139 |
| 140 // Updates |devices_| when there is a change to the CBCentralManager's state. |
| 141 void LowEnergyCentralManagerUpdatedState(); |
| 142 |
| 139 // Removes from |devices_| any previously paired, connected or seen devices | 143 // Removes from |devices_| any previously paired, connected or seen devices |
| 140 // which are no longer present. Notifies observers. | 144 // which are no longer present. Notifies observers. |
| 141 void RemoveTimedOutDevices(); | 145 void RemoveTimedOutDevices(); |
| 142 | 146 |
| 143 // Updates |devices_| to include the currently paired devices and notifies | 147 // Updates |devices_| to include the currently paired devices and notifies |
| 144 // observers. | 148 // observers. |
| 145 void AddPairedDevices(); | 149 void AddPairedDevices(); |
| 146 | 150 |
| 151 // Private method for testing. Resets |low_energy_central_manager_| to |
| 152 // |central_manager| and sets |low_energy_central_manager_delegate_| as its |
| 153 // delegate. Should be called only when CoreBluetooth is available. |
| 154 void SetCentralManagerForTesting(CBCentralManager* central_manager); |
| 155 |
| 147 std::string address_; | 156 std::string address_; |
| 148 std::string name_; | 157 std::string name_; |
| 149 bool powered_; | 158 bool powered_; |
| 150 | 159 |
| 151 int num_discovery_sessions_; | 160 int num_discovery_sessions_; |
| 152 | 161 |
| 153 // Discovery manager for Bluetooth Classic. | 162 // Discovery manager for Bluetooth Classic. |
| 154 scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_; | 163 scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_; |
| 155 | 164 |
| 156 // Discovery manager for Bluetooth Low Energy. | 165 // Discovery manager for Bluetooth Low Energy. |
| 157 scoped_ptr<BluetoothLowEnergyDiscoveryManagerMac> | 166 scoped_ptr<BluetoothLowEnergyDiscoveryManagerMac> |
| 158 low_energy_discovery_manager_; | 167 low_energy_discovery_manager_; |
| 159 | 168 |
| 169 // Underlying CoreBluetooth CBCentralManager and its delegate. |
| 170 base::scoped_nsobject<CBCentralManager> low_energy_central_manager_; |
| 171 base::scoped_nsobject<BluetoothLowEnergyCentralManagerDelegate> |
| 172 low_energy_central_manager_delegate_; |
| 173 |
| 160 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 174 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 161 | 175 |
| 162 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; | 176 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; |
| 163 | 177 |
| 164 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); | 178 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); |
| 165 }; | 179 }; |
| 166 | 180 |
| 167 } // namespace device | 181 } // namespace device |
| 168 | 182 |
| 169 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 183 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ |
| OLD | NEW |