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

Unified Diff: ios/chrome/browser/physical_web/start_physical_web_discovery.mm

Issue 2317183002: Start the Physical Web scanner on Chrome start (Closed)
Patch Set: swap conditional Created 4 years, 3 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
« no previous file with comments | « ios/chrome/browser/physical_web/start_physical_web_discovery.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/physical_web/start_physical_web_discovery.mm
diff --git a/ios/chrome/browser/physical_web/start_physical_web_discovery.mm b/ios/chrome/browser/physical_web/start_physical_web_discovery.mm
new file mode 100644
index 0000000000000000000000000000000000000000..74e43310b6fa1bb37ab770e2ac6f726fbe3c9bef
--- /dev/null
+++ b/ios/chrome/browser/physical_web/start_physical_web_discovery.mm
@@ -0,0 +1,42 @@
+// 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.
+
+#include "ios/chrome/browser/physical_web/start_physical_web_discovery.h"
+
+#import <CoreLocation/CoreLocation.h>
+
+#include "components/physical_web/data_source/physical_web_data_source.h"
+#include "ios/chrome/browser/application_context.h"
+#include "ios/chrome/browser/experimental_flags.h"
+#include "ios/chrome/browser/physical_web/physical_web_constants.h"
+#include "ios/chrome/browser/pref_names.h"
+
+void StartPhysicalWebDiscovery(PrefService* pref_service) {
+ // Do not scan if the Physical Web feature is disabled by a command line flag
+ // or Chrome Variations experiment.
+ if (!experimental_flags::IsPhysicalWebEnabled()) {
+ return;
+ }
+
+ // Do not scan for nearby devices if the user has explicitly disabled the
+ // Physical Web feature.
+ int preference_state =
+ pref_service->GetInteger(prefs::kIosPhysicalWebEnabled);
+ if (preference_state == physical_web::kPhysicalWebOff) {
+ return;
+ }
+
+ // In the default (onboarding) state, enable Physical Web scanning if the user
+ // has granted the Location app permission.
+ if (preference_state == physical_web::kPhysicalWebOnboarding) {
+ CLAuthorizationStatus auth_status = [CLLocationManager authorizationStatus];
+ if (auth_status != kCLAuthorizationStatusAuthorizedWhenInUse &&
+ auth_status != kCLAuthorizationStatusAuthorizedAlways) {
+ return;
+ }
+ pref_service->SetInteger(prefs::kIosPhysicalWebEnabled, true);
+ }
+
+ GetApplicationContext()->GetPhysicalWebDataSource()->StartDiscovery(true);
+}
« no previous file with comments | « ios/chrome/browser/physical_web/start_physical_web_discovery.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698