Commit 5d83266c authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

[Autofill Assistant] Wire up starting of trigger scripts.

Introduces a new script parameter to allow triggers to instruct the
client to start the new trigger script experience. This will need to be
modified to take into account the new Chrome setting, once that has been
merged.

Bug: b/171776026
Change-Id: I1b8cf4b4f127bd8946197273e61185f7b7d1ad78
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2524525
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarMarian Fechete <marianfe@google.com>
Cr-Commit-Position: refs/heads/master@{#826200}
parent 48341fab
......@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.autofill_assistant;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantArguments.PARAMETER_REQUEST_TRIGGER_SCRIPT;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantArguments.PARAMETER_STARTED_WITH_TRIGGER_SCRIPT;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantArguments.PARAMETER_TRIGGER_FIRST_TIME_USER;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantArguments.PARAMETER_TRIGGER_RETURNING_TIME_USER;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantArguments.PARAMETER_TRIGGER_SCRIPT_USED;
......@@ -17,9 +19,11 @@ import androidx.annotation.Nullable;
import org.chromium.base.Callback;
import org.chromium.base.annotations.UsedByReflection;
import org.chromium.chrome.browser.ActivityTabProvider;
import org.chromium.chrome.browser.autofill_assistant.metrics.LiteScriptFinishedState;
import org.chromium.chrome.browser.autofill_assistant.metrics.LiteScriptOnboarding;
import org.chromium.chrome.browser.autofill_assistant.metrics.LiteScriptStarted;
import org.chromium.chrome.browser.autofill_assistant.metrics.OnBoarding;
import org.chromium.chrome.browser.autofill_assistant.trigger_scripts.AssistantTriggerScriptBridge;
import org.chromium.chrome.browser.browser_controls.BrowserControlsStateProvider;
import org.chromium.chrome.browser.compositor.CompositorViewHolder;
import org.chromium.chrome.browser.signin.UnifiedConsentServiceBridge;
......@@ -40,13 +44,38 @@ public class AutofillAssistantModuleEntryImpl implements AutofillAssistantModule
Context context, @NonNull WebContents webContents, boolean skipOnboarding,
boolean isChromeCustomTab, @NonNull String initialUrl, Map<String, String> parameters,
String experimentIds, @Nullable String callerAccount, @Nullable String userName) {
if (!TextUtils.isEmpty(parameters.get(PARAMETER_TRIGGER_FIRST_TIME_USER))) {
if (shouldStartTriggerScript(parameters)) {
if (!UnifiedConsentServiceBridge.isUrlKeyedAnonymizedDataCollectionEnabled(
AutofillAssistantUiController.getProfile())) {
// Opt-out users who have disabled anonymous data collection.
return;
}
// Start trigger script and transition to regular flow on success.
if (TextUtils.equals(parameters.get(PARAMETER_REQUEST_TRIGGER_SCRIPT), "true")) {
AssistantTriggerScriptBridge triggerScriptController =
new AssistantTriggerScriptBridge();
triggerScriptController.start(bottomSheetController, context, webContents,
initialUrl, parameters, experimentIds,
new AssistantTriggerScriptBridge.Delegate() {
@Override
public void onTriggerScriptFinished(
@LiteScriptFinishedState int finishedState) {
if (finishedState
== LiteScriptFinishedState.LITE_SCRIPT_PROMPT_SUCCEEDED) {
parameters.put(PARAMETER_STARTED_WITH_TRIGGER_SCRIPT, "true");
startAutofillAssistantRegular(bottomSheetController,
browserControls, compositorViewHolder, context,
webContents, skipOnboarding, isChromeCustomTab,
initialUrl, parameters, experimentIds, callerAccount,
userName);
}
}
});
return;
}
// Legacy lite scripts, remove as soon as possible.
boolean isFirstTimeUser =
AutofillAssistantPreferencesUtil.isAutofillAssistantFirstTimeLiteScriptUser();
String firstTimeUserScriptPath = parameters.get(PARAMETER_TRIGGER_FIRST_TIME_USER);
......@@ -75,6 +104,12 @@ public class AutofillAssistantModuleEntryImpl implements AutofillAssistantModule
experimentIds, callerAccount, userName);
}
/** Whether {@code parameters} indicate that a trigger script should be started. */
private boolean shouldStartTriggerScript(Map<String, String> parameters) {
return !TextUtils.isEmpty(parameters.get(PARAMETER_TRIGGER_FIRST_TIME_USER))
|| TextUtils.equals(parameters.get(PARAMETER_REQUEST_TRIGGER_SCRIPT), "true");
}
/**
* Starts a 'lite' autofill assistant script in the background. Does not show the onboarding.
* Does not have access to any information aside from the trigger script paths. Calls {@code
......@@ -100,7 +135,8 @@ public class AutofillAssistantModuleEntryImpl implements AutofillAssistantModule
boolean isChromeCustomTab, @NonNull String initialUrl, Map<String, String> parameters,
String experimentIds, @Nullable String callerAccount, @Nullable String userName) {
if (skipOnboarding) {
if (parameters.containsKey(PARAMETER_TRIGGER_SCRIPT_USED)) {
if (parameters.containsKey(PARAMETER_TRIGGER_SCRIPT_USED)
|| parameters.containsKey(PARAMETER_STARTED_WITH_TRIGGER_SCRIPT)) {
AutofillAssistantMetrics.recordLiteScriptOnboarding(
webContents, LiteScriptOnboarding.LITE_SCRIPT_ONBOARDING_ALREADY_ACCEPTED);
}
......@@ -116,7 +152,8 @@ public class AutofillAssistantModuleEntryImpl implements AutofillAssistantModule
experimentIds, parameters, context, bottomSheetController, browserControls,
compositorViewHolder, bottomSheetController.getScrimCoordinator());
onboardingCoordinator.show(accepted -> {
if (parameters.containsKey(PARAMETER_TRIGGER_SCRIPT_USED)) {
if (parameters.containsKey(PARAMETER_TRIGGER_SCRIPT_USED)
|| parameters.containsKey(PARAMETER_STARTED_WITH_TRIGGER_SCRIPT)) {
AutofillAssistantMetrics.recordLiteScriptOnboarding(webContents,
accepted ? LiteScriptOnboarding.LITE_SCRIPT_ONBOARDING_SEEN_AND_ACCEPTED
: LiteScriptOnboarding.LITE_SCRIPT_ONBOARDING_SEEN_AND_REJECTED);
......
......@@ -99,12 +99,25 @@ public class AutofillAssistantArguments {
/** Special parameter for returning user script path. */
static final String PARAMETER_TRIGGER_RETURNING_TIME_USER = "TRIGGER_RETURNING_USER";
// Deprecated, remove as soon as possible.
/** Special output parameter that should hold which of the trigger scripts was used, if any. */
static final String PARAMETER_TRIGGER_SCRIPT_USED = "TRIGGER_SCRIPT_USED";
/** Special parameter for declaring a user to be in a lite script experiment. */
static final String PARAMETER_LITE_SCRIPT_EXPERIMENT = "TRIGGER_SCRIPT_EXPERIMENT";
/**
* Special parameter for instructing the client to request and run a trigger script prior to
* starting the regular flow.
*/
static final String PARAMETER_REQUEST_TRIGGER_SCRIPT = "REQUEST_TRIGGER_SCRIPT";
/**
* Special output boolean parameter that will be set to true for regular scripts that were
* started with a trigger script.
*/
static final String PARAMETER_STARTED_WITH_TRIGGER_SCRIPT = "STARTED_WITH_TRIGGER_SCRIPT";
/**
* Identifier used by parameters/or special intent that indicates experiments passed from
* the caller.
......
......@@ -114,16 +114,19 @@ public class AutofillAssistantFacade {
arguments.isLiteScriptExperiment() ? LITE_SCRIPT_EXPERIMENT_TRIAL_EXPERIMENT
: LITE_SCRIPT_EXPERIMENT_TRIAL_CONTROL);
if (!AutofillAssistantPreferencesUtil.isAutofillAssistantSwitchOn()) {
if (!AutofillAssistantPreferencesUtil.isProactiveHelpSwitchOn()) {
// Opt out users who have disabled the proactive help Chrome setting.
AutofillAssistantMetrics.recordLiteScriptStarted(tab.getWebContents(),
AutofillAssistantPreferencesUtil
.isAutofillAssistantLiteScriptCancelThresholdReached()
? LiteScriptStarted.LITE_SCRIPT_CANCELED_TWO_TIMES
: LiteScriptStarted.LITE_SCRIPT_ONBOARDING_REJECTED);
// Opt-out users who have seen and rejected the onboarding, or who have canceled
// the lite script too many times.
LiteScriptStarted.LITE_SCRIPT_PROACTIVE_TRIGGERING_DISABLED);
return;
}
if (!AutofillAssistantPreferencesUtil.isAutofillAssistantSwitchOn()) {
// Legacy. This should no longer happen, because the proactive help switch
// should only be 'on' if the autofill assistant switch is 'on' as well.
return;
}
if (AutofillAssistantModuleEntryProvider.INSTANCE.getModuleEntryIfInstalled()
== null) {
// Opt-out users who don't have DFM installed.
......
......@@ -188,8 +188,6 @@ class Metrics {
enum class LiteScriptStarted {
// Device did not have DFM downloaded.
LITE_SCRIPT_DFM_UNAVAILABLE = 0,
// User has rejected the onboarding and thus opted out of the experience.
LITE_SCRIPT_ONBOARDING_REJECTED = 2,
// User has not seen the lite script before and will see first time
// experience.
LITE_SCRIPT_FIRST_TIME_USER = 3,
......@@ -210,6 +208,8 @@ class Metrics {
// User has explicitly rejected the lite script two times and thus opted
// out of the experience.
LITE_SCRIPT_CANCELED_TWO_TIMES = 1,
// User has rejected the onboarding and thus opted out of the experience.
LITE_SCRIPT_ONBOARDING_REJECTED = 2,
kMaxValue = LITE_SCRIPT_INTENT_RECEIVED
};
......
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