Chromium Code Reviews| 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 d42f7b280ece41d8dd50d1e385f40a713f090f45..41f8f4dc8445f3602b8f0e419b379ef997a4d951 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 |
| @@ -10,6 +10,7 @@ import android.content.SharedPreferences; |
| import android.graphics.Bitmap; |
| import android.os.AsyncTask; |
| +import org.chromium.base.ContextUtils; |
| import org.chromium.base.ThreadUtils; |
| import org.chromium.base.VisibleForTesting; |
| import org.chromium.blink_public.platform.WebDisplayMode; |
| @@ -80,11 +81,10 @@ public class WebappDataStorage { |
| /** |
| * Opens an instance of WebappDataStorage for the web app specified. Must not be run on the UI |
| * thread. |
| - * @param context The context to open the SharedPreferences. |
| * @param webappId The ID of the web app which is being opened. |
| */ |
| - static WebappDataStorage open(final Context context, final String webappId) { |
| - final WebappDataStorage storage = sFactory.create(context, webappId); |
| + static WebappDataStorage open(final String webappId) { |
| + final WebappDataStorage storage = sFactory.create(webappId); |
| if (storage.getLastUsedTime() == LAST_USED_INVALID) { |
| // If the last used time is invalid then ensure that there is no data in the |
| // WebappDataStorage which needs to be cleaned up. |
| @@ -96,18 +96,15 @@ public class WebappDataStorage { |
| /** |
| * Asynchronously retrieves the time which this WebappDataStorage was last opened. Used in |
| * testing. |
| - * @param context The context to read the SharedPreferences file. |
| * @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. |
| */ |
| @VisibleForTesting |
| - public static void getLastUsedTime(final Context context, final String webappId, |
| - final FetchCallback<Long> callback) { |
| + public static void getLastUsedTime(final String webappId, final FetchCallback<Long> callback) { |
| new AsyncTask<Void, Void, Long>() { |
| @Override |
| protected final Long doInBackground(Void... nothing) { |
| - long lastUsed = new WebappDataStorage(context.getApplicationContext(), webappId) |
| - .getLastUsedTime(); |
| + long lastUsed = new WebappDataStorage(webappId).getLastUsedTime(); |
| assert lastUsed != LAST_USED_INVALID; |
| return lastUsed; |
| } |
| @@ -123,17 +120,15 @@ public class WebappDataStorage { |
| /** |
| * Asynchronously retrieves the scope stored in this WebappDataStorage. The scope is the URL |
| * over which the web app data is applied to. Used in testing. |
| - * @param context The context to read the SharedPreferences file. |
| * @param webappId The ID of the web app the used time is being read for. |
| * @param callback Called when the scope has been retrieved. |
| */ |
| @VisibleForTesting |
| - public static void getScope(final Context context, final String webappId, |
| - final FetchCallback<String> callback) { |
| + public static void getScope(final String webappId, final FetchCallback<String> callback) { |
| new AsyncTask<Void, Void, String>() { |
| @Override |
| protected final String doInBackground(Void... nothing) { |
| - return new WebappDataStorage(context.getApplicationContext(), webappId).getScope(); |
| + return new WebappDataStorage(webappId).getScope(); |
| } |
| @Override |
| @@ -146,17 +141,15 @@ public class WebappDataStorage { |
| /** |
| * Asynchronously retrieves the URL stored in this WebappDataStorage. Used in testing. |
| - * @param context The context to read the SharedPreferences file. |
| * @param webappId The ID of the web app the used time is being read for. |
| * @param callback Called when the URL has been retrieved. |
| */ |
| @VisibleForTesting |
| - public static void getUrl(final Context context, final String webappId, |
| - final FetchCallback<String> callback) { |
| + public static void getUrl(final String webappId, final FetchCallback<String> callback) { |
| new AsyncTask<Void, Void, String>() { |
| @Override |
| protected final String doInBackground(Void... nothing) { |
| - return new WebappDataStorage(context.getApplicationContext(), webappId).getUrl(); |
| + return new WebappDataStorage(webappId).getUrl(); |
| } |
| @Override |
| @@ -170,23 +163,21 @@ 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) { |
| + static void deleteDataForWebapp(final String webappId) { |
| assert !ThreadUtils.runningOnUiThread(); |
| - openSharedPreferences(context, webappId).edit().clear().apply(); |
| + openSharedPreferences(webappId).edit().clear().apply(); |
| } |
| /** |
| * Deletes the URL and scope, and sets all timestamps to 0 in SharedPreferences. |
| * This does not remove the stored splash screen image (if any) for the app. |
| - * @param context The context to read the SharedPreferences file. |
| * @param webappId The ID of the web app for which history is being cleared. |
| */ |
| - static void clearHistory(final Context context, final String webappId) { |
| + static void clearHistory(final String webappId) { |
| assert !ThreadUtils.runningOnUiThread(); |
| - SharedPreferences.Editor editor = openSharedPreferences(context, webappId).edit(); |
| + SharedPreferences.Editor editor = openSharedPreferences(webappId).edit(); |
| // The last used time is set to 0 to ensure that a valid value is always present. |
| // If the web app is not launched prior to the next cleanup, then its remaining data will be |
| @@ -216,14 +207,14 @@ public class WebappDataStorage { |
| sFactory = factory; |
| } |
| - private static SharedPreferences openSharedPreferences(Context context, String webappId) { |
| - return context.getApplicationContext().getSharedPreferences( |
| + private static SharedPreferences openSharedPreferences(String webappId) { |
| + return ContextUtils.getApplicationContext().getSharedPreferences( |
|
Peter Wen
2016/09/22 19:45:31
Yes, context.getApplicationContext() is the exact
|
| SHARED_PREFS_FILE_PREFIX + webappId, Context.MODE_PRIVATE); |
| } |
| - protected WebappDataStorage(Context context, String webappId) { |
| + protected WebappDataStorage(String webappId) { |
| mId = webappId; |
| - mPreferences = openSharedPreferences(context, webappId); |
| + mPreferences = openSharedPreferences(webappId); |
| } |
| /** |
| @@ -491,8 +482,8 @@ public class WebappDataStorage { |
| /** |
| * Generates a WebappDataStorage class for a specified web app. |
| */ |
| - public WebappDataStorage create(final Context context, final String webappId) { |
| - return new WebappDataStorage(context, webappId); |
| + public WebappDataStorage create(final String webappId) { |
| + return new WebappDataStorage(webappId); |
| } |
| } |