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

Unified Diff: ios/chrome/common/physical_web/ios_chrome_physical_web_data_source.mm

Issue 2113473002: Add a Physical Web data source (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: components/physical_web.gypi Created 4 years, 5 months 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/common/physical_web/ios_chrome_physical_web_data_source.mm
diff --git a/ios/chrome/common/physical_web/ios_chrome_physical_web_data_source.mm b/ios/chrome/common/physical_web/ios_chrome_physical_web_data_source.mm
new file mode 100644
index 0000000000000000000000000000000000000000..44a746ad0554ad58cc40b062a101c7b36917a443
--- /dev/null
+++ b/ios/chrome/common/physical_web/ios_chrome_physical_web_data_source.mm
@@ -0,0 +1,45 @@
+// 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/ios_chrome_physical_web_data_source.h"
+
+void IOSChromePhysicalWebDataSource::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:static_cast<BOOL>(network_request_enabled)];
sdefresne 2016/08/02 22:23:36 There is no need to cast a bool to a BOOL. I think
mattreynolds 2016/08/04 00:56:12 Done.
+ [scanner_ start];
+}
+
+void IOSChromePhysicalWebDataSource::StopDiscovery() {
+ [scanner_ stop];
+ scanner_.reset();
+}
+
+std::unique_ptr<base::ListValue> IOSChromePhysicalWebDataSource::GetMetadata() {
+ std::unique_ptr<base::ListValue> metadata = [scanner_ metadata];
+ if (metadata.get() == NULL) {
sdefresne 2016/08/02 22:23:36 if (!metadata) metadata = base::MakeUnique<base:
mattreynolds 2016/08/04 00:56:12 Done.
+ metadata.reset(new base::ListValue());
+ }
+ return metadata;
+}
+
+bool IOSChromePhysicalWebDataSource::HasUnresolvedDiscoveries() {
+ return [scanner_ unresolvedBeaconsCount] > 0;
+}
+
+IOSChromePhysicalWebDataSource::IOSChromePhysicalWebDataSource() {}
sdefresne 2016/08/02 22:23:36 Please keep method in the same order as in the hea
mattreynolds 2016/08/04 00:56:12 Done.
+
+IOSChromePhysicalWebDataSource::~IOSChromePhysicalWebDataSource() {
+ StopDiscovery();
+}

Powered by Google App Engine
This is Rietveld 408576698