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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHost.java

Issue 2515293004: Chrome talks to Play to install WebAPKs. (Closed)
Patch Set: Add a test for play install webapk. Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.webapps; 5 package org.chromium.chrome.browser.webapps;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.DialogInterface; 8 import android.content.DialogInterface;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.os.StrictMode; 10 import android.os.StrictMode;
11 import android.provider.Settings; 11 import android.provider.Settings;
12 import android.support.v7.app.AlertDialog; 12 import android.support.v7.app.AlertDialog;
13 import android.text.TextUtils;
13 14
14 import org.chromium.base.CommandLine; 15 import org.chromium.base.CommandLine;
15 import org.chromium.base.ContextUtils; 16 import org.chromium.base.ContextUtils;
16 import org.chromium.base.Log; 17 import org.chromium.base.Log;
17 import org.chromium.base.annotations.CalledByNative; 18 import org.chromium.base.annotations.CalledByNative;
18 import org.chromium.chrome.R; 19 import org.chromium.chrome.R;
19 import org.chromium.chrome.browser.ChromeFeatureList; 20 import org.chromium.chrome.browser.ChromeFeatureList;
20 import org.chromium.chrome.browser.ChromeSwitches; 21 import org.chromium.chrome.browser.ChromeSwitches;
21 import org.chromium.chrome.browser.ChromeVersionInfo; 22 import org.chromium.chrome.browser.ChromeVersionInfo;
22 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; 23 import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
24 import org.chromium.components.variations.VariationsAssociatedData;
23 import org.chromium.webapk.lib.client.WebApkValidator; 25 import org.chromium.webapk.lib.client.WebApkValidator;
24 26
25 /** 27 /**
26 * Contains functionality needed for Chrome to host WebAPKs. 28 * Contains functionality needed for Chrome to host WebAPKs.
27 */ 29 */
28 public class ChromeWebApkHost { 30 public class ChromeWebApkHost {
31 /** Flag to enable installing WebAPKs using Google Play. */
32 private static final String PLAY_INSTALL = "play_install";
33
29 private static final String TAG = "ChromeWebApkHost"; 34 private static final String TAG = "ChromeWebApkHost";
30 35
31 private static Boolean sEnabledForTesting; 36 private static Boolean sEnabledForTesting;
32 37
33 public static void init() { 38 public static void init() {
34 WebApkValidator.initWithBrowserHostSignature(ChromeWebApkHostSignature.E XPECTED_SIGNATURE); 39 WebApkValidator.initWithBrowserHostSignature(ChromeWebApkHostSignature.E XPECTED_SIGNATURE);
35 } 40 }
36 41
37 public static void initForTesting(boolean enabled) { 42 public static void initForTesting(boolean enabled) {
38 sEnabledForTesting = enabled; 43 sEnabledForTesting = enabled;
39 } 44 }
40 45
41 public static boolean isEnabled() { 46 public static boolean isEnabled() {
42 if (sEnabledForTesting != null) return sEnabledForTesting; 47 if (sEnabledForTesting != null) return sEnabledForTesting;
43 48
44 return isEnabledInPrefs(); 49 return isEnabledInPrefs();
45 } 50 }
46 51
52 /** Return whether installing WebAPKs using Google Play is enabled. */
53 public static boolean canUseGooglePlayToInstallWebApk() {
54 if (!isEnabled()) return false;
55 return TextUtils.equals(VariationsAssociatedData.getVariationParamValue(
56 ChromeFeatureList.WEBAPKS, PLAY_INSTALL), "true");
57 }
58
47 @CalledByNative 59 @CalledByNative
48 private static boolean areWebApkEnabled() { 60 private static boolean areWebApkEnabled() {
49 return ChromeWebApkHost.isEnabled(); 61 return ChromeWebApkHost.isEnabled();
50 } 62 }
51 63
52 /** 64 /**
53 * Check the cached value to figure out if the feature is enabled. We have 65 * Check the cached value to figure out if the feature is enabled. We have t o use the cached
54 * to use the cached value because native library may not yet been loaded. 66 * value because native library may not yet been loaded.
55 *
56 * @return Whether the feature is enabled. 67 * @return Whether the feature is enabled.
57 */ 68 */
58 private static boolean isEnabledInPrefs() { 69 private static boolean isEnabledInPrefs() {
59 // Will go away once the feature is enabled for everyone by default. 70 // Will go away once the feature is enabled for everyone by default.
60 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); 71 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
61 try { 72 try {
62 return ChromePreferenceManager.getInstance( 73 return ChromePreferenceManager.getInstance(
63 ContextUtils.getApplicationContext()).getCachedWebApkRuntime Enabled(); 74 ContextUtils.getApplicationContext()).getCachedWebApkRuntime Enabled();
64 } finally { 75 } finally {
65 StrictMode.setThreadPolicy(oldPolicy); 76 StrictMode.setThreadPolicy(oldPolicy);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 165 }
155 }); 166 });
156 builder.setNegativeButton(android.R.string.cancel, new DialogInterface.O nClickListener() { 167 builder.setNegativeButton(android.R.string.cancel, new DialogInterface.O nClickListener() {
157 @Override 168 @Override
158 public void onClick(DialogInterface dialog, int id) {} 169 public void onClick(DialogInterface dialog, int id) {}
159 }); 170 });
160 AlertDialog dialog = builder.create(); 171 AlertDialog dialog = builder.create();
161 dialog.show(); 172 dialog.show();
162 } 173 }
163 } 174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698