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

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: Don't use play install in webapk_installer_unittest. 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..6ed8b9e2ead1b877e30e3784cb59422fae941dfe 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;
+
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() {
+ return sGooglePlayWebApkInstallDelegate != null;
+ }
+
+ @CalledByNative
private void destroy() {
- ApplicationStatus.unregisterApplicationStateListener(mListener);
+ if (mListener != null) {
+ ApplicationStatus.unregisterApplicationStateListener(mListener);
+ }
+ mListener = null;
mNativePointer = 0;
}
@@ -86,7 +109,59 @@ 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.
+ */
+ @CalledByNative
+ private void installWebApkFromPlayStoreAsyncAndMonitorInstallation(String packageName,
+ int version, String title, String token) {
pkotwicz 2016/12/02 22:27:04 Shouldn't this method return a boolean? So that th
Xi Han 2016/12/05 17:27:54 Done.
+ if (sGooglePlayWebApkInstallDelegate == null) return;
+
+ Callback<Boolean> callback = new Callback<Boolean>() {
+ @Override
+ public void onResult(Boolean success) {
+ if (mNativePointer != 0) {
+ nativeOnInstallFinished(mNativePointer, success);
+ }
+ }
+ };
+ 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.
+ */
+ @CalledByNative
+ private void updateAsyncFromPlayStore(String packageName, int version, String title,
+ String token) {
pkotwicz 2016/12/02 22:27:04 Shouldn't this method return a boolean? So that th
Xi Han 2016/12/05 17:27:54 Done.
+ if (sGooglePlayWebApkInstallDelegate == null) return;
+
+ // TODO(hanxi):crbug.com/634499. Adds a callback to show an infobar after the update
+ // succeeded.
+ sGooglePlayWebApkInstallDelegate.installAsync(packageName, version, title, token, null);
pkotwicz 2016/12/02 22:52:21 You should return the return value of GooglePlayWe
Xi Han 2016/12/05 17:27:54 Done.
+ }
+
+ /**
+ * Sends intent to Android to show prompt and install downloaded WebAPK.
* @param filePath File to install.
*/
private boolean installDownloadedWebApk(String filePath) {
@@ -132,18 +207,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