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 #include "ios/chrome/browser/physical_web/start_physical_web_discovery.h" |
| 6 |
| 7 #import <CoreLocation/CoreLocation.h> |
| 8 |
| 9 #include "components/physical_web/data_source/physical_web_data_source.h" |
| 10 #include "ios/chrome/browser/application_context.h" |
| 11 #include "ios/chrome/browser/experimental_flags.h" |
| 12 #include "ios/chrome/browser/physical_web/physical_web_constants.h" |
| 13 #include "ios/chrome/browser/pref_names.h" |
| 14 |
| 15 void StartPhysicalWebDiscovery(PrefService* pref_service) { |
| 16 // Do not scan if the Physical Web feature is disabled by a command line flag |
| 17 // or Chrome Variations experiment. |
| 18 if (!experimental_flags::IsPhysicalWebEnabled()) { |
| 19 return; |
| 20 } |
| 21 |
| 22 // Do not scan for nearby devices if the user has explicitly disabled the |
| 23 // Physical Web feature. |
| 24 int preference_state = |
| 25 pref_service->GetInteger(prefs::kIosPhysicalWebEnabled); |
| 26 if (preference_state == physical_web::kPhysicalWebOff) { |
| 27 return; |
| 28 } |
| 29 |
| 30 // In the default (onboarding) state, enable Physical Web scanning if the user |
| 31 // has granted the Location app permission. |
| 32 if (preference_state == physical_web::kPhysicalWebOnboarding) { |
| 33 CLAuthorizationStatus auth_status = [CLLocationManager authorizationStatus]; |
| 34 if (auth_status != kCLAuthorizationStatusAuthorizedWhenInUse && |
| 35 auth_status != kCLAuthorizationStatusAuthorizedAlways) { |
| 36 return; |
| 37 } |
| 38 pref_service->SetInteger(prefs::kIosPhysicalWebEnabled, true); |
| 39 } |
| 40 |
| 41 GetApplicationContext()->GetPhysicalWebDataSource()->StartDiscovery(true); |
| 42 } |
OLD | NEW |