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

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

Issue 2860193002: Correctly record WebAPK install source for Launch.HomescreenSource (Closed)
Patch Set: Rebase. Created 3 years, 7 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/WebappLauncherActivity.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappLauncherActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappLauncherActivity.java
index 34d2e1a287fcae91d144532e2cf5483e90d6ae74..a232f04b66ad689b7d37309dd32e758ad99464f6 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappLauncherActivity.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappLauncherActivity.java
@@ -9,6 +9,7 @@ import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
+import android.os.StrictMode;
import android.text.TextUtils;
import android.util.Base64;
@@ -79,7 +80,15 @@ public class WebappLauncherActivity extends Activity {
// - the intent was sent by Chrome.
if (validWebApk || isValidMacForUrl(webappUrl, webappMac)
|| wasIntentFromChrome(intent)) {
- LaunchMetrics.recordHomeScreenLaunchIntoStandaloneActivity(webappUrl, webappSource);
+ int source = webappSource;
+ // Retrieves the source of the WebAPK from WebappDataStorage if it is unknown. The
+ // {@link webappSource} will not be unknown in the case of an external intent or a
+ // notification that launches a WebAPK. Otherwise, it's not trustworthy and we must read
+ // the SharedPreference to get the installation source.
+ if (validWebApk && (webappSource == ShortcutSource.UNKNOWN)) {
+ source = getWebApkSource(webappInfo);
+ }
+ LaunchMetrics.recordHomeScreenLaunchIntoStandaloneActivity(webappUrl, source);
Intent launchIntent = createWebappLaunchIntent(webappInfo, webappSource, validWebApk);
startActivity(launchIntent);
return;
@@ -92,6 +101,27 @@ public class WebappLauncherActivity extends Activity {
launchInTab(webappUrl, webappSource);
}
+ // Gets the source of a WebAPK from the WebappDataStorage if the source has been stored before.
+ private int getWebApkSource(WebappInfo webappInfo) {
+ WebappDataStorage storage = null;
+
+ StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
+ try {
+ WebappRegistry.warmUpSharedPrefsForId(webappInfo.id());
+ storage = WebappRegistry.getInstance().getWebappDataStorage(webappInfo.id());
+ } finally {
+ StrictMode.setThreadPolicy(oldPolicy);
+ }
+
+ if (storage != null) {
+ int source = storage.getSource();
+ if (source != ShortcutSource.UNKNOWN) {
+ return source;
+ }
+ }
+ return ShortcutSource.WEBAPK_UNKNOWN;
+ }
+
private void launchInTab(String webappUrl, int webappSource) {
if (TextUtils.isEmpty(webappUrl)) return;

Powered by Google App Engine
This is Rietveld 408576698