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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInstaller.java

Issue 2515293004: Chrome talks to Play to install WebAPKs. (Closed)
Patch Set: Upload the missing GooglePlayWebApkInstallDelegate. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInstaller.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInstaller.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInstaller.java
index 2b3a2c9fb66f47a8b1437241f5ee51515d29292a..b5d42030f7f4599ddcf493d4ed9950f57e2c2a8c 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInstaller.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInstaller.java
@@ -13,6 +13,7 @@ import android.os.Looper;
import org.chromium.base.ApplicationState;
import org.chromium.base.ApplicationStatus;
+import org.chromium.base.Callback;
import org.chromium.base.ContentUriUtils;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative;
@@ -45,18 +46,40 @@ public class WebApkInstaller {
/** Weak pointer to the native WebApkInstaller. */
private long mNativePointer;
+ /** Talks to Google Play to install WebAPKs. */
+ private static GooglePlayWebApkInstallDelegate sGooglePlayWebApkInstallDelegate;
dominickn 2016/12/08 03:31:26 Is there a reason why you need this to be a static
Xi Han 2016/12/08 18:03:07 This is because this delegate binds to the Play in
+
private WebApkInstaller(long nativePtr) {
mNativePointer = nativePtr;
}
+ /** Sets the GooglePlayWebApkInstallDelegate. */
+ public static void setGooglePlayWebApkInstallDelegate(
+ GooglePlayWebApkInstallDelegate delegate) {
+ sGooglePlayWebApkInstallDelegate = delegate;
+ }
+
+ /** Gets the GooglePlayWebApkInstallDelegate. */
+ public static GooglePlayWebApkInstallDelegate getGooglePlayWebApkInstallDelegate() {
+ return sGooglePlayWebApkInstallDelegate;
+ }
+
@CalledByNative
private static WebApkInstaller create(long nativePtr) {
return new WebApkInstaller(nativePtr);
}
@CalledByNative
+ private boolean hasGooglePlayWebApkInstallDelegate() {
dominickn 2016/12/08 03:31:26 canInstallFromPlay?
Xi Han 2016/12/08 18:03:07 Even with the "play-install-webapk" flag turning o
+ return sGooglePlayWebApkInstallDelegate != null;
+ }
+
+ @CalledByNative
private void destroy() {
- ApplicationStatus.unregisterApplicationStateListener(mListener);
+ if (mListener != null) {
+ ApplicationStatus.unregisterApplicationStateListener(mListener);
+ }
+ mListener = null;
mNativePointer = 0;
}
@@ -86,7 +109,65 @@ public class WebApkInstaller {
}
/**
- * Send intent to Android to show prompt and install downloaded WebAPK.
+ * Installs a WebAPK from Google Play and monitors the installation.
+ * @param packageName The package name of the WebAPK to install.
+ * @param version The version of WebAPK to install.
+ * @param title The title of the WebAPK to display during installation.
+ * @param token The token from WebAPK Server.
+ * @return True if the install was started. A "true" return value does not guarantee that the
+ * install succeeds.
+ */
+ @CalledByNative
+ private boolean installWebApkFromGooglePlayAsync(String packageName, int version, String title,
+ String token) {
+ if (sGooglePlayWebApkInstallDelegate == null) return false;
+
+ Callback<Boolean> callback = new Callback<Boolean>() {
+ @Override
+ public void onResult(Boolean success) {
+ if (mNativePointer != 0) {
+ nativeOnInstallFinished(mNativePointer, success);
+ }
+ }
+ };
+ return sGooglePlayWebApkInstallDelegate.installAsync(packageName, version, title, token,
+ callback);
+ }
+
+ /**
+ * Updates a WebAPK.
+ * @param filePath File to update.
+ * @return True if the update was started. A "true" return value does not guarantee that the
+ * update succeeds.
+ */
+ @CalledByNative
+ private boolean updateAsyncFromNative(String filePath) {
+ mIsInstall = false;
+ return installDownloadedWebApk(filePath);
+ }
+
+ /**
+ * Updates a WebAPK using Google Play.
+ * @param packageName The package name of the WebAPK to install.
+ * @param version The version of WebAPK to install.
+ * @param title The title of the WebAPK to display during installation.
+ * @param token The token from WebAPK Server.
+ * @return True if the update was started. A "true" return value does not guarantee that the
+ * update succeeds.
+ */
+ @CalledByNative
+ private boolean updateAsyncFromGooglePlay(String packageName, int version, String title,
+ String token) {
+ if (sGooglePlayWebApkInstallDelegate == null) return false;
+
+ // TODO(hanxi):crbug.com/634499. Adds a callback to show an infobar after the update
+ // succeeded.
+ return sGooglePlayWebApkInstallDelegate.installAsync(packageName, version, title, token,
+ null);
+ }
+
+ /**
+ * Sends intent to Android to show prompt and install downloaded WebAPK.
* @param filePath File to install.
*/
private boolean installDownloadedWebApk(String filePath) {
@@ -132,18 +213,6 @@ public class WebApkInstaller {
}
}
- /**
- * Updates a WebAPK.
- * @param filePath File to update.
- * @return True if the update was started. A "true" return value does not guarantee that the
- * update succeeds.
- */
- @CalledByNative
- private boolean updateAsyncFromNative(String filePath) {
- mIsInstall = false;
- return installDownloadedWebApk(filePath);
- }
-
private ApplicationStatus.ApplicationStateListener createApplicationStateListener() {
return new ApplicationStatus.ApplicationStateListener() {
@Override

Powered by Google App Engine
This is Rietveld 408576698