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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 14 #include "base/mac/scoped_nsobject.h" | 14 #include "base/mac/scoped_nsobject.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "device/bluetooth/bluetooth_adapter.h" | 18 #include "device/bluetooth/bluetooth_adapter.h" |
| 19 #include "device/bluetooth/bluetooth_audio_sink.h" | 19 #include "device/bluetooth/bluetooth_audio_sink.h" |
| 20 #include "device/bluetooth/bluetooth_discovery_manager_mac.h" | 20 #include "device/bluetooth/bluetooth_discovery_manager_mac.h" |
| 21 #include "device/bluetooth/bluetooth_export.h" | 21 #include "device/bluetooth/bluetooth_export.h" |
| 22 #include "device/bluetooth/bluetooth_low_energy_device_mac.h" | |
| 23 #include "device/bluetooth/bluetooth_low_energy_discovery_manager_mac.h" | |
| 22 | 24 |
| 23 @class IOBluetoothDevice; | 25 @class IOBluetoothDevice; |
| 24 @class NSArray; | 26 @class NSArray; |
| 25 @class NSDate; | 27 @class NSDate; |
| 26 | 28 |
| 27 namespace base { | 29 namespace base { |
| 28 | 30 |
| 29 class SequencedTaskRunner; | 31 class SequencedTaskRunner; |
| 30 | 32 |
| 31 } // namespace base | 33 } // namespace base |
| 32 | 34 |
| 33 namespace device { | 35 namespace device { |
| 34 | 36 |
| 35 class BluetoothAdapterMacTest; | 37 class BluetoothAdapterMacTest; |
| 36 | 38 |
| 37 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac | 39 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac |
| 38 : public BluetoothAdapter, | 40 : public BluetoothAdapter, |
| 39 public BluetoothDiscoveryManagerMac::Observer { | 41 public BluetoothDiscoveryManagerMac::Observer, |
| 42 public BluetoothLowEnergyDiscoveryManagerMac::Observer { | |
| 40 public: | 43 public: |
| 41 static base::WeakPtr<BluetoothAdapter> CreateAdapter(); | 44 static base::WeakPtr<BluetoothAdapter> CreateAdapter(); |
| 42 | 45 |
| 43 // BluetoothAdapter: | 46 // BluetoothAdapter overrides: |
| 44 std::string GetAddress() const override; | 47 std::string GetAddress() const override; |
| 45 std::string GetName() const override; | 48 std::string GetName() const override; |
| 46 void SetName(const std::string& name, | 49 void SetName(const std::string& name, |
| 47 const base::Closure& callback, | 50 const base::Closure& callback, |
| 48 const ErrorCallback& error_callback) override; | 51 const ErrorCallback& error_callback) override; |
| 49 bool IsInitialized() const override; | 52 bool IsInitialized() const override; |
| 50 bool IsPresent() const override; | 53 bool IsPresent() const override; |
| 51 bool IsPowered() const override; | 54 bool IsPowered() const override; |
| 52 void SetPowered(bool powered, | 55 void SetPowered(bool powered, |
| 53 const base::Closure& callback, | 56 const base::Closure& callback, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 69 const CreateServiceErrorCallback& error_callback) override; | 72 const CreateServiceErrorCallback& error_callback) override; |
| 70 void RegisterAudioSink( | 73 void RegisterAudioSink( |
| 71 const BluetoothAudioSink::Options& options, | 74 const BluetoothAudioSink::Options& options, |
| 72 const AcquiredCallback& callback, | 75 const AcquiredCallback& callback, |
| 73 const BluetoothAudioSink::ErrorCallback& error_callback) override; | 76 const BluetoothAudioSink::ErrorCallback& error_callback) override; |
| 74 void RegisterAdvertisement( | 77 void RegisterAdvertisement( |
| 75 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, | 78 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, |
| 76 const CreateAdvertisementCallback& callback, | 79 const CreateAdvertisementCallback& callback, |
| 77 const CreateAdvertisementErrorCallback& error_callback) override; | 80 const CreateAdvertisementErrorCallback& error_callback) override; |
| 78 | 81 |
| 79 // BluetoothDiscoveryManagerMac::Observer overrides | 82 // BluetoothDiscoveryManagerMac::Observer overrides: |
| 80 void DeviceFound(IOBluetoothDevice* device) override; | 83 void ClassicDeviceFound(IOBluetoothDevice* device) override; |
| 81 void DiscoveryStopped(bool unexpected) override; | 84 void ClassicDiscoveryStopped(bool unexpected) override; |
| 85 | |
| 86 // BluetoothLowEnergyDiscoveryManagerMac::Observer override: | |
| 87 void LowEnergyDeviceUpdated(CBPeripheral* peripheral, | |
| 88 NSDictionary* advertisementData, | |
| 89 int rssi) override; | |
| 82 | 90 |
| 83 // Registers that a new |device| has connected to the local host. | 91 // Registers that a new |device| has connected to the local host. |
| 84 void DeviceConnected(IOBluetoothDevice* device); | 92 void DeviceConnected(IOBluetoothDevice* device); |
| 85 | 93 |
| 86 protected: | 94 protected: |
| 87 // BluetoothAdapter: | 95 // BluetoothAdapter override: |
| 88 void RemovePairingDelegateInternal( | 96 void RemovePairingDelegateInternal( |
| 89 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; | 97 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; |
| 90 | 98 |
| 91 private: | 99 private: |
| 92 friend class BluetoothAdapterMacTest; | 100 friend class BluetoothAdapterMacTest; |
| 93 | 101 |
| 94 BluetoothAdapterMac(); | 102 BluetoothAdapterMac(); |
| 95 ~BluetoothAdapterMac() override; | 103 ~BluetoothAdapterMac() override; |
| 96 | 104 |
| 97 // BluetoothAdapter: | 105 // BluetoothAdapter overrides: |
| 98 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, | 106 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, |
| 99 const base::Closure& callback, | 107 const base::Closure& callback, |
| 100 const ErrorCallback& error_callback) override; | 108 const ErrorCallback& error_callback) override; |
| 101 void RemoveDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, | 109 void RemoveDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, |
| 102 const base::Closure& callback, | 110 const base::Closure& callback, |
| 103 const ErrorCallback& error_callback) override; | 111 const ErrorCallback& error_callback) override; |
| 104 void SetDiscoveryFilter(scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, | 112 void SetDiscoveryFilter(scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, |
| 105 const base::Closure& callback, | 113 const base::Closure& callback, |
| 106 const ErrorCallback& error_callback) override; | 114 const ErrorCallback& error_callback) override; |
| 107 | 115 |
|
scheib
2015/06/05 18:10:20
Comment.
krstnmnlsn
2015/06/09 01:08:09
Done.
| |
| 116 bool StartDiscovery(BluetoothDiscoveryFilter* discovery_filter); | |
| 117 | |
| 108 void Init(); | 118 void Init(); |
| 109 void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner); | 119 void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner); |
| 110 void PollAdapter(); | 120 void PollAdapter(); |
| 111 | 121 |
| 112 // Registers that a new |device| has replied to an Inquiry, is paired, or has | 122 // Registers that a new |device| has replied to an Inquiry, is paired, or has |
| 113 // connected to the local host. | 123 // connected to the local host. |
| 114 void DeviceAdded(IOBluetoothDevice* device); | 124 void ClassicDeviceAdded(IOBluetoothDevice* device); |
| 115 | 125 |
| 116 // Updates |devices_| to include the currently paired devices, as well as any | 126 // Updates |devices_| to include the currently paired devices, as well as any |
| 117 // connected, but unpaired, devices. Notifies observers if any previously | 127 // connected, but unpaired, devices. Notifies observers if any previously |
| 118 // paired or connected devices are no longer present. | 128 // paired or connected devices are no longer present. |
| 119 void UpdateDevices(); | 129 void UpdateDevices(); |
| 120 | 130 |
| 121 std::string address_; | 131 std::string address_; |
| 122 std::string name_; | 132 std::string name_; |
| 123 bool powered_; | 133 bool powered_; |
| 124 | 134 |
| 125 int num_discovery_sessions_; | 135 int num_discovery_sessions_; |
| 126 | 136 |
| 127 // Discovery manager for Bluetooth Classic. | 137 // Discovery manager for Bluetooth Classic. |
| 128 scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_; | 138 scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_; |
| 129 | 139 |
| 140 // Discovery manager for Bluetooth Low Energy. | |
| 141 scoped_ptr<BluetoothLowEnergyDiscoveryManagerMac> | |
| 142 low_energy_discovery_manager_; | |
| 143 | |
| 130 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 144 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 131 | 145 |
| 132 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; | 146 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; |
| 133 | 147 |
| 134 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); | 148 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); |
| 135 }; | 149 }; |
| 136 | 150 |
| 137 } // namespace device | 151 } // namespace device |
| 138 | 152 |
| 139 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 153 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ |
| OLD | NEW |