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 9ef04698f393a7ae27da573c08b4c4e79981fb67..0b9426818b154dad97f2a3ecd948980ec3bca5af 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 |
| @@ -38,36 +38,75 @@ public class WebappRegistry { |
| static final long WEBAPP_UNOPENED_CLEANUP_DURATION = TimeUnit.DAYS.toMillis(13L * 7L); |
| /** |
| - * Called when a retrieval of the stored web apps occurs. |
| + * Called when a retrieval of the set of stored web app ids occurs. |
|
gone
2016/04/01 23:44:48
nit: IDs
dominickn
2016/04/04 07:26:24
Done.
|
| */ |
| public interface FetchCallback { |
| public void onWebappIdsRetrieved(Set<String> readObject); |
| } |
| /** |
| - * Registers the existence of a web app and creates the SharedPreference for it. |
| + * Called when a retrieval of the stored WebappDataStorage occurs. The storage parameter will |
| + * be null if the web app queried for was not in the registry. |
| + */ |
| + public interface FetchWebappDataStorageCallback { |
| + public void onWebappDataStorageRetrieved(WebappDataStorage storage); |
| + } |
| + |
| + /** |
| + * Registers the existence of a web app, creates the SharedPreference for it, and returns the |
| + * resulting WebappDataStorage object. |
| * @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. |
| */ |
| - public static void registerWebapp(final Context context, final String webappId, |
| - final String scope) { |
| + public static WebappDataStorage registerWebapp(final Context context, final String webappId) { |
| + final WebappDataStorage storage = new WebappDataStorage(context, webappId); |
| new AsyncTask<Void, Void, Void>() { |
| @Override |
| protected final Void doInBackground(Void... nothing) { |
| SharedPreferences preferences = openSharedPreferences(context); |
| + // The set returned by getRegisteredWebappIds must be treated as immutable, so we |
| + // make a copy to edit and save. |
| Set<String> webapps = new HashSet<String>(getRegisteredWebappIds(preferences)); |
| boolean added = webapps.add(webappId); |
| assert added; |
| + preferences.edit().putStringSet(KEY_WEBAPP_SET, webapps).apply(); |
| + |
| // Update the last used time, so we can guarantee that a web app which appears in |
| // the registry will have a last used time != WebappDataStorage.LAST_USED_INVALID. |
| - WebappDataStorage storage = new WebappDataStorage(context, webappId); |
| - storage.setScope(scope); |
| storage.updateLastUsedTime(); |
| - preferences.edit().putStringSet(KEY_WEBAPP_SET, webapps).apply(); |
| return null; |
| } |
| }.execute(); |
| + |
| + return storage; |
| + } |
| + |
| + /** |
| + * 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, |
| + final FetchWebappDataStorageCallback callback) { |
| + new AsyncTask<Void, Void, Boolean>() { |
| + @Override |
| + protected final Boolean doInBackground(Void... nothing) { |
| + SharedPreferences preferences = openSharedPreferences(context); |
| + return getRegisteredWebappIds(preferences).contains(webappId); |
| + } |
| + |
| + protected final void onPostExecute(Boolean exists) { |
| + WebappDataStorage storage = null; |
| + if (exists) { |
| + storage = WebappDataStorage.open(context, webappId); |
| + } |
| + callback.onWebappDataStorageRetrieved(storage); |
| + } |
| + }.execute(); |
| } |
| /** |