Commit 09aacee5 authored by mattreynolds's avatar mattreynolds Committed by Commit bot

Start the Physical Web scanner on Chrome start

When Chrome is started, enable foreground scanning for Physical Web
URLs. The scanner will remain enabled until Chrome is closed or the
Physical Web preference is disabled, but scanning will only occur when
the Chrome app is in the foreground.

BUG=630769

Review-Url: https://codereview.chromium.org/2317183002
Cr-Commit-Position: refs/heads/master@{#417411}
parent 8ba6f35c
......@@ -320,6 +320,8 @@ source_set("browser") {
"physical_web/create_physical_web_data_source.h",
"physical_web/create_physical_web_data_source.mm",
"physical_web/physical_web_constants.h",
"physical_web/start_physical_web_discovery.h",
"physical_web/start_physical_web_discovery.mm",
"pref_names.cc",
"pref_names.h",
"prefs/browser_prefs.h",
......
......@@ -39,6 +39,7 @@
#include "ios/chrome/browser/ios_chrome_field_trials.h"
#include "ios/chrome/browser/metrics/field_trial_synchronizer.h"
#include "ios/chrome/browser/open_from_clipboard/create_clipboard_recent_content.h"
#include "ios/chrome/browser/physical_web/start_physical_web_discovery.h"
#include "ios/chrome/browser/pref_names.h"
#include "ios/chrome/browser/translate/translate_service_ios.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
......@@ -177,6 +178,8 @@ void IOSChromeMainParts::PreMainMessageLoopRun() {
translate::TranslateDownloadManager::RequestLanguageList(
last_used_browser_state->GetPrefs());
StartPhysicalWebDiscovery(last_used_browser_state->GetPrefs());
}
void IOSChromeMainParts::PostMainMessageLoopRun() {
......
// 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.
#ifndef IOS_CHROME_BROWSER_PHYSICAL_WEB_START_PHYSICAL_WEB_DISCOVERY_H_
#define IOS_CHROME_BROWSER_PHYSICAL_WEB_START_PHYSICAL_WEB_DISCOVERY_H_
#include "components/prefs/pref_service.h"
// Checks the environment and starts Physical Web discovery if the required
// conditions are met.
void StartPhysicalWebDiscovery(PrefService* pref_service);
#endif // IOS_CHROME_BROWSER_PHYSICAL_WEB_START_PHYSICAL_WEB_DISCOVERY_H_
// 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);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment