Remove chromeos==0 blacklist for test_isolation_mode.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_low_energy_discovery_manager_mac.h
blobc3f707c7fd2c15603296537cb1ae46d5cbf08703
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
3 // found in the LICENSE file.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_
8 #if defined(OS_IOS)
9 #import <CoreBluetooth/CoreBluetooth.h>
10 #else
11 #import <IOBluetooth/IOBluetooth.h>
12 #endif
14 #include "base/mac/scoped_nsobject.h"
15 #include "base/mac/sdk_forward_declarations.h"
16 #include "device/bluetooth/bluetooth_device.h"
18 @class BluetoothLowEnergyDiscoveryManagerMacBridge;
20 namespace device {
22 class BluetoothLowEnergyDeviceMac;
23 class BluetoothLowEnergyDiscoveryManagerMacDelegate;
25 // This class will scan for Bluetooth LE device on Mac.
26 class BluetoothLowEnergyDiscoveryManagerMac {
27 public:
28 // Interface for being notified of events during a device discovery session.
29 class Observer {
30 public:
31 // Called when |this| manager has found a device or an update on a device.
32 virtual void LowEnergyDeviceUpdated(CBPeripheral* peripheral,
33 NSDictionary* advertisementData,
34 int rssi) = 0;
36 protected:
37 virtual ~Observer() {}
40 virtual ~BluetoothLowEnergyDiscoveryManagerMac();
42 // Returns true, if discovery is currently being performed.
43 virtual bool IsDiscovering() const;
45 // Initiates a discovery session.
46 // BluetoothLowEnergyDeviceMac objects discovered within a previous
47 // discovery session will be invalid.
48 virtual void StartDiscovery(BluetoothDevice::UUIDList services_uuids);
50 // Stops a discovery session.
51 virtual void StopDiscovery();
53 // Returns a new BluetoothLowEnergyDiscoveryManagerMac.
54 static BluetoothLowEnergyDiscoveryManagerMac* Create(Observer* observer);
56 protected:
57 // Called when a discovery or an update of a BLE device occurred.
58 virtual void DiscoveredPeripheral(CBPeripheral* peripheral,
59 NSDictionary* advertisementData,
60 int rssi);
62 // The device discovery can really be started when Bluetooth is powered on.
63 // The method TryStartDiscovery() is called when it's a good time to try to
64 // start the BLE device discovery. It will check if the discovery session has
65 // been started and if the Bluetooth is powered and then really start the
66 // CoreBluetooth BLE device discovery.
67 virtual void TryStartDiscovery();
69 private:
70 explicit BluetoothLowEnergyDiscoveryManagerMac(Observer* observer);
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);
77 friend class BluetoothLowEnergyDiscoveryManagerMacDelegate;
78 friend class BluetoothAdapterMacTest;
80 // Observer interested in notifications from us.
81 Observer* observer_;
83 // Underlying CoreBluetooth central manager.
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.
91 base::scoped_nsobject<CBCentralManager> manager_;
93 // Discovery has been initiated by calling the API StartDiscovery().
94 bool discovering_;
96 // A discovery has been initiated but has not started yet because it's
97 // waiting for Bluetooth to turn on.
98 bool pending_;
100 // Delegate of the central manager.
101 base::scoped_nsobject<BluetoothLowEnergyDiscoveryManagerMacBridge> bridge_;
103 // List of service UUIDs to scan.
104 BluetoothDevice::UUIDList services_uuids_;
106 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDiscoveryManagerMac);
109 } // namespace device
111 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_