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

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

Issue 1329083002: Clear webapp storage when site data is cleared (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rework to use AsyncTask rather than IO thread 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 fe19baaa4b8a989dac549b7ba1c400cbc802d928..291159f80cba76887422c0a9eea33690fc736aeb 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
@@ -8,6 +8,9 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
+import org.chromium.base.VisibleForTesting;
+import org.chromium.base.annotations.CalledByNative;
+
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -27,6 +30,13 @@ public class WebappRegistry {
static final String KEY_WEBAPP_SET = "webapp_set";
/**
+ * Called when a retrieval of the stored web apps occurs.
gone 2015/09/09 23:30:39 nit: You used "webapp" in the added comment for We
Lalit Maganti 2015/09/10 09:41:57 OK I choose "web app" for all text for consistency
+ */
+ public interface FetchCallback {
+ public void onWebappIdsRetrieved(Set<String> readObject);
+ }
+
+ /**
* Registers the existence of a web app and creates the SharedPreference for it.
* @param context Context to open the registry with.
* @param webappId The id of the web app to register.
@@ -35,10 +45,8 @@ public class WebappRegistry {
new AsyncTask<Void, Void, Void>() {
@Override
protected final Void doInBackground(Void... nothing) {
- SharedPreferences preferences = context.getSharedPreferences(
- REGISTRY_FILE_NAME, Context.MODE_PRIVATE);
- Set<String> webapps = new HashSet<String>(
- preferences.getStringSet(KEY_WEBAPP_SET, Collections.<String>emptySet()));
+ SharedPreferences preferences = openSharedPreferences(context);
+ Set<String> webapps = new HashSet<String>(getRegisteredWebappIds(preferences));
boolean added = webapps.add(webappId);
assert added;
@@ -61,9 +69,7 @@ public class WebappRegistry {
new AsyncTask<Void, Void, Set<String>>() {
@Override
protected final Set<String> doInBackground(Void... nothing) {
- SharedPreferences preferences = context.getSharedPreferences(
- REGISTRY_FILE_NAME, Context.MODE_PRIVATE);
- return preferences.getStringSet(KEY_WEBAPP_SET, Collections.<String>emptySet());
+ return getRegisteredWebappIds(openSharedPreferences(context));
}
@Override
@@ -73,13 +79,47 @@ public class WebappRegistry {
}.execute();
}
- private WebappRegistry() {
+ /** Deletes the data of all webapps as well as the registry tracking the webapps. */
gone 2015/09/09 23:30:39 nit: replace "as well as" with ", as well as" or
Lalit Maganti 2015/09/10 09:41:57 Done.
+ @VisibleForTesting
+ static void unregisterAllWebapps(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.deleteDataForWebapp(context, id);
+ }
+ preferences.edit().clear().commit();
+ return null;
+ }
+
+ @Override
+ protected final void onPostExecute(Void nothing) {
+ callback.run();
+ }
+ }.execute();
}
- /**
- * Called when a retrieval of the stored web apps occurs.
- */
- public interface FetchCallback {
- public void onWebappIdsRetrieved(Set<String> readObject);
+ @CalledByNative
+ private static void unregisterAllWebapps(Context context, final long callbackPointer) {
+ unregisterAllWebapps(context, new Runnable() {
+ @Override
+ public void run() {
+ nativeOnWebappsUnregistered(callbackPointer);
+ }
+ });
+ }
+
+ private static SharedPreferences openSharedPreferences(Context context) {
+ return context.getSharedPreferences(REGISTRY_FILE_NAME, Context.MODE_PRIVATE);
+ }
+
+ private static Set<String> getRegisteredWebappIds(SharedPreferences preferences) {
+ return preferences.getStringSet(KEY_WEBAPP_SET, Collections.<String>emptySet());
+ }
+
+ private static native void nativeOnWebappsUnregistered(long callbackPointer);
gone 2015/09/09 23:30:39 native call definitions always go at the bottom.
Lalit Maganti 2015/09/10 09:41:57 Done.
+
+ private WebappRegistry() {
}
}

Powered by Google App Engine
This is Rietveld 408576698