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

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: 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..da176539607033caa53dbb8f2edaa27f2892f203 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 10:27:11 /** Represents a period of 4 weeks in milliseconds
Lalit Maganti 2015/09/24 12:35:44 Done.
+ static final long FULL_CLEANUP_DURATION = 4 * 7 * 24 * 60 * 60 * 1000;
+
+ /* Represnts a period of 13 weeks in milliseconds */
gone 2015/09/24 10:27:12 same fix as above. rename to WEBAPP_UNOPENED_CLEA
Lalit Maganti 2015/09/24 12:35:44 Done.
+ static final long WEBAPP_NON_OPEN_CLEANUP_DURATION = 13 * 7 * 24 * 60 * 60 * 1000;
/**
* Called when a retrieval of the stored web apps occurs.
@@ -81,6 +88,39 @@ public class WebappRegistry {
}
/**
+ * Deletes the data for all "old" web apps. i.e. webapps which have not been opened by the user
gone 2015/09/24 10:27:11 nit: web apps or webapps. instead of leaving usef
Lalit Maganti 2015/09/24 12:35:44 Done.
+ * in a certain period of time.
+ * @param context Context to open the registry with.
+ */
+ static void unregisterOldWebapps(final Context context) {
+ new AsyncTask<Void, Void, Void>() {
+ @Override
+ protected final Void doInBackground(Void... nothing) {
+ SharedPreferences preferences = openSharedPreferences(context);
+ long currentTime = System.currentTimeMillis();
+ 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_NON_OPEN_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