| 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.pm.PackageInfo; | 7 import android.content.pm.PackageInfo; |
| 8 import android.content.pm.PackageManager; | 8 import android.content.pm.PackageManager; |
| 9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
| 10 import android.text.TextUtils; | 10 import android.text.TextUtils; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // | 143 // |
| 144 // If the Web Manifest was not found and an upgrade is not requested, ke
ep on fetching | 144 // If the Web Manifest was not found and an upgrade is not requested, ke
ep on fetching |
| 145 // Web Manifests as the user navigates. For instance, the WebAPK's start
_url might not | 145 // Web Manifests as the user navigates. For instance, the WebAPK's start
_url might not |
| 146 // point to a Web Manifest because start_url redirects to the WebAPK's m
ain page. | 146 // point to a Web Manifest because start_url redirects to the WebAPK's m
ain page. |
| 147 if (gotManifest || needsUpgrade) { | 147 if (gotManifest || needsUpgrade) { |
| 148 destroyFetcher(); | 148 destroyFetcher(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 if (!needsUpgrade) { | 151 if (!needsUpgrade) { |
| 152 if (!mStorage.didPreviousUpdateSucceed()) { | 152 if (!mStorage.didPreviousUpdateSucceed()) { |
| 153 recordUpdate(mStorage, true /* success */, false /* relaxUpdates
*/); | 153 recordUpdate(mStorage, WebApkInstallResult.SUCCESS, false /* rel
axUpdates */); |
| 154 } | 154 } |
| 155 return; | 155 return; |
| 156 } | 156 } |
| 157 | 157 |
| 158 // Set WebAPK update as having failed in case that Chrome is killed prio
r to | 158 // Set WebAPK update as having failed in case that Chrome is killed prio
r to |
| 159 // {@link onBuiltWebApk} being called. | 159 // {@link onBuiltWebApk} being called. |
| 160 recordUpdate(mStorage, false /* success */, false /* relaxUpdates*/); | 160 recordUpdate(mStorage, WebApkInstallResult.FAILURE, false /* relaxUpdate
s*/); |
| 161 | 161 |
| 162 if (fetchedInfo != null) { | 162 if (fetchedInfo != null) { |
| 163 scheduleUpdate(fetchedInfo, bestIconUrl, false /* isManifestStale */
); | 163 scheduleUpdate(fetchedInfo, bestIconUrl, false /* isManifestStale */
); |
| 164 return; | 164 return; |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Tell the server that the our version of the Web Manifest might be sta
le and to ignore | 167 // Tell the server that the our version of the Web Manifest might be sta
le and to ignore |
| 168 // our Web Manifest data if the server's Web Manifest data is newer. Thi
s scenario can | 168 // our Web Manifest data if the server's Web Manifest data is newer. Thi
s scenario can |
| 169 // occur if the Web Manifest is temporarily unreachable. | 169 // occur if the Web Manifest is temporarily unreachable. |
| 170 scheduleUpdate(mInfo, "" /* bestIconUrl */, true /* isManifestStale */); | 170 scheduleUpdate(mInfo, "" /* bestIconUrl */, true /* isManifestStale */); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 if (isShellApkVersionOutOfDate(info)) return true; | 290 if (isShellApkVersionOutOfDate(info)) return true; |
| 291 | 291 |
| 292 return mStorage.shouldCheckForUpdate(); | 292 return mStorage.shouldCheckForUpdate(); |
| 293 } | 293 } |
| 294 | 294 |
| 295 /** | 295 /** |
| 296 * Updates {@link WebappDataStorage} with the time of the latest WebAPK upda
te and whether the | 296 * Updates {@link WebappDataStorage} with the time of the latest WebAPK upda
te and whether the |
| 297 * WebAPK update succeeded. | 297 * WebAPK update succeeded. |
| 298 */ | 298 */ |
| 299 private static void recordUpdate( | 299 private static void recordUpdate( |
| 300 WebappDataStorage storage, boolean success, boolean relaxUpdates) { | 300 WebappDataStorage storage, int webApkInstallResult, boolean relaxUpd
ates) { |
| 301 // Update the request time and result together. It prevents getting a co
rrect request time | 301 // Update the request time and result together. It prevents getting a co
rrect request time |
| 302 // but a result from the previous request. | 302 // but a result from the previous request. |
| 303 storage.updateTimeOfLastWebApkUpdateRequestCompletion(); | 303 storage.updateTimeOfLastWebApkUpdateRequestCompletion(); |
| 304 storage.updateDidLastWebApkUpdateRequestSucceed(success); | 304 storage.updateDidLastWebApkUpdateRequestSucceed( |
| 305 webApkInstallResult == WebApkInstallResult.SUCCESS); |
| 305 storage.setRelaxedUpdates(relaxUpdates); | 306 storage.setRelaxedUpdates(relaxUpdates); |
| 306 } | 307 } |
| 307 | 308 |
| 308 /** | 309 /** |
| 309 * Checks whether the WebAPK needs to be updated. | 310 * Checks whether the WebAPK needs to be updated. |
| 310 * @param info Meta data from WebAPK's Android Manifest. | 311 * @param info Meta data from WebAPK's Android Manifest. |
| 311 * @param fetchedInfo Fetched data for Web Manifest. | 312 * @param fetchedInfo Fetched data for Web Manifest. |
| 312 * @param bestFetchedIconUrl The icon URL in {@link fetchedInfo#iconUrlToMur
mur2HashMap()} best | 313 * @param bestFetchedIconUrl The icon URL in {@link fetchedInfo#iconUrlToMur
mur2HashMap()} best |
| 313 * suited for use as the launcher icon on this dev
ice. | 314 * suited for use as the launcher icon on this dev
ice. |
| 314 */ | 315 */ |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 */ | 353 */ |
| 353 protected boolean urlsMatchIgnoringFragments(String url1, String url2) { | 354 protected boolean urlsMatchIgnoringFragments(String url1, String url2) { |
| 354 return UrlUtilities.urlsMatchIgnoringFragments(url1, url2); | 355 return UrlUtilities.urlsMatchIgnoringFragments(url1, url2); |
| 355 } | 356 } |
| 356 | 357 |
| 357 /** | 358 /** |
| 358 * Called after either a request to update the WebAPK has been sent or the u
pdate process | 359 * Called after either a request to update the WebAPK has been sent or the u
pdate process |
| 359 * fails. | 360 * fails. |
| 360 */ | 361 */ |
| 361 @CalledByNative | 362 @CalledByNative |
| 362 private static void onBuiltWebApk(String id, boolean success, boolean relaxU
pdates) { | 363 private static void onBuiltWebApk(String id, int webApkInstallResult, boolea
n relaxUpdates) { |
| 363 WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataSt
orage(id); | 364 WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataSt
orage(id); |
| 364 if (storage == null) return; | 365 if (storage == null) return; |
| 365 | 366 |
| 366 recordUpdate(storage, success, relaxUpdates); | 367 recordUpdate(storage, webApkInstallResult, relaxUpdates); |
| 367 } | 368 } |
| 368 | 369 |
| 369 private static native void nativeUpdateAsync(String id, String startUrl, Str
ing scope, | 370 private static native void nativeUpdateAsync(String id, String startUrl, Str
ing scope, |
| 370 String name, String shortName, String bestIconUrl, Bitmap bestIcon,
String[] iconUrls, | 371 String name, String shortName, String bestIconUrl, Bitmap bestIcon,
String[] iconUrls, |
| 371 String[] iconHashes, int displayMode, int orientation, long themeCol
or, | 372 String[] iconHashes, int displayMode, int orientation, long themeCol
or, |
| 372 long backgroundColor, String manifestUrl, String webApkPackage, int
webApkVersion, | 373 long backgroundColor, String manifestUrl, String webApkPackage, int
webApkVersion, |
| 373 boolean isManifestStale); | 374 boolean isManifestStale); |
| 374 } | 375 } |
| OLD | NEW |