| Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java
|
| index ecba3522f26ecb8349a1665177d1461d8cc88110..c8b2e8ddc10a190f4aa2b84d92012d6f199e749b 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java
|
| @@ -84,9 +84,10 @@
|
| // The default shell Apk version of WebAPKs.
|
| static final int DEFAULT_SHELL_APK_VERSION = 1;
|
|
|
| - // Invalid constants for timestamps and URLs. '0' is used as the invalid timestamp as
|
| - // WebappRegistry and WebApkUpdateManager assume that timestamps are always valid.
|
| - static final long TIMESTAMP_INVALID = 0;
|
| + // Unset/invalid constants for last used times and URLs. 0 is used as the null last used time as
|
| + // WebappRegistry assumes that this is always a valid timestamp.
|
| + static final long LAST_USED_UNSET = 0;
|
| + static final long LAST_USED_INVALID = -1;
|
| static final String URL_INVALID = "";
|
| static final int VERSION_INVALID = 0;
|
|
|
| @@ -138,8 +139,14 @@
|
| * Opens an instance of WebappDataStorage for the web app specified.
|
| * @param webappId The ID of the web app.
|
| */
|
| - static WebappDataStorage open(String webappId) {
|
| - return sFactory.create(webappId);
|
| + static WebappDataStorage open(final String webappId) {
|
| + final WebappDataStorage storage = sFactory.create(webappId);
|
| + if (storage.getLastUsedTime() == LAST_USED_INVALID) {
|
| + // If the last used time is invalid then ensure that there is no data in the
|
| + // WebappDataStorage which needs to be cleaned up.
|
| + assert storage.isEmpty();
|
| + }
|
| + return storage;
|
| }
|
|
|
| /**
|
| @@ -314,7 +321,10 @@
|
| void clearHistory() {
|
| SharedPreferences.Editor editor = mPreferences.edit();
|
|
|
| - editor.remove(KEY_LAST_USED);
|
| + // The last used time is set to 0 to ensure that a valid value is always present.
|
| + // If the web app is not launched prior to the next cleanup, then its remaining data will be
|
| + // removed. Otherwise, the next launch from home screen will update the last used time.
|
| + editor.putLong(KEY_LAST_USED, LAST_USED_UNSET);
|
| editor.remove(KEY_URL);
|
| editor.remove(KEY_SCOPE);
|
| editor.remove(KEY_LAST_CHECK_WEB_MANIFEST_UPDATE_TIME);
|
| @@ -354,7 +364,7 @@
|
| * Returns the last used time of this object, or -1 if it is not stored.
|
| */
|
| public long getLastUsedTime() {
|
| - return mPreferences.getLong(KEY_LAST_USED, TIMESTAMP_INVALID);
|
| + return mPreferences.getLong(KEY_LAST_USED, LAST_USED_INVALID);
|
| }
|
|
|
| /**
|
| @@ -396,7 +406,7 @@
|
| * updated. This time needs to be set when the WebAPK is registered.
|
| */
|
| private long getLastCheckForWebManifestUpdateTime() {
|
| - return mPreferences.getLong(KEY_LAST_CHECK_WEB_MANIFEST_UPDATE_TIME, TIMESTAMP_INVALID);
|
| + return mPreferences.getLong(KEY_LAST_CHECK_WEB_MANIFEST_UPDATE_TIME, LAST_USED_INVALID);
|
| }
|
|
|
| /**
|
| @@ -413,7 +423,7 @@
|
| * This time needs to be set when the WebAPK is registered.
|
| */
|
| long getLastWebApkUpdateRequestCompletionTime() {
|
| - return mPreferences.getLong(KEY_LAST_UPDATE_REQUEST_COMPLETE_TIME, TIMESTAMP_INVALID);
|
| + return mPreferences.getLong(KEY_LAST_UPDATE_REQUEST_COMPLETE_TIME, LAST_USED_INVALID);
|
| }
|
|
|
| /**
|
| @@ -475,7 +485,7 @@
|
| */
|
| boolean didPreviousUpdateSucceed() {
|
| long lastUpdateCompletionTime = getLastWebApkUpdateRequestCompletionTime();
|
| - if (lastUpdateCompletionTime == TIMESTAMP_INVALID) {
|
| + if (lastUpdateCompletionTime == WebappDataStorage.LAST_USED_INVALID) {
|
| return true;
|
| }
|
| return getDidLastWebApkUpdateRequestSucceed();
|
|
|