Chromium Code Reviews| Index: device/bluetooth/test/mock_bluetooth_central_manager_mac.mm |
| diff --git a/device/bluetooth/test/mock_bluetooth_central_manager_mac.mm b/device/bluetooth/test/mock_bluetooth_central_manager_mac.mm |
| index fbb0dff41e75d315a5044a6e61dde508fe7382fd..703c6f3ec1783c5f24e4fefdb3269215929a7985 100644 |
| --- a/device/bluetooth/test/mock_bluetooth_central_manager_mac.mm |
| +++ b/device/bluetooth/test/mock_bluetooth_central_manager_mac.mm |
| @@ -4,10 +4,15 @@ |
| #import "device/bluetooth/test/mock_bluetooth_central_manager_mac.h" |
| +#import "base/mac/scoped_nsobject.h" |
| #import "device/bluetooth/test/bluetooth_test_mac.h" |
| #import "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" |
| -@implementation MockCentralManager |
| +using base::scoped_nsobject; |
| + |
| +@implementation MockCentralManager { |
| + scoped_nsobject<NSMutableDictionary> _connectedMockPeripheralPerServiceUUID; |
| +} |
| @synthesize scanForPeripheralsCallCount = _scanForPeripheralsCallCount; |
| @synthesize stopScanCallCount = _stopScanCallCount; |
| @@ -15,6 +20,15 @@ |
| @synthesize state = _state; |
| @synthesize bluetoothTestMac = _bluetoothTestMac; |
| +- (instancetype)init { |
| + self = [super init]; |
| + if (self) { |
| + _connectedMockPeripheralPerServiceUUID.reset( |
| + [[NSMutableDictionary alloc] init]); |
| + } |
| + return self; |
| +} |
| + |
| - (BOOL)isKindOfClass:(Class)aClass { |
| if (aClass == [CBCentralManager class] || |
| [aClass isSubclassOfClass:[CBCentralManager class]]) { |
| @@ -53,4 +67,28 @@ |
| } |
| } |
| +- (NSArray*)retrieveConnectedPeripheralsWithServices:(NSArray*)services { |
|
ortuno
2016/10/31 04:30:51
Save the services used in this function. That way
jlebel
2016/11/07 01:43:18
Done.
|
| + NSMutableArray* connectedPeripherals = [[NSMutableArray alloc] init]; |
| + for (CBUUID* uuid in services) { |
| + NSSet* peripheralSet = |
| + [_connectedMockPeripheralPerServiceUUID.get() objectForKey:uuid]; |
| + [connectedPeripherals addObjectsFromArray:peripheralSet.allObjects]; |
| + } |
| + return connectedPeripherals; |
| +} |
| + |
| +- (void)setConnectedMockPeripheral:(CBPeripheral*)peripheral |
| + withServiceUUIDs:(NSSet*)serviceUUIDs { |
| + for (CBUUID* uuid in serviceUUIDs) { |
| + NSMutableSet* peripheralSet = |
| + [_connectedMockPeripheralPerServiceUUID.get() objectForKey:uuid]; |
| + if (!peripheralSet) { |
| + peripheralSet = [NSMutableSet set]; |
| + [_connectedMockPeripheralPerServiceUUID.get() setObject:peripheralSet |
| + forKey:uuid]; |
| + } |
| + [peripheralSet addObject:peripheral]; |
| + } |
| +} |
| + |
| @end |