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

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

Issue 1867543002: Enable deep-linking from notifications for recently used web apps on the Android home screen. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bulk-webappdatastorage
Patch Set: Address nits Created 4 years, 8 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/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.

Powered by Google App Engine
This is Rietveld 408576698