Chromium Code Reviews| 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..e4edac13a3d7712a70bd254d5e2bfbcc52dda68f 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"; |
| + |
| + /** Represents a period of 4 weeks in milliseconds */ |
| + static final long FULL_CLEANUP_DURATION = 4 * 7 * 24 * 60 * 60 * 1000; |
|
mlamouri (slow - plz ping)
2015/09/24 15:20:04
Could you use http://docs.oracle.com/javase/7/docs
Lalit Maganti
2015/09/24 16:09:38
Done.
|
| + |
| + /** Represents a period of 13 weeks in milliseconds */ |
| + static final long WEBAPP_UNOPENED_CLEANUP_DURATION = 13 * 7 * 24 * 60 * 60 * 1000; |
|
mlamouri (slow - plz ping)
2015/09/24 15:20:04
ditto
Lalit Maganti
2015/09/24 16:09:37
Done.
|
| /** |
| * Called when a retrieval of the stored web apps occurs. |
| @@ -81,6 +88,40 @@ 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. Cleanup is run, at most, once a month. |
| + * @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; |
|
mlamouri (slow - plz ping)
2015/09/24 15:20:04
nit: I would use parenthesis: |if ((currentTime -
Lalit Maganti
2015/09/24 16:09:37
Done.
|
| + |
| + 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) continue; |
|
mlamouri (slow - plz ping)
2015/09/24 15:20:04
ditto
Lalit Maganti
2015/09/24 16:09:37
Done.
|
| + |
| + 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 |