Skip to content

Commit

Permalink
[Android WebAPK] Delete "WebAPK update request" file if update is no …
Browse files Browse the repository at this point in the history
…longer needed

BUG=713655

Change-Id: Ie0d98bb91de833328472f4455661665013ff0296
Reviewed-on: https://chromium-review.googlesource.com/698953
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: Dominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506586}
  • Loading branch information
pkotwicz authored and Commit Bot committed Oct 5, 2017
1 parent 3069a57 commit 3b23851
Showing 1 changed file with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void onGotManifestData(WebApkInfo fetchedInfo, String primaryIconUrl,

if (!needsUpgrade) {
if (!mStorage.didPreviousUpdateSucceed()) {
recordUpdate(WebApkInstallResult.SUCCESS, false /* relaxUpdates */);
onFinishedUpdate(WebApkInstallResult.SUCCESS, false /* relaxUpdates */);
}
return;
}
Expand Down Expand Up @@ -199,18 +199,12 @@ protected void buildUpdateRequestAndSchedule(final WebApkInfo info, String prima
}

final String updateRequestPath = mStorage.createAndSetUpdateRequestFilePath(info);
Callback<Boolean> callback = new Callback<Boolean>() {
@Override
public void onResult(Boolean success) {
if (!success) {
recordUpdate(WebApkInstallResult.FAILURE, false /* relaxUpdates*/);
mStorage.updateLastRequestedShellApkVersion(
WebApkVersion.CURRENT_SHELL_APK_VERSION);
mStorage.deletePendingUpdateRequestFile();
return;
}
scheduleUpdate(updateRequestPath);
Callback<Boolean> callback = (success) -> {
if (!success) {
onFinishedUpdate(WebApkInstallResult.FAILURE, false /* relaxUpdates*/);
return;
}
scheduleUpdate(updateRequestPath);
};
nativeStoreWebApkUpdateRequestToFile(updateRequestPath, info.manifestStartUrl(),
info.scopeUri().toString(), info.name(), info.shortName(), primaryIconUrl,
Expand Down Expand Up @@ -259,15 +253,8 @@ private void updateAsync(String updateRequestPath) {
* Sends update request to the WebAPK Server.
*/
protected void updateAsyncImpl(String updateRequestPath) {
WebApkUpdateCallback callback = new WebApkUpdateCallback() {
@Override
public void onResultFromNative(@WebApkInstallResult int result, boolean relaxUpdates) {
recordUpdate(result, relaxUpdates);
mStorage.updateLastRequestedShellApkVersion(
WebApkVersion.CURRENT_SHELL_APK_VERSION);
mStorage.deletePendingUpdateRequestFile();
}
};
WebApkUpdateCallback callback =
(result, relaxUpdates) -> onFinishedUpdate(result, relaxUpdates);
nativeUpdateWebApkFromFile(updateRequestPath, callback);
}

Expand Down Expand Up @@ -334,14 +321,24 @@ private boolean shouldCheckIfWebManifestUpdated(WebApkInfo info) {

/**
* Updates {@link WebappDataStorage} with the time of the latest WebAPK update and whether the
* WebAPK update succeeded.
* WebAPK update succeeded. Also updates the last requested "shell APK version".
*/
private void recordUpdate(@WebApkInstallResult int result, boolean relaxUpdates) {
// Update the request time and result together. It prevents getting a correct request time
// but a result from the previous request.
mStorage.updateTimeOfLastWebApkUpdateRequestCompletion();
mStorage.updateDidLastWebApkUpdateRequestSucceed(result == WebApkInstallResult.SUCCESS);
mStorage.setRelaxedUpdates(relaxUpdates);
mStorage.updateLastRequestedShellApkVersion(WebApkVersion.CURRENT_SHELL_APK_VERSION);
}

/**
* Callback for when WebAPK update finishes or succeeds. Unlike {@link #recordUpdate()}
* cannot be called while update is in progress.
*/
private void onFinishedUpdate(@WebApkInstallResult int result, boolean relaxUpdates) {
recordUpdate(result, relaxUpdates);
mStorage.deletePendingUpdateRequestFile();
}

/**
Expand Down

0 comments on commit 3b23851

Please sign in to comment.