Commit 17e2b41a authored by Henry Jian's avatar Henry Jian Committed by Commit Bot

add a new chrome launch metrics source, WST for file

Previously, we have ShortcutSource.WEBAPK_SHARE_TARGET to show
chrome is launched as a result of user sharing text. As we
introduce the ability for WebAPK to receive file sharing,
we add ShortcutSource.WEBAPK_SHARE_TARGET_FILE to show
that chrome is launched as a result of binary file sharing.

Change-Id: Id21d055baad3e5ff1ddb55309d1e6b278f144117
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1668089
Commit-Queue: Henry Jian <hzjian@google.com>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Reviewed-by: default avatarPeter Kotwicz <pkotwicz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#671346}
parent 447a6e80
......@@ -179,16 +179,6 @@ public class WebApkInfo extends WebappInfo {
return null;
}
String url = urlFromIntent(intent);
int source = sourceFromIntent(intent);
if (source == ShortcutSource.EXTERNAL_INTENT) {
if (IntentHandler.determineExternalIntentSource(intent)
== IntentHandler.ExternalAppId.CHROME) {
source = ShortcutSource.EXTERNAL_INTENT_FROM_CHROME;
}
}
// Force navigation if the extra is not specified to avoid breaking deep linking for old
// WebAPKs which don't specify the {@link ShortcutHelper#EXTRA_FORCE_NAVIGATION} intent
// extra.
......@@ -215,6 +205,22 @@ public class WebApkInfo extends WebappInfo {
}
}
}
String url = urlFromIntent(intent);
int source = sourceFromIntent(intent);
if (source == ShortcutSource.EXTERNAL_INTENT) {
if (IntentHandler.determineExternalIntentSource(intent)
== IntentHandler.ExternalAppId.CHROME) {
source = ShortcutSource.EXTERNAL_INTENT_FROM_CHROME;
}
}
if (source == ShortcutSource.WEBAPK_SHARE_TARGET && shareData != null
&& shareData.files != null && shareData.files.size() > 0) {
source = ShortcutSource.WEBAPK_SHARE_TARGET_FILE;
}
boolean canUseSplashFromContentProvider = IntentUtils.safeGetBooleanExtra(
intent, WebApkConstants.EXTRA_SPLASH_PROVIDED_BY_WEBAPK, false);
......
......@@ -406,6 +406,7 @@ public class WebappInfo {
int source = source();
return source != ShortcutSource.NOTIFICATION && source != ShortcutSource.EXTERNAL_INTENT
&& source != ShortcutSource.EXTERNAL_INTENT_FROM_CHROME
&& source != ShortcutSource.WEBAPK_SHARE_TARGET;
&& source != ShortcutSource.WEBAPK_SHARE_TARGET
&& source != ShortcutSource.WEBAPK_SHARE_TARGET_FILE;
}
}
......@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.webapps;
import android.content.Intent;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Browser;
......@@ -28,6 +29,7 @@ import org.chromium.webapk.lib.common.WebApkMetaDataKeys;
import org.chromium.webapk.lib.common.splash.SplashLayout;
import org.chromium.webapk.test.WebApkTestHelper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
......@@ -428,6 +430,33 @@ public class WebApkInfoTest {
Assert.assertEquals(ShortcutSource.EXTERNAL_INTENT, info.source());
}
/**
* Test that ShortcutSource#SHARE_TARGET is rewritten to
* ShortcutSource#WEBAPK_SHARE_TARGET_FILE if the WebAPK is launched as a result of user sharing
* a binary file.
*/
@Test
public void testOverrideShareTargetSourceIfLaunchedFromFileSharing() {
Bundle bundle = new Bundle();
bundle.putString(WebApkMetaDataKeys.START_URL, START_URL);
WebApkTestHelper.registerWebApkWithMetaData(
WEBAPK_PACKAGE_NAME, bundle, null /* shareTargetMetaData */);
Intent intent = new Intent();
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WEBAPK_PACKAGE_NAME);
intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL);
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_SELECTED_SHARE_TARGET_ACTIVITY_CLASS_NAME,
"something");
ArrayList<Uri> uris = new ArrayList<>();
uris.add(Uri.parse("mock-uri-3"));
intent.putExtra(Intent.EXTRA_STREAM, uris);
intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.WEBAPK_SHARE_TARGET);
WebApkInfo info = WebApkInfo.create(intent);
Assert.assertEquals(ShortcutSource.WEBAPK_SHARE_TARGET_FILE, info.source());
}
/**
* Test when a distributor is not specified, the default distributor value for a WebAPK
* installed by Chrome is |WebApkInfo.WebApkDistributor.BROWSER|, while for an Unbound WebAPK is
......
......@@ -87,7 +87,7 @@ struct ShortcutInfo {
// Used for Trusted Web Activities launched from third party Android apps.
SOURCE_TRUSTED_WEB_ACTIVITY = 12,
// Used for WebAPK intents received as a result of share events.
// Used for WebAPK intents received as a result of text sharing events.
SOURCE_WEBAPK_SHARE_TARGET = 13,
// Used for WebAPKs launched via an external intent from this Chrome APK.
......@@ -95,7 +95,11 @@ struct ShortcutInfo {
// report SOURCE_EXTERNAL_INTENT.
SOURCE_EXTERNAL_INTENT_FROM_CHROME = 14,
SOURCE_COUNT = 15
// Used for WebAPK intents received as a result of binary file sharing
// events.
SOURCE_WEBAPK_SHARE_TARGET_FILE = 15,
SOURCE_COUNT = 16
};
explicit ShortcutInfo(const GURL& shortcut_url);
......
......@@ -32610,6 +32610,7 @@ Called by update_gpu_driver_bug_workaround_entries.py.-->
<int value="12" label="Trusted Web Activity"/>
<int value="13" label="WebShareTarget (WebAPK)"/>
<int value="14" label="External intent from Chrome (WebAPK)"/>
<int value="15" label="WebShareTarget for Files (WebAPK)"/>
</enum>
<enum name="LaunchIntentFlags">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment