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

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

Issue 2108983002: Use ContextUtils in PhysicalWeb (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update tests to use new methods 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: 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 8f806babc0f35ed229a70a020eea62eb679bc316..ed8716c8502a4c6165850c2fe128d75b43c27011 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
@@ -4,12 +4,10 @@
package org.chromium.chrome.browser.physicalweb;
-import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import org.chromium.base.ContextUtils;
-import org.chromium.chrome.browser.ChromeApplication;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager;
@@ -37,10 +35,9 @@ public class PhysicalWeb {
/**
* Checks whether the Physical Web preference is switched to On.
*
- * @param context An instance of android.content.Context
* @return boolean {@code true} if the preference is On.
*/
- public static boolean isPhysicalWebPreferenceEnabled(Context context) {
+ public static boolean isPhysicalWebPreferenceEnabled() {
return PrivacyPreferencesManager.getInstance().isPhysicalWebEnabled();
}
@@ -48,42 +45,37 @@ public class PhysicalWeb {
* Checks whether the Physical Web onboard flow is active and the user has
* not yet elected to either enable or decline the feature.
*
- * @param context An instance of android.content.Context
* @return boolean {@code true} if onboarding is complete.
*/
- public static boolean isOnboarding(Context context) {
+ public static boolean isOnboarding() {
return PrivacyPreferencesManager.getInstance().isPhysicalWebOnboarding();
}
/**
* Start the Physical Web feature.
* At the moment, this only enables URL discovery over BLE.
- * @param application An instance of {@link ChromeApplication}, used to get the
- * appropriate PhysicalWebBleClient implementation.
*/
- public static void startPhysicalWeb(final ChromeApplication application) {
- PhysicalWebBleClient.getInstance(application).backgroundSubscribe(new Runnable() {
+ public static void startPhysicalWeb() {
+ PhysicalWebBleClient.getInstance().backgroundSubscribe(new Runnable() {
@Override
public void run() {
// We need to clear the list of nearby URLs so that they can be repopulated by the
// new subscription, but we don't know whether we are already subscribed, so we need
// to pass a callback so that we can clear as soon as we are resubscribed.
- UrlManager.getInstance(application).clearNearbyUrls();
+ UrlManager.getInstance().clearNearbyUrls();
}
});
}
/**
* Stop the Physical Web feature.
- * @param application An instance of {@link ChromeApplication}, used to get the
- * appropriate PhysicalWebBleClient implementation.
*/
- public static void stopPhysicalWeb(final ChromeApplication application) {
- PhysicalWebBleClient.getInstance(application).backgroundUnsubscribe(new Runnable() {
+ public static void stopPhysicalWeb() {
+ PhysicalWebBleClient.getInstance().backgroundUnsubscribe(new Runnable() {
@Override
public void run() {
// This isn't absolutely necessary, but it's nice to clean up all our shared prefs.
- UrlManager.getInstance(application).clearAllUrls();
+ UrlManager.getInstance().clearAllUrls();
}
});
}
@@ -100,12 +92,9 @@ public class PhysicalWeb {
/**
* Increments a value tracking how many times we've shown the Physical Web
* opt-in notification.
- *
- * @param context An instance of android.content.Context
*/
- public static void recordOptInNotification(Context context) {
- SharedPreferences sharedPreferences =
- ContextUtils.getAppSharedPreferences();
+ public static void recordOptInNotification() {
+ SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences();
int value = sharedPreferences.getInt(PREF_PHYSICAL_WEB_NOTIFY_COUNT, 0);
sharedPreferences.edit().putInt(PREF_PHYSICAL_WEB_NOTIFY_COUNT, value + 1).apply();
}
@@ -113,34 +102,29 @@ public class PhysicalWeb {
/**
* Gets the current count of how many times a high-priority opt-in notification
* has been shown.
- *
- * @param context An instance of android.content.Context
* @return an integer representing the high-priority notifification display count.
*/
- public static int getOptInNotifyCount(Context context) {
- SharedPreferences sharedPreferences =
- ContextUtils.getAppSharedPreferences();
+ public static int getOptInNotifyCount() {
+ SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences();
return sharedPreferences.getInt(PREF_PHYSICAL_WEB_NOTIFY_COUNT, 0);
}
/**
* Perform various Physical Web operations that should happen on startup.
- * @param application An instance of {@link ChromeApplication}.
*/
- public static void onChromeStart(ChromeApplication application) {
+ public static void onChromeStart() {
// The PhysicalWebUma calls in this method should be called only when the native library is
// loaded. This is always the case on chrome startup.
- if (featureIsEnabled()
- && (isPhysicalWebPreferenceEnabled(application) || isOnboarding(application))) {
+ if (featureIsEnabled() && (isPhysicalWebPreferenceEnabled() || isOnboarding())) {
boolean ignoreOtherClients =
ChromeFeatureList.isEnabled(IGNORE_OTHER_CLIENTS_FEATURE_NAME);
ContextUtils.getAppSharedPreferences().edit()
.putBoolean(PREF_IGNORE_OTHER_CLIENTS, ignoreOtherClients)
.apply();
- startPhysicalWeb(application);
- PhysicalWebUma.uploadDeferredMetrics(application);
+ startPhysicalWeb();
+ PhysicalWebUma.uploadDeferredMetrics();
} else {
- stopPhysicalWeb(application);
+ stopPhysicalWeb();
}
}
}

Powered by Google App Engine
This is Rietveld 408576698