| OLD | NEW |
| 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/test/mock_bluetooth_cbperipheral_mac.h" | 5 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "device/bluetooth/test/bluetooth_test_mac.h" | 9 #include "device/bluetooth/test/bluetooth_test_mac.h" |
| 10 #include "device/bluetooth/test/mock_bluetooth_cbservice_mac.h" | 10 #include "device/bluetooth/test/mock_bluetooth_cbservice_mac.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 return [self initWithIdentifier:identifier name:nil]; | 38 return [self initWithIdentifier:identifier name:nil]; |
| 39 } | 39 } |
| 40 | 40 |
| 41 - (instancetype)initWithIdentifier:(NSUUID*)identifier { | 41 - (instancetype)initWithIdentifier:(NSUUID*)identifier { |
| 42 return [self initWithIdentifier:identifier name:nil]; | 42 return [self initWithIdentifier:identifier name:nil]; |
| 43 } | 43 } |
| 44 | 44 |
| 45 - (instancetype)initWithIdentifier:(NSUUID*)identifier name:(NSString*)name { | 45 - (instancetype)initWithIdentifier:(NSUUID*)identifier name:(NSString*)name { |
| 46 self = [super init]; | 46 self = [super init]; |
| 47 if (self) { | 47 if (self) { |
| 48 _services.reset([[NSMutableArray alloc] init]); | |
| 49 _identifier.reset([identifier retain]); | 48 _identifier.reset([identifier retain]); |
| 50 if (name) { | 49 if (name) { |
| 51 _name.reset([name retain]); | 50 _name.reset([name retain]); |
| 52 } else { | 51 } else { |
| 53 _name.reset( | 52 _name.reset( |
| 54 [@(device::BluetoothTestBase::kTestDeviceName.c_str()) retain]); | 53 [@(device::BluetoothTestBase::kTestDeviceName.c_str()) retain]); |
| 55 } | 54 } |
| 56 _state = CBPeripheralStateDisconnected; | 55 _state = CBPeripheralStateDisconnected; |
| 57 } | 56 } |
| 58 return self; | 57 return self; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 69 - (BOOL)isMemberOfClass:(Class)aClass { | 68 - (BOOL)isMemberOfClass:(Class)aClass { |
| 70 if (aClass == [CBPeripheral class] || | 69 if (aClass == [CBPeripheral class] || |
| 71 [aClass isSubclassOfClass:[CBPeripheral class]]) { | 70 [aClass isSubclassOfClass:[CBPeripheral class]]) { |
| 72 return YES; | 71 return YES; |
| 73 } | 72 } |
| 74 return [super isKindOfClass:aClass]; | 73 return [super isKindOfClass:aClass]; |
| 75 } | 74 } |
| 76 | 75 |
| 77 - (void)setState:(CBPeripheralState)state { | 76 - (void)setState:(CBPeripheralState)state { |
| 78 _state = state; | 77 _state = state; |
| 78 if (_state == CBPeripheralStateDisconnected) { |
| 79 _services = nil; |
| 80 } |
| 79 } | 81 } |
| 80 | 82 |
| 81 - (void)discoverServices:(NSArray*)serviceUUIDs { | 83 - (void)discoverServices:(NSArray*)serviceUUIDs { |
| 82 if (_bluetoothTestMac) { | 84 if (_bluetoothTestMac) { |
| 83 _bluetoothTestMac->OnFakeBluetoothServiceDiscovery(); | 85 _bluetoothTestMac->OnFakeBluetoothServiceDiscovery(); |
| 84 } | 86 } |
| 85 } | 87 } |
| 86 | 88 |
| 87 - (void)removeAllServices { | 89 - (void)removeAllServices { |
| 88 [_services.get() removeAllObjects]; | 90 [_services.get() removeAllObjects]; |
| 89 } | 91 } |
| 90 | 92 |
| 91 - (void)addServices:(NSArray*)services { | 93 - (void)addServices:(NSArray*)services { |
| 94 if (!_services.get()) { |
| 95 _services.reset([[NSMutableArray alloc] init]); |
| 96 } |
| 92 for (CBUUID* uuid in services) { | 97 for (CBUUID* uuid in services) { |
| 93 base::scoped_nsobject<MockCBService> service( | 98 base::scoped_nsobject<MockCBService> service( |
| 94 [[MockCBService alloc] initWithCBUUID:uuid primary:YES]); | 99 [[MockCBService alloc] initWithCBUUID:uuid primary:YES]); |
| 95 [_services.get() addObject:service.get().service]; | 100 [_services.get() addObject:service.get().service]; |
| 96 } | 101 } |
| 97 } | 102 } |
| 98 | 103 |
| 99 - (void)didDiscoverWithError:(NSError*)error { | 104 - (void)didDiscoverServicesWithError:(NSError*)error { |
| 100 [_delegate peripheral:self.peripheral didDiscoverServices:error]; | 105 [_delegate peripheral:self.peripheral didDiscoverServices:error]; |
| 101 } | 106 } |
| 102 | 107 |
| 103 - (void)removeService:(CBService*)service { | 108 - (void)removeService:(CBService*)service { |
| 104 base::scoped_nsobject<CBService> serviceToRemove(service, | 109 base::scoped_nsobject<CBService> serviceToRemove(service, |
| 105 base::scoped_policy::RETAIN); | 110 base::scoped_policy::RETAIN); |
| 106 DCHECK(serviceToRemove); | 111 DCHECK(serviceToRemove); |
| 107 [_services.get() removeObject:serviceToRemove]; | 112 [_services.get() removeObject:serviceToRemove]; |
| 108 // -[CBPeripheralDelegate peripheral:didModifyServices:] is only available | 113 // -[CBPeripheralDelegate peripheral:didModifyServices:] is only available |
| 109 // with 10.9. It is safe to call this method (even if chrome is running on | 114 // with 10.9. It is safe to call this method (even if chrome is running on |
| (...skipping 16 matching lines...) Expand all Loading... |
| 126 | 131 |
| 127 - (NSArray*)services { | 132 - (NSArray*)services { |
| 128 return _services.get(); | 133 return _services.get(); |
| 129 } | 134 } |
| 130 | 135 |
| 131 - (CBPeripheral*)peripheral { | 136 - (CBPeripheral*)peripheral { |
| 132 return ObjCCast<CBPeripheral>(self); | 137 return ObjCCast<CBPeripheral>(self); |
| 133 } | 138 } |
| 134 | 139 |
| 135 @end | 140 @end |
| OLD | NEW |