| 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..6eb1921b2801762235a88d5fd785e989c80841bd 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 originUrl) {
|
| new AsyncTask<Void, Void, Void>() {
|
| @Override
|
| protected final Void doInBackground(Void... nothing) {
|
| @@ -58,10 +59,12 @@ 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 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.
|
| + WebappDataStorage storage = new WebappDataStorage(context, webappId);
|
| + storage.updateOriginUrl(originUrl);
|
| + storage.updateLastUsedTime(System.currentTimeMillis());
|
| preferences.edit().putStringSet(KEY_WEBAPP_SET, webapps).apply();
|
| return null;
|
| }
|
| @@ -89,8 +92,9 @@ 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.
|
| @@ -156,6 +160,39 @@ public class WebappRegistry {
|
| });
|
| }
|
|
|
| + /**
|
| + * Deletes the origin URL 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) {
|
| + if (callback == null) return;
|
| + 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);
|
| +}
|
|
|