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

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

Issue 1329083002: Clear webapp storage when site data is cleared (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix silly test mistake 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/WebappDataStorage.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java
index 37511a3ccab40c6e2f30e3e24c989cb5a3750a48..20291a2541802e923175bd09af2adab8656b2b22 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java
@@ -36,7 +36,7 @@ public class WebappDataStorage {
private final SharedPreferences mPreferences;
/**
- * Opens an instance of WebappDataStorage for the webapp specified.
+ * Opens an instance of WebappDataStorage for the web app specified.
* @param context The context to open the SharedPreferences.
* @param webappId The ID of the web app which is being opened.
*/
@@ -57,7 +57,7 @@ public class WebappDataStorage {
* Asynchronously retrieves the time which this WebappDataStorage was last
* opened using {@link WebappDataStorage#open(Context, String)}.
* @param context The context to read the SharedPreferences file.
- * @param webappId The ID of the webapp the used time is being read for.
+ * @param webappId The ID of the web app the used time is being read for.
* @param callback Called when the last used time has been retrieved.
*/
public static void getLastUsedTime(final Context context, final String webappId,
@@ -79,6 +79,17 @@ public class WebappDataStorage {
}
/**
+ * Deletes the data for a web app by clearing all the information inside the SharedPreferences
+ * file. This does NOT delete the file itself but the file is left empty.
+ * @param context The context to read the SharedPreferences file.
+ * @param webappId The ID of the web app being deleted.
+ */
+ static void deleteDataForWebapp(final Context context, final String webappId) {
+ assert !ThreadUtils.runningOnUiThread();
+ openSharedPreferences(context, webappId).edit().clear().commit();
+ }
+
+ /**
* Sets the factory used to generate WebappDataStorage objects.
*/
@VisibleForTesting
@@ -86,11 +97,15 @@ public class WebappDataStorage {
sFactory = factory;
}
- protected WebappDataStorage(Context context, String webappId) {
- mPreferences = context.getApplicationContext().getSharedPreferences(
+ private static SharedPreferences openSharedPreferences(Context context, String webappId) {
+ return context.getApplicationContext().getSharedPreferences(
SHARED_PREFS_FILE_PREFIX + webappId, Context.MODE_PRIVATE);
}
+ protected WebappDataStorage(Context context, String webappId) {
+ mPreferences = openSharedPreferences(context, webappId);
+ }
+
/*
* Asynchronously retrieves the splash screen image associated with the
* current web app.

Powered by Google App Engine
This is Rietveld 408576698