| 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_DISCOVERY_MANAGER_MAC_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_ | 
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_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 | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 21 | 21 | 
| 22 class BluetoothLowEnergyDeviceMac; | 22 class BluetoothLowEnergyDeviceMac; | 
| 23 class BluetoothLowEnergyDiscoveryManagerMacDelegate; | 23 class BluetoothLowEnergyDiscoveryManagerMacDelegate; | 
| 24 | 24 | 
| 25 // This class will scan for Bluetooth LE device on Mac. | 25 // This class will scan for Bluetooth LE device on Mac. | 
| 26 class BluetoothLowEnergyDiscoveryManagerMac { | 26 class BluetoothLowEnergyDiscoveryManagerMac { | 
| 27  public: | 27  public: | 
| 28   // Interface for being notified of events during a device discovery session. | 28   // Interface for being notified of events during a device discovery session. | 
| 29   class Observer { | 29   class Observer { | 
| 30    public: | 30    public: | 
| 31     // Called when |this| manager has found a device. | 31     // Called when |this| manager has found a device or an update on a device. | 
| 32     virtual void DeviceFound(BluetoothLowEnergyDeviceMac* device) = 0; | 32     virtual void LowEnergyDeviceUpdated(CBPeripheral* peripheral, | 
| 33 | 33                                         NSDictionary* advertisementData, | 
| 34     // Called when |this| manager has updated on a device. | 34                                         int rssi) = 0; | 
| 35     virtual void DeviceUpdated(BluetoothLowEnergyDeviceMac* device) = 0; |  | 
| 36 | 35 | 
| 37    protected: | 36    protected: | 
| 38     virtual ~Observer() {} | 37     virtual ~Observer() {} | 
| 39   }; | 38   }; | 
| 40 | 39 | 
| 41   virtual ~BluetoothLowEnergyDiscoveryManagerMac(); | 40   virtual ~BluetoothLowEnergyDiscoveryManagerMac(); | 
| 42 | 41 | 
| 43   // Returns true, if discovery is currently being performed. | 42   // Returns true, if discovery is currently being performed. | 
| 44   virtual bool IsDiscovering() const; | 43   virtual bool IsDiscovering() const; | 
| 45 | 44 | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 62 | 61 | 
| 63   // The device discovery can really be started when Bluetooth is powered on. | 62   // The device discovery can really be started when Bluetooth is powered on. | 
| 64   // The method TryStartDiscovery() is called when it's a good time to try to | 63   // The method TryStartDiscovery() is called when it's a good time to try to | 
| 65   // start the BLE device discovery. It will check if the discovery session has | 64   // start the BLE device discovery. It will check if the discovery session has | 
| 66   // been started and if the Bluetooth is powered and then really start the | 65   // been started and if the Bluetooth is powered and then really start the | 
| 67   // CoreBluetooth BLE device discovery. | 66   // CoreBluetooth BLE device discovery. | 
| 68   virtual void TryStartDiscovery(); | 67   virtual void TryStartDiscovery(); | 
| 69 | 68 | 
| 70  private: | 69  private: | 
| 71   explicit BluetoothLowEnergyDiscoveryManagerMac(Observer* observer); | 70   explicit BluetoothLowEnergyDiscoveryManagerMac(Observer* observer); | 
| 72   void ClearDevices(); | 71 | 
|  | 72   // Private method for testing.  Resets |manager_| to |manager| and set | 
|  | 73   // |bridge_| as its delegate.  Only for use on OSX 10.7 or later, where | 
|  | 74   // CoreBluetooth is available. | 
|  | 75   virtual void SetManagerForTesting(CBCentralManager* manager); | 
| 73 | 76 | 
| 74   friend class BluetoothLowEnergyDiscoveryManagerMacDelegate; | 77   friend class BluetoothLowEnergyDiscoveryManagerMacDelegate; | 
|  | 78   friend class BluetoothAdapterMacTest; | 
| 75 | 79 | 
| 76   // Observer interested in notifications from us. | 80   // Observer interested in notifications from us. | 
| 77   Observer* observer_; | 81   Observer* observer_; | 
| 78 | 82 | 
| 79   // Underlaying CoreBluetooth central manager. | 83   // Underlying CoreBluetooth central manager. | 
|  | 84   // | 
|  | 85   // Note: Intentionally leaked. Deallocating CBCentralManager | 
|  | 86   // results in a crash, at least when running OSX 10.9.5 on a | 
|  | 87   // mac_chromuim_rel_ng trybot. On the other hand, restricting |manager_| use | 
|  | 88   // to 10.10 and later would mean the code is unrun and untested by the current | 
|  | 89   // trybots. To work around this we call retain on |manager_| after allocation, | 
|  | 90   // so that the object is leaked. | 
| 80   base::scoped_nsobject<CBCentralManager> manager_; | 91   base::scoped_nsobject<CBCentralManager> manager_; | 
| 81 | 92 | 
| 82   // Discovery has been initiated by calling the API StartDiscovery(). | 93   // Discovery has been initiated by calling the API StartDiscovery(). | 
| 83   bool discovering_; | 94   bool discovering_; | 
| 84 | 95 | 
| 85   // A discovery has been initiated but has not started yet because it's | 96   // A discovery has been initiated but has not started yet because it's | 
| 86   // waiting for Bluetooth to turn on. | 97   // waiting for Bluetooth to turn on. | 
| 87   bool pending_; | 98   bool pending_; | 
| 88 | 99 | 
| 89   // Delegate of the central manager. | 100   // Delegate of the central manager. | 
| 90   base::scoped_nsobject<BluetoothLowEnergyDiscoveryManagerMacBridge> bridge_; | 101   base::scoped_nsobject<BluetoothLowEnergyDiscoveryManagerMacBridge> bridge_; | 
| 91 | 102 | 
| 92   // Map of the device identifiers to the discovered device. |  | 
| 93   std::map<const std::string, BluetoothLowEnergyDeviceMac*> devices_; |  | 
| 94 |  | 
| 95   // List of service UUIDs to scan. | 103   // List of service UUIDs to scan. | 
| 96   BluetoothDevice::UUIDList services_uuids_; | 104   BluetoothDevice::UUIDList services_uuids_; | 
| 97 | 105 | 
| 98   DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDiscoveryManagerMac); | 106   DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDiscoveryManagerMac); | 
| 99 }; | 107 }; | 
| 100 | 108 | 
| 101 }  // namespace device | 109 }  // namespace device | 
| 102 | 110 | 
| 103 #endif  // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_ | 111 #endif  // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_ | 
| OLD | NEW | 
|---|