Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappRegistry.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappRegistry.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappRegistry.java |
index dff54ad1e36ae6b3c2f3b12acefbf6d0b55b8a11..2c2857fb231903e82a2fa485ba55bef365027810 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappRegistry.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappRegistry.java |
@@ -28,6 +28,13 @@ public class WebappRegistry { |
static final String REGISTRY_FILE_NAME = "webapp_registry"; |
static final String KEY_WEBAPP_SET = "webapp_set"; |
+ static final String KEY_LAST_CLEANUP = "last_cleanup"; |
+ |
+ /** Represnts a period of 4 weeks in milliseconds */ |
gone
2015/09/24 12:45:09
Represents.
Lalit Maganti
2015/09/24 12:49:25
Done and below too.
|
+ static final long FULL_CLEANUP_DURATION = 4 * 7 * 24 * 60 * 60 * 1000; |
+ |
+ /** Represnts a period of 13 weeks in milliseconds */ |
+ static final long WEBAPP_UNOPENED_CLEANUP_DURATION = 13 * 7 * 24 * 60 * 60 * 1000; |
/** |
* Called when a retrieval of the stored web apps occurs. |
@@ -81,6 +88,41 @@ public class WebappRegistry { |
} |
/** |
+ * Deletes the data for all "old" web apps. i.e. web apps which have not been opened by the user |
+ * in the last 3 months. The task also checks if it has been run in the past month and if so |
+ * does not proceed with cleanup. |
gone
2015/09/24 12:45:09
"Cleanup is run at most once a month"?
Lalit Maganti
2015/09/24 12:49:25
Done.
|
+ * @param context Context to open the registry with. |
+ * @param currentTime The current time which will be checked to decide if the task should be run |
+ * and if a web app should be cleaned up. |
+ */ |
+ static void unregisterOldWebapps(final Context context, final long currentTime) { |
+ new AsyncTask<Void, Void, Void>() { |
+ @Override |
+ protected final Void doInBackground(Void... nothing) { |
+ SharedPreferences preferences = openSharedPreferences(context); |
+ long lastCleanup = preferences.getLong(KEY_LAST_CLEANUP, 0); |
+ if (currentTime - lastCleanup < FULL_CLEANUP_DURATION) return null; |
+ |
+ Set<String> currentWebapps = getRegisteredWebappIds(preferences); |
+ Set<String> retainedWebapps = new HashSet<String>(currentWebapps); |
+ for (String id : currentWebapps) { |
+ long lastUsed = new WebappDataStorage(context, id).getLastUsedTime(); |
+ if (currentTime - lastUsed >= WEBAPP_UNOPENED_CLEANUP_DURATION) { |
+ WebappDataStorage.deleteDataForWebapp(context, id); |
+ retainedWebapps.remove(id); |
+ } |
+ } |
+ |
+ preferences.edit() |
+ .putLong(KEY_LAST_CLEANUP, currentTime) |
+ .putStringSet(KEY_WEBAPP_SET, retainedWebapps) |
+ .commit(); |
+ return null; |
+ } |
+ }.execute(); |
+ } |
+ |
+ /** |
* Deletes the data of all web apps, as well as the registry tracking the web apps. |
*/ |
@VisibleForTesting |