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_mac_discovery_manager.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 BluetoothMacDiscoveryManager::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 16 matching lines...) Expand all Loading... | |
63 int channel, | 63 int channel, |
64 bool insecure, | 64 bool insecure, |
65 const CreateServiceCallback& callback, | 65 const CreateServiceCallback& callback, |
66 const CreateServiceErrorCallback& error_callback) OVERRIDE; | 66 const CreateServiceErrorCallback& error_callback) OVERRIDE; |
67 virtual void CreateL2capService( | 67 virtual void CreateL2capService( |
68 const BluetoothUUID& uuid, | 68 const BluetoothUUID& uuid, |
69 int psm, | 69 int psm, |
70 const CreateServiceCallback& callback, | 70 const CreateServiceCallback& callback, |
71 const CreateServiceErrorCallback& error_callback) OVERRIDE; | 71 const CreateServiceErrorCallback& error_callback) OVERRIDE; |
72 | 72 |
73 // called by BluetoothAdapterMacDelegate. | 73 // BluetoothMacDiscoveryManager::Observer overrides |
74 void DeviceInquiryStarted(IOBluetoothDeviceInquiry* inquiry); | 74 virtual void DeviceFound(BluetoothMacDiscoveryManager* manager, |
75 void DeviceFound(IOBluetoothDeviceInquiry* inquiry, | 75 IOBluetoothDevice* device) OVERRIDE; |
76 IOBluetoothDevice* device); | 76 virtual void DiscoveryStopped(BluetoothMacDiscoveryManager* manager, |
77 void DeviceInquiryComplete(IOBluetoothDeviceInquiry* inquiry, | 77 bool unexpected) OVERRIDE; |
78 IOReturn error, | |
79 bool aborted); | |
80 | 78 |
81 protected: | 79 protected: |
82 // BluetoothAdapter: | 80 // BluetoothAdapter: |
83 virtual void RemovePairingDelegateInternal( | 81 virtual void RemovePairingDelegateInternal( |
84 device::BluetoothDevice::PairingDelegate* pairing_delegate) OVERRIDE; | 82 device::BluetoothDevice::PairingDelegate* pairing_delegate) OVERRIDE; |
85 | 83 |
86 private: | 84 private: |
87 friend class BluetoothAdapterMacTest; | 85 friend class BluetoothAdapterMacTest; |
88 | 86 |
89 enum DiscoveryStatus { | |
90 NOT_DISCOVERING, | |
91 DISCOVERY_STARTING, | |
92 DISCOVERING, | |
93 DISCOVERY_STOPPING | |
94 }; | |
95 | |
96 BluetoothAdapterMac(); | 87 BluetoothAdapterMac(); |
97 virtual ~BluetoothAdapterMac(); | 88 virtual ~BluetoothAdapterMac(); |
98 | 89 |
99 // BluetoothAdapter: | 90 // BluetoothAdapter: |
100 virtual void AddDiscoverySession( | 91 virtual void AddDiscoverySession( |
101 const base::Closure& callback, | 92 const base::Closure& callback, |
102 const ErrorCallback& error_callback) OVERRIDE; | 93 const ErrorCallback& error_callback) OVERRIDE; |
103 virtual void RemoveDiscoverySession( | 94 virtual void RemoveDiscoverySession( |
104 const base::Closure& callback, | 95 const base::Closure& callback, |
105 const ErrorCallback& error_callback) OVERRIDE; | 96 const ErrorCallback& error_callback) OVERRIDE; |
106 | 97 |
107 void Init(); | 98 void Init(); |
108 void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner); | 99 void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner); |
109 void PollAdapter(); | 100 void PollAdapter(); |
110 | 101 |
111 // Updates |devices_| to be consistent with |devices|. | 102 // Updates |devices_| to be consistent with |devices|. |
112 void UpdateDevices(NSArray* devices); | 103 void UpdateDevices(NSArray* devices); |
113 | 104 |
114 void MaybeStartDeviceInquiry(); | |
115 void MaybeStopDeviceInquiry(); | |
116 | |
117 typedef std::vector<std::pair<base::Closure, ErrorCallback> > | |
118 DiscoveryCallbackList; | |
119 void RunCallbacks(const DiscoveryCallbackList& callback_list, | |
120 bool success) const; | |
121 | |
122 std::string address_; | 105 std::string address_; |
123 std::string name_; | 106 std::string name_; |
124 bool powered_; | 107 bool powered_; |
125 DiscoveryStatus discovery_status_; | |
126 | 108 |
127 DiscoveryCallbackList on_start_discovery_callbacks_; | 109 int num_discovery_sessions_; |
128 DiscoveryCallbackList on_stop_discovery_callbacks_; | |
129 size_t num_discovery_listeners_; | |
130 | 110 |
131 base::scoped_nsobject<BluetoothAdapterMacDelegate> adapter_delegate_; | 111 // Discovery manager for classic discovery. |
Ilya Sherman
2014/06/10 01:10:59
Optional nit: I'd replace the second "discovery" w
armansito
2014/06/10 21:56:50
Done.
| |
132 base::scoped_nsobject<IOBluetoothDeviceInquiry> device_inquiry_; | 112 scoped_ptr<BluetoothMacDiscoveryManager> classic_discovery_manager_; |
133 | 113 |
134 // A list of discovered device addresses. | 114 // A list of discovered device addresses. |
135 // This list is used to check if the same device is discovered twice during | 115 // This list is used to check if the same device is discovered twice during |
136 // the discovery between consecutive inquiries. | 116 // the discovery between consecutive inquiries. |
137 base::hash_set<std::string> discovered_devices_; | 117 base::hash_set<std::string> discovered_devices_; |
138 | 118 |
139 // Timestamp for the recently accessed device. | 119 // Timestamp for the recently accessed device. |
140 // Used to determine if |devices_| needs an update. | 120 // Used to determine if |devices_| needs an update. |
141 base::scoped_nsobject<NSDate> recently_accessed_device_timestamp_; | 121 base::scoped_nsobject<NSDate> recently_accessed_device_timestamp_; |
142 | 122 |
143 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 123 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
144 | 124 |
145 // List of observers interested in event notifications from us. | 125 // List of observers interested in event notifications from us. |
146 ObserverList<BluetoothAdapter::Observer> observers_; | 126 ObserverList<BluetoothAdapter::Observer> observers_; |
147 | 127 |
148 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; | 128 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; |
149 | 129 |
150 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); | 130 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); |
151 }; | 131 }; |
152 | 132 |
153 } // namespace device | 133 } // namespace device |
154 | 134 |
155 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 135 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ |
OLD | NEW |