| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_LOW_ENERGY_DEVICE_MAC_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ |
| 7 | 7 |
| 8 #if defined(OS_IOS) | 8 #if defined(OS_IOS) |
| 9 #import <CoreBluetooth/CoreBluetooth.h> | 9 #import <CoreBluetooth/CoreBluetooth.h> |
| 10 #else | 10 #else // !defined(OS_IOS) |
| 11 #import <IOBluetooth/IOBluetooth.h> | 11 #import <IOBluetooth/IOBluetooth.h> |
| 12 #endif | 12 #endif // defined(OS_IOS) |
| 13 | 13 |
| 14 #include "base/mac/scoped_nsobject.h" | 14 #include "base/mac/scoped_nsobject.h" |
| 15 #include "base/mac/sdk_forward_declarations.h" | 15 #include "base/mac/sdk_forward_declarations.h" |
| 16 #include "crypto/sha2.h" |
| 16 #include "device/bluetooth/bluetooth_device_mac.h" | 17 #include "device/bluetooth/bluetooth_device_mac.h" |
| 17 | 18 |
| 18 namespace device { | 19 namespace device { |
| 19 | 20 |
| 20 class BluetoothLowEnergyDiscoverManagerMac; | 21 class BluetoothLowEnergyDiscoverManagerMac; |
| 21 | 22 |
| 22 class BluetoothLowEnergyDeviceMac : public BluetoothDeviceMac { | 23 class DEVICE_BLUETOOTH_EXPORT BluetoothLowEnergyDeviceMac |
| 24 : public BluetoothDeviceMac { |
| 23 public: | 25 public: |
| 24 BluetoothLowEnergyDeviceMac(CBPeripheral* peripheral, | 26 BluetoothLowEnergyDeviceMac(CBPeripheral* peripheral, |
| 25 NSDictionary* advertisementData, | 27 NSDictionary* advertisementData, |
| 26 int rssi); | 28 int rssi); |
| 27 ~BluetoothLowEnergyDeviceMac() override; | 29 ~BluetoothLowEnergyDeviceMac() override; |
| 28 | 30 |
| 29 int GetRSSI() const; | 31 int GetRSSI() const; |
| 30 | 32 |
| 31 // BluetoothDevice overrides. | 33 // BluetoothDevice overrides. |
| 32 std::string GetIdentifier() const override; | 34 std::string GetIdentifier() const override; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 // BluetoothDevice override. | 79 // BluetoothDevice override. |
| 78 std::string GetDeviceName() const override; | 80 std::string GetDeviceName() const override; |
| 79 | 81 |
| 80 // Updates information about the device. | 82 // Updates information about the device. |
| 81 virtual void Update(CBPeripheral* peripheral, | 83 virtual void Update(CBPeripheral* peripheral, |
| 82 NSDictionary* advertisementData, | 84 NSDictionary* advertisementData, |
| 83 int rssi); | 85 int rssi); |
| 84 | 86 |
| 85 static std::string GetPeripheralIdentifier(CBPeripheral* peripheral); | 87 static std::string GetPeripheralIdentifier(CBPeripheral* peripheral); |
| 86 | 88 |
| 89 // Hashes and truncates the peripheral identifier to deterministically |
| 90 // construct an address. The use of fake addresses is a temporary fix before |
| 91 // we switch to using bluetooth identifiers throughout Chrome. |
| 92 // http://crbug.com/507824 |
| 93 static std::string GetPeripheralHashAddress(CBPeripheral* peripheral); |
| 94 |
| 87 private: | 95 private: |
| 88 friend class BluetoothAdapterMac; | 96 friend class BluetoothAdapterMac; |
| 97 friend class BluetoothAdapterMacTest; |
| 98 |
| 99 // Equivalent to [peripheral_ state]. Allows compilation on OS X 10.6. |
| 100 CBPeripheralState GetPeripheralState() const; |
| 89 | 101 |
| 90 // CoreBluetooth data structure. | 102 // CoreBluetooth data structure. |
| 91 base::scoped_nsobject<CBPeripheral> peripheral_; | 103 base::scoped_nsobject<CBPeripheral> peripheral_; |
| 92 | 104 |
| 93 // RSSI value. | 105 // RSSI value. |
| 94 int rssi_; | 106 int rssi_; |
| 95 | 107 |
| 96 // Whether the device is connectable. | 108 // Whether the device is connectable. |
| 97 bool connectable_; | 109 bool connectable_; |
| 98 | 110 |
| 111 // The peripheral's identifier, as returned by [CBPeripheral identifier]. |
| 112 std::string identifier_; |
| 113 |
| 114 // A local address for the device created by hashing the peripheral |
| 115 // identifier. |
| 116 std::string hash_address_; |
| 117 |
| 99 // Stores the time of the most recent call to Update(). | 118 // Stores the time of the most recent call to Update(). |
| 100 base::scoped_nsobject<NSDate> last_update_time_; | 119 base::scoped_nsobject<NSDate> last_update_time_; |
| 101 | 120 |
| 102 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac); | 121 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac); |
| 103 }; | 122 }; |
| 104 | 123 |
| 105 } // namespace device | 124 } // namespace device |
| 106 | 125 |
| 107 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ | 126 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ |
| OLD | NEW |