| Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkUpdateManager.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkUpdateManager.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkUpdateManager.java
|
| index 68943599223d5846481232b1b6c1e9e9712ad2d2..305caf08bed33e5fc296dca69e84b3a04571c591 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkUpdateManager.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkUpdateManager.java
|
| @@ -61,6 +61,9 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| /** The WebApkActivity which owns the WebApkUpdateManager. */
|
| private final WebApkActivity mActivity;
|
|
|
| + /** The WebappDataStorage with cached data about prior update requests. */
|
| + private WebappDataStorage mStorage;
|
| +
|
| /**
|
| * Whether the previous WebAPK update succeeded. True if there has not been any update attempts.
|
| */
|
| @@ -84,8 +87,9 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| }
|
| }
|
|
|
| - public WebApkUpdateManager(WebApkActivity activity) {
|
| + public WebApkUpdateManager(WebApkActivity activity, WebappDataStorage storage) {
|
| mActivity = activity;
|
| + mStorage = storage;
|
| }
|
|
|
| /**
|
| @@ -96,11 +100,9 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| */
|
| public void updateIfNeeded(Tab tab, WebApkInfo info) {
|
| mInfo = info;
|
| + mPreviousUpdateSucceeded = didPreviousUpdateSucceed();
|
|
|
| - WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataStorage(mInfo.id());
|
| - mPreviousUpdateSucceeded = didPreviousUpdateSucceed(storage);
|
| -
|
| - if (!shouldCheckIfWebManifestUpdated(storage, mInfo, mPreviousUpdateSucceeded)) return;
|
| + if (!shouldCheckIfWebManifestUpdated(mInfo, mPreviousUpdateSucceeded)) return;
|
|
|
| mFetcher = buildFetcher();
|
| mFetcher.start(tab, mInfo, this);
|
| @@ -138,8 +140,7 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
|
|
| @Override
|
| public void onGotManifestData(WebApkInfo fetchedInfo, String bestIconUrl) {
|
| - WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataStorage(mInfo.id());
|
| - storage.updateTimeOfLastCheckForUpdatedWebManifest();
|
| + mStorage.updateTimeOfLastCheckForUpdatedWebManifest();
|
|
|
| boolean gotManifest = (fetchedInfo != null);
|
| boolean needsUpgrade = isShellApkVersionOutOfDate(mInfo)
|
| @@ -165,14 +166,14 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
|
|
| if (!needsUpgrade) {
|
| if (!mPreviousUpdateSucceeded) {
|
| - recordUpdate(storage, true);
|
| + recordUpdate(mStorage, true);
|
| }
|
| return;
|
| }
|
|
|
| // Set WebAPK update as having failed in case that Chrome is killed prior to
|
| // {@link onBuiltWebApk} being called.
|
| - recordUpdate(storage, false);
|
| + recordUpdate(mStorage, false);
|
|
|
| if (fetchedInfo != null) {
|
| scheduleUpdate(fetchedInfo, bestIconUrl, false /* isManifestStale */);
|
| @@ -197,9 +198,7 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| * fetched WebApkInfo otherwise.
|
| */
|
| protected void scheduleUpdate(WebApkInfo info, String bestIconUrl, boolean isManifestStale) {
|
| - WebappDataStorage storage =
|
| - WebappRegistry.getInstance().getWebappDataStorage(info.id());
|
| - int numberOfUpdateRequests = storage.getUpdateRequests();
|
| + int numberOfUpdateRequests = mStorage.getUpdateRequests();
|
| boolean forceUpdateNow = numberOfUpdateRequests >= MAX_UPDATE_ATTEMPTS;
|
| if (!isInForeground() || forceUpdateNow) {
|
| updateAsync(info, bestIconUrl, isManifestStale);
|
| @@ -207,7 +206,7 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| return;
|
| }
|
|
|
| - storage.recordUpdateRequest();
|
| + mStorage.recordUpdateRequest();
|
| // The {@link numberOfUpdateRequests} can never exceed 2 here (otherwise we'll have taken
|
| // the branch above and have returned before reaching this statement).
|
| WebApkUma.recordUpdateRequestQueued(numberOfUpdateRequests);
|
| @@ -225,8 +224,7 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| */
|
| private void updateAsync(WebApkInfo info, String bestIconUrl, boolean isManifestStale) {
|
| updateAsyncImpl(info, bestIconUrl, isManifestStale);
|
| - WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataStorage(mInfo.id());
|
| - storage.resetUpdateRequests();
|
| + mStorage.resetUpdateRequests();
|
| mPendingUpdate = null;
|
| }
|
|
|
| @@ -289,13 +287,13 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| * Returns whether the previous WebAPK update attempt succeeded. Returns true if there has not
|
| * been any update attempts.
|
| */
|
| - private static boolean didPreviousUpdateSucceed(WebappDataStorage storage) {
|
| - long lastUpdateCompletionTime = storage.getLastWebApkUpdateRequestCompletionTime();
|
| + private boolean didPreviousUpdateSucceed() {
|
| + long lastUpdateCompletionTime = mStorage.getLastWebApkUpdateRequestCompletionTime();
|
| if (lastUpdateCompletionTime == WebappDataStorage.LAST_USED_INVALID
|
| || lastUpdateCompletionTime == WebappDataStorage.LAST_USED_UNSET) {
|
| return true;
|
| }
|
| - return storage.getDidLastWebApkUpdateRequestSucceed();
|
| + return mStorage.getDidLastWebApkUpdateRequestSucceed();
|
| }
|
|
|
| /**
|
| @@ -308,13 +306,12 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| /**
|
| * Returns whether the Web Manifest should be refetched to check whether it has been updated.
|
| * TODO: Make this method static once there is a static global clock class.
|
| - * @param storage WebappDataStorage with the WebAPK's cached data.
|
| * @param info Meta data from WebAPK's Android Manifest.
|
| * @param previousUpdateSucceeded Whether the previous update attempt succeeded.
|
| * True if there has not been any update attempts.
|
| */
|
| - private boolean shouldCheckIfWebManifestUpdated(
|
| - WebappDataStorage storage, WebApkInfo info, boolean previousUpdateSucceeded) {
|
| + private boolean shouldCheckIfWebManifestUpdated(WebApkInfo info,
|
| + boolean previousUpdateSucceeded) {
|
| if (!sUpdatesEnabled) {
|
| return false;
|
| }
|
| @@ -329,11 +326,11 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| if (isShellApkVersionOutOfDate(info)) return true;
|
|
|
| long now = currentTimeMillis();
|
| - long sinceLastCheckDurationMs = now - storage.getLastCheckForWebManifestUpdateTime();
|
| + long sinceLastCheckDurationMs = now - mStorage.getLastCheckForWebManifestUpdateTime();
|
| if (sinceLastCheckDurationMs >= FULL_CHECK_UPDATE_INTERVAL) return true;
|
|
|
| long sinceLastUpdateRequestDurationMs =
|
| - now - storage.getLastWebApkUpdateRequestCompletionTime();
|
| + now - mStorage.getLastWebApkUpdateRequestCompletionTime();
|
| return sinceLastUpdateRequestDurationMs >= RETRY_UPDATE_DURATION
|
| && !previousUpdateSucceeded;
|
| }
|
| @@ -405,6 +402,8 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| @CalledByNative
|
| private static void onBuiltWebApk(String id, boolean success) {
|
| WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataStorage(id);
|
| + if (storage == null) return;
|
| +
|
| recordUpdate(storage, success);
|
| }
|
|
|
|
|