Chromium Code Reviews| 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 52d6628d101c49953c12e115b3eaeab39772e113..fb810d35f799368599ced1a2db9f8fce560e2f0a 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 |
| @@ -10,6 +10,7 @@ import android.content.pm.PackageManager; |
| import android.content.pm.PackageManager.NameNotFoundException; |
| import android.os.AsyncTask; |
| +import org.chromium.base.ContextUtils; |
| import org.chromium.base.ThreadUtils; |
| import org.chromium.base.VisibleForTesting; |
| import org.chromium.base.annotations.CalledByNative; |
| @@ -58,18 +59,18 @@ public class WebappRegistry { |
| } |
| /** |
| - * Registers the existence of a web app, creates the SharedPreference for it, and runs the |
| + * Registers the existence of a web app, creates a SharedPreference entry for it, and runs the |
| * supplied callback (if not null) on the UI thread with the resulting WebappDataStorage object. |
| - * @param context Context to open the registry with. |
| * @param webappId The id of the web app to register. |
| * @param callback The callback to run with the WebappDataStorage argument. |
| * @return The storage object for the web app. |
| */ |
| - public static void registerWebapp(final Context context, final String webappId, |
| + public static void registerWebapp(final String webappId, |
| final FetchWebappDataStorageCallback callback) { |
| new AsyncTask<Void, Void, WebappDataStorage>() { |
| @Override |
| protected final WebappDataStorage doInBackground(Void... nothing) { |
| + Context context = ContextUtils.getApplicationContext(); |
| SharedPreferences preferences = openSharedPreferences(context); |
|
Peter Wen
2016/09/21 14:58:41
Same as above, openSharedPreferences doesn't need
dominickn
2016/09/22 03:47:00
Done.
|
| // The set returned by getRegisteredWebappIds must be treated as immutable, so we |
| // make a copy to edit and save. |
| @@ -97,15 +98,15 @@ public class WebappRegistry { |
| /** |
| * Runs the callback, supplying the WebappDataStorage object for webappId, or null if the web |
| * app has not been registered. |
| - * @param context Context to open the registry with. |
| * @param webappId The id of the web app to register. |
| * @return The storage object for the web app, or null if webappId is not registered. |
| */ |
| - public static void getWebappDataStorage(final Context context, final String webappId, |
| + public static void getWebappDataStorage(final String webappId, |
| final FetchWebappDataStorageCallback callback) { |
| new AsyncTask<Void, Void, WebappDataStorage>() { |
| @Override |
| protected final WebappDataStorage doInBackground(Void... nothing) { |
| + Context context = ContextUtils.getApplicationContext(); |
| SharedPreferences preferences = openSharedPreferences(context); |
| if (getRegisteredWebappIds(preferences).contains(webappId)) { |
| WebappDataStorage storage = WebappDataStorage.open(context, webappId); |
| @@ -126,15 +127,15 @@ public class WebappRegistry { |
| * Runs the callback, supplying the WebappDataStorage object whose scope most closely matches |
| * the provided URL, or null if a matching web app cannot be found. The most closely matching |
| * scope is the longest scope which has the same prefix as the URL to open. |
| - * @param context Context to open the registry with. |
| * @param url The URL to search for. |
| * @return The storage object for the web app, or null if webappId is not registered. |
| */ |
| - public static void getWebappDataStorageForUrl(final Context context, final String url, |
| + public static void getWebappDataStorageForUrl(final String url, |
| final FetchWebappDataStorageCallback callback) { |
| new AsyncTask<Void, Void, WebappDataStorage>() { |
| @Override |
| protected final WebappDataStorage doInBackground(Void... nothing) { |
| + Context context = ContextUtils.getApplicationContext(); |
| SharedPreferences preferences = openSharedPreferences(context); |
| WebappDataStorage bestMatch = null; |
| int largestOverlap = 0; |
| @@ -158,15 +159,15 @@ public class WebappRegistry { |
| /** |
| * Asynchronously retrieves the list of web app IDs which this registry is aware of. |
| - * @param context Context to open the registry with. |
| * @param callback Called when the set has been retrieved. The set may be empty. |
| */ |
| @VisibleForTesting |
| - public static void getRegisteredWebappIds(final Context context, final FetchCallback callback) { |
| + public static void getRegisteredWebappIds(final FetchCallback callback) { |
| new AsyncTask<Void, Void, Set<String>>() { |
| @Override |
| protected final Set<String> doInBackground(Void... nothing) { |
| - return getRegisteredWebappIds(openSharedPreferences(context)); |
| + return getRegisteredWebappIds( |
| + openSharedPreferences(ContextUtils.getApplicationContext())); |
| } |
| @Override |
| @@ -183,14 +184,14 @@ public class WebappRegistry { |
| * used time set to 0 by the user clearing their history. Cleanup is run, at most, once a month. |
| * 2. Deletes the data for all WebAPKs that have been uninstalled in the last 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. |
| */ |
| - static void unregisterOldWebapps(final Context context, final long currentTime) { |
| + static void unregisterOldWebapps(final long currentTime) { |
| new AsyncTask<Void, Void, Void>() { |
| @Override |
| protected final Void doInBackground(Void... nothing) { |
| + Context context = ContextUtils.getApplicationContext(); |
| SharedPreferences preferences = openSharedPreferences(context); |
| long lastCleanup = preferences.getLong(KEY_LAST_CLEANUP, 0); |
| if ((currentTime - lastCleanup) < FULL_CLEANUP_DURATION) return null; |
| @@ -238,11 +239,11 @@ public class WebappRegistry { |
| * tracking those web apps. |
| */ |
| @VisibleForTesting |
| - static void unregisterWebappsForUrls( |
| - final Context context, final UrlFilter urlFilter, final Runnable callback) { |
| + static void unregisterWebappsForUrls(final UrlFilter urlFilter, final Runnable callback) { |
| new AsyncTask<Void, Void, Void>() { |
| @Override |
| protected final Void doInBackground(Void... nothing) { |
| + Context context = ContextUtils.getApplicationContext(); |
| SharedPreferences preferences = openSharedPreferences(context); |
| Set<String> registeredWebapps = |
| new HashSet<>(getRegisteredWebappIds(preferences)); |
| @@ -277,8 +278,8 @@ public class WebappRegistry { |
| @CalledByNative |
| static void unregisterWebappsForUrls( |
| - Context context, final UrlFilterBridge urlFilter, final long callbackPointer) { |
| - unregisterWebappsForUrls(context, urlFilter, new Runnable() { |
| + final UrlFilterBridge urlFilter, final long callbackPointer) { |
| + unregisterWebappsForUrls(urlFilter, new Runnable() { |
| @Override |
| public void run() { |
| urlFilter.destroy(); |
| @@ -292,11 +293,11 @@ public class WebappRegistry { |
| * matches |urlFilter|. |
| */ |
| @VisibleForTesting |
| - static void clearWebappHistoryForUrls( |
| - final Context context, final UrlFilter urlFilter, final Runnable callback) { |
| + static void clearWebappHistoryForUrls(final UrlFilter urlFilter, final Runnable callback) { |
| new AsyncTask<Void, Void, Void>() { |
| @Override |
| protected final Void doInBackground(Void... nothing) { |
| + Context context = ContextUtils.getApplicationContext(); |
| SharedPreferences preferences = openSharedPreferences(context); |
| for (String id : getRegisteredWebappIds(preferences)) { |
| if (urlFilter.matchesUrl(WebappDataStorage.open(context, id).getUrl())) { |
| @@ -316,8 +317,8 @@ public class WebappRegistry { |
| @CalledByNative |
| static void clearWebappHistoryForUrls( |
| - Context context, final UrlFilterBridge urlFilter, final long callbackPointer) { |
| - clearWebappHistoryForUrls(context, urlFilter, new Runnable() { |
| + final UrlFilterBridge urlFilter, final long callbackPointer) { |
| + clearWebappHistoryForUrls(urlFilter, new Runnable() { |
| @Override |
| public void run() { |
| urlFilter.destroy(); |