| 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_discovery_manager_mac.h" |
| 19 | 20 |
| 20 @class BluetoothAdapterMacDelegate; | |
| 21 @class IOBluetoothDevice; | 21 @class IOBluetoothDevice; |
| 22 @class IOBluetoothDeviceInquiry; | |
| 23 @class NSArray; | 22 @class NSArray; |
| 24 @class NSDate; | 23 @class NSDate; |
| 25 | 24 |
| 26 namespace base { | 25 namespace base { |
| 27 | 26 |
| 28 class SequencedTaskRunner; | 27 class SequencedTaskRunner; |
| 29 | 28 |
| 30 } // namespace base | 29 } // namespace base |
| 31 | 30 |
| 32 namespace device { | 31 namespace device { |
| 33 | 32 |
| 34 class BluetoothAdapterMacTest; | 33 class BluetoothAdapterMacTest; |
| 35 | 34 |
| 36 class BluetoothAdapterMac : public BluetoothAdapter { | 35 class BluetoothAdapterMac : public BluetoothAdapter, |
| 36 public BluetoothDiscoveryManagerMac::Observer { |
| 37 public: | 37 public: |
| 38 static base::WeakPtr<BluetoothAdapter> CreateAdapter(); | 38 static base::WeakPtr<BluetoothAdapter> CreateAdapter(); |
| 39 | 39 |
| 40 // BluetoothAdapter: | 40 // BluetoothAdapter: |
| 41 virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE; | 41 virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE; |
| 42 virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE; | 42 virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE; |
| 43 virtual std::string GetAddress() const OVERRIDE; | 43 virtual std::string GetAddress() const OVERRIDE; |
| 44 virtual std::string GetName() const OVERRIDE; | 44 virtual std::string GetName() const OVERRIDE; |
| 45 virtual void SetName(const std::string& name, | 45 virtual void SetName(const std::string& name, |
| 46 const base::Closure& callback, | 46 const base::Closure& callback, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 62 const BluetoothUUID& uuid, | 62 const BluetoothUUID& uuid, |
| 63 int channel, | 63 int channel, |
| 64 const CreateServiceCallback& callback, | 64 const CreateServiceCallback& callback, |
| 65 const CreateServiceErrorCallback& error_callback) OVERRIDE; | 65 const CreateServiceErrorCallback& error_callback) OVERRIDE; |
| 66 virtual void CreateL2capService( | 66 virtual void CreateL2capService( |
| 67 const BluetoothUUID& uuid, | 67 const BluetoothUUID& uuid, |
| 68 int psm, | 68 int psm, |
| 69 const CreateServiceCallback& callback, | 69 const CreateServiceCallback& callback, |
| 70 const CreateServiceErrorCallback& error_callback) OVERRIDE; | 70 const CreateServiceErrorCallback& error_callback) OVERRIDE; |
| 71 | 71 |
| 72 // called by BluetoothAdapterMacDelegate. | 72 // BluetoothDiscoveryManagerMac::Observer overrides |
| 73 void DeviceInquiryStarted(IOBluetoothDeviceInquiry* inquiry); | 73 virtual void DeviceFound(BluetoothDiscoveryManagerMac* manager, |
| 74 void DeviceFound(IOBluetoothDeviceInquiry* inquiry, | 74 IOBluetoothDevice* device) OVERRIDE; |
| 75 IOBluetoothDevice* device); | 75 virtual void DiscoveryStopped(BluetoothDiscoveryManagerMac* manager, |
| 76 void DeviceInquiryComplete(IOBluetoothDeviceInquiry* inquiry, | 76 bool unexpected) OVERRIDE; |
| 77 IOReturn error, | |
| 78 bool aborted); | |
| 79 | 77 |
| 80 protected: | 78 protected: |
| 81 // BluetoothAdapter: | 79 // BluetoothAdapter: |
| 82 virtual void RemovePairingDelegateInternal( | 80 virtual void RemovePairingDelegateInternal( |
| 83 device::BluetoothDevice::PairingDelegate* pairing_delegate) OVERRIDE; | 81 device::BluetoothDevice::PairingDelegate* pairing_delegate) OVERRIDE; |
| 84 | 82 |
| 85 private: | 83 private: |
| 86 friend class BluetoothAdapterMacTest; | 84 friend class BluetoothAdapterMacTest; |
| 87 | 85 |
| 88 enum DiscoveryStatus { | |
| 89 NOT_DISCOVERING, | |
| 90 DISCOVERY_STARTING, | |
| 91 DISCOVERING, | |
| 92 DISCOVERY_STOPPING | |
| 93 }; | |
| 94 | |
| 95 BluetoothAdapterMac(); | 86 BluetoothAdapterMac(); |
| 96 virtual ~BluetoothAdapterMac(); | 87 virtual ~BluetoothAdapterMac(); |
| 97 | 88 |
| 98 // BluetoothAdapter: | 89 // BluetoothAdapter: |
| 99 virtual void AddDiscoverySession( | 90 virtual void AddDiscoverySession( |
| 100 const base::Closure& callback, | 91 const base::Closure& callback, |
| 101 const ErrorCallback& error_callback) OVERRIDE; | 92 const ErrorCallback& error_callback) OVERRIDE; |
| 102 virtual void RemoveDiscoverySession( | 93 virtual void RemoveDiscoverySession( |
| 103 const base::Closure& callback, | 94 const base::Closure& callback, |
| 104 const ErrorCallback& error_callback) OVERRIDE; | 95 const ErrorCallback& error_callback) OVERRIDE; |
| 105 | 96 |
| 106 void Init(); | 97 void Init(); |
| 107 void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner); | 98 void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner); |
| 108 void PollAdapter(); | 99 void PollAdapter(); |
| 109 | 100 |
| 110 // Updates |devices_| to be consistent with |devices|. | 101 // Updates |devices_| to be consistent with |devices|. |
| 111 void UpdateDevices(NSArray* devices); | 102 void UpdateDevices(NSArray* devices); |
| 112 | 103 |
| 113 void MaybeStartDeviceInquiry(); | |
| 114 void MaybeStopDeviceInquiry(); | |
| 115 | |
| 116 typedef std::vector<std::pair<base::Closure, ErrorCallback> > | |
| 117 DiscoveryCallbackList; | |
| 118 void RunCallbacks(const DiscoveryCallbackList& callback_list, | |
| 119 bool success) const; | |
| 120 | |
| 121 std::string address_; | 104 std::string address_; |
| 122 std::string name_; | 105 std::string name_; |
| 123 bool powered_; | 106 bool powered_; |
| 124 DiscoveryStatus discovery_status_; | |
| 125 | 107 |
| 126 DiscoveryCallbackList on_start_discovery_callbacks_; | 108 int num_discovery_sessions_; |
| 127 DiscoveryCallbackList on_stop_discovery_callbacks_; | |
| 128 size_t num_discovery_listeners_; | |
| 129 | 109 |
| 130 base::scoped_nsobject<BluetoothAdapterMacDelegate> adapter_delegate_; | 110 // Discovery manager for Bluetooth Classic. |
| 131 base::scoped_nsobject<IOBluetoothDeviceInquiry> device_inquiry_; | 111 scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_; |
| 132 | 112 |
| 133 // A list of discovered device addresses. | 113 // A list of discovered device addresses. |
| 134 // This list is used to check if the same device is discovered twice during | 114 // This list is used to check if the same device is discovered twice during |
| 135 // the discovery between consecutive inquiries. | 115 // the discovery between consecutive inquiries. |
| 136 base::hash_set<std::string> discovered_devices_; | 116 base::hash_set<std::string> discovered_devices_; |
| 137 | 117 |
| 138 // Timestamp for the recently accessed device. | 118 // Timestamp for the recently accessed device. |
| 139 // Used to determine if |devices_| needs an update. | 119 // Used to determine if |devices_| needs an update. |
| 140 base::scoped_nsobject<NSDate> recently_accessed_device_timestamp_; | 120 base::scoped_nsobject<NSDate> recently_accessed_device_timestamp_; |
| 141 | 121 |
| 142 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 122 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 143 | 123 |
| 144 // List of observers interested in event notifications from us. | 124 // List of observers interested in event notifications from us. |
| 145 ObserverList<BluetoothAdapter::Observer> observers_; | 125 ObserverList<BluetoothAdapter::Observer> observers_; |
| 146 | 126 |
| 147 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; | 127 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; |
| 148 | 128 |
| 149 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); | 129 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); |
| 150 }; | 130 }; |
| 151 | 131 |
| 152 } // namespace device | 132 } // namespace device |
| 153 | 133 |
| 154 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 134 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ |
| OLD | NEW |