| 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 3c4bd649acc5159c4475ebd082fb6d99abd44b54..b3098ca7f5a74b29a019b6a6116ba8d5d42d8439 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
|
| @@ -25,8 +25,8 @@ import java.util.Map;
|
| import java.util.concurrent.TimeUnit;
|
|
|
| /**
|
| - * WebApkUpdateManager manages when to check for updates to the WebAPK's Web Manifest, and sends
|
| - * an update request to the WebAPK Server when an update is needed.
|
| + * WebApkUpdateManager manages when to check for updates to the WebAPK's Web Manifest, and sends an
|
| + * update request to the WebAPK Server when an update is needed.
|
| */
|
| public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| private static final String TAG = "WebApkUpdateManager";
|
| @@ -35,14 +35,14 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| public static final long FULL_CHECK_UPDATE_INTERVAL = TimeUnit.DAYS.toMillis(3L);
|
|
|
| /**
|
| - * Number of milliseconds to wait before re-requesting an updated WebAPK from the WebAPK
|
| - * server if the previous update attempt failed.
|
| + * Number of milliseconds to wait before re-requesting an updated WebAPK from the WebAPK server
|
| + * if the previous update attempt failed.
|
| */
|
| public static final long RETRY_UPDATE_DURATION = TimeUnit.HOURS.toMillis(12L);
|
|
|
| /**
|
| - * Number of times to wait for updating the WebAPK after it is moved to the background prior
|
| - * to doing the update while the WebAPK is in the foreground.
|
| + * Number of times to wait for updating the WebAPK after it is moved to the background prior to
|
| + * doing the update while the WebAPK is in the foreground.
|
| */
|
| private static final int MAX_UPDATE_ATTEMPTS = 3;
|
|
|
| @@ -71,12 +71,12 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| */
|
| private static class PendingUpdate {
|
| public WebApkInfo mUpdateInfo;
|
| - public String mBestIconUrl;
|
| + public String mBestPrimaryIconUrl;
|
| public boolean mIsManifestStale;
|
|
|
| - public PendingUpdate(WebApkInfo info, String bestIconUrl, boolean isManifestStale) {
|
| + public PendingUpdate(WebApkInfo info, String bestPrimaryIconUrl, boolean isManifestStale) {
|
| mUpdateInfo = info;
|
| - mBestIconUrl = bestIconUrl;
|
| + mBestPrimaryIconUrl = bestPrimaryIconUrl;
|
| mIsManifestStale = isManifestStale;
|
| }
|
| }
|
| @@ -86,9 +86,10 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| }
|
|
|
| /**
|
| - * Checks whether the WebAPK's Web Manifest has changed. Requests an updated WebAPK if the
|
| - * Web Manifest has changed. Skips the check if the check was done recently.
|
| - * @param tab The tab of the WebAPK.
|
| + * Checks whether the WebAPK's Web Manifest has changed. Requests an updated WebAPK if the Web
|
| + * Manifest has changed. Skips the check if the check was done recently.
|
| + *
|
| + * @param tab The tab of the WebAPK.
|
| * @param info The WebApkInfo of the WebAPK.
|
| */
|
| public void updateIfNeeded(Tab tab, WebApkInfo info) {
|
| @@ -105,11 +106,12 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
|
|
| /**
|
| * It sends the pending update request to the WebAPK server if exits.
|
| + *
|
| * @return Whether a pending update request is sent to the WebAPK server.
|
| */
|
| public boolean requestPendingUpdate() {
|
| if (mPendingUpdate != null) {
|
| - updateAsync(mPendingUpdate.mUpdateInfo, mPendingUpdate.mBestIconUrl,
|
| + updateAsync(mPendingUpdate.mUpdateInfo, mPendingUpdate.mBestPrimaryIconUrl,
|
| mPendingUpdate.mIsManifestStale);
|
| return true;
|
| }
|
| @@ -130,13 +132,13 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| }
|
|
|
| @Override
|
| - public void onGotManifestData(WebApkInfo fetchedInfo, String bestIconUrl) {
|
| + public void onGotManifestData(WebApkInfo fetchedInfo, String bestPrimaryIconUrl) {
|
| WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataStorage(mInfo.id());
|
| storage.updateTimeOfLastCheckForUpdatedWebManifest();
|
|
|
| boolean gotManifest = (fetchedInfo != null);
|
| boolean needsUpgrade = isShellApkVersionOutOfDate(mInfo)
|
| - || (gotManifest && needsUpdate(mInfo, fetchedInfo, bestIconUrl));
|
| + || (gotManifest && needsUpdate(mInfo, fetchedInfo, bestPrimaryIconUrl));
|
| Log.v(TAG, "Got Manifest: " + gotManifest);
|
| Log.v(TAG, "WebAPK upgrade needed: " + needsUpgrade);
|
|
|
| @@ -144,10 +146,10 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| // Manifests as the user navigates to avoid sending multiple WebAPK update requests. In
|
| // particular:
|
| // - A WebAPK update request on the initial load because the Shell APK version is out of
|
| - // date.
|
| + // date.
|
| // - A second WebAPK update request once the user navigates to a page which points to the
|
| - // correct Web Manifest URL because the Web Manifest has been updated by the Web
|
| - // developer.
|
| + // correct Web Manifest URL because the Web Manifest has been updated by the Web
|
| + // developer.
|
| //
|
| // If the Web Manifest was not found and an upgrade is not requested, keep on fetching
|
| // Web Manifests as the user navigates. For instance, the WebAPK's start_url might not
|
| @@ -168,7 +170,7 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| recordUpdate(storage, false);
|
|
|
| if (fetchedInfo != null) {
|
| - scheduleUpdate(fetchedInfo, bestIconUrl, false /* isManifestStale */);
|
| + scheduleUpdate(fetchedInfo, bestPrimaryIconUrl, false /* isManifestStale */);
|
| return;
|
| }
|
|
|
| @@ -189,13 +191,13 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| * Sends update request to WebAPK Server if the WebAPK is running in the background; caches the
|
| * fetched WebApkInfo otherwise.
|
| */
|
| - protected void scheduleUpdate(WebApkInfo info, String bestIconUrl, boolean isManifestStale) {
|
| - WebappDataStorage storage =
|
| - WebappRegistry.getInstance().getWebappDataStorage(info.id());
|
| + protected void scheduleUpdate(WebApkInfo info, String bestPrimaryIconUrl,
|
| + boolean isManifestStale) {
|
| + WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataStorage(info.id());
|
| int numberOfUpdateRequests = storage.getUpdateRequests();
|
| - boolean forceUpdateNow = numberOfUpdateRequests >= MAX_UPDATE_ATTEMPTS;
|
| + boolean forceUpdateNow = numberOfUpdateRequests >= MAX_UPDATE_ATTEMPTS;
|
| if (!isInForeground() || forceUpdateNow) {
|
| - updateAsync(info, bestIconUrl, isManifestStale);
|
| + updateAsync(info, bestPrimaryIconUrl, isManifestStale);
|
| WebApkUma.recordUpdateRequestSent(WebApkUma.UPDATE_REQUEST_SENT_FIRST_TRY);
|
| return;
|
| }
|
| @@ -204,7 +206,7 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| // 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);
|
| - mPendingUpdate = new PendingUpdate(info, bestIconUrl, isManifestStale);
|
| + mPendingUpdate = new PendingUpdate(info, bestPrimaryIconUrl, isManifestStale);
|
| }
|
|
|
| /** Returns whether the associated WebApkActivity is running in foreground. */
|
| @@ -216,8 +218,8 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| /**
|
| * Sends update request to the WebAPK Server and cleanup.
|
| */
|
| - private void updateAsync(WebApkInfo info, String bestIconUrl, boolean isManifestStale) {
|
| - updateAsyncImpl(info, bestIconUrl, isManifestStale);
|
| + private void updateAsync(WebApkInfo info, String bestPrimaryIconUrl, boolean isManifestStale) {
|
| + updateAsyncImpl(info, bestPrimaryIconUrl, isManifestStale);
|
| WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataStorage(mInfo.id());
|
| storage.resetUpdateRequests();
|
| mPendingUpdate = null;
|
| @@ -226,7 +228,8 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| /**
|
| * Sends update request to the WebAPK Server.
|
| */
|
| - protected void updateAsyncImpl(WebApkInfo info, String bestIconUrl, boolean isManifestStale) {
|
| + protected void updateAsyncImpl(WebApkInfo info, String bestPrimaryIconUrl,
|
| + boolean isManifestStale) {
|
| if (info == null) {
|
| return;
|
| }
|
| @@ -243,7 +246,8 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| i++;
|
| }
|
| nativeUpdateAsync(info.id(), info.manifestStartUrl(), info.scopeUri().toString(),
|
| - info.name(), info.shortName(), bestIconUrl, info.icon(), iconUrls, iconHashes,
|
| + info.name(), info.shortName(), bestPrimaryIconUrl, info.icon(), iconUrls,
|
| + iconHashes,
|
| info.displayMode(), info.orientation(), info.themeColor(), info.backgroundColor(),
|
| info.manifestUrl(), info.webApkPackageName(), versionCode, isManifestStale);
|
| }
|
| @@ -268,8 +272,8 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| */
|
| private int readVersionCodeFromAndroidManifest(String webApkPackage) {
|
| try {
|
| - PackageManager packageManager =
|
| - ContextUtils.getApplicationContext().getPackageManager();
|
| + PackageManager packageManager = ContextUtils.getApplicationContext()
|
| + .getPackageManager();
|
| PackageInfo packageInfo = packageManager.getPackageInfo(webApkPackage, 0);
|
| return packageInfo.versionCode;
|
| } catch (PackageManager.NameNotFoundException e) {
|
| @@ -301,15 +305,16 @@ 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.
|
| + * @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) {
|
| if (CommandLine.getInstance().hasSwitch(
|
| - ChromeSwitches.CHECK_FOR_WEB_MANIFEST_UPDATE_ON_STARTUP)) {
|
| + ChromeSwitches.CHECK_FOR_WEB_MANIFEST_UPDATE_ON_STARTUP)) {
|
| return true;
|
| }
|
|
|
| @@ -321,8 +326,8 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| long sinceLastCheckDurationMs = now - storage.getLastCheckForWebManifestUpdateTime();
|
| if (sinceLastCheckDurationMs >= FULL_CHECK_UPDATE_INTERVAL) return true;
|
|
|
| - long sinceLastUpdateRequestDurationMs =
|
| - now - storage.getLastWebApkUpdateRequestCompletionTime();
|
| + long sinceLastUpdateRequestDurationMs = now
|
| + - storage.getLastWebApkUpdateRequestCompletionTime();
|
| return sinceLastUpdateRequestDurationMs >= RETRY_UPDATE_DURATION
|
| && !previousUpdateSucceeded;
|
| }
|
| @@ -340,23 +345,26 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
|
|
| /**
|
| * Checks whether the WebAPK needs to be updated.
|
| - * @param info Meta data from WebAPK's Android Manifest.
|
| - * @param fetchedInfo Fetched data for Web Manifest.
|
| + *
|
| + * @param info Meta data from WebAPK's Android Manifest.
|
| + * @param fetchedInfo Fetched data for Web Manifest.
|
| * @param bestFetchedIconUrl The icon URL in {@link fetchedInfo#iconUrlToMurmur2HashMap()} best
|
| - * suited for use as the launcher icon on this device.
|
| + * suited for use as the launcher icon on this device.
|
| */
|
| - private boolean needsUpdate(WebApkInfo info, WebApkInfo fetchedInfo, String bestIconUrl) {
|
| + private boolean needsUpdate(WebApkInfo info, WebApkInfo fetchedInfo,
|
| + String bestPrimaryIconUrl) {
|
| // We should have computed the Murmur2 hash for the bitmap at the best icon URL for
|
| // {@link fetchedInfo} (but not the other icon URLs.)
|
| - String fetchedBestIconMurmur2Hash = fetchedInfo.iconUrlToMurmur2HashMap().get(bestIconUrl);
|
| - String bestIconMurmur2Hash =
|
| - findMurmur2HashForUrlIgnoringFragment(mInfo.iconUrlToMurmur2HashMap(), bestIconUrl);
|
| + String fetchedBestPrimaryIconMurmur2Hash = fetchedInfo.iconUrlToMurmur2HashMap()
|
| + .get(bestPrimaryIconUrl);
|
| + String bestPrimaryIconMurmur2Hash = findMurmur2HashForUrlIgnoringFragment(
|
| + mInfo.iconUrlToMurmur2HashMap(), bestPrimaryIconUrl);
|
|
|
| - return !TextUtils.equals(bestIconMurmur2Hash, fetchedBestIconMurmur2Hash)
|
| + return !TextUtils.equals(bestPrimaryIconMurmur2Hash, fetchedBestPrimaryIconMurmur2Hash)
|
| || !urlsMatchIgnoringFragments(
|
| - mInfo.scopeUri().toString(), fetchedInfo.scopeUri().toString())
|
| + mInfo.scopeUri().toString(), fetchedInfo.scopeUri().toString())
|
| || !urlsMatchIgnoringFragments(
|
| - mInfo.manifestStartUrl(), fetchedInfo.manifestStartUrl())
|
| + mInfo.manifestStartUrl(), fetchedInfo.manifestStartUrl())
|
| || !TextUtils.equals(mInfo.shortName(), fetchedInfo.shortName())
|
| || !TextUtils.equals(mInfo.name(), fetchedInfo.name())
|
| || mInfo.backgroundColor() != fetchedInfo.backgroundColor()
|
| @@ -388,8 +396,7 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| }
|
|
|
| /**
|
| - * Called after either a request to update the WebAPK has been sent or the update process
|
| - * fails.
|
| + * Called after either a request to update the WebAPK has been sent or the update process fails.
|
| */
|
| @CalledByNative
|
| private static void onBuiltWebApk(String id, boolean success) {
|
| @@ -398,7 +405,8 @@ public class WebApkUpdateManager implements WebApkUpdateDataFetcher.Observer {
|
| }
|
|
|
| private static native void nativeUpdateAsync(String id, String startUrl, String scope,
|
| - String name, String shortName, String bestIconUrl, Bitmap bestIcon, String[] iconUrls,
|
| + String name, String shortName, String bestPrimaryIconUrl, Bitmap bestPrimaryIcon,
|
| + String[] iconUrls,
|
| String[] iconHashes, int displayMode, int orientation, long themeColor,
|
| long backgroundColor, String manifestUrl, String webApkPackage, int webApkVersion,
|
| boolean isManifestStale);
|
|
|