Index: device/bluetooth/bluetooth_adapter_mac.h |
diff --git a/device/bluetooth/bluetooth_adapter_mac.h b/device/bluetooth/bluetooth_adapter_mac.h |
index c8414817d89c1fdfff79cd178076f3009ed7d225..8b051fe33b2186ccbf9846d38e1e197067c05a07 100644 |
--- a/device/bluetooth/bluetooth_adapter_mac.h |
+++ b/device/bluetooth/bluetooth_adapter_mac.h |
@@ -17,7 +17,7 @@ |
#include "base/observer_list.h" |
#include "device/bluetooth/bluetooth_adapter.h" |
-@class BluetoothAdapterMacDelegate; |
+@class BluetoothDeviceInquiryDelegate; |
@class IOBluetoothDevice; |
@class IOBluetoothDeviceInquiry; |
@class NSArray; |
@@ -32,6 +32,7 @@ class SequencedTaskRunner; |
namespace device { |
class BluetoothAdapterMacTest; |
+class BluetoothMacClassicDiscoveryManager; |
class BluetoothAdapterMac : public BluetoothAdapter { |
public: |
@@ -70,13 +71,9 @@ class BluetoothAdapterMac : public BluetoothAdapter { |
const CreateServiceCallback& callback, |
const CreateServiceErrorCallback& error_callback) OVERRIDE; |
- // called by BluetoothAdapterMacDelegate. |
- void DeviceInquiryStarted(IOBluetoothDeviceInquiry* inquiry); |
- void DeviceFound(IOBluetoothDeviceInquiry* inquiry, |
- IOBluetoothDevice* device); |
- void DeviceInquiryComplete(IOBluetoothDeviceInquiry* inquiry, |
- IOReturn error, |
- bool aborted); |
+ // Called by BluetoothMacClassicDiscoveryManager. |
+ void DeviceFound(IOBluetoothDevice* device); |
+ void ClassicDiscoveryStopped(bool unexpected); |
protected: |
// BluetoothAdapter: |
@@ -86,13 +83,6 @@ class BluetoothAdapterMac : public BluetoothAdapter { |
private: |
friend class BluetoothAdapterMacTest; |
- enum DiscoveryStatus { |
- NOT_DISCOVERING, |
- DISCOVERY_STARTING, |
- DISCOVERING, |
- DISCOVERY_STOPPING |
- }; |
- |
BluetoothAdapterMac(); |
virtual ~BluetoothAdapterMac(); |
@@ -111,25 +101,14 @@ class BluetoothAdapterMac : public BluetoothAdapter { |
// Updates |devices_| to be consistent with |devices|. |
void UpdateDevices(NSArray* devices); |
- void MaybeStartDeviceInquiry(); |
- void MaybeStopDeviceInquiry(); |
- |
- typedef std::vector<std::pair<base::Closure, ErrorCallback> > |
- DiscoveryCallbackList; |
- void RunCallbacks(const DiscoveryCallbackList& callback_list, |
- bool success) const; |
- |
std::string address_; |
std::string name_; |
bool powered_; |
- DiscoveryStatus discovery_status_; |
- DiscoveryCallbackList on_start_discovery_callbacks_; |
- DiscoveryCallbackList on_stop_discovery_callbacks_; |
- size_t num_discovery_listeners_; |
+ int num_discovery_sessions_; |
- base::scoped_nsobject<BluetoothAdapterMacDelegate> adapter_delegate_; |
- base::scoped_nsobject<IOBluetoothDeviceInquiry> device_inquiry_; |
+ scoped_ptr<BluetoothMacClassicDiscoveryManager> |
+ classic_discovery_session_manager_; |
// A list of discovered device addresses. |
// This list is used to check if the same device is discovered twice during |
@@ -150,6 +129,48 @@ class BluetoothAdapterMac : public BluetoothAdapter { |
DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); |
}; |
+// Class used by BluetoothAdapterMac to manage a classic discovery session. |
+// This class makes sure that a device inquiry is being performed as long as |
+// discovery has been requested by the adapter. Instances are created and owned |
+// by BluetoothAdapterMac and should not be created by others. |
+class BluetoothMacClassicDiscoveryManager { |
keybuk
2014/06/09 17:57:39
I dislike having multiple classes in a header like
|
+ public: |
+ BluetoothMacClassicDiscoveryManager(BluetoothAdapterMac* adapter); |
+ ~BluetoothMacClassicDiscoveryManager(); |
+ |
+ // Returns true, if discovery is currently being performed. |
+ bool IsDiscovering() const; |
+ |
+ // Initiates a discovery session. Returns true on success, or if discovery |
+ // is already running. |
+ bool StartDiscovery(); |
+ bool StopDiscovery(); |
+ |
+ // Called by BluetoothDeviceInquiryDelegate. |
+ void DeviceInquiryStarted(IOBluetoothDeviceInquiry* inquiry); |
+ void DeviceFound(IOBluetoothDeviceInquiry* inquiry, |
+ IOBluetoothDevice* device); |
+ void DeviceInquiryComplete(IOBluetoothDeviceInquiry* inquiry, |
+ IOReturn error, |
+ bool aborted); |
+ |
+ private: |
+ // The requested discovery state. |
+ bool should_do_discovery_; |
+ |
+ // The current inquiry state. |
+ bool inquiry_running_; |
+ |
+ // The BluetoothAdapterMac that this instance belongs to. |
+ BluetoothAdapterMac* adapter_; |
+ |
+ // Objective-C objects for running and tracking device inquiry. |
+ base::scoped_nsobject<BluetoothDeviceInquiryDelegate> inquiry_delegate_; |
+ base::scoped_nsobject<IOBluetoothDeviceInquiry> inquiry_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(BluetoothMacClassicDiscoveryManager); |
+}; |
+ |
} // namespace device |
#endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ |