Chromium Code Reviews| 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 24 matching lines...) Expand all Loading... | |
| 35 @class BluetoothLowEnergyCentralManagerDelegate; | 35 @class BluetoothLowEnergyCentralManagerDelegate; |
| 36 | 36 |
| 37 namespace device { | 37 namespace device { |
| 38 | 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 static base::WeakPtr<BluetoothAdapter> CreateAdapterForTest( | |
| 46 std::string name, | |
| 47 std::string address, | |
| 48 scoped_refptr<base::SequencedTaskRunner> ui_task_runner); | |
| 45 | 49 |
| 46 // BluetoothAdapter overrides: | 50 // BluetoothAdapter overrides: |
| 47 std::string GetAddress() const override; | 51 std::string GetAddress() const override; |
| 48 std::string GetName() const override; | 52 std::string GetName() const override; |
| 49 void SetName(const std::string& name, | 53 void SetName(const std::string& name, |
| 50 const base::Closure& callback, | 54 const base::Closure& callback, |
| 51 const ErrorCallback& error_callback) override; | 55 const ErrorCallback& error_callback) override; |
| 52 bool IsInitialized() const override; | 56 bool IsInitialized() const override; |
| 53 bool IsPresent() const override; | 57 bool IsPresent() const override; |
| 54 bool IsPowered() const override; | 58 bool IsPowered() const override; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 85 | 89 |
| 86 // Registers that a new |device| has connected to the local host. | 90 // Registers that a new |device| has connected to the local host. |
| 87 void DeviceConnected(IOBluetoothDevice* device); | 91 void DeviceConnected(IOBluetoothDevice* device); |
| 88 | 92 |
| 89 // We only use CoreBluetooth when OS X >= 10.10. This because the | 93 // We only use CoreBluetooth when OS X >= 10.10. This because the |
| 90 // CBCentralManager destructor was found to crash on the mac_chromium_rel_ng | 94 // CBCentralManager destructor was found to crash on the mac_chromium_rel_ng |
| 91 // builder running 10.9.5. May also cause blued to crash on OS X 10.9.5 | 95 // builder running 10.9.5. May also cause blued to crash on OS X 10.9.5 |
| 92 // (crbug.com/506287). | 96 // (crbug.com/506287). |
| 93 static bool IsLowEnergyAvailable(); | 97 static bool IsLowEnergyAvailable(); |
| 94 | 98 |
| 99 // Resets |low_energy_central_manager_| to |central_manager| and sets | |
| 100 // |low_energy_central_manager_delegate_| as its delegate. Should be called | |
|
scheib
2015/07/17 21:26:04
'its' is a tad ambiguous. Try "as the manager's de
krstnmnlsn
2015/07/17 23:14:50
Done.
| |
| 101 // only when CoreBluetooth is available. | |
| 102 void SetCentralManagerForTesting(CBCentralManager* central_manager); | |
| 103 | |
| 95 protected: | 104 protected: |
| 96 // BluetoothAdapter override: | 105 // BluetoothAdapter override: |
| 97 void RemovePairingDelegateInternal( | 106 void RemovePairingDelegateInternal( |
| 98 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; | 107 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; |
| 99 | 108 |
| 100 private: | 109 private: |
| 101 // The length of time that must elapse since the last Inquiry response (on | 110 // The length of time that must elapse since the last Inquiry response (on |
| 102 // Classic devices) or call to BluetoothLowEnergyDevice::Update() (on Low | 111 // Classic devices) or call to BluetoothLowEnergyDevice::Update() (on Low |
| 103 // Energy) before a discovered device is considered to be no longer available. | 112 // Energy) before a discovered device is considered to be no longer available. |
| 104 const static NSTimeInterval kDiscoveryTimeoutSec; | 113 const static NSTimeInterval kDiscoveryTimeoutSec; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 void LowEnergyCentralManagerUpdatedState(); | 150 void LowEnergyCentralManagerUpdatedState(); |
| 142 | 151 |
| 143 // Removes from |devices_| any previously paired, connected or seen devices | 152 // Removes from |devices_| any previously paired, connected or seen devices |
| 144 // which are no longer present. Notifies observers. | 153 // which are no longer present. Notifies observers. |
| 145 void RemoveTimedOutDevices(); | 154 void RemoveTimedOutDevices(); |
| 146 | 155 |
| 147 // Updates |devices_| to include the currently paired devices and notifies | 156 // Updates |devices_| to include the currently paired devices and notifies |
| 148 // observers. | 157 // observers. |
| 149 void AddPairedDevices(); | 158 void AddPairedDevices(); |
| 150 | 159 |
| 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 | |
| 156 std::string address_; | 160 std::string address_; |
| 157 std::string name_; | 161 std::string name_; |
| 158 bool powered_; | 162 bool classic_powered_; |
| 159 | |
| 160 int num_discovery_sessions_; | 163 int num_discovery_sessions_; |
| 161 | 164 |
| 162 // Discovery manager for Bluetooth Classic. | 165 // Discovery manager for Bluetooth Classic. |
| 163 scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_; | 166 scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_; |
| 164 | 167 |
| 165 // Discovery manager for Bluetooth Low Energy. | 168 // Discovery manager for Bluetooth Low Energy. |
| 166 scoped_ptr<BluetoothLowEnergyDiscoveryManagerMac> | 169 scoped_ptr<BluetoothLowEnergyDiscoveryManagerMac> |
| 167 low_energy_discovery_manager_; | 170 low_energy_discovery_manager_; |
| 168 | 171 |
| 169 // Underlying CoreBluetooth CBCentralManager and its delegate. | 172 // Underlying CoreBluetooth CBCentralManager and its delegate. |
| 170 base::scoped_nsobject<CBCentralManager> low_energy_central_manager_; | 173 base::scoped_nsobject<CBCentralManager> low_energy_central_manager_; |
| 171 base::scoped_nsobject<BluetoothLowEnergyCentralManagerDelegate> | 174 base::scoped_nsobject<BluetoothLowEnergyCentralManagerDelegate> |
| 172 low_energy_central_manager_delegate_; | 175 low_energy_central_manager_delegate_; |
| 173 | 176 |
| 174 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 177 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 175 | 178 |
| 176 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; | 179 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; |
| 177 | 180 |
| 178 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); | 181 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); |
| 179 }; | 182 }; |
| 180 | 183 |
| 181 } // namespace device | 184 } // namespace device |
| 182 | 185 |
| 183 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 186 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ |
| OLD | NEW |