Reland "Reland "[AF] Add account indication footer to AutofillSaveCardInfoBar""

This reverts commit cd50c5655c6c1bb7d1d2c40908313174554c1e34.

Reason for revert: Relanding with tests removed, as discussed offline

Original change's description:
> Revert "Reland "[AF] Add account indication footer to AutofillSaveCardInfoBar""
>
> This reverts commit 6e85e7a4603787886fa8fc58b597e2b570e1bbc8.
>
> Reason for revert: crbug.com/1147678
>
> Original change's description:
> > Reland "[AF] Add account indication footer to AutofillSaveCardInfoBar"
> >
> > This is a reland of ba7d881429d42944c172ca7ca13938f78d5c4f1f. Two changes were made:
> > 1) A null pointer check is added to AutofillSaveCardInfoBar.java, and
> > 2) In AutofillUpstreamTest.java, startMainActivityWithURL() is replaced with loadUrl().
> >
> > Original change's description:
> > > [AF] Add account indication footer to AutofillSaveCardInfoBar
> > >
> > > The footer is shown only to signed-in users have more than one account, and who do not sync.
> > >
> > > Screenshot with feature enabled in light mode:
> > > https://screenshot.googleplex.com/ApVmkMVQakM6ai9
> > >
> > > Screenshot with feature enabled in dark mode:
> > > https://screenshot.googleplex.com/BJB2jUuGoH3T5jM
> > >
> > > Bug: 1135847, 1146186
> > > Change-Id: Ia2e031a48920e44e66503fab62f26ed87b8e1d92
> > > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2496184
> > > Commit-Queue: Anne Lim <[email protected]>
> > > Reviewed-by: Marc Treib <[email protected]>
> > > Reviewed-by: Matthew Jones <[email protected]>
> > > Reviewed-by: Jared Saul <[email protected]>
> > > Cr-Commit-Position: refs/heads/master@{#823710}
> >
> > Bug: 1135847
> > Change-Id: Ifd9d514234a3af82330686373578f54ffd3427c8
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2522219
> > Commit-Queue: Anne Lim <[email protected]>
> > Reviewed-by: Matthew Jones <[email protected]>
> > Reviewed-by: Jared Saul <[email protected]>
> > Reviewed-by: Marc Treib <[email protected]>
> > Cr-Commit-Position: refs/heads/master@{#825853}
>
> [email protected],[email protected],[email protected],[email protected],[email protected]
>
> Change-Id: I09677d00d3c73763eb0c95ba56fee01bedbb149a
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: 1135847, 1147678
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2531084
> Reviewed-by: Wei-Yin Chen (陳威尹) <[email protected]>
> Commit-Queue: Wei-Yin Chen (陳威尹) <[email protected]>
> Cr-Commit-Position: refs/heads/master@{#826176}

[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]

# Not skipping CQ checks because this is a reland.

Bug: 1135847
Bug: 1147678
Change-Id: I0277fa6869b760612b960b47eca7ba6114efeef0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2533277
Reviewed-by: Marc Treib <[email protected]>
Reviewed-by: Jared Saul <[email protected]>
Reviewed-by: Matthew Jones <[email protected]>
Reviewed-by: Anne Lim <[email protected]>
Commit-Queue: Anne Lim <[email protected]>
Cr-Commit-Position: refs/heads/master@{#826550}
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index 3c7a78c..346f0c6 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -6663,6 +6663,17 @@
      FEATURE_WITH_PARAMS_VALUE_TYPE(blink::features::kCheckOfflineCapability,
                                     kCheckOfflineCapabilityVariations,
                                     "CheckOfflineCapability")},
+#if defined(OS_ANDROID)
+    {"enable-autofill-save-card-info-bar-account-indication-footer",
+     flag_descriptions::
+         kEnableAutofillSaveCardInfoBarAccountIndicationFooterName,
+     flag_descriptions::
+         kEnableAutofillSaveCardInfoBarAccountIndicationFooterDescription,
+     kOsAndroid,
+     FEATURE_VALUE_TYPE(
+         autofill::features::
+             kAutofillEnableSaveCardInfoBarAccountIndicationFooter)},
+#endif
     {"detect-form-submission-on-form-clear",
      flag_descriptions::kDetectFormSubmissionOnFormClearName,
      flag_descriptions::kDetectFormSubmissionOnFormClearDescription, kOsAll,
diff --git a/chrome/browser/flag-metadata.json b/chrome/browser/flag-metadata.json
index 2837e7cf..7b1a7418 100644
--- a/chrome/browser/flag-metadata.json
+++ b/chrome/browser/flag-metadata.json
@@ -1262,6 +1262,11 @@
     "expiry_milestone": 78
   },
   {
+    "name": "enable-autofill-save-card-info-bar-account-indication-footer",
+    "owners": [ "[email protected], [email protected]"],
+    "expiry_milestone": 95
+  },
+  {
     "name": "enable-autofill-upi-vpa",
     "owners": [ "cfroussios" ],
     "expiry_milestone": 88
diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
index 85a3429..6bbcb95 100644
--- a/chrome/browser/flag_descriptions.cc
+++ b/chrome/browser/flag_descriptions.cc
@@ -524,6 +524,12 @@
     "When enabled, a footer indicating user's e-mail address will appear at "
     "the bottom of corresponding password InfoBars.";
 
+const char kEnableAutofillSaveCardInfoBarAccountIndicationFooterName[] =
+    "Display SaveCardInfoBar footer with account indication information";
+const char kEnableAutofillSaveCardInfoBarAccountIndicationFooterDescription[] =
+    "When enabled, a footer indicating user's e-mail address will appear at "
+    "the bottom of SaveCardInfoBar.";
+
 const char kEnableAutofillCreditCardCvcPromptGoogleLogoName[] =
     "Enable Google Pay branding on CVC prompt on Android";
 const char kEnableAutofillCreditCardCvcPromptGoogleLogoDescription[] =
diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h
index b2969f0..b3e13b0 100644
--- a/chrome/browser/flag_descriptions.h
+++ b/chrome/browser/flag_descriptions.h
@@ -332,6 +332,10 @@
 extern const char
     kEnableAutofillPasswordInfoBarAccountIndicationFooterDescription[];
 
+extern const char kEnableAutofillSaveCardInfoBarAccountIndicationFooterName[];
+extern const char
+    kEnableAutofillSaveCardInfoBarAccountIndicationFooterDescription[];
+
 extern const char kEnableExperimentalCookieFeaturesName[];
 extern const char kEnableExperimentalCookieFeaturesDescription[];
 
diff --git a/chrome/browser/flags/android/chrome_feature_list.cc b/chrome/browser/flags/android/chrome_feature_list.cc
index 3b88ac9..d6940a6 100644
--- a/chrome/browser/flags/android/chrome_feature_list.cc
+++ b/chrome/browser/flags/android/chrome_feature_list.cc
@@ -70,6 +70,7 @@
     &autofill::features::kAutofillCreditCardAuthentication,
     &autofill::features::kAutofillDownstreamCvcPromptUseGooglePayLogo,
     &autofill::features::kAutofillEnablePasswordInfoBarAccountIndicationFooter,
+    &autofill::features::kAutofillEnableSaveCardInfoBarAccountIndicationFooter,
     &autofill::features::kAutofillKeyboardAccessory,
     &autofill::features::kAutofillManualFallbackAndroid,
     &autofill::features::kAutofillRefreshStyleAndroid,
diff --git a/chrome/browser/flags/android/java/src/org/chromium/chrome/browser/flags/ChromeFeatureList.java b/chrome/browser/flags/android/java/src/org/chromium/chrome/browser/flags/ChromeFeatureList.java
index f36890f..60cd183 100644
--- a/chrome/browser/flags/android/java/src/org/chromium/chrome/browser/flags/ChromeFeatureList.java
+++ b/chrome/browser/flags/android/java/src/org/chromium/chrome/browser/flags/ChromeFeatureList.java
@@ -203,6 +203,8 @@
             "AutofillEnableGoogleIssuedCard";
     public static final String AUTOFILL_ENABLE_PASSWORD_INFO_BAR_ACCOUNT_INDICATION_FOOTER =
             "AutofillEnablePasswordInfoBarAccountIndicationFooter";
+    public static final String AUTOFILL_ENABLE_SAVE_CARD_INFO_BAR_ACCOUNT_INDICATION_FOOTER =
+            "AutofillEnableSaveCardInfoBarAccountIndicationFooter";
     public static final String ADJUST_WEBAPK_INSTALLATION_SPACE = "AdjustWebApkInstallationSpace";
     public static final String ANDROID_DEFAULT_BROWSER_PROMO = "AndroidDefaultBrowserPromo";
     public static final String ANDROID_MANAGED_BY_MENU_ITEM = "AndroidManagedByMenuItem";
diff --git a/chrome/browser/ui/android/infobars/autofill_save_card_infobar.cc b/chrome/browser/ui/android/infobars/autofill_save_card_infobar.cc
index e43d83fc..f60ce4b 100644
--- a/chrome/browser/ui/android/infobars/autofill_save_card_infobar.cc
+++ b/chrome/browser/ui/android/infobars/autofill_save_card_infobar.cc
@@ -24,15 +24,20 @@
 namespace autofill {
 
 std::unique_ptr<infobars::InfoBar> CreateSaveCardInfoBarMobile(
-    std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile> delegate) {
-  return std::make_unique<AutofillSaveCardInfoBar>(std::move(delegate));
+    std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile> delegate,
+    base::Optional<AccountInfo> account_info) {
+  return std::make_unique<AutofillSaveCardInfoBar>(std::move(delegate),
+                                                   account_info);
 }
 
 }  // namespace autofill
 
 AutofillSaveCardInfoBar::AutofillSaveCardInfoBar(
-    std::unique_ptr<autofill::AutofillSaveCardInfoBarDelegateMobile> delegate)
-    : ChromeConfirmInfoBar(std::move(delegate)) {}
+    std::unique_ptr<autofill::AutofillSaveCardInfoBarDelegateMobile> delegate,
+    base::Optional<AccountInfo> account_info)
+    : ChromeConfirmInfoBar(std::move(delegate)) {
+  account_info_ = account_info;
+}
 
 AutofillSaveCardInfoBar::~AutofillSaveCardInfoBar() {}
 
@@ -59,7 +64,10 @@
               env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK)),
           base::android::ConvertUTF16ToJavaString(
               env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL)),
-          delegate->IsGooglePayBrandingEnabled());
+          delegate->IsGooglePayBrandingEnabled(),
+          account_info_.has_value()
+              ? ConvertToJavaAccountInfo(env, account_info_.value())
+              : nullptr);
 
   Java_AutofillSaveCardInfoBar_setDescriptionText(
       env, java_delegate,
diff --git a/chrome/browser/ui/android/infobars/autofill_save_card_infobar.h b/chrome/browser/ui/android/infobars/autofill_save_card_infobar.h
index 97c2d05..c4df1a0 100644
--- a/chrome/browser/ui/android/infobars/autofill_save_card_infobar.h
+++ b/chrome/browser/ui/android/infobars/autofill_save_card_infobar.h
@@ -11,6 +11,7 @@
 
 #include "base/macros.h"
 #include "chrome/browser/ui/android/infobars/chrome_confirm_infobar.h"
+#include "components/signin/public/identity_manager/account_info.h"
 
 namespace autofill {
 class AutofillSaveCardInfoBarDelegateMobile;
@@ -20,8 +21,9 @@
 class AutofillSaveCardInfoBar : public ChromeConfirmInfoBar {
  public:
   explicit AutofillSaveCardInfoBar(
-      std::unique_ptr<autofill::AutofillSaveCardInfoBarDelegateMobile>
-          delegate);
+      std::unique_ptr<autofill::AutofillSaveCardInfoBarDelegateMobile> delegate,
+      base::Optional<AccountInfo> account_info);
+
   ~AutofillSaveCardInfoBar() override;
 
   // Called when a link in the legal message text was clicked.
@@ -40,6 +42,8 @@
   // are stored in /chrome and /components cannot depend on /chrome.
   int GetGooglePayBrandingIconId();
 
+  base::Optional<AccountInfo> account_info_;
+
   DISALLOW_COPY_AND_ASSIGN(AutofillSaveCardInfoBar);
 };
 
diff --git a/chrome/browser/ui/autofill/chrome_autofill_client.cc b/chrome/browser/ui/autofill/chrome_autofill_client.cc
index 4b959f7f..f7b2630 100644
--- a/chrome/browser/ui/autofill/chrome_autofill_client.cc
+++ b/chrome/browser/ui/autofill/chrome_autofill_client.cc
@@ -404,7 +404,8 @@
               /*upload=*/false, options, card, LegalMessageLines(),
               /*upload_save_card_callback=*/
               AutofillClient::UploadSaveCardPromptCallback(),
-              /*local_save_card_callback=*/std::move(callback), GetPrefs())));
+              /*local_save_card_callback=*/std::move(callback), GetPrefs()),
+          base::nullopt));
 #else
   // Do lazy initialization of SaveCardBubbleControllerImpl.
   SaveCardBubbleControllerImpl::CreateForWebContents(web_contents());
@@ -428,9 +429,19 @@
               /*upload_save_card_callback=*/std::move(callback),
               /*local_save_card_callback=*/
               AutofillClient::LocalSaveCardPromptCallback(), GetPrefs());
+  bool sync_disabled_wallet_transport_enabled =
+      GetPersonalDataManager()->GetSyncSigninState() ==
+      autofill::AutofillSyncSigninState::kSignedInAndWalletSyncTransportEnabled;
+
+  base::Optional<AccountInfo> account_info = base::nullopt;
+  // AccountInfo data should be passed down only if sync is off and user has
+  // multiple accounts.
+  if (sync_disabled_wallet_transport_enabled && IsMultipleAccountUser()) {
+    account_info = GetAccountInfo();
+  }
   InfoBarService::FromWebContents(web_contents())
       ->AddInfoBar(CreateSaveCardInfoBarMobile(
-          std::move(save_card_info_bar_delegate_mobile)));
+          std::move(save_card_info_bar_delegate_mobile), account_info));
 #else
   // Do lazy initialization of SaveCardBubbleControllerImpl.
   SaveCardBubbleControllerImpl::CreateForWebContents(web_contents());
@@ -718,6 +729,22 @@
   return Profile::FromBrowserContext(web_contents()->GetBrowserContext());
 }
 
+base::Optional<AccountInfo> ChromeAutofillClient::GetAccountInfo() {
+  signin::IdentityManager* identity_manager =
+      IdentityManagerFactory::GetForProfile(GetProfile());
+  CoreAccountId account_id =
+      identity_manager->GetPrimaryAccountId(signin::ConsentLevel::kNotRequired);
+  return identity_manager
+      ->FindExtendedAccountInfoForAccountWithRefreshTokenByAccountId(
+          account_id);
+}
+
+bool ChromeAutofillClient::IsMultipleAccountUser() {
+  signin::IdentityManager* identity_manager =
+      IdentityManagerFactory::GetForProfile(GetProfile());
+  return identity_manager->GetAccountsWithRefreshTokens().size() > 1;
+}
+
 base::string16 ChromeAutofillClient::GetAccountHolderName() {
   Profile* profile = GetProfile();
   if (!profile)
diff --git a/chrome/browser/ui/autofill/chrome_autofill_client.h b/chrome/browser/ui/autofill/chrome_autofill_client.h
index 1233d02..cd0cdd1 100644
--- a/chrome/browser/ui/autofill/chrome_autofill_client.h
+++ b/chrome/browser/ui/autofill/chrome_autofill_client.h
@@ -14,6 +14,7 @@
 #include "base/i18n/rtl.h"
 #include "base/macros.h"
 #include "base/memory/weak_ptr.h"
+#include "base/optional.h"
 #include "build/build_config.h"
 #include "chrome/browser/autofill/autofill_gstatic_reader.h"
 #include "chrome/browser/profiles/profile.h"
@@ -21,6 +22,7 @@
 #include "components/autofill/core/browser/logging/log_manager.h"
 #include "components/autofill/core/browser/payments/legal_message_line.h"
 #include "components/autofill/core/browser/ui/payments/card_unmask_prompt_controller_impl.h"
+#include "components/signin/public/identity_manager/account_info.h"
 #include "content/public/browser/web_contents_observer.h"
 #include "content/public/browser/web_contents_user_data.h"
 
@@ -174,6 +176,8 @@
   explicit ChromeAutofillClient(content::WebContents* web_contents);
 
   Profile* GetProfile() const;
+  base::Optional<AccountInfo> GetAccountInfo();
+  bool IsMultipleAccountUser();
   base::string16 GetAccountHolderName();
 
   std::unique_ptr<payments::PaymentsClient> payments_client_;