Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHost.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHost.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHost.java |
| index dd7c4a392bbdf2d4fb1c20cc37e642c7255461fd..cb71b9c64903c4570d3c65a780e9eed69dfdc0ed 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHost.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHost.java |
| @@ -4,14 +4,25 @@ |
| package org.chromium.chrome.browser.webapps; |
| +import android.os.StrictMode; |
| + |
| +import org.chromium.base.CommandLine; |
| +import org.chromium.base.ContextUtils; |
| +import org.chromium.base.FieldTrialList; |
| +import org.chromium.base.Log; |
| +import org.chromium.chrome.browser.ChromeSwitches; |
| +import org.chromium.chrome.browser.preferences.ChromePreferenceManager; |
| import org.chromium.webapk.lib.client.WebApkValidator; |
| /** |
| * Contains functionality needed for Chrome to host WebAPKs. |
| */ |
| public class ChromeWebApkHost { |
| - // The public key to verify whether a WebAPK is signed by WebAPK Minting Server. |
| - // TODO(hanxi): Update {@link EXPECTED_SIGNATURE} when the real signature is available. |
| + // The public key to verify whether a WebAPK is signed by WebAPK Minting |
| + // Server. |
| + // TODO(hanxi): Update {@link EXPECTED_SIGNATURE} when the real signature is |
| + // available. |
| + // TODO(yfriedman): Move this to resoures (so it can vary by channel) |
| private static final byte[] EXPECTED_SIGNATURE = new byte[] { |
| 48, -126, 3, -121, 48, -126, 2, 111, -96, 3, 2, 1, 2, 2, 4, 20, -104, -66, -126, 48, 13, |
| 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 11, 5, 0, 48, 116, 49, 11, 48, 9, 6, 3, 85, 4, |
| @@ -61,7 +72,64 @@ public class ChromeWebApkHost { |
| -125, -31, -18, -52, 49, -73 |
| }; |
| + /** Finch experiment name. */ |
| + private static final String WEBAPK_DISABLE_EXPERIMENT_NAME = "WebApkKillSwitch"; |
| + |
| + /** Finch experiment group which forces webapks off. */ |
|
pkotwicz
2016/08/15 15:27:52
Nit: webapks -> WebAPKs
Yaron
2016/08/16 01:08:42
Done.
|
| + private static final String WEBAPK_RUNTIME_DISABLED = "Disabled"; |
| + |
| public static void init() { |
| WebApkValidator.initWithBrowserHostSignature(EXPECTED_SIGNATURE); |
| } |
| + |
| + private static Boolean sEnabledForTesting; |
|
pkotwicz
2016/08/15 15:27:52
For my general knowledge, why is this static not w
Yaron
2016/08/16 01:08:42
no good reason, moved.
|
| + |
| + public static void initForTesting(boolean enabled) { |
| + sEnabledForTesting = enabled; |
| + } |
| + |
| + public static boolean isEnabled() { |
| + if (sEnabledForTesting != null) return sEnabledForTesting; |
| + |
| + return isEnabledInPrefs(); |
| + } |
| + |
| + /** |
| + * Check the cached value to figure out if the feature is enabled. We have |
| + * to use the cached value because native library may not yet been loaded. |
| + * |
| + * @return Whether the feature is enabled. |
| + */ |
| + private static boolean isEnabledInPrefs() { |
| + // Will go away once the feature is enabled for everyone by default. |
| + StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| + try { |
| + return ChromePreferenceManager.getInstance( |
| + ContextUtils.getApplicationContext()).getCachedWebApkRuntimeEnabled(); |
| + } finally { |
| + StrictMode.setThreadPolicy(oldPolicy); |
| + } |
| + } |
| + |
| + /** |
| + * Once native is loaded we can consult the command-line (set via about:flags) and also finch |
| + * state to see if we should enable WebApks. |
|
pkotwicz
2016/08/15 15:27:52
Nit: "WebApks" -> "WebAPKs". We use WebApks capita
Yaron
2016/08/16 01:08:42
Done.
|
| + */ |
| + public static void cacheEnabledStateForNextLaunch() { |
| + boolean isEnabled = false; |
| + boolean wasEnabled = isEnabledInPrefs(); |
| + CommandLine instance = CommandLine.getInstance(); |
| + String experiment = FieldTrialList.findFullName(WEBAPK_DISABLE_EXPERIMENT_NAME); |
|
pkotwicz
2016/08/15 15:27:52
Nit: I think that it might be clearer if you conde
Yaron
2016/08/16 01:08:42
Done.
|
| + if (WEBAPK_RUNTIME_DISABLED.equals(experiment)) { |
| + isEnabled = false; |
| + } else if (instance.hasSwitch(ChromeSwitches.ENABLE_WEBAPK)) { |
| + isEnabled = true; |
| + } |
| + |
| + if (isEnabled != wasEnabled) { |
| + Log.d("TAG", "WebApk setting changed (%s => %s)", wasEnabled, isEnabled); |
|
pkotwicz
2016/08/15 15:27:52
Nit: Did you intend to use a different tag name th
Yaron
2016/08/16 01:08:42
Done.
|
| + ChromePreferenceManager.getInstance(ContextUtils.getApplicationContext()) |
| + .setCachedWebApkRuntimeEnabled(isEnabled); |
| + } |
| + } |
| } |