| OLD | NEW |
| 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.Intent; | 8 import android.content.Intent; |
| 9 import android.content.pm.PackageManager; | 9 import android.content.pm.PackageManager; |
| 10 import android.net.Uri; | 10 import android.net.Uri; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 113 } |
| 114 | 114 |
| 115 // Check whether the WebAPK package is already installed. The WebAPK may
have been installed | 115 // Check whether the WebAPK package is already installed. The WebAPK may
have been installed |
| 116 // by another Chrome version (e.g. Chrome Dev). We have to do this check
because the Play | 116 // by another Chrome version (e.g. Chrome Dev). We have to do this check
because the Play |
| 117 // install API fails silently if the package is already installed. | 117 // install API fails silently if the package is already installed. |
| 118 if (isWebApkInstalled(packageName)) { | 118 if (isWebApkInstalled(packageName)) { |
| 119 notify(WebApkInstallResult.SUCCESS); | 119 notify(WebApkInstallResult.SUCCESS); |
| 120 return; | 120 return; |
| 121 } | 121 } |
| 122 | 122 |
| 123 Callback<Boolean> callback = new Callback<Boolean>() { | 123 Callback<Integer> callback = new Callback<Integer>() { |
| 124 @Override | 124 @Override |
| 125 public void onResult(Boolean success) { | 125 public void onResult(Integer result) { |
| 126 // TODO(pkotwicz): Send WebApkInstallResult.PROBABLE_FAILURE res
ult if | 126 WebApkInstaller.this.notify(result); |
| 127 // install timed out. | |
| 128 WebApkInstaller.this.notify( | |
| 129 success ? WebApkInstallResult.SUCCESS : WebApkInstallRes
ult.FAILURE); | |
| 130 } | 127 } |
| 131 }; | 128 }; |
| 132 mGooglePlayWebApkInstallDelegate.installAsync( | 129 mGooglePlayWebApkInstallDelegate.installAsync( |
| 133 packageName, version, title, token, url, callback); | 130 packageName, version, title, token, url, callback); |
| 134 } | 131 } |
| 135 | 132 |
| 136 private void notify(@WebApkInstallResult.WebApkInstallResultEnum int result)
{ | 133 private void notify(@WebApkInstallResult.WebApkInstallResultEnum int result)
{ |
| 137 if (mListener != null) { | 134 if (mListener != null) { |
| 138 ApplicationStatus.unregisterApplicationStateListener(mListener); | 135 ApplicationStatus.unregisterApplicationStateListener(mListener); |
| 139 mListener = null; | 136 mListener = null; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 * @param url The start URL of the WebAPK to install. | 170 * @param url The start URL of the WebAPK to install. |
| 174 */ | 171 */ |
| 175 @CalledByNative | 172 @CalledByNative |
| 176 private void updateAsyncFromGooglePlay( | 173 private void updateAsyncFromGooglePlay( |
| 177 String packageName, int version, String title, String token, String
url) { | 174 String packageName, int version, String title, String token, String
url) { |
| 178 if (mGooglePlayWebApkInstallDelegate == null) { | 175 if (mGooglePlayWebApkInstallDelegate == null) { |
| 179 notify(WebApkInstallResult.FAILURE); | 176 notify(WebApkInstallResult.FAILURE); |
| 180 return; | 177 return; |
| 181 } | 178 } |
| 182 | 179 |
| 183 Callback<Boolean> callback = new Callback<Boolean>() { | 180 Callback<Integer> callback = new Callback<Integer>() { |
| 184 @Override | 181 @Override |
| 185 public void onResult(Boolean success) { | 182 public void onResult(Integer result) { |
| 186 // TODO(pkotwicz): Send WebApkInstallResult.PROBABLE_FAILURE res
ult if | 183 WebApkInstaller.this.notify(result); |
| 187 // update timed out. | |
| 188 WebApkInstaller.this.notify( | |
| 189 success ? WebApkInstallResult.SUCCESS : WebApkInstallRes
ult.FAILURE); | |
| 190 } | 184 } |
| 191 }; | 185 }; |
| 192 mGooglePlayWebApkInstallDelegate.installAsync( | 186 mGooglePlayWebApkInstallDelegate.installAsync( |
| 193 packageName, version, title, token, url, callback); | 187 packageName, version, title, token, url, callback); |
| 194 } | 188 } |
| 195 | 189 |
| 196 /** | 190 /** |
| 197 * Sends intent to Android to show prompt to install or update downloaded We
bAPK. | 191 * Sends intent to Android to show prompt to install or update downloaded We
bAPK. |
| 198 * @param filePath File to install. | 192 * @param filePath File to install. |
| 199 */ | 193 */ |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 245 } |
| 252 | 246 |
| 253 private boolean isWebApkInstalled(String packageName) { | 247 private boolean isWebApkInstalled(String packageName) { |
| 254 PackageManager packageManager = ContextUtils.getApplicationContext().get
PackageManager(); | 248 PackageManager packageManager = ContextUtils.getApplicationContext().get
PackageManager(); |
| 255 return InstallerDelegate.isInstalled(packageManager, packageName); | 249 return InstallerDelegate.isInstalled(packageManager, packageName); |
| 256 } | 250 } |
| 257 | 251 |
| 258 private native void nativeOnInstallFinished( | 252 private native void nativeOnInstallFinished( |
| 259 long nativeWebApkInstaller, @WebApkInstallResult.WebApkInstallResult
Enum int result); | 253 long nativeWebApkInstaller, @WebApkInstallResult.WebApkInstallResult
Enum int result); |
| 260 } | 254 } |
| OLD | NEW |