Chromium Code Reviews| Index: device/bluetooth/bluetooth_device_mac.mm |
| diff --git a/device/bluetooth/bluetooth_device_mac.mm b/device/bluetooth/bluetooth_device_mac.mm |
| index d0a676203e29454e61b43c1d73cbdee12ff66462..d7ddb54d524e7d8047e41576aec7b620305e5dd9 100644 |
| --- a/device/bluetooth/bluetooth_device_mac.mm |
| +++ b/device/bluetooth/bluetooth_device_mac.mm |
| @@ -4,23 +4,50 @@ |
| #include "device/bluetooth/bluetooth_device_mac.h" |
| +#include <IOBluetooth/Bluetooth.h> |
| +#import <IOBluetooth/objc/IOBluetoothDevice.h> |
| +#import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h> |
| + |
| #include <string> |
| #include "base/basictypes.h" |
| +#include "base/hash.h" |
| +#include "base/stringprintf.h" |
| +#include "base/strings/sys_string_conversions.h" |
| #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" |
| #include "device/bluetooth/bluetooth_service_record_mac.h" |
| +// Replicate specific 10.7 SDK declarations for building with prior SDKs. |
| +#if !defined(MAC_OS_X_VERSION_10_7) || \ |
| +MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
| + |
| +@interface IOBluetoothDevice (LionSDKDeclarations) |
| +- (NSString*)addressString; |
| +- (NSString*)name; |
| +- (unsigned int)classOfDevice; |
| +- (NSArray*)services; |
| +@end |
| + |
| +#endif // MAC_OS_X_VERSION_10_7 |
| + |
| namespace device { |
| -BluetoothDeviceMac::BluetoothDeviceMac() |
| - : BluetoothDevice() { |
| +BluetoothDeviceMac::BluetoothDeviceMac(const IOBluetoothDevice* device) |
| + : BluetoothDevice(), |
| + device_fingerprint_(ComputeDeviceFingerprint(device)) { |
| + name_ = base::SysNSStringToUTF8([device name]); |
| + address_ = base::SysNSStringToUTF8([device addressString]); |
| + bluetooth_class_ = [device classOfDevice]; |
| + connected_ = [device isConnected]; |
| + bonded_ = [device isPaired]; |
| + visible_ = true; |
| } |
| BluetoothDeviceMac::~BluetoothDeviceMac() { |
| } |
| bool BluetoothDeviceMac::IsPaired() const { |
| - return false; |
| + return bonded_; |
| } |
| const BluetoothDevice::ServiceList& BluetoothDeviceMac::GetServices() const { |
| @@ -107,4 +134,25 @@ void BluetoothDeviceMac::ClearOutOfBandPairingData( |
| NOTIMPLEMENTED(); |
| } |
| +// static |
| +uint32 BluetoothDeviceMac::ComputeDeviceFingerprint( |
| + const IOBluetoothDevice* device) { |
| + std::string device_string = base::StringPrintf("%s|%s|%u|%d|%d", |
| + base::SysNSStringToUTF8([device name]).c_str(), |
| + base::SysNSStringToUTF8([device addressString]).c_str(), |
| + [device classOfDevice], |
| + [device isConnected], |
| + [device isPaired]); |
| + |
| + for (IOBluetoothSDPServiceRecord* record in [device services]) { |
| + base::StringAppendF( |
| + &device_string, |
| + "|%s|%u", |
| + base::SysNSStringToUTF8([record getServiceName]).c_str(), |
| + [[record attributes] count]); |
|
Avi (use Gerrit)
2013/03/26 19:15:51
This breaks the 64-bit build. NSUInteger shouldn't
|
| + } |
| + |
| + return base::Hash(device_string); |
| +} |
| + |
| } // namespace device |