Chromium Code Reviews| Index: ios/chrome/common/physical_web/physical_web_data_source_ios.mm |
| diff --git a/ios/chrome/common/physical_web/physical_web_data_source_ios.mm b/ios/chrome/common/physical_web/physical_web_data_source_ios.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bbfad21385cc72c90c0d8b00bc55615616dbe0b2 |
| --- /dev/null |
| +++ b/ios/chrome/common/physical_web/physical_web_data_source_ios.mm |
| @@ -0,0 +1,43 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ios/chrome/common/physical_web/physical_web_data_source_ios.h" |
| + |
| +void PhysicalWebDataSourceIOS::StartDiscovery(bool network_request_enabled) { |
| + // If there are unresolved beacons it means the scanner is started but does |
| + // not have network requests enabled. In this case we should avoid recreating |
| + // the scanner as it would clear the cache of nearby beacons. |
| + if (network_request_enabled && HasUnresolvedDiscoveries()) { |
| + [scanner_ setNetworkRequestEnabled:YES]; |
| + return; |
| + } |
| + |
| + [scanner_ stop]; |
| + scanner_.reset([[PhysicalWebScanner alloc] initWithDelegate:nil]); |
| + [scanner_ setNetworkRequestEnabled:(BOOL)network_request_enabled]; |
|
Olivier
2016/06/30 08:14:11
no C cast.
Use static_cast<BOOL> instead
mattreynolds
2016/06/30 17:51:58
Done.
|
| + [scanner_ start]; |
| +} |
| + |
| +void PhysicalWebDataSourceIOS::StopDiscovery() { |
| + [scanner_ stop]; |
| + scanner_.reset(); |
| +} |
| + |
| +std::unique_ptr<base::ListValue> PhysicalWebDataSourceIOS::GetMetadata() { |
| + std::unique_ptr<base::ListValue> metadata = [scanner_ metadata]; |
| + if (metadata.get() == NULL) { |
| + metadata.reset(new base::ListValue()); |
| + } |
| + return metadata; |
| +} |
| + |
| +bool PhysicalWebDataSourceIOS::HasUnresolvedDiscoveries() { |
| + return [scanner_ unresolvedBeaconsCount] > 0; |
| +} |
| + |
| +PhysicalWebDataSourceIOS::PhysicalWebDataSourceIOS() {} |
| + |
| +PhysicalWebDataSourceIOS::~PhysicalWebDataSourceIOS() { |
| + StopDiscovery(); |
| +} |