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

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

Issue 1749603002: Store URLs in WebappDataStorage, and purge them when history is cleared. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 9 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 607aea1e350b334d3effd6f8d435d297f3f8d541..9ef04698f393a7ae27da573c08b4c4e79981fb67 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
@@ -49,7 +49,8 @@ public class WebappRegistry {
* @param context Context to open the registry with.
* @param webappId The id of the web app to register.
*/
- public static void registerWebapp(final Context context, final String webappId) {
+ public static void registerWebapp(final Context context, final String webappId,
+ final String scope) {
new AsyncTask<Void, Void, Void>() {
@Override
protected final Void doInBackground(Void... nothing) {
@@ -58,10 +59,11 @@ public class WebappRegistry {
boolean added = webapps.add(webappId);
assert added;
- // Update the last used time of the {@link WebappDataStorage} so we can guarantee
- // that the used time will be set (ie. != WebappDataStorage.INVALID_LAST_USED) if a
- // web app appears in the registry.
- new WebappDataStorage(context, webappId).updateLastUsedTime();
+ // Update the last used time, so we can guarantee that a web app which appears in
+ // the registry will have a last used time != WebappDataStorage.LAST_USED_INVALID.
+ WebappDataStorage storage = new WebappDataStorage(context, webappId);
+ storage.setScope(scope);
+ storage.updateLastUsedTime();
preferences.edit().putStringSet(KEY_WEBAPP_SET, webapps).apply();
return null;
}
@@ -89,8 +91,10 @@ 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.
+ * Deletes the data for all "old" web apps.
+ * "Old" web apps have not been opened by the user in the last 3 months, or have had their last
+ * used time set to 0 by the user clearing their history. 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.
@@ -140,7 +144,7 @@ public class WebappRegistry {
@Override
protected final void onPostExecute(Void nothing) {
- if (callback == null) return;
+ assert callback != null;
callback.run();
}
}.execute();
@@ -156,6 +160,39 @@ public class WebappRegistry {
});
}
+ /**
+ * Deletes the scope and sets the last used time to 0 for all web apps.
+ */
+ @VisibleForTesting
+ static void clearWebappHistory(final Context context, final Runnable callback) {
+ new AsyncTask<Void, Void, Void>() {
+ @Override
+ protected final Void doInBackground(Void... nothing) {
+ SharedPreferences preferences = openSharedPreferences(context);
+ for (String id : getRegisteredWebappIds(preferences)) {
+ WebappDataStorage.clearHistory(context, id);
+ }
+ return null;
+ }
+
+ @Override
+ protected final void onPostExecute(Void nothing) {
+ assert callback != null;
+ callback.run();
+ }
+ }.execute();
+ }
+
+ @CalledByNative
+ static void clearWebappHistory(Context context, final long callbackPointer) {
+ clearWebappHistory(context, new Runnable() {
+ @Override
+ public void run() {
+ nativeOnClearedWebappHistory(callbackPointer);
+ }
+ });
+ }
+
private static SharedPreferences openSharedPreferences(Context context) {
return context.getSharedPreferences(REGISTRY_FILE_NAME, Context.MODE_PRIVATE);
}
@@ -168,4 +205,5 @@ public class WebappRegistry {
}
private static native void nativeOnWebappsUnregistered(long callbackPointer);
-}
+ private static native void nativeOnClearedWebappHistory(long callbackPointer);
+}

Powered by Google App Engine
This is Rietveld 408576698