Chromium Code Reviews| 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 894ed3983d37215b81754834b52902fe17670762..e97cb03287bd503813d8e9b8e3fbea4edf204837 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 |
| @@ -41,8 +41,8 @@ public class WebApkInstaller { |
| /** Monitors installation progress. */ |
| private InstallerDelegate mInstallTask; |
| - /** Indicates whether to install or update a WebAPK. */ |
| - private boolean mIsInstall; |
| + /** Whether a homescreen shortcut should be added on success. */ |
| + private boolean mAddHomescreenShortcut; |
| /** Weak pointer to the native WebApkInstaller. */ |
| private long mNativePointer; |
| @@ -75,16 +75,13 @@ public class WebApkInstaller { |
| } |
| /** |
| - * Installs a WebAPK and monitors the installation process. |
| + * Installs WebAPK via "unsigned sources" using APK downloaded to {@link filePath}. |
| * @param filePath File to install. |
| * @param packageName Package name to install WebAPK at. |
| - * @return True if the install was started. A "true" return value does not guarantee that the |
| - * install succeeds. |
| */ |
| @CalledByNative |
| - private boolean installAsyncAndMonitorInstallationFromNative( |
| - String filePath, String packageName) { |
| - mIsInstall = true; |
| + private void installDownloadedWebApkAsync(String filePath, String packageName) { |
| + mAddHomescreenShortcut = true; |
| mWebApkPackageName = packageName; |
| // Start monitoring the installation. |
| @@ -96,7 +93,9 @@ public class WebApkInstaller { |
| mListener = createApplicationStateListener(); |
| ApplicationStatus.registerApplicationStateListener(mListener); |
| - return installDownloadedWebApk(filePath); |
| + if (!installOrUpdateDownloadedWebApkImpl(filePath)) { |
|
dominickn
2017/03/13 23:13:37
Nit: can you add a comment explaining that we only
|
| + notify(false); |
| + } |
| } |
| /** |
| @@ -134,21 +133,29 @@ public class WebApkInstaller { |
| } |
| private void notify(boolean success) { |
| + if (mListener != null) { |
| + ApplicationStatus.unregisterApplicationStateListener(mListener); |
| + mListener = null; |
| + } |
| + mInstallTask = null; |
| if (mNativePointer != 0) { |
| nativeOnInstallFinished(mNativePointer, success); |
| } |
| + if (mAddHomescreenShortcut && success) { |
| + ShortcutHelper.addWebApkShortcut( |
| + ContextUtils.getApplicationContext(), mWebApkPackageName); |
| + } |
| } |
| /** |
| - * Updates a WebAPK. |
| + * Updates WebAPK via "unsigned sources" using APK downloaded to {@link filePath}. |
| * @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 void updateUsingDownloadedWebApkAsync(String filePath) { |
| + // We can't use InstallerDelegate to detect whether updates are successful. If there was no |
| + // error in delivering the intent, assume that the update is successful. |
| + notify(installOrUpdateDownloadedWebApkImpl(filePath)); |
| } |
| /** |
| @@ -178,12 +185,10 @@ public class WebApkInstaller { |
| } |
| /** |
| - * Sends intent to Android to show prompt and install downloaded WebAPK. |
| + * Sends intent to Android to show prompt to install or update downloaded WebAPK. |
| * @param filePath File to install. |
| */ |
| - private boolean installDownloadedWebApk(String filePath) { |
| - // TODO(pkotwicz|hanxi): For Chrome Stable figure out a different way of installing |
| - // WebAPKs which does not involve enabling "installation from Unsigned Sources". |
| + private boolean installOrUpdateDownloadedWebApkImpl(String filePath) { |
| Context context = ContextUtils.getApplicationContext(); |
| Intent intent; |
| File pathToInstall = new File(filePath); |
| @@ -207,23 +212,11 @@ public class WebApkInstaller { |
| @Override |
| public void onInstallFinished(InstallerDelegate task, boolean success) { |
| if (mInstallTask != task) return; |
| - onInstallFinishedInternal(success); |
| + WebApkInstaller.this.notify(success); |
| } |
| }; |
| } |
| - private void onInstallFinishedInternal(boolean success) { |
| - ApplicationStatus.unregisterApplicationStateListener(mListener); |
| - mInstallTask = null; |
| - if (mNativePointer != 0) { |
| - nativeOnInstallFinished(mNativePointer, success); |
| - } |
| - if (success && mIsInstall) { |
| - ShortcutHelper.addWebApkShortcut(ContextUtils.getApplicationContext(), |
| - mWebApkPackageName); |
| - } |
| - } |
| - |
| private ApplicationStatus.ApplicationStateListener createApplicationStateListener() { |
| return new ApplicationStatus.ApplicationStateListener() { |
| @Override |
| @@ -238,7 +231,7 @@ public class WebApkInstaller { |
| */ |
| if (newState == ApplicationState.HAS_RUNNING_ACTIVITIES |
| && !isWebApkInstalled(mWebApkPackageName)) { |
| - onInstallFinishedInternal(false); |
| + WebApkInstaller.this.notify(false); |
| return; |
| } |
| } |