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

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

Issue 2507213003: Stop providing Physical Web metadata after Bluetooth is disabled (Closed)
Patch Set: report URLs as lost when Bluetooth is disabled Created 4 years, 1 month 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 #import <CoreBluetooth/CoreBluetooth.h> 7 #import <CoreBluetooth/CoreBluetooth.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 return; 153 return;
154 for (PhysicalWebRequest* request in pendingRequests_.get()) { 154 for (PhysicalWebRequest* request in pendingRequests_.get()) {
155 [request cancel]; 155 [request cancel];
156 } 156 }
157 [pendingRequests_ removeAllObjects]; 157 [pendingRequests_ removeAllObjects];
158 if (!pendingStart_ && [self bluetoothEnabled]) { 158 if (!pendingStart_ && [self bluetoothEnabled]) {
159 [self reallyStop]; 159 [self reallyStop];
160 } 160 }
161 pendingStart_ = NO; 161 pendingStart_ = NO;
162 started_ = NO; 162 started_ = NO;
163 if (onLostDetectionEnabled_ && [devices_ count]) {
164 [delegate_ scannerUpdatedDevices:self];
165 }
163 } 166 }
164 167
165 - (NSArray*)devices { 168 - (NSArray*)devices {
169 if (![self bluetoothEnabled]) {
170 return [NSArray array];
171 }
166 return [devices_ sortedArrayUsingComparator:^(id obj1, id obj2) { 172 return [devices_ sortedArrayUsingComparator:^(id obj1, id obj2) {
167 PhysicalWebDevice* device1 = obj1; 173 PhysicalWebDevice* device1 = obj1;
168 PhysicalWebDevice* device2 = obj2; 174 PhysicalWebDevice* device2 = obj2;
169 // Sorts in ascending order. 175 // Sorts in ascending order.
170 if ([device1 rank] > [device2 rank]) { 176 if ([device1 rank] > [device2 rank]) {
171 return NSOrderedDescending; 177 return NSOrderedDescending;
172 } 178 }
173 if ([device1 rank] < [device2 rank]) { 179 if ([device1 rank] < [device2 rank]) {
174 return NSOrderedAscending; 180 return NSOrderedAscending;
175 } 181 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 [[NSTimer scheduledTimerWithTimeInterval:kUpdateIntervalSeconds 264 [[NSTimer scheduledTimerWithTimeInterval:kUpdateIntervalSeconds
259 target:self 265 target:self
260 selector:@selector(onUpdateTimeElapsed:) 266 selector:@selector(onUpdateTimeElapsed:)
261 userInfo:nil 267 userInfo:nil
262 repeats:YES] retain]); 268 repeats:YES] retain]);
263 } 269 }
264 [centralManager_ scanForPeripheralsWithServices:serviceUUIDs options:nil]; 270 [centralManager_ scanForPeripheralsWithServices:serviceUUIDs options:nil];
265 } 271 }
266 272
267 - (void)reallyStop { 273 - (void)reallyStop {
268 if (updateTimer_.get()) {
269 [updateTimer_ invalidate];
270 updateTimer_.reset();
271 }
272
273 [centralManager_ stopScan]; 274 [centralManager_ stopScan];
274 } 275 }
275 276
276 - (void)onUpdateTimeElapsed:(NSTimer*)timer { 277 - (void)onUpdateTimeElapsed:(NSTimer*)timer {
277 NSDate* now = [NSDate date]; 278 NSDate* now = [NSDate date];
278 NSMutableArray* lostDevices = [NSMutableArray array]; 279 NSMutableArray* lostDevices = [NSMutableArray array];
279 NSMutableArray* lostUnresolvedDevices = [NSMutableArray array]; 280 NSMutableArray* lostUnresolvedDevices = [NSMutableArray array];
280 NSMutableArray* lostScannedUrls = [NSMutableArray array]; 281 NSMutableArray* lostScannedUrls = [NSMutableArray array];
281 282
282 for (PhysicalWebDevice* device in devices_.get()) { 283 for (PhysicalWebDevice* device in devices_.get()) {
(...skipping 30 matching lines...) Expand all
313 [pendingRequests_ removeObjectsInArray:requestsToRemove]; 314 [pendingRequests_ removeObjectsInArray:requestsToRemove];
314 315
315 if ([lostDevices count]) { 316 if ([lostDevices count]) {
316 [delegate_ scannerUpdatedDevices:self]; 317 [delegate_ scannerUpdatedDevices:self];
317 } 318 }
318 319
319 // TODO(crbug.com/657056): Remove this workaround when radar is fixed. 320 // TODO(crbug.com/657056): Remove this workaround when radar is fixed.
320 // For unknown reasons, when scanning for longer periods (on the order of 321 // For unknown reasons, when scanning for longer periods (on the order of
321 // minutes), the scanner is less reliable at detecting all nearby URLs. As a 322 // minutes), the scanner is less reliable at detecting all nearby URLs. As a
322 // workaround, we restart the scanner each time we check for lost URLs. 323 // workaround, we restart the scanner each time we check for lost URLs.
323 NSArray* serviceUUIDs = @[ 324 if (!pendingStart_) {
324 [CBUUID UUIDWithString:kUriBeaconServiceUUID], 325 NSArray* serviceUUIDs = @[
325 [CBUUID UUIDWithString:kEddystoneBeaconServiceUUID] 326 [CBUUID UUIDWithString:kUriBeaconServiceUUID],
326 ]; 327 [CBUUID UUIDWithString:kEddystoneBeaconServiceUUID]
327 [centralManager_ stopScan]; 328 ];
328 [centralManager_ scanForPeripheralsWithServices:serviceUUIDs options:nil]; 329 [centralManager_ stopScan];
330 [centralManager_ scanForPeripheralsWithServices:serviceUUIDs options:nil];
331 }
332
333 if (updateTimer_.get() && pendingStart_ && [devices_ count] == 0) {
334 [updateTimer_ invalidate];
335 updateTimer_.reset();
336 }
329 } 337 }
330 338
331 #pragma mark - 339 #pragma mark -
332 #pragma mark CBCentralManagerDelegate methods 340 #pragma mark CBCentralManagerDelegate methods
333 341
334 - (void)centralManagerDidUpdateState:(CBCentralManager*)central { 342 - (void)centralManagerDidUpdateState:(CBCentralManager*)central {
335 if ([self bluetoothEnabled]) { 343 if ([self bluetoothEnabled]) {
336 if (pendingStart_) 344 if (pendingStart_)
337 [self reallyStart]; 345 [self reallyStart];
338 } else { 346 } else {
339 if (started_ && !pendingStart_) { 347 if (started_ && !pendingStart_) {
340 pendingStart_ = YES; 348 pendingStart_ = YES;
341 [self reallyStop];
mattreynolds 2016/11/18 00:03:25 This was a bug, calling [centralManager_ stopScan]
342 } 349 }
343 } 350 }
344 [delegate_ scannerBluetoothStatusUpdated:self]; 351 [delegate_ scannerBluetoothStatusUpdated:self];
345 } 352 }
346 353
347 + (BeaconType)beaconTypeForAdvertisementData:(NSDictionary*)advertisementData { 354 + (BeaconType)beaconTypeForAdvertisementData:(NSDictionary*)advertisementData {
348 NSDictionary* serviceData = 355 NSDictionary* serviceData =
349 [advertisementData objectForKey:CBAdvertisementDataServiceDataKey]; 356 [advertisementData objectForKey:CBAdvertisementDataServiceDataKey];
350 if ([serviceData objectForKey:[CBUUID UUIDWithString:kUriBeaconServiceUUID]]) 357 if ([serviceData objectForKey:[CBUUID UUIDWithString:kUriBeaconServiceUUID]])
351 return BEACON_TYPE_URIBEACON; 358 return BEACON_TYPE_URIBEACON;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 [strongSelf.get()->devices_ addObject:device]; 491 [strongSelf.get()->devices_ addObject:device];
485 [strongSelf.get()->delegate_ scannerUpdatedDevices:weakSelf]; 492 [strongSelf.get()->delegate_ scannerUpdatedDevices:weakSelf];
486 [strongSelf.get()->finalUrls_ addObject:[device url]]; 493 [strongSelf.get()->finalUrls_ addObject:[device url]];
487 } 494 }
488 } 495 }
489 [strongSelf.get()->pendingRequests_ removeObject:strongRequest]; 496 [strongSelf.get()->pendingRequests_ removeObject:strongRequest];
490 }]; 497 }];
491 } 498 }
492 499
493 @end 500 @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