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

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

Issue 2458613004: Record the initial state of the Physical Web at startup (Closed)
Patch Set: changes for olivierrobin@, rohitrao@, sdefresne@ 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
OLDNEW
(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 #include "base/values.h"
9 #import "ios/chrome/common/physical_web/physical_web_scanner.h"
10
11 IOSChromePhysicalWebDataSource::IOSChromePhysicalWebDataSource() {}
12
13 IOSChromePhysicalWebDataSource::~IOSChromePhysicalWebDataSource() {
14 StopDiscovery();
15 }
16
17 void IOSChromePhysicalWebDataSource::StartDiscovery(
18 bool network_request_enabled) {
19 // If there are unresolved beacons it means the scanner is started but does
20 // not have network requests enabled. In this case we should avoid recreating
21 // the scanner as it would clear the cache of nearby beacons.
22 if (network_request_enabled && HasUnresolvedDiscoveries()) {
23 [scanner_ setNetworkRequestEnabled:YES];
24 return;
25 }
26
27 [scanner_ stop];
28 scanner_.reset([[PhysicalWebScanner alloc] initWithDelegate:nil]);
29
30 // Configure the scanner to notify us when a URL is no longer nearby.
31 [scanner_ setOnLostDetectionEnabled:YES];
32 [scanner_ setNetworkRequestEnabled:network_request_enabled];
33 [scanner_ start];
34 }
35
36 void IOSChromePhysicalWebDataSource::StopDiscovery() {
37 [scanner_ stop];
38 scanner_.reset();
39 }
40
41 std::unique_ptr<base::ListValue> IOSChromePhysicalWebDataSource::GetMetadata() {
42 if (!scanner_) {
43 return base::MakeUnique<base::ListValue>();
44 }
45 return [scanner_ metadata];
46 }
47
48 bool IOSChromePhysicalWebDataSource::HasUnresolvedDiscoveries() {
49 return [scanner_ unresolvedBeaconsCount] > 0;
50 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698