Index: chrome/android/java/src/org/chromium/chrome/browser/util/FeatureUtilities.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/util/FeatureUtilities.java b/chrome/android/java/src/org/chromium/chrome/browser/util/FeatureUtilities.java |
index 2089a3bc9ad737432c59f35c72ed42cf48fd8fc8..8742ff0dc17ccab075fc86f8c98fa846626bcb12 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/util/FeatureUtilities.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/util/FeatureUtilities.java |
@@ -12,14 +12,21 @@ import android.content.pm.PackageManager; |
import android.content.pm.ResolveInfo; |
import android.os.Build; |
import android.os.Bundle; |
+import android.os.StrictMode; |
import android.os.UserManager; |
import android.speech.RecognizerIntent; |
+import android.text.TextUtils; |
+import org.chromium.base.ApplicationStatus; |
import org.chromium.base.CommandLine; |
+import org.chromium.base.Log; |
import org.chromium.base.ThreadUtils; |
import org.chromium.base.VisibleForTesting; |
import org.chromium.chrome.browser.ChromeSwitches; |
+import org.chromium.chrome.browser.ChromeVersionInfo; |
+import org.chromium.chrome.browser.preferences.ChromePreferenceManager; |
import org.chromium.chrome.browser.preferences.DocumentModeManager; |
+import org.chromium.components.variations.VariationsAssociatedData; |
import org.chromium.sync.signin.AccountManagerHelper; |
import org.chromium.ui.base.DeviceFormFactor; |
@@ -30,9 +37,17 @@ import java.util.List; |
* this device. |
*/ |
public class FeatureUtilities { |
+ private static final String TAG = "FeatureUtilities"; |
+ private static final String HERB_EXPERIMENT_NAME = "TabManagementExperiment"; |
+ private static final String HERB_EXPERIMENT_FLAVOR_PARAM = "type"; |
+ |
private static Boolean sHasGoogleAccountAuthenticator; |
private static Boolean sHasRecognitionIntentHandler; |
private static Boolean sDocumentModeDisabled; |
+ |
+ private static String sCachedHerbFlavor; |
+ private static boolean sIsHerbFlavorCached; |
+ |
/** Used to track if cached command line flags should be refreshed. */ |
private static CommandLine.ResetListener sResetListener = null; |
@@ -171,6 +186,60 @@ public class FeatureUtilities { |
CommandLine.addResetListener(sResetListener); |
} |
+ /** |
+ * @return Which flavor of Herb is active, or null if a prototype isn't being tested. |
+ */ |
+ public static String getHerbFlavor() { |
+ if (!sIsHerbFlavorCached) { |
+ Context context = ApplicationStatus.getApplicationContext(); |
+ if (isDocumentMode(context)) return null; |
+ if (ChromeVersionInfo.isStableBuild() || ChromeVersionInfo.isBetaBuild()) return null; |
+ if (DeviceFormFactor.isTablet(context)) return null; |
+ |
+ // Allowing disk access for preferences while prototyping. |
+ sCachedHerbFlavor = null; |
+ StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
+ try { |
+ sCachedHerbFlavor = |
+ ChromePreferenceManager.getInstance(context).getCachedHerbFlavor(); |
+ } finally { |
+ StrictMode.setThreadPolicy(oldPolicy); |
+ } |
+ |
+ sIsHerbFlavorCached = true; |
+ Log.d(TAG, "Retrieved cached Herb flavor: " + sCachedHerbFlavor); |
+ } |
+ |
+ return sCachedHerbFlavor; |
+ } |
+ |
+ /** |
+ * Caches which flavor of Herb the user prefers from native. |
+ */ |
+ public static void cacheHerbFlavor() { |
+ String oldFlavor = getHerbFlavor(); |
+ String newFlavor = null; |
+ |
+ // Check the experiment value before the command line. |
+ String experimentValue = VariationsAssociatedData.getVariationParamValue( |
+ HERB_EXPERIMENT_NAME, HERB_EXPERIMENT_FLAVOR_PARAM); |
+ |
+ newFlavor = CommandLine.getInstance().getSwitchValue(ChromeSwitches.HERB_FLAVOR, null); |
+ if (TextUtils.isEmpty(newFlavor)) { |
+ Log.d(TAG, "Caching flavor from experiment: " + experimentValue); |
+ newFlavor = experimentValue; |
+ } else { |
+ Log.d(TAG, "Caching flavor from command line: " + newFlavor); |
+ } |
+ |
+ sCachedHerbFlavor = newFlavor; |
+ |
+ if (!TextUtils.equals(oldFlavor, newFlavor)) { |
+ Context context = ApplicationStatus.getApplicationContext(); |
+ ChromePreferenceManager.getInstance(context).setCachedHerbFlavor(newFlavor); |
+ } |
+ } |
+ |
private static native void nativeSetDocumentModeEnabled(boolean enabled); |
private static native void nativeSetCustomTabVisible(boolean visible); |
public static native void nativeSetSqlMmapDisabledByDefault(); |