Roll src/third_party/WebKit 7bf0c31:94af568 (svn 202004:202005)
[chromium-blink-merge.git] / device / bluetooth / bluetooth_low_energy_discovery_manager_mac.h
blobcef82b5b4633e581dc6c211819bef96126c5b07d
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 namespace device {
20 // This class will scan for Bluetooth LE device on Mac.
21 class BluetoothLowEnergyDiscoveryManagerMac {
22 public:
23 // Interface for being notified of events during a device discovery session.
24 class Observer {
25 public:
26 // Called when |this| manager has found a device or an update on a device.
27 virtual void LowEnergyDeviceUpdated(CBPeripheral* peripheral,
28 NSDictionary* advertisementData,
29 int rssi) = 0;
31 protected:
32 virtual ~Observer() {}
35 virtual ~BluetoothLowEnergyDiscoveryManagerMac();
37 // Returns true, if discovery is currently being performed.
38 virtual bool IsDiscovering() const;
40 // Initiates a discovery session.
41 // BluetoothLowEnergyDeviceMac objects discovered within a previous
42 // discovery session will be invalid.
43 virtual void StartDiscovery(BluetoothDevice::UUIDList services_uuids);
45 // Stops a discovery session.
46 virtual void StopDiscovery();
48 // Returns a new BluetoothLowEnergyDiscoveryManagerMac.
49 static BluetoothLowEnergyDiscoveryManagerMac* Create(Observer* observer);
51 virtual void SetCentralManager(CBCentralManager* central_manager);
53 protected:
54 // Called when a discovery or an update of a BLE device occurred.
55 virtual void DiscoveredPeripheral(CBPeripheral* peripheral,
56 NSDictionary* advertisementData,
57 int rssi);
59 // The device discovery can really be started when Bluetooth is powered on.
60 // The method TryStartDiscovery() is called when it's a good time to try to
61 // start the BLE device discovery. It will check if the discovery session has
62 // been started and if the Bluetooth is powered and then really start the
63 // CoreBluetooth BLE device discovery.
64 virtual void TryStartDiscovery();
66 private:
67 explicit BluetoothLowEnergyDiscoveryManagerMac(Observer* observer);
69 friend class BluetoothAdapterMacTest;
70 friend class BluetoothLowEnergyCentralManagerBridge;
72 // Observer interested in notifications from us.
73 Observer* observer_;
75 // Underlying CoreBluetooth central manager, owned by |observer_|.
76 CBCentralManager* central_manager_ = nil;
78 // Discovery has been initiated by calling the API StartDiscovery().
79 bool discovering_;
81 // A discovery has been initiated but has not started yet because it's
82 // waiting for Bluetooth to turn on.
83 bool pending_;
85 // List of service UUIDs to scan.
86 BluetoothDevice::UUIDList services_uuids_;
88 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDiscoveryManagerMac);
91 } // namespace device
93 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_