[Android][WebSignin] Add SignedInWithAddedAccount metric

This CL adds the metric SignedInWithAddedAccount for the web sign-in
flow when a user added an account and signed in with the account.

(cherry picked from commit f7da4a8c0fbff0e264c03484e7b187aa707cebaa)

Bug: 1136776
Change-Id: Icb79b2a8cd187aa85e82928692575a351946b888
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2464266
Commit-Queue: Alice Wang <[email protected]>
Reviewed-by: Boris Sazonov <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#816947}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2474779
Reviewed-by: Alice Wang <[email protected]>
Cr-Commit-Position: refs/branch-heads/4280@{#409}
Cr-Branched-From: ea420fb963f9658c9969b6513c56b8f47efa1a2a-refs/heads/master@{#812852}
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/signin/account_picker/AccountConsistencyPromoAction.java b/chrome/android/java/src/org/chromium/chrome/browser/signin/account_picker/AccountConsistencyPromoAction.java
index a103016..cb1ab0a 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/signin/account_picker/AccountConsistencyPromoAction.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/signin/account_picker/AccountConsistencyPromoAction.java
@@ -25,6 +25,7 @@
         AccountConsistencyPromoAction.SIGNED_IN_WITH_NON_DEFAULT_ACCOUNT,
         AccountConsistencyPromoAction.SHOWN,
         AccountConsistencyPromoAction.SUPPRESSED_SIGNIN_NOT_ALLOWED,
+        AccountConsistencyPromoAction.SIGNED_IN_WITH_ADDED_ACCOUNT,
 })
 @Retention(RetentionPolicy.SOURCE)
 public @interface AccountConsistencyPromoAction {
@@ -71,5 +72,12 @@
      */
     int SUPPRESSED_SIGNIN_NOT_ALLOWED = 7;
 
-    int MAX = 8;
+    /**
+     * User has added an account and signed in with this account.
+     * When this metric is recorded, we won't record SIGNED_IN_WITH_DEFAULT_ACCOUNT or
+     * SIGNED_IN_WITH_NON_DEFAULT_ACCOUNT.
+     */
+    int SIGNED_IN_WITH_ADDED_ACCOUNT = 8;
+
+    int MAX = 9;
 }
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/signin/account_picker/AccountPickerBottomSheetMediator.java b/chrome/android/java/src/org/chromium/chrome/browser/signin/account_picker/AccountPickerBottomSheetMediator.java
index 3a935e6..d8195d1 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/signin/account_picker/AccountPickerBottomSheetMediator.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/signin/account_picker/AccountPickerBottomSheetMediator.java
@@ -41,6 +41,7 @@
     private final AccountsChangeObserver mAccountsChangeObserver = this::onAccountListUpdated;
     private @Nullable String mSelectedAccountName;
     private @Nullable String mDefaultAccountName;
+    private @Nullable String mAddedAccountName;
 
     AccountPickerBottomSheetMediator(Context context, AccountPickerDelegate accountPickerDelegate) {
         mAccountPickerDelegate = accountPickerDelegate;
@@ -53,6 +54,7 @@
 
         mAccountManagerFacade = AccountManagerFacadeProvider.getInstance();
         mAccountManagerFacade.addObserver(mAccountsChangeObserver);
+        mAddedAccountName = null;
         onAccountListUpdated();
     }
 
@@ -80,7 +82,10 @@
     public void addAccount() {
         AccountPickerDelegate.recordAccountConsistencyPromoAction(
                 AccountConsistencyPromoAction.ADD_ACCOUNT);
-        mAccountPickerDelegate.addAccount(accountName -> onAccountSelected(accountName, false));
+        mAccountPickerDelegate.addAccount(accountName -> {
+            mAddedAccountName = accountName;
+            onAccountSelected(accountName, false);
+        });
     }
 
     /**
@@ -206,10 +211,16 @@
 
     private void signIn() {
         mModel.set(AccountPickerBottomSheetProperties.VIEW_STATE, ViewState.SIGNIN_IN_PROGRESS);
-        AccountPickerDelegate.recordAccountConsistencyPromoAction(
-                TextUtils.equals(mSelectedAccountName, mDefaultAccountName)
-                        ? AccountConsistencyPromoAction.SIGNED_IN_WITH_DEFAULT_ACCOUNT
-                        : AccountConsistencyPromoAction.SIGNED_IN_WITH_NON_DEFAULT_ACCOUNT);
+        if (TextUtils.equals(mSelectedAccountName, mAddedAccountName)) {
+            AccountPickerDelegate.recordAccountConsistencyPromoAction(
+                    AccountConsistencyPromoAction.SIGNED_IN_WITH_ADDED_ACCOUNT);
+        } else if (TextUtils.equals(mSelectedAccountName, mDefaultAccountName)) {
+            AccountPickerDelegate.recordAccountConsistencyPromoAction(
+                    AccountConsistencyPromoAction.SIGNED_IN_WITH_DEFAULT_ACCOUNT);
+        } else {
+            AccountPickerDelegate.recordAccountConsistencyPromoAction(
+                    AccountConsistencyPromoAction.SIGNED_IN_WITH_NON_DEFAULT_ACCOUNT);
+        }
         new AsyncTask<String>() {
             @Override
             protected String doInBackground() {
diff --git a/tools/metrics/histograms/enums.xml b/tools/metrics/histograms/enums.xml
index 59657b44..44b1896 100644
--- a/tools/metrics/histograms/enums.xml
+++ b/tools/metrics/histograms/enums.xml
@@ -972,6 +972,9 @@
     Promo is not shown due to sign-in being disallowed either by an enterprise
     policy or by |Allow Chrome sign-in| toggle.
   </int>
+  <int value="8" label="SignedInWithAddedAccount">
+    User has added an account and signed in with this account.
+  </int>
 </enum>
 
 <enum name="AccountManagerAccountAdditionSource">