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 153e3941b2ef1f79e1e5d16d67fd8910e3596ac2..115f9f8ffab3330a57811ac6498f2de2881fc4da 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 |
@@ -104,7 +104,6 @@ public class WebappRegistry { |
SharedPreferences preferences = openSharedPreferences(context); |
if (getRegisteredWebappIds(preferences).contains(webappId)) { |
WebappDataStorage storage = WebappDataStorage.open(context, webappId); |
- storage.updateLastUsedTime(); |
return storage; |
} |
return null; |
@@ -119,6 +118,40 @@ 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, |
+ final FetchWebappDataStorageCallback callback) { |
+ new AsyncTask<Void, Void, WebappDataStorage>() { |
+ @Override |
+ protected final WebappDataStorage doInBackground(Void... nothing) { |
+ SharedPreferences preferences = openSharedPreferences(context); |
+ WebappDataStorage bestMatch = null; |
+ int largestOverlap = 0; |
+ for (String id : getRegisteredWebappIds(preferences)) { |
+ WebappDataStorage storage = WebappDataStorage.open(context, id); |
+ String scope = storage.getScope(); |
+ if (url.startsWith(scope) && scope.length() > largestOverlap) { |
+ bestMatch = storage; |
+ largestOverlap = scope.length(); |
+ } |
+ } |
+ return bestMatch; |
+ } |
+ |
+ protected final void onPostExecute(WebappDataStorage storage) { |
+ assert callback != null; |
+ callback.onWebappDataStorageRetrieved(storage); |
+ } |
+ }.execute(); |
+ } |
+ |
+ /** |
* 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. |