OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/common/physical_web/ios_chrome_physical_web_data_source.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/values.h" |
| 10 #import "ios/chrome/common/physical_web/physical_web_scanner.h" |
| 11 |
| 12 IOSChromePhysicalWebDataSource::IOSChromePhysicalWebDataSource() {} |
| 13 |
| 14 IOSChromePhysicalWebDataSource::~IOSChromePhysicalWebDataSource() { |
| 15 StopDiscovery(); |
| 16 } |
| 17 |
| 18 void IOSChromePhysicalWebDataSource::StartDiscovery( |
| 19 bool network_request_enabled) { |
| 20 // If there are unresolved beacons it means the scanner is started but does |
| 21 // not have network requests enabled. In this case we should avoid recreating |
| 22 // the scanner as it would clear the cache of nearby beacons. |
| 23 if (network_request_enabled && HasUnresolvedDiscoveries()) { |
| 24 [scanner_ setNetworkRequestEnabled:YES]; |
| 25 return; |
| 26 } |
| 27 |
| 28 [scanner_ stop]; |
| 29 scanner_.reset([[PhysicalWebScanner alloc] initWithDelegate:nil]); |
| 30 [scanner_ setNetworkRequestEnabled:network_request_enabled]; |
| 31 [scanner_ start]; |
| 32 } |
| 33 |
| 34 void IOSChromePhysicalWebDataSource::StopDiscovery() { |
| 35 [scanner_ stop]; |
| 36 scanner_.reset(); |
| 37 } |
| 38 |
| 39 std::unique_ptr<base::ListValue> IOSChromePhysicalWebDataSource::GetMetadata() { |
| 40 std::unique_ptr<base::ListValue> metadata = [scanner_ metadata]; |
| 41 DCHECK(metadata); |
| 42 return metadata; |
| 43 } |
| 44 |
| 45 bool IOSChromePhysicalWebDataSource::HasUnresolvedDiscoveries() { |
| 46 return [scanner_ unresolvedBeaconsCount] > 0; |
| 47 } |
OLD | NEW |