[Android][WebSignin] Record error metrics for web sign-in flow

This CL records two error metrics for the web sign-in flow.

(cherry picked from commit 6e3508ec0c228c58c64ebb1401a7a5b31e7028a0)

Bug: 1138925
Change-Id: Ieb5e5b04b1593e1f4e22ffdd9afd7ad0229fbd75
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2479163
Reviewed-by: Boris Sazonov <[email protected]>
Commit-Queue: Alice Wang <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#817895}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2484695
Reviewed-by: Alice Wang <[email protected]>
Cr-Commit-Position: refs/branch-heads/4280@{#481}
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 c83e121..4bbea88f 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
@@ -29,6 +29,8 @@
         AccountConsistencyPromoAction.DISMISSED_SCRIM,
         AccountConsistencyPromoAction.DISMISSED_SWIPE_DOWN,
         AccountConsistencyPromoAction.DISMISSED_OTHER,
+        AccountConsistencyPromoAction.AUTH_ERROR_SHOWN,
+        AccountConsistencyPromoAction.GENERIC_ERROR_SHOWN,
 })
 @Retention(RetentionPolicy.SOURCE)
 public @interface AccountConsistencyPromoAction {
@@ -97,5 +99,15 @@
      */
     int DISMISSED_OTHER = 11;
 
-    int MAX = 12;
+    /**
+     * The auth error screen was shown to the user.
+     */
+    int AUTH_ERROR_SHOWN = 12;
+
+    /**
+     * The generic error screen was shown to the user.
+     */
+    int GENERIC_ERROR_SHOWN = 13;
+
+    int MAX = 14;
 }
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 4b0f055..f35da8e 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
@@ -20,6 +20,7 @@
 import org.chromium.components.signin.AccountsChangeObserver;
 import org.chromium.components.signin.base.CoreAccountId;
 import org.chromium.components.signin.base.CoreAccountInfo;
+import org.chromium.components.signin.base.GoogleServiceAuthError;
 import org.chromium.components.signin.base.GoogleServiceAuthError.State;
 import org.chromium.ui.modelutil.PropertyModel;
 
@@ -229,17 +230,26 @@
             protected void onPostExecute(String accountGaiaId) {
                 CoreAccountInfo coreAccountInfo = new CoreAccountInfo(
                         new CoreAccountId(accountGaiaId), mSelectedAccountName, accountGaiaId);
-                mAccountPickerDelegate.signIn(coreAccountInfo, error -> {
-                    @ViewState
-                    int newViewState = error.getState() == State.INVALID_GAIA_CREDENTIALS
-                            ? ViewState.SIGNIN_AUTH_ERROR
-                            : ViewState.SIGNIN_GENERAL_ERROR;
-                    mModel.set(AccountPickerBottomSheetProperties.VIEW_STATE, newViewState);
-                });
+                mAccountPickerDelegate.signIn(
+                        coreAccountInfo, AccountPickerBottomSheetMediator.this::onSigninFailed);
             }
         }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
     }
 
+    private void onSigninFailed(GoogleServiceAuthError error) {
+        final @AccountConsistencyPromoAction int promoAction;
+        final @ViewState int newViewState;
+        if (error.getState() == State.INVALID_GAIA_CREDENTIALS) {
+            promoAction = AccountConsistencyPromoAction.AUTH_ERROR_SHOWN;
+            newViewState = ViewState.SIGNIN_AUTH_ERROR;
+        } else {
+            promoAction = AccountConsistencyPromoAction.GENERIC_ERROR_SHOWN;
+            newViewState = ViewState.SIGNIN_GENERAL_ERROR;
+        }
+        AccountPickerDelegate.recordAccountConsistencyPromoAction(promoAction);
+        mModel.set(AccountPickerBottomSheetProperties.VIEW_STATE, newViewState);
+    }
+
     private void updateCredentials() {
         mAccountPickerDelegate.updateCredentials(mSelectedAccountName, (isSuccess) -> {
             if (isSuccess) {
diff --git a/tools/metrics/histograms/enums.xml b/tools/metrics/histograms/enums.xml
index 38a696d..2464cb2 100644
--- a/tools/metrics/histograms/enums.xml
+++ b/tools/metrics/histograms/enums.xml
@@ -984,6 +984,12 @@
   <int value="11" label="DismissedOther">
     User has dismissed the promo by other means.
   </int>
+  <int value="12" label="AuthErrorShown">
+    The auth error screen was shown to the user.
+  </int>
+  <int value="13" label="GenericErrorShown">
+    The generic error screen was shown to the user.
+  </int>
 </enum>
 
 <enum name="AccountManagerAccountAdditionSource">