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/memory/ptr_util.h" | |
8 | |
9 IOSChromePhysicalWebDataSource::IOSChromePhysicalWebDataSource() {} | |
10 | |
11 IOSChromePhysicalWebDataSource::~IOSChromePhysicalWebDataSource() { | |
12 StopDiscovery(); | |
13 } | |
14 | |
15 void IOSChromePhysicalWebDataSource::StartDiscovery( | |
16 bool network_request_enabled) { | |
17 // If there are unresolved beacons it means the scanner is started but does | |
18 // not have network requests enabled. In this case we should avoid recreating | |
19 // the scanner as it would clear the cache of nearby beacons. | |
20 if (network_request_enabled && HasUnresolvedDiscoveries()) { | |
21 [scanner_ setNetworkRequestEnabled:YES]; | |
22 return; | |
23 } | |
24 | |
25 [scanner_ stop]; | |
26 scanner_.reset([[PhysicalWebScanner alloc] initWithDelegate:nil]); | |
27 [scanner_ setNetworkRequestEnabled:network_request_enabled]; | |
28 [scanner_ start]; | |
29 } | |
30 | |
31 void IOSChromePhysicalWebDataSource::StopDiscovery() { | |
32 [scanner_ stop]; | |
33 scanner_.reset(); | |
34 } | |
35 | |
36 std::unique_ptr<base::ListValue> IOSChromePhysicalWebDataSource::GetMetadata() { | |
37 std::unique_ptr<base::ListValue> metadata = [scanner_ metadata]; | |
sdefresne
2016/08/04 19:23:47
It look like the current implementation of -[Physi
mattreynolds
2016/08/04 21:14:34
Done.
| |
38 if (!metadata) { | |
39 metadata = base::MakeUnique<base::ListValue>(); | |
40 } | |
41 return metadata; | |
42 } | |
43 | |
44 bool IOSChromePhysicalWebDataSource::HasUnresolvedDiscoveries() { | |
45 return [scanner_ unresolvedBeaconsCount] > 0; | |
46 } | |
OLD | NEW |