Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1124)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappRegistry.java

Issue 1359383002: webapps: Add cleanup task when opening up WebappActivity to clean old web apps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webapp-cleanup
Patch Set: Address review comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698