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

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

Issue 2339253002: bluetooth: mac: add connected LE devices to chooser (Closed)
Patch Set: Adding BluetoothAdapter::RetrievedConnectedPeripherals() and the implementation in BluetoothAdapter… Created 4 years, 2 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 #include "device/bluetooth/bluetooth_low_energy_discovery_manager_mac.h" 5 #include "device/bluetooth/bluetooth_low_energy_discovery_manager_mac.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/mac/mac_util.h" 9 #include "base/mac/mac_util.h"
10 #include "base/mac/sdk_forward_declarations.h" 10 #include "base/mac/sdk_forward_declarations.h"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "device/bluetooth/bluetooth_adapter_mac.h" 12 #include "device/bluetooth/bluetooth_adapter_mac.h"
13 #include "device/bluetooth/bluetooth_low_energy_device_mac.h" 13 #include "device/bluetooth/bluetooth_low_energy_device_mac.h"
14 14
15 namespace device { 15 namespace device {
16 16
17 BluetoothLowEnergyDiscoveryManagerMac:: 17 BluetoothLowEnergyDiscoveryManagerMac::
18 ~BluetoothLowEnergyDiscoveryManagerMac() { 18 ~BluetoothLowEnergyDiscoveryManagerMac() {
19 } 19 }
20 20
21 bool BluetoothLowEnergyDiscoveryManagerMac::IsDiscovering() const { 21 bool BluetoothLowEnergyDiscoveryManagerMac::IsDiscovering() const {
22 return discovering_; 22 return discovering_;
23 } 23 }
24 24
25 void BluetoothLowEnergyDiscoveryManagerMac::StartDiscovery( 25 void BluetoothLowEnergyDiscoveryManagerMac::StartDiscovery(
26 BluetoothDevice::UUIDList services_uuids) { 26 NSArray* services_uuids) {
27 discovering_ = true; 27 discovering_ = true;
28 pending_ = true; 28 pending_ = true;
29 services_uuids_ = services_uuids; 29 services_uuids_.reset(services_uuids, base::scoped_policy::RETAIN);
30 TryStartDiscovery(); 30 TryStartDiscovery();
31 } 31 }
32 32
33 void BluetoothLowEnergyDiscoveryManagerMac::TryStartDiscovery() { 33 void BluetoothLowEnergyDiscoveryManagerMac::TryStartDiscovery() {
34 if (!discovering_) { 34 if (!discovering_) {
35 VLOG(1) << "TryStartDiscovery !discovering_"; 35 VLOG(1) << "TryStartDiscovery !discovering_";
36 return; 36 return;
37 } 37 }
38 38
39 if (!pending_) { 39 if (!pending_) {
40 VLOG(1) << "TryStartDiscovery !pending_"; 40 VLOG(1) << "TryStartDiscovery !pending_";
41 return; 41 return;
42 } 42 }
43 43
44 if (!central_manager_) { 44 if (!central_manager_) {
45 VLOG(1) << "TryStartDiscovery !central_manager_"; 45 VLOG(1) << "TryStartDiscovery !central_manager_";
46 return; 46 return;
47 } 47 }
48 48
49 if ([central_manager_ state] != CBCentralManagerStatePoweredOn) { 49 if ([central_manager_ state] != CBCentralManagerStatePoweredOn) {
50 VLOG(1) << "TryStartDiscovery != CBCentralManagerStatePoweredOn"; 50 VLOG(1) << "TryStartDiscovery != CBCentralManagerStatePoweredOn";
51 return; 51 return;
52 } 52 }
53 53
54 // Converts the services UUIDs to a CoreBluetooth data structure.
55 NSMutableArray* services = nil;
56 if (!services_uuids_.empty()) {
57 services = [NSMutableArray array];
58 for (auto& service_uuid : services_uuids_) {
59 NSString* uuidString =
60 base::SysUTF8ToNSString(service_uuid.canonical_value().c_str());
61 CBUUID* uuid = [CBUUID UUIDWithString:uuidString];
62 [services addObject:uuid];
63 }
64 };
65
66 VLOG(1) << "TryStartDiscovery scanForPeripheralsWithServices"; 54 VLOG(1) << "TryStartDiscovery scanForPeripheralsWithServices";
67 // Start a scan with the Allow Duplicates option so that we get notified 55 // Start a scan with the Allow Duplicates option so that we get notified
68 // of each new Advertisement Packet. This allows us to provide up to date 56 // of each new Advertisement Packet. This allows us to provide up to date
69 // values for RSSI, Advertised Services, Advertised Data, etc. 57 // values for RSSI, Advertised Services, Advertised Data, etc.
70 [central_manager_ 58 [central_manager_
71 scanForPeripheralsWithServices:services 59 scanForPeripheralsWithServices:services_uuids_
ortuno 2016/09/28 23:15:52 This seems unrelated. Please do in another patch.
jlebel 2016/10/05 14:09:41 Done.
72 options:@{ 60 options:@{
73 CBCentralManagerScanOptionAllowDuplicatesKey : 61 CBCentralManagerScanOptionAllowDuplicatesKey :
74 @YES 62 @YES
75 }]; 63 }];
76 pending_ = false; 64 pending_ = false;
77 } 65 }
78 66
79 void BluetoothLowEnergyDiscoveryManagerMac::StopDiscovery() { 67 void BluetoothLowEnergyDiscoveryManagerMac::StopDiscovery() {
80 VLOG(1) << "StopDiscovery"; 68 VLOG(1) << "StopDiscovery";
81 if (discovering_ && !pending_) { 69 if (discovering_ && !pending_) {
(...skipping 21 matching lines...) Expand all
103 } 91 }
104 92
105 BluetoothLowEnergyDiscoveryManagerMac::BluetoothLowEnergyDiscoveryManagerMac( 93 BluetoothLowEnergyDiscoveryManagerMac::BluetoothLowEnergyDiscoveryManagerMac(
106 Observer* observer) 94 Observer* observer)
107 : observer_(observer) { 95 : observer_(observer) {
108 DCHECK(BluetoothAdapterMac::IsLowEnergyAvailable()); 96 DCHECK(BluetoothAdapterMac::IsLowEnergyAvailable());
109 discovering_ = false; 97 discovering_ = false;
110 } 98 }
111 99
112 } // namespace device 100 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698