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. |
gone
2016/03/08 22:40:39
nit: Rework this comment so that i.e. != WebappDat
dominickn
2016/03/09 08:18:32
Done.
|
+ 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. |
gone
2016/03/08 22:40:39
nit: newline between this and @param
dominickn
2016/03/09 08:18:32
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. |
@@ -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; |
gone
2016/03/08 22:40:39
Is this callback == null check here only for tests
dominickn
2016/03/09 08:18:32
I just copied from the block above this one. I'll
|
+ callback.run(); |
+ } |
+ }.execute(); |
+ } |
+ |
+ @CalledByNative |
+ static void clearWebappHistory(Context context, final long callbackPointer) { |
gone
2016/03/08 22:40:39
If this is only called by native code, use private
dominickn
2016/03/09 08:18:32
I did this in patchset #3, but it fails to compile
gone
2016/03/10 23:27:21
Strange... it's definitely called, isn't it? I me
dominickn
2016/03/11 05:14:42
Done.
|
+ 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); |
+} |