Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: device/bluetooth/bluetooth_low_energy_discovery_manager_mac.h

Issue 1226133006: Move CBCentralManager from the Discovery Manager to Adapter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@adddevs
Patch Set: comment edit Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #import <IOBluetooth/IOBluetooth.h> 11 #import <IOBluetooth/IOBluetooth.h>
12 #endif 12 #endif
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 "device/bluetooth/bluetooth_device.h" 16 #include "device/bluetooth/bluetooth_device.h"
17 17
18 @class BluetoothLowEnergyDiscoveryManagerMacBridge;
19
20 namespace device { 18 namespace device {
21 19
22 class BluetoothLowEnergyDeviceMac;
23 class BluetoothLowEnergyDiscoveryManagerMacDelegate;
24
25 // This class will scan for Bluetooth LE device on Mac. 20 // This class will scan for Bluetooth LE device on Mac.
26 class BluetoothLowEnergyDiscoveryManagerMac { 21 class BluetoothLowEnergyDiscoveryManagerMac {
27 public: 22 public:
28 // Interface for being notified of events during a device discovery session. 23 // Interface for being notified of events during a device discovery session.
29 class Observer { 24 class Observer {
30 public: 25 public:
31 // Called when |this| manager has found a device or an update on a device. 26 // Called when |this| manager has found a device or an update on a device.
32 virtual void LowEnergyDeviceUpdated(CBPeripheral* peripheral, 27 virtual void LowEnergyDeviceUpdated(CBPeripheral* peripheral,
33 NSDictionary* advertisementData, 28 NSDictionary* advertisementData,
34 int rssi) = 0; 29 int rssi) = 0;
(...skipping 11 matching lines...) Expand all
46 // BluetoothLowEnergyDeviceMac objects discovered within a previous 41 // BluetoothLowEnergyDeviceMac objects discovered within a previous
47 // discovery session will be invalid. 42 // discovery session will be invalid.
48 virtual void StartDiscovery(BluetoothDevice::UUIDList services_uuids); 43 virtual void StartDiscovery(BluetoothDevice::UUIDList services_uuids);
49 44
50 // Stops a discovery session. 45 // Stops a discovery session.
51 virtual void StopDiscovery(); 46 virtual void StopDiscovery();
52 47
53 // Returns a new BluetoothLowEnergyDiscoveryManagerMac. 48 // Returns a new BluetoothLowEnergyDiscoveryManagerMac.
54 static BluetoothLowEnergyDiscoveryManagerMac* Create(Observer* observer); 49 static BluetoothLowEnergyDiscoveryManagerMac* Create(Observer* observer);
55 50
51 virtual void SetCentralManager(CBCentralManager* central_manager);
52
56 protected: 53 protected:
57 // Called when a discovery or an update of a BLE device occurred. 54 // Called when a discovery or an update of a BLE device occurred.
58 virtual void DiscoveredPeripheral(CBPeripheral* peripheral, 55 virtual void DiscoveredPeripheral(CBPeripheral* peripheral,
59 NSDictionary* advertisementData, 56 NSDictionary* advertisementData,
60 int rssi); 57 int rssi);
61 58
62 // The device discovery can really be started when Bluetooth is powered on. 59 // 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 60 // 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 61 // 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 62 // been started and if the Bluetooth is powered and then really start the
66 // CoreBluetooth BLE device discovery. 63 // CoreBluetooth BLE device discovery.
67 virtual void TryStartDiscovery(); 64 virtual void TryStartDiscovery();
68 65
69 private: 66 private:
70 explicit BluetoothLowEnergyDiscoveryManagerMac(Observer* observer); 67 explicit BluetoothLowEnergyDiscoveryManagerMac(Observer* observer);
71 68
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);
76
77 friend class BluetoothLowEnergyDiscoveryManagerMacDelegate;
78 friend class BluetoothAdapterMacTest; 69 friend class BluetoothAdapterMacTest;
70 friend class BluetoothLowEnergyCentralManagerBridge;
79 71
80 // Observer interested in notifications from us. 72 // Observer interested in notifications from us.
81 Observer* observer_; 73 Observer* observer_;
82 74
83 // Underlying CoreBluetooth central manager. 75 // Underlying CoreBluetooth central manager, owned by |observer_|.
84 base::scoped_nsobject<CBCentralManager> manager_; 76 CBCentralManager* central_manager_ = nil;
85 77
86 // Discovery has been initiated by calling the API StartDiscovery(). 78 // Discovery has been initiated by calling the API StartDiscovery().
87 bool discovering_; 79 bool discovering_;
88 80
89 // A discovery has been initiated but has not started yet because it's 81 // A discovery has been initiated but has not started yet because it's
90 // waiting for Bluetooth to turn on. 82 // waiting for Bluetooth to turn on.
91 bool pending_; 83 bool pending_;
92 84
93 // Delegate of the central manager.
94 base::scoped_nsobject<BluetoothLowEnergyDiscoveryManagerMacBridge> bridge_;
95
96 // List of service UUIDs to scan. 85 // List of service UUIDs to scan.
97 BluetoothDevice::UUIDList services_uuids_; 86 BluetoothDevice::UUIDList services_uuids_;
98 87
99 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDiscoveryManagerMac); 88 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDiscoveryManagerMac);
100 }; 89 };
101 90
102 } // namespace device 91 } // namespace device
103 92
104 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_ 93 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698