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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWeb.java

Issue 2762733002: Add PhysicalWeb.updateScans() (Closed)
Patch Set: Remove dead store Created 3 years, 9 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 | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PhysicalWebPreferenceFragment.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWeb.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWeb.java b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWeb.java
index 0b0f6c277c1a962b4385776f762850a499d29c6a..7af61412addc7a7e5aa3af1425226b2a46292892 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWeb.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWeb.java
@@ -71,32 +71,6 @@ public class PhysicalWeb {
}
/**
- * Starts the Physical Web feature.
- * At the moment, this only enables URL discovery over BLE.
- */
- public static void startPhysicalWeb() {
- // Only subscribe to Nearby if we have the location permission.
- LocationUtils locationUtils = LocationUtils.getInstance();
- if (locationUtils.hasAndroidLocationPermission()
- && locationUtils.isSystemLocationSettingEnabled()) {
- new NearbyBackgroundSubscription(NearbySubscription.SUBSCRIBE).run();
- }
- }
-
- /**
- * Stops the Physical Web feature.
- */
- public static void stopPhysicalWeb() {
- new NearbyBackgroundSubscription(NearbySubscription.UNSUBSCRIBE, new Runnable() {
- @Override
- public void run() {
- // This isn't absolutely necessary, but it's nice to clean up all our shared prefs.
- UrlManager.getInstance().clearAllUrls();
- }
- }).run();
- }
-
- /**
* Increments a value tracking how many times we've shown the Physical Web
* opt-in notification.
*/
@@ -120,8 +94,10 @@ public class PhysicalWeb {
* Performs various Physical Web operations that should happen on startup.
*/
public static void onChromeStart() {
+ // In the case that the user has disabled our flag and restarted, this is a minimal code
+ // path to disable our subscription to Nearby.
if (!featureIsEnabled()) {
- stopPhysicalWeb();
+ new NearbyBackgroundSubscription(NearbySubscription.UNSUBSCRIBE).run();
return;
}
@@ -130,12 +106,10 @@ public class PhysicalWeb {
PrivacyPreferencesManager.getInstance().setPhysicalWebEnabled(true);
}
- if (isPhysicalWebPreferenceEnabled()) {
- startPhysicalWeb();
- // The PhysicalWebUma call in this method should be called only when the native library
- // is loaded. This is always the case on chrome startup.
- PhysicalWebUma.uploadDeferredMetrics();
- }
+ updateScans();
+ // The PhysicalWebUma call in this method should be called only when the native library
+ // is loaded. This is always the case on chrome startup.
+ PhysicalWebUma.uploadDeferredMetrics();
}
/**
@@ -181,4 +155,19 @@ public class PhysicalWeb {
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
return bluetoothAdapter != null && bluetoothAdapter.getBluetoothLeAdvertiser() != null;
}
+
+ /**
+ * Examines the environment in order to decide whether we should begin or end a scan.
+ */
+ public static void updateScans() {
+ LocationUtils locationUtils = LocationUtils.getInstance();
+ if (!locationUtils.hasAndroidLocationPermission()
+ || !locationUtils.isSystemLocationSettingEnabled()
+ || !isPhysicalWebPreferenceEnabled()) {
+ new NearbyBackgroundSubscription(NearbySubscription.UNSUBSCRIBE).run();
+ return;
+ }
+
+ new NearbyBackgroundSubscription(NearbySubscription.SUBSCRIBE).run();
+ }
}
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PhysicalWebPreferenceFragment.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698