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

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

Issue 2126583002: Reland: Use metadata when launching WebAPKs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 115f9f8ffab3330a57811ac6498f2de2881fc4da..32ad44cdb8759514636a2e4f3440e8ef1f6ff6a4 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
@@ -6,8 +6,11 @@ package org.chromium.chrome.browser.webapps;
import android.content.Context;
import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.os.AsyncTask;
+import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
@@ -173,9 +176,10 @@ public class WebappRegistry {
}
/**
- * Deletes the data for all "old" web apps.
+ * 1. Deletes the data for all "old" web apps.
* "Old" web apps have not been opened by the user in the last 3 months, or have had their last
* 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
@@ -191,10 +195,16 @@ public class WebappRegistry {
Set<String> currentWebapps = getRegisteredWebappIds(preferences);
Set<String> retainedWebapps = new HashSet<String>(currentWebapps);
+ PackageManager pm = context.getPackageManager();
for (String id : currentWebapps) {
- long lastUsed = new WebappDataStorage(context, id).getLastUsedTime();
- if ((currentTime - lastUsed) < WEBAPP_UNOPENED_CLEANUP_DURATION) continue;
-
+ WebappDataStorage storage = new WebappDataStorage(context, id);
+ String webApkPackage = storage.getWebApkPackageName();
+ if (webApkPackage != null) {
+ if (isWebApkInstalled(pm, webApkPackage)) continue;
+ } else {
+ long lastUsed = storage.getLastUsedTime();
+ if ((currentTime - lastUsed) < WEBAPP_UNOPENED_CLEANUP_DURATION) continue;
+ }
WebappDataStorage.deleteDataForWebapp(context, id);
retainedWebapps.remove(id);
}
@@ -209,6 +219,19 @@ public class WebappRegistry {
}
/**
+ * Returns whether the given WebAPK is still installed.
+ */
+ private static boolean isWebApkInstalled(PackageManager pm, String webApkPackage) {
+ assert !ThreadUtils.runningOnUiThread();
+ try {
+ pm.getPackageInfo(webApkPackage, PackageManager.GET_ACTIVITIES);
+ } catch (NameNotFoundException e) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
* Deletes the data of all web apps, as well as the registry tracking the web apps.
*/
@VisibleForTesting

Powered by Google App Engine
This is Rietveld 408576698