| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 const BluetoothAudioSink::ErrorCallback& error_callback) override; | 76 const BluetoothAudioSink::ErrorCallback& error_callback) override; |
| 77 void RegisterAdvertisement( | 77 void RegisterAdvertisement( |
| 78 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, | 78 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, |
| 79 const CreateAdvertisementCallback& callback, | 79 const CreateAdvertisementCallback& callback, |
| 80 const CreateAdvertisementErrorCallback& error_callback) override; | 80 const CreateAdvertisementErrorCallback& error_callback) override; |
| 81 | 81 |
| 82 // BluetoothDiscoveryManagerMac::Observer overrides: | 82 // BluetoothDiscoveryManagerMac::Observer overrides: |
| 83 void ClassicDeviceFound(IOBluetoothDevice* device) override; | 83 void ClassicDeviceFound(IOBluetoothDevice* device) override; |
| 84 void ClassicDiscoveryStopped(bool unexpected) override; | 84 void ClassicDiscoveryStopped(bool unexpected) override; |
| 85 | 85 |
| 86 // BluetoothLowEnergyDiscoveryManagerMac::Observer override: | |
| 87 void LowEnergyDeviceUpdated(CBPeripheral* peripheral, | |
| 88 NSDictionary* advertisementData, | |
| 89 int rssi) override; | |
| 90 | |
| 91 // Registers that a new |device| has connected to the local host. | 86 // Registers that a new |device| has connected to the local host. |
| 92 void DeviceConnected(IOBluetoothDevice* device); | 87 void DeviceConnected(IOBluetoothDevice* device); |
| 93 | 88 |
| 94 // We only use CoreBluetooth when OS X >= 10.10. This because the | 89 // 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 | 90 // 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 | 91 // builder running 10.9.5. May also cause blued to crash on OS X 10.9.5 |
| 97 // (crbug.com/506287). | 92 // (crbug.com/506287). |
| 98 static bool IsLowEnergyAvailable(); | 93 static bool IsLowEnergyAvailable(); |
| 99 | 94 |
| 100 protected: | 95 protected: |
| 101 // BluetoothAdapter override: | 96 // BluetoothAdapter override: |
| 102 void RemovePairingDelegateInternal( | 97 void RemovePairingDelegateInternal( |
| 103 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; | 98 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; |
| 104 | 99 |
| 105 private: | 100 private: |
| 101 // The length of time that must elapse since the last Inquiry response (on |
| 102 // Classic devices) or call to BluetoothLowEnergyDevice::Update() (on Low |
| 103 // Energy) before a discovered device is considered to be no longer available. |
| 104 const static NSTimeInterval kDiscoveryTimeoutSec; |
| 105 |
| 106 friend class BluetoothAdapterMacTest; | 106 friend class BluetoothAdapterMacTest; |
| 107 | 107 |
| 108 BluetoothAdapterMac(); | 108 BluetoothAdapterMac(); |
| 109 ~BluetoothAdapterMac() override; | 109 ~BluetoothAdapterMac() override; |
| 110 | 110 |
| 111 // BluetoothAdapter overrides: | 111 // BluetoothAdapter overrides: |
| 112 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, | 112 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, |
| 113 const base::Closure& callback, | 113 const base::Closure& callback, |
| 114 const ErrorCallback& error_callback) override; | 114 const ErrorCallback& error_callback) override; |
| 115 void RemoveDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, | 115 void RemoveDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, |
| 116 const base::Closure& callback, | 116 const base::Closure& callback, |
| 117 const ErrorCallback& error_callback) override; | 117 const ErrorCallback& error_callback) override; |
| 118 void SetDiscoveryFilter(scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, | 118 void SetDiscoveryFilter(scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, |
| 119 const base::Closure& callback, | 119 const base::Closure& callback, |
| 120 const ErrorCallback& error_callback) override; | 120 const ErrorCallback& error_callback) override; |
| 121 | 121 |
| 122 // Start classic and/or low energy discovery sessions, according to the | 122 // Start classic and/or low energy discovery sessions, according to the |
| 123 // filter. If a discovery session is already running the filter is updated. | 123 // filter. If a discovery session is already running the filter is updated. |
| 124 bool StartDiscovery(BluetoothDiscoveryFilter* discovery_filter); | 124 bool StartDiscovery(BluetoothDiscoveryFilter* discovery_filter); |
| 125 | 125 |
| 126 void Init(); | 126 void Init(); |
| 127 void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner); | 127 void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner); |
| 128 void PollAdapter(); | 128 void PollAdapter(); |
| 129 | 129 |
| 130 // Registers that a new |device| has replied to an Inquiry, is paired, or has | 130 // Registers that a new |device| has replied to an Inquiry, is paired, or has |
| 131 // connected to the local host. | 131 // connected to the local host. |
| 132 void ClassicDeviceAdded(IOBluetoothDevice* device); | 132 void ClassicDeviceAdded(IOBluetoothDevice* device); |
| 133 | 133 |
| 134 // Updates |devices_| to include the currently paired devices, as well as any | 134 // BluetoothLowEnergyDiscoveryManagerMac::Observer override: |
| 135 // connected, but unpaired, devices. Notifies observers if any previously | 135 void LowEnergyDeviceUpdated(CBPeripheral* peripheral, |
| 136 // paired or connected devices are no longer present. | 136 NSDictionary* advertisement_data, |
| 137 void UpdateDevices(); | 137 int rssi) override; |
| 138 |
| 139 // Removes from |devices_| any previously paired, connected or seen devices |
| 140 // which are no longer present. Notifies observers. |
| 141 void RemoveTimedOutDevices(); |
| 142 |
| 143 // Updates |devices_| to include the currently paired devices and notifies |
| 144 // observers. |
| 145 void AddPairedDevices(); |
| 138 | 146 |
| 139 std::string address_; | 147 std::string address_; |
| 140 std::string name_; | 148 std::string name_; |
| 141 bool powered_; | 149 bool powered_; |
| 142 | 150 |
| 143 int num_discovery_sessions_; | 151 int num_discovery_sessions_; |
| 144 | 152 |
| 145 // Discovery manager for Bluetooth Classic. | 153 // Discovery manager for Bluetooth Classic. |
| 146 scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_; | 154 scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_; |
| 147 | 155 |
| 148 // Discovery manager for Bluetooth Low Energy. | 156 // Discovery manager for Bluetooth Low Energy. |
| 149 scoped_ptr<BluetoothLowEnergyDiscoveryManagerMac> | 157 scoped_ptr<BluetoothLowEnergyDiscoveryManagerMac> |
| 150 low_energy_discovery_manager_; | 158 low_energy_discovery_manager_; |
| 151 | 159 |
| 152 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 160 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 153 | 161 |
| 154 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; | 162 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; |
| 155 | 163 |
| 156 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); | 164 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); |
| 157 }; | 165 }; |
| 158 | 166 |
| 159 } // namespace device | 167 } // namespace device |
| 160 | 168 |
| 161 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 169 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ |
| OLD | NEW |