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

Side by Side Diff: ios/chrome/common/physical_web/physical_web_scanner.mm

Issue 2066493007: Updates PhysicalWebScanner to use the new CBManagerState enum. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #import "ios/chrome/common/physical_web/physical_web_scanner.h" 5 #import "ios/chrome/common/physical_web/physical_web_scanner.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #import <CoreBluetooth/CoreBluetooth.h> 10 #import <CoreBluetooth/CoreBluetooth.h>
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 centralManager_.reset(); 107 centralManager_.reset();
108 [super dealloc]; 108 [super dealloc];
109 } 109 }
110 110
111 - (void)start { 111 - (void)start {
112 [self stop]; 112 [self stop];
113 [finalUrls_ removeAllObjects]; 113 [finalUrls_ removeAllObjects];
114 [devicesUrls_ removeAllObjects]; 114 [devicesUrls_ removeAllObjects];
115 [devices_ removeAllObjects]; 115 [devices_ removeAllObjects];
116 started_ = YES; 116 started_ = YES;
117 if ([centralManager_ state] == CBCentralManagerStatePoweredOn) 117 if ([self bluetoothEnabled])
118 [self reallyStart]; 118 [self reallyStart];
119 else 119 else
120 pendingStart_ = YES; 120 pendingStart_ = YES;
121 } 121 }
122 122
123 - (void)stop { 123 - (void)stop {
124 if (!started_) 124 if (!started_)
125 return; 125 return;
126 for (PhysicalWebRequest* request in pendingRequests_.get()) { 126 for (PhysicalWebRequest* request in pendingRequests_.get()) {
127 [request cancel]; 127 [request cancel];
128 } 128 }
129 [pendingRequests_ removeAllObjects]; 129 [pendingRequests_ removeAllObjects];
130 if (!pendingStart_ && 130 if (!pendingStart_ && [self bluetoothEnabled]) {
131 [centralManager_ state] == CBCentralManagerStatePoweredOn) {
132 [centralManager_ stopScan]; 131 [centralManager_ stopScan];
133 } 132 }
134 pendingStart_ = NO; 133 pendingStart_ = NO;
135 started_ = NO; 134 started_ = NO;
136 } 135 }
137 136
138 - (NSArray*)devices { 137 - (NSArray*)devices {
139 return [devices_ sortedArrayUsingComparator:^(id obj1, id obj2) { 138 return [devices_ sortedArrayUsingComparator:^(id obj1, id obj2) {
140 PhysicalWebDevice* device1 = obj1; 139 PhysicalWebDevice* device1 = obj1;
141 PhysicalWebDevice* device2 = obj2; 140 PhysicalWebDevice* device2 = obj2;
(...skipping 21 matching lines...) Expand all
163 [self requestMetadataForDevice:device]; 162 [self requestMetadataForDevice:device];
164 } 163 }
165 [unresolvedDevices_ removeAllObjects]; 164 [unresolvedDevices_ removeAllObjects];
166 } 165 }
167 166
168 - (int)unresolvedBeaconsCount { 167 - (int)unresolvedBeaconsCount {
169 return [unresolvedDevices_ count]; 168 return [unresolvedDevices_ count];
170 } 169 }
171 170
172 - (BOOL)bluetoothEnabled { 171 - (BOOL)bluetoothEnabled {
172 // TODO(crbug.com/619982): The CBManager base class appears to still be in
173 // flux. Unwind this #ifdef once the APIs settle.
174 #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
175 return [centralManager_ state] == CBManagerStatePoweredOn;
176 #else
173 return [centralManager_ state] == CBCentralManagerStatePoweredOn; 177 return [centralManager_ state] == CBCentralManagerStatePoweredOn;
178 #endif
174 } 179 }
175 180
176 - (void)reallyStart { 181 - (void)reallyStart {
177 pendingStart_ = NO; 182 pendingStart_ = NO;
178 NSArray* serviceUUIDs = @[ 183 NSArray* serviceUUIDs = @[
179 [CBUUID UUIDWithString:kUriBeaconServiceUUID], 184 [CBUUID UUIDWithString:kUriBeaconServiceUUID],
180 [CBUUID UUIDWithString:kEddystoneBeaconServiceUUID] 185 [CBUUID UUIDWithString:kEddystoneBeaconServiceUUID]
181 ]; 186 ];
182 [centralManager_ scanForPeripheralsWithServices:serviceUUIDs options:nil]; 187 [centralManager_ scanForPeripheralsWithServices:serviceUUIDs options:nil];
183 } 188 }
184 189
185 #pragma mark - 190 #pragma mark -
186 #pragma mark CBCentralManagerDelegate methods 191 #pragma mark CBCentralManagerDelegate methods
187 192
188 - (void)centralManagerDidUpdateState:(CBCentralManager*)central { 193 - (void)centralManagerDidUpdateState:(CBCentralManager*)central {
189 if ([centralManager_ state] == CBCentralManagerStatePoweredOn) { 194 if ([self bluetoothEnabled]) {
190 if (pendingStart_) 195 if (pendingStart_)
191 [self reallyStart]; 196 [self reallyStart];
192 } else { 197 } else {
193 if (started_ && !pendingStart_) { 198 if (started_ && !pendingStart_) {
194 pendingStart_ = YES; 199 pendingStart_ = YES;
195 [centralManager_ stopScan]; 200 [centralManager_ stopScan];
196 } 201 }
197 } 202 }
198 [delegate_ scannerBluetoothStatusUpdated:self]; 203 [delegate_ scannerBluetoothStatusUpdated:self];
199 } 204 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 [strongSelf.get()->devices_ addObject:device]; 321 [strongSelf.get()->devices_ addObject:device];
317 [strongSelf.get()->delegate_ scannerUpdatedDevices:weakSelf]; 322 [strongSelf.get()->delegate_ scannerUpdatedDevices:weakSelf];
318 [strongSelf.get()->finalUrls_ addObject:[device url]]; 323 [strongSelf.get()->finalUrls_ addObject:[device url]];
319 } 324 }
320 } 325 }
321 [strongSelf.get()->pendingRequests_ removeObject:strongRequest]; 326 [strongSelf.get()->pendingRequests_ removeObject:strongRequest];
322 }]; 327 }];
323 } 328 }
324 329
325 @end 330 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698