[Autofill]: Add profile and payment methods toggle buttons in settings/autofill.

Both AutofillProfileEnabled and AutofillCreditCardEnabled are preferences
that can't be modified by the user. This CL adds a toggle button for each one of
them in settings/autofill.
These flags do not delete existing data, therefore we don't want addresses and
payment methods to disapear when toggling the flag.
To fix that, this CL moves enabling logic from
PersonalDataManager::Get[Profiles/CreditCards]() to
PersonalDataManager::Get[Profiles/CreditCards]ToSuggest()

Bug: 860526
Tbr: eugenebut@
Cq-Include-Trybots: luci.chromium.try:closure_compilation;luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I03f6e16294ae2a07da854c4d276e95f1a47ebbc0
Reviewed-on: https://chromium-review.googlesource.com/1129471
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Reviewed-by: Rouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: Moe Ahmadi <mahmadi@chromium.org>
Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: Sebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576679}
diff --git a/chrome/app/settings_strings.grdp b/chrome/app/settings_strings.grdp
index 7a74a2bd..7d0ad77 100644
--- a/chrome/app/settings_strings.grdp
+++ b/chrome/app/settings_strings.grdp
@@ -625,6 +625,12 @@
   <message name="IDS_SETTINGS_AUTOFILL_TOGGLE_LABEL" desc="Label for a toggle that allows users to control whether forms should be autofilled with data such as addresses and credit cards, but not passwords.">
     Autofill forms
   </message>
+  <message name="IDS_SETTINGS_AUTOFILL_ENABLE_PROFILES_TOGGLE_LABEL" desc="Label for a toggle that allows users to control whether addresses should be saved and forms should be autofilled with them.">
+    Save and fill addresses
+  </message>
+  <message name="IDS_SETTINGS_AUTOFILL_ENABLE_CREDIT_CARDS_TOGGLE_LABEL" desc="Label for a toggle that allows users to control whether credit cards should be saved and forms should be autofilled with it.">
+    Save and fill payment methods
+  </message>
   <message name="IDS_SETTINGS_AUTOFILL_ADDRESSES_HEADING" desc="Title for the list of addresses that chrome has saved for use in filling in forms.">
     Addresses
   </message>
@@ -754,13 +760,6 @@
   <message name="IDS_SETTINGS_PAYMENT_METHODS_NONE" desc="Placeholder that is shown when there are no payment methods in the list of saved payment methods.">
     Saved payment methods will appear here
   </message>
-  <!-- TODO(https://crbug.com/854562): Remove this string (and use "IDS_SETTINGS_PAYMENT_METHODS_DISABLED" instead) once Autofill Home is fully launched. -->
-  <message name="IDS_SETTINGS_CREDIT_CARD_DISABLED" desc="Placeholder that is shown when credit card autofill has been disabled by policy.">
-    Saved cards are disabled by your administrator
-  </message>
-  <message name="IDS_SETTINGS_PAYMENT_METHODS_DISABLED" desc="Placeholder that is shown when payment methods autofill has been disabled by policy.">
-    Saved payment methods are disabled by your administrator
-  </message>
   <message name="IDS_SETTINGS_PASSWORDS_NONE" desc="Placeholder that is shown when there are no passwords in the list of saved passwords.">
     Saved passwords will appear here
   </message>
diff --git a/chrome/browser/resources/settings/passwords_and_forms_page/autofill_section.html b/chrome/browser/resources/settings/passwords_and_forms_page/autofill_section.html
index 4fea904c..1e0dc70 100644
--- a/chrome/browser/resources/settings/passwords_and_forms_page/autofill_section.html
+++ b/chrome/browser/resources/settings/passwords_and_forms_page/autofill_section.html
@@ -82,11 +82,20 @@
         </extension-controlled-indicator>
       </div>
     </template>
+    <settings-toggle-button id="autofillProfileToggle"
+        class="settings-box first"
+        aria-label="$i18n{autofill}" no-extension-indicator
+        label="$i18n{enableProfilesLabel}"
+        pref="{{prefs.autofill.profile_enabled}}"
+        disabled$="[[!prefs.autofill.enabled.value]]">
+    </settings-toggle-button>
     <div class="settings-box continuation">
       <h2 class="start">$i18n{addresses}</h2>
       <paper-button id="addAddress"
           class="secondary-button header-aligned-button"
-          on-click="onAddAddressTap_">
+          on-click="onAddAddressTap_"
+          disabled$="[[eitherIsDisabled_(prefs.autofill.enabled.value,
+              prefs.autofill.profile_enabled.value)]]">
         $i18n{add}
       </paper-button>
     </div>
@@ -138,69 +147,68 @@
           on-close="onAddressDialogClosed_">
       </settings-address-edit-dialog>
     </template>
-    <div class="settings-box first">
+    <settings-toggle-button id="autofillCreditCardToggle"
+        class="settings-box first"
+        aria-label="$i18n{autofill}" no-extension-indicator
+        label="$i18n{enableCreditCardsLabel}"
+        pref="{{prefs.autofill.credit_card_enabled}}"
+        disabled$="[[!prefs.autofill.enabled.value]]">
+    </settings-toggle-button>
+    <div class="settings-box continuation">
       <h2 class="start">$i18n{creditCards}</h2>
       <paper-button id="addCreditCard"
           class="secondary-button header-aligned-button"
           on-click="onAddCreditCardTap_"
-          hidden$="[[isDisabled_(prefs.autofill.credit_card_enabled)]]">
+          disabled$="[[eitherIsDisabled_(prefs.autofill.enabled.value,
+                           prefs.autofill.credit_card_enabled.value)]]">
         $i18n{add}
       </paper-button>
     </div>
     <div class="list-frame">
-      <template is="dom-if"
-          if="[[!isDisabled_(prefs.autofill.credit_card_enabled)]]">
-        <div id="creditCardsHeading" class="list-item column-header"
-            hidden$="[[!hasSome_(creditCards)]]">
-          <div class="type-column">$i18n{creditCardType}</div>
-          <div class="expiration-column">$i18n{creditCardExpiration}</div>
-        </div>
-        <div id="creditCardList" class="vertical-list list-with-header">
-          <template is="dom-repeat" items="[[creditCards]]">
-            <div class="list-item">
-              <div class="type-column">
-                <span id="creditCardLabel">[[item.metadata.summaryLabel]]</span>
-                <span class="payments-label"
-                    hidden$="[[item.metadata.isLocal]]">
-                  <span hidden$="[[item.metadata.isCached]]">
-                    $i18n{googlePayments}
-                  </span>
-                  <span hidden$="[[!item.metadata.isCached]]">
-                    $i18n{googlePaymentsCached}
-                  </span>
+      <div id="creditCardsHeading" class="list-item column-header"
+          hidden$="[[!hasSome_(creditCards)]]">
+        <div class="type-column">$i18n{creditCardType}</div>
+        <div class="expiration-column">$i18n{creditCardExpiration}</div>
+      </div>
+      <div id="creditCardList" class="vertical-list list-with-header">
+        <template is="dom-repeat" items="[[creditCards]]">
+          <div class="list-item">
+            <div class="type-column">
+              <span id="creditCardLabel">[[item.metadata.summaryLabel]]</span>
+              <span class="payments-label"
+                  hidden$="[[item.metadata.isLocal]]">
+                <span hidden$="[[item.metadata.isCached]]">
+                  $i18n{googlePayments}
                 </span>
-              </div>
-              <div class="expiration-column">
-                <div id="creditCardExpiration"
-                    class="expiration-date">[[expiration_(item)]]</div>
-                <template is="dom-if" if="[[showDots_(item.metadata)]]">
-                  <paper-icon-button-light class="icon-more-vert">
-                    <button id="creditCardMenu" title="$i18n{moreActions}"
-                        on-click="onCreditCardMenuTap_">
-                    </button>
-                  </paper-icon-button-light>
-                </template>
-                <template is="dom-if" if="[[!showDots_(item.metadata)]]">
-                  <paper-icon-button-light actionable class="icon-external">
-                    <button id="remoteCreditCardLink"
-                        on-click="onRemoteEditCreditCardTap_">
-                    </button>
-                  </paper-icon-button-light>
-                </template>
-              </div>
+                <span hidden$="[[!item.metadata.isCached]]">
+                  $i18n{googlePaymentsCached}
+                </span>
+              </span>
             </div>
-          </template>
-        </div>
-        <div id="noCreditCardsLabel" class="list-item"
-            hidden$="[[hasSome_(creditCards)]]">
-          $i18n{noCreditCardsFound}
-        </div>
-      </template>
-      <div id="CreditCardsDisabledLabel" class="list-item"
-          hidden$="[[!isDisabled_(prefs.autofill.credit_card_enabled)]]">
-        <cr-policy-indicator indicator-type="userPolicy"
-            icon-aria-label="$i18n{noCreditCardsPolicy}"></cr-policy-indicator>
-        $i18n{noCreditCardsPolicy}
+            <div class="expiration-column">
+              <div id="creditCardExpiration"
+                  class="expiration-date">[[expiration_(item)]]</div>
+              <template is="dom-if" if="[[showDots_(item.metadata)]]">
+                <paper-icon-button-light class="icon-more-vert">
+                  <button id="creditCardMenu" title="$i18n{moreActions}"
+                      on-click="onCreditCardMenuTap_">
+                  </button>
+                </paper-icon-button-light>
+              </template>
+              <template is="dom-if" if="[[!showDots_(item.metadata)]]">
+                <paper-icon-button-light actionable class="icon-external">
+                  <button id="remoteCreditCardLink"
+                      on-click="onRemoteEditCreditCardTap_">
+                  </button>
+                </paper-icon-button-light>
+              </template>
+            </div>
+          </div>
+        </template>
+      </div>
+      <div id="noCreditCardsLabel" class="list-item"
+          hidden$="[[hasSome_(creditCards)]]">
+        $i18n{noCreditCardsFound}
       </div>
     </div>
     <cr-action-menu id="creditCardSharedMenu">
diff --git a/chrome/browser/resources/settings/passwords_and_forms_page/autofill_section.js b/chrome/browser/resources/settings/passwords_and_forms_page/autofill_section.js
index f70059b..36ad55d 100644
--- a/chrome/browser/resources/settings/passwords_and_forms_page/autofill_section.js
+++ b/chrome/browser/resources/settings/passwords_and_forms_page/autofill_section.js
@@ -441,16 +441,16 @@
   },
 
   /**
-   * Returns true if the pref has been explicitly disabled.
-   * @param {Object} pref
+   * Returns true if either pref value is false.
+   * @param {boolean} pref1Value
+   * @param {boolean} pref2Value
    * @return {boolean}
    * @private
    */
-  isDisabled_: function(pref) {
-    return !!pref && (pref.value === false);
+  eitherIsDisabled_: function(pref1Value, pref2Value) {
+    return !pref1Value || !pref2Value;
   },
 
-
   /**
    * Listens for the save-address event, and calls the private API.
    * @param {!Event} event
diff --git a/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc b/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc
index 0d21d27..5918900 100644
--- a/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc
+++ b/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc
@@ -1376,6 +1376,10 @@
       {"googlePayments", IDS_SETTINGS_GOOGLE_PAYMENTS},
       {"googlePaymentsCached", IDS_SETTINGS_GOOGLE_PAYMENTS_CACHED},
       {"autofillFormsLabel", IDS_SETTINGS_AUTOFILL_TOGGLE_LABEL},
+      {"enableProfilesLabel",
+       IDS_SETTINGS_AUTOFILL_ENABLE_PROFILES_TOGGLE_LABEL},
+      {"enableCreditCardsLabel",
+       IDS_SETTINGS_AUTOFILL_ENABLE_CREDIT_CARDS_TOGGLE_LABEL},
       {"addresses", IDS_SETTINGS_AUTOFILL_ADDRESSES_HEADING},
       {"addAddressTitle", IDS_SETTINGS_AUTOFILL_ADDRESSES_ADD_TITLE},
       {"editAddressTitle", IDS_SETTINGS_AUTOFILL_ADDRESSES_EDIT_TITLE},
@@ -1450,8 +1454,6 @@
                                     IDS_SETTINGS_AUTOFILL_PAYMENT_METHODS);
     html_source->AddLocalizedString("noCreditCardsFound",
                                     IDS_SETTINGS_PAYMENT_METHODS_NONE);
-    html_source->AddLocalizedString("noCreditCardsPolicy",
-                                    IDS_SETTINGS_PAYMENT_METHODS_DISABLED);
   } else {
     html_source->AddLocalizedString("autofill", IDS_SETTINGS_AUTOFILL);
     html_source->AddLocalizedString("passwords", IDS_SETTINGS_PASSWORDS);
@@ -1459,8 +1461,6 @@
                                     IDS_SETTINGS_AUTOFILL_CREDIT_CARD_HEADING);
     html_source->AddLocalizedString("noCreditCardsFound",
                                     IDS_SETTINGS_CREDIT_CARD_NONE);
-    html_source->AddLocalizedString("noCreditCardsPolicy",
-                                    IDS_SETTINGS_CREDIT_CARD_DISABLED);
   }
 
   html_source->AddString(
diff --git a/chrome/test/data/webui/settings/passwords_and_forms_browsertest.js b/chrome/test/data/webui/settings/passwords_and_forms_browsertest.js
index ea9ae3f..e73849a 100644
--- a/chrome/test/data/webui/settings/passwords_and_forms_browsertest.js
+++ b/chrome/test/data/webui/settings/passwords_and_forms_browsertest.js
@@ -85,6 +85,11 @@
           value: autofill,
         },
         {
+          key: 'autofill.profile_enabled',
+          type: chrome.settingsPrivate.PrefType.BOOLEAN,
+          value: true,
+        },
+        {
           key: 'autofill.credit_card_enabled',
           type: chrome.settingsPrivate.PrefType.BOOLEAN,
           value: true,
diff --git a/chrome/test/data/webui/settings/settings_autofill_section_browsertest.js b/chrome/test/data/webui/settings/settings_autofill_section_browsertest.js
index 3eeac68..9f8cacd 100644
--- a/chrome/test/data/webui/settings/settings_autofill_section_browsertest.js
+++ b/chrome/test/data/webui/settings/settings_autofill_section_browsertest.js
@@ -116,11 +116,11 @@
    * Creates the autofill section for the given lists.
    * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList
    * @param {!Array<!chrome.passwordsPrivate.ExceptionEntry>} exceptionList
-   * @param {!Object} pref_value
+   * @param {!Object} prefValues
    * @return {!Object}
    * @private
    */
-  createAutofillSection_: function(addresses, creditCards, pref_value) {
+  createAutofillSection_: function(addresses, creditCards, prefValues) {
     // Override the AutofillManagerImpl for testing.
     this.autofillManager = new TestAutofillManager();
     this.autofillManager.data.addresses = addresses;
@@ -128,7 +128,7 @@
     AutofillManagerImpl.instance_ = this.autofillManager;
 
     const section = document.createElement('settings-autofill-section');
-    section.prefs = {autofill: {credit_card_enabled: pref_value}};
+    section.prefs = {autofill: prefValues};
     document.body.appendChild(section);
     Polymer.dom.flush();
 
@@ -171,7 +171,9 @@
     test('testAutofillExtensionIndicator', function() {
       // Initializing with fake prefs
       const section = document.createElement('settings-autofill-section');
-      section.prefs = {autofill: {enabled: {}, credit_card_enabled: {}}};
+      section.prefs = {
+        autofill: {enabled: {}, credit_card_enabled: {}, profile_enabled: {}}
+      };
       document.body.appendChild(section);
 
       assertFalse(!!section.$$('#autofillExtensionIndicator'));
@@ -199,7 +201,8 @@
     });
 
     test('verifyCreditCardCount', function() {
-      const section = self.createAutofillSection_([], [], {});
+      const section = self.createAutofillSection_(
+          [], [], {enabled: {value: true}, credit_card_enabled: {value: true}});
 
       const creditCardList = section.$$('#creditCardList');
       assertTrue(!!creditCardList);
@@ -207,14 +210,26 @@
 
       assertFalse(section.$$('#noCreditCardsLabel').hidden);
       assertTrue(section.$$('#creditCardsHeading').hidden);
-      assertTrue(section.$$('#CreditCardsDisabledLabel').hidden);
+      assertFalse(section.$$('#autofillCreditCardToggle').disabled);
+      assertFalse(section.$$('#addCreditCard').disabled);
+    });
+
+    test('verifyDisabled', function() {
+      const section = self.createAutofillSection_(
+          [], [],
+          {enabled: {value: false}, credit_card_enabled: {value: true}});
+
+      assertTrue(section.$$('#autofillCreditCardToggle').disabled);
+      assertTrue(section.$$('#addCreditCard').disabled);
     });
 
     test('verifyCreditCardsDisabled', function() {
-      const section = self.createAutofillSection_([], [], {value: false});
+      const section = self.createAutofillSection_(
+          [], [],
+          {enabled: {value: true}, credit_card_enabled: {value: false}});
 
-      assertEquals(0, section.querySelectorAll('#creditCardList').length);
-      assertFalse(section.$$('#CreditCardsDisabledLabel').hidden);
+      assertFalse(section.$$('#autofillCreditCardToggle').disabled);
+      assertTrue(section.$$('#addCreditCard').disabled);
     });
 
     test('verifyCreditCardCount', function() {
@@ -227,7 +242,9 @@
         FakeDataMaker.creditCardEntry(),
       ];
 
-      const section = self.createAutofillSection_([], creditCards, {});
+      const section = self.createAutofillSection_(
+          [], creditCards,
+          {enabled: {value: true}, credit_card_enabled: {value: true}});
       const creditCardList = section.$$('#creditCardList');
       assertTrue(!!creditCardList);
       assertEquals(
@@ -236,7 +253,8 @@
 
       assertTrue(section.$$('#noCreditCardsLabel').hidden);
       assertFalse(section.$$('#creditCardsHeading').hidden);
-      assertTrue(section.$$('#CreditCardsDisabledLabel').hidden);
+      assertFalse(section.$$('#autofillCreditCardToggle').disabled);
+      assertFalse(section.$$('#addCreditCard').disabled);
     });
 
     test('verifyCreditCardFields', function() {
@@ -540,7 +558,8 @@
     });
 
     test('verifyNoAddresses', function() {
-      const section = self.createAutofillSection_([], [], {});
+      const section = self.createAutofillSection_(
+          [], [], {enabled: {value: true}, profile_enabled: {value: true}});
 
       const addressList = section.$.addressList;
       assertTrue(!!addressList);
@@ -548,6 +567,8 @@
       assertEquals(1, addressList.children.length);
 
       assertFalse(section.$.noAddressesLabel.hidden);
+      assertFalse(section.$$('#addAddress').disabled);
+      assertFalse(section.$$('#autofillProfileToggle').disabled);
     });
 
     test('verifyAddressCount', function() {
@@ -559,7 +580,9 @@
         FakeDataMaker.addressEntry(),
       ];
 
-      const section = self.createAutofillSection_(addresses, [], {});
+      const section = self.createAutofillSection_(
+          addresses, [],
+          {enabled: {value: true}, profile_enabled: {value: true}});
 
       const addressList = section.$.addressList;
       assertTrue(!!addressList);
@@ -567,6 +590,24 @@
           addresses.length, addressList.querySelectorAll('.list-item').length);
 
       assertTrue(section.$.noAddressesLabel.hidden);
+      assertFalse(section.$$('#autofillProfileToggle').disabled);
+      assertFalse(section.$$('#addAddress').disabled);
+    });
+
+    test('verifyDisabled', function() {
+      const section = self.createAutofillSection_(
+          [], [], {enabled: {value: false}, profile_enabled: {value: true}});
+
+      assertTrue(section.$$('#autofillProfileToggle').disabled);
+      assertTrue(section.$$('#addAddress').disabled);
+    });
+
+    test('verifyAddressDisabled', function() {
+      const section = self.createAutofillSection_(
+          [], [], {enabled: {value: true}, profile_enabled: {value: false}});
+
+      assertFalse(section.$$('#autofillProfileToggle').disabled);
+      assertTrue(section.$$('#addAddress').disabled);
     });
 
     test('verifyAddressFields', function() {
diff --git a/components/autofill/core/browser/address_combobox_model_unittest.cc b/components/autofill/core/browser/address_combobox_model_unittest.cc
index 487e735..a886a88 100644
--- a/components/autofill/core/browser/address_combobox_model_unittest.cc
+++ b/components/autofill/core/browser/address_combobox_model_unittest.cc
@@ -17,6 +17,7 @@
 
 TEST(AddressComboboxModelTest, Empty) {
   TestPersonalDataManager test_personal_data_manager;
+  test_personal_data_manager.SetAutofillProfileEnabled(true);
 
   AddressComboboxModel model(test_personal_data_manager, kAppLocale, "");
   EXPECT_EQ(1, model.GetItemCount());
@@ -27,6 +28,7 @@
 
 TEST(AddressComboboxModelTest, OneAddress) {
   TestPersonalDataManager test_personal_data_manager;
+  test_personal_data_manager.SetAutofillProfileEnabled(true);
   AutofillProfile profile1(test::GetFullProfile());
   test_personal_data_manager.AddProfile(profile1);
 
@@ -45,6 +47,7 @@
 
 TEST(AddressComboboxModelTest, TwoAddresses) {
   TestPersonalDataManager test_personal_data_manager;
+  test_personal_data_manager.SetAutofillProfileEnabled(true);
   AutofillProfile profile1(test::GetFullProfile());
   AutofillProfile profile2(test::GetFullProfile2());
 
@@ -70,6 +73,7 @@
 
 TEST(AddressComboboxModelTest, AddAnAddress) {
   TestPersonalDataManager test_personal_data_manager;
+  test_personal_data_manager.SetAutofillProfileEnabled(true);
   AutofillProfile profile1(test::GetFullProfile());
   test_personal_data_manager.AddProfile(profile1);
 
diff --git a/components/autofill/core/browser/autofill_wallet_data_type_controller.cc b/components/autofill/core/browser/autofill_wallet_data_type_controller.cc
index 1a094ec..575c9e4 100644
--- a/components/autofill/core/browser/autofill_wallet_data_type_controller.cc
+++ b/components/autofill/core/browser/autofill_wallet_data_type_controller.cc
@@ -39,10 +39,6 @@
       autofill::prefs::kAutofillWalletImportEnabled,
       base::Bind(&AutofillWalletDataTypeController::OnUserPrefChanged,
                  base::AsWeakPtr(this)));
-  pref_registrar_.Add(
-      autofill::prefs::kAutofillCreditCardEnabled,
-      base::Bind(&AutofillWalletDataTypeController::OnUserPrefChanged,
-                 base::AsWeakPtr(this)));
 }
 
 AutofillWalletDataTypeController::~AutofillWalletDataTypeController() {}
@@ -124,8 +120,7 @@
   // Require the user-visible pref to be enabled to sync Wallet data/metadata,
   // and also check that Autofill for credit cards is not disabled by policy.
   PrefService* ps = sync_client_->GetPrefService();
-  return ps->GetBoolean(autofill::prefs::kAutofillWalletImportEnabled) &&
-         ps->GetBoolean(autofill::prefs::kAutofillCreditCardEnabled);
+  return ps->GetBoolean(autofill::prefs::kAutofillWalletImportEnabled);
 }
 void AutofillWalletDataTypeController::DisableForPolicy() {
   if (state() != NOT_RUNNING && state() != STOPPING) {
diff --git a/components/autofill/core/browser/autofill_wallet_data_type_controller_unittest.cc b/components/autofill/core/browser/autofill_wallet_data_type_controller_unittest.cc
index c9f958d..b6d29b62 100644
--- a/components/autofill/core/browser/autofill_wallet_data_type_controller_unittest.cc
+++ b/components/autofill/core/browser/autofill_wallet_data_type_controller_unittest.cc
@@ -178,7 +178,7 @@
   EXPECT_EQ(syncer::DataTypeController::RUNNING, autofill_wallet_dtc_->state());
   EXPECT_FALSE(last_error_.IsSet());
   EXPECT_EQ(syncer::AUTOFILL_WALLET_DATA, last_type_);
-  GetPrefService()->SetBoolean(autofill::prefs::kAutofillCreditCardEnabled,
+  GetPrefService()->SetBoolean(autofill::prefs::kAutofillWalletImportEnabled,
                                false);
   base::RunLoop().RunUntilIdle();
   EXPECT_TRUE(last_error_.IsSet());
@@ -187,7 +187,7 @@
 TEST_F(AutofillWalletDataTypeControllerTest, DatatypeDisabledAtStartup) {
   SetStartExpectations();
   web_data_service_->LoadDatabase();
-  GetPrefService()->SetBoolean(autofill::prefs::kAutofillCreditCardEnabled,
+  GetPrefService()->SetBoolean(autofill::prefs::kAutofillWalletImportEnabled,
                                false);
   EXPECT_EQ(syncer::DataTypeController::NOT_RUNNING,
             autofill_wallet_dtc_->state());
diff --git a/components/autofill/core/browser/personal_data_manager.cc b/components/autofill/core/browser/personal_data_manager.cc
index f7b77e22..a357916 100644
--- a/components/autofill/core/browser/personal_data_manager.cc
+++ b/components/autofill/core/browser/personal_data_manager.cc
@@ -738,6 +738,9 @@
 }
 
 void PersonalDataManager::AddProfile(const AutofillProfile& profile) {
+  if (!IsAutofillProfileEnabled())
+    return;
+
   if (is_off_the_record_)
     return;
 
@@ -804,6 +807,9 @@
 }
 
 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) {
+  if (!IsAutofillCreditCardEnabled())
+    return;
+
   if (is_off_the_record_)
     return;
 
@@ -1088,8 +1094,6 @@
 
 std::vector<AutofillProfile*> PersonalDataManager::GetProfiles() const {
   std::vector<AutofillProfile*> result;
-  if (!IsAutofillProfileEnabled())
-    return result;
   result.reserve(web_profiles_.size());
   for (const auto& profile : web_profiles_)
     result.push_back(profile.get());
@@ -1108,9 +1112,6 @@
 
 std::vector<CreditCard*> PersonalDataManager::GetLocalCreditCards() const {
   std::vector<CreditCard*> result;
-  if (!IsAutofillCreditCardEnabled())
-    return result;
-
   result.reserve(local_credit_cards_.size());
   for (const auto& card : local_credit_cards_)
     result.push_back(card.get());
@@ -1119,7 +1120,7 @@
 
 std::vector<CreditCard*> PersonalDataManager::GetServerCreditCards() const {
   std::vector<CreditCard*> result;
-  if (!IsAutofillCreditCardEnabled() || !IsAutofillWalletImportEnabled())
+  if (!IsAutofillWalletImportEnabled())
     return result;
 
   result.reserve(server_credit_cards_.size());
@@ -1130,8 +1131,6 @@
 
 std::vector<CreditCard*> PersonalDataManager::GetCreditCards() const {
   std::vector<CreditCard*> result;
-  if (!IsAutofillCreditCardEnabled())
-    return result;
 
   result.reserve(local_credit_cards_.size() + server_credit_cards_.size());
   for (const auto& card : local_credit_cards_)
@@ -1150,6 +1149,9 @@
 
 std::vector<AutofillProfile*> PersonalDataManager::GetProfilesToSuggest()
     const {
+  if (!IsAutofillProfileEnabled())
+    return std::vector<AutofillProfile*>{};
+
   std::vector<AutofillProfile*> profiles = GetProfiles();
 
   // Rank the suggestions by frecency (see AutofillDataModel for details).
@@ -1317,6 +1319,9 @@
 // with a vector instead of a list.
 const std::vector<CreditCard*> PersonalDataManager::GetCreditCardsToSuggest(
     bool include_server_cards) const {
+  if (!IsAutofillCreditCardEnabled())
+    return std::vector<CreditCard*>{};
+
   std::vector<CreditCard*> credit_cards;
   if (include_server_cards && ShouldSuggestServerCards()) {
     credit_cards = GetCreditCards();
@@ -2203,7 +2208,7 @@
   // server addresses have a chance to merge into the non-verified local
   // profiles.
   std::vector<AutofillProfile> local_profiles;
-  for (AutofillProfile* existing_profile : GetProfilesToSuggest()) {
+  for (AutofillProfile* existing_profile : GetProfiles()) {
     local_profiles.push_back(*existing_profile);
   }
 
diff --git a/components/autofill/core/browser/personal_data_manager.h b/components/autofill/core/browser/personal_data_manager.h
index 43ba7af..b79c908 100644
--- a/components/autofill/core/browser/personal_data_manager.h
+++ b/components/autofill/core/browser/personal_data_manager.h
@@ -408,6 +408,9 @@
                            GetCreditCardSuggestions_CreditCardAutofillDisabled);
   FRIEND_TEST_ALL_PREFIXES(PersonalDataManagerTest,
                            GetCreditCardSuggestions_NoCardsLoadedIfDisabled);
+  FRIEND_TEST_ALL_PREFIXES(
+      PersonalDataManagerTest,
+      GetCreditCardSuggestions_NoCreditCardsAddedIfDisabled);
   FRIEND_TEST_ALL_PREFIXES(PersonalDataManagerTest,
                            ClearProfileNonSettingsOrigins);
   FRIEND_TEST_ALL_PREFIXES(PersonalDataManagerTest,
diff --git a/components/autofill/core/browser/personal_data_manager_unittest.cc b/components/autofill/core/browser/personal_data_manager_unittest.cc
index c5710e2..f8146ce 100644
--- a/components/autofill/core/browser/personal_data_manager_unittest.cc
+++ b/components/autofill/core/browser/personal_data_manager_unittest.cc
@@ -2014,8 +2014,10 @@
   WaitForOnPersonalDataChanged();
   personal_data_->ConvertWalletAddressesAndUpdateWalletCards();
 
+  // Check that profiles were saved.
+  EXPECT_EQ(2U, personal_data_->GetProfiles().size());
   // Expect no autofilled values or suggestions.
-  EXPECT_EQ(0U, personal_data_->GetProfiles().size());
+  EXPECT_EQ(0U, personal_data_->GetProfilesToSuggest().size());
 
   std::vector<Suggestion> suggestions = personal_data_->GetProfileSuggestions(
       AutofillType(ADDRESS_HOME_STREET_ADDRESS), base::ASCIIToUTF16("123"),
@@ -2058,6 +2060,7 @@
 
   // Expect 2 autofilled values or suggestions.
   EXPECT_EQ(2U, personal_data_->GetProfiles().size());
+  EXPECT_EQ(2U, personal_data_->GetProfilesToSuggest().size());
 
   // Disable CProfile autofill.
   personal_data_->pref_service_->SetBoolean(prefs::kAutofillProfileEnabled,
@@ -2066,7 +2069,7 @@
   ResetPersonalDataManager(USER_MODE_NORMAL);
 
   // Expect no profile values or suggestions were loaded.
-  EXPECT_EQ(0U, personal_data_->GetProfiles().size());
+  EXPECT_EQ(0U, personal_data_->GetProfilesToSuggest().size());
 
   std::vector<Suggestion> suggestions = personal_data_->GetProfileSuggestions(
       AutofillType(ADDRESS_HOME_STREET_ADDRESS), base::ASCIIToUTF16("123"),
@@ -2321,8 +2324,12 @@
   personal_data_->Refresh();
   WaitForOnPersonalDataChanged();
 
+  // Check that profiles were saved.
+  EXPECT_EQ(5U, personal_data_->GetCreditCards().size());
   // Expect no autofilled values or suggestions.
-  EXPECT_EQ(0U, personal_data_->GetCreditCards().size());
+  EXPECT_EQ(
+      0U, personal_data_->GetCreditCardsToSuggest(/*include_server_cards=*/true)
+              .size());
 
   std::vector<Suggestion> suggestions =
       personal_data_->GetCreditCardSuggestions(
@@ -2371,7 +2378,9 @@
   ResetPersonalDataManager(USER_MODE_NORMAL);
 
   // Expect no credit card values or suggestions were loaded.
-  EXPECT_EQ(0U, personal_data_->GetCreditCards().size());
+  EXPECT_EQ(
+      0U, personal_data_->GetCreditCardsToSuggest(/*include_server_cards=*/true)
+              .size());
 
   std::vector<Suggestion> suggestions =
       personal_data_->GetCreditCardSuggestions(
@@ -2381,6 +2390,26 @@
   ASSERT_EQ(0U, suggestions.size());
 }
 
+// Test that local profiles are not added if |kAutofillProfileEnabled| is set to
+// |false|.
+TEST_F(PersonalDataManagerTest,
+       GetCreditCardSuggestions_NoCreditCardsAddedIfDisabled) {
+  // Disable Profile autofill.
+  personal_data_->pref_service_->SetBoolean(prefs::kAutofillCreditCardEnabled,
+                                            false);
+
+  // Add a local credit card.
+  CreditCard credit_card("002149C1-EE28-4213-A3B9-DA243FFF021B",
+                         "https://www.example.com");
+  test::SetCreditCardInfo(&credit_card, "Bonnie Parker",
+                          "5105105105105100" /* Mastercard */, "04", "2999",
+                          "1");
+  personal_data_->AddCreditCard(credit_card);
+
+  // Expect no profile values or suggestions were added.
+  EXPECT_EQ(0U, personal_data_->GetCreditCards().size());
+}
+
 // Test that expired cards are ordered by frecency and are always suggested
 // after non expired cards even if they have a higher frecency score.
 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ExpiredCards) {
diff --git a/components/autofill/core/browser/test_personal_data_manager.h b/components/autofill/core/browser/test_personal_data_manager.h
index 91c18748..2c2b6cd 100644
--- a/components/autofill/core/browser/test_personal_data_manager.h
+++ b/components/autofill/core/browser/test_personal_data_manager.h
@@ -92,6 +92,10 @@
     autofill_credit_card_enabled_ = autofill_credit_card_enabled;
   }
 
+  void SetAutofillProfileEnabled(bool autofill_profile_enabled) {
+    autofill_profile_enabled_ = autofill_profile_enabled;
+  }
+
   void SetAutofillWalletImportEnabled(bool autofill_wallet_import_enabled) {
     autofill_wallet_import_enabled_ = autofill_wallet_import_enabled;
   }
diff --git a/components/payments/content/payment_request_state_unittest.cc b/components/payments/content/payment_request_state_unittest.cc
index 3daa6931..a2763ed 100644
--- a/components/payments/content/payment_request_state_unittest.cc
+++ b/components/payments/content/payment_request_state_unittest.cc
@@ -34,6 +34,7 @@
         address_(autofill::test::GetFullProfile()),
         credit_card_visa_(autofill::test::GetCreditCard()) {
     test_personal_data_manager_.SetAutofillCreditCardEnabled(true);
+    test_personal_data_manager_.SetAutofillProfileEnabled(true);
     test_personal_data_manager_.SetAutofillWalletImportEnabled(true);
     test_personal_data_manager_.AddProfile(address_);
     credit_card_visa_.set_billing_address_id(address_.guid());
diff --git a/ios/chrome/browser/payments/ios_payment_instrument_launcher_unittest.mm b/ios/chrome/browser/payments/ios_payment_instrument_launcher_unittest.mm
index 98d4bf0..a8107ffc 100644
--- a/ios/chrome/browser/payments/ios_payment_instrument_launcher_unittest.mm
+++ b/ios/chrome/browser/payments/ios_payment_instrument_launcher_unittest.mm
@@ -75,6 +75,7 @@
  protected:
   PaymentRequestIOSPaymentInstrumentLauncherTest()
       : chrome_browser_state_(TestChromeBrowserState::Builder().Build()) {
+    test_personal_data_manager_.SetAutofillProfileEnabled(true);
     test_personal_data_manager_.SetAutofillCreditCardEnabled(true);
     test_personal_data_manager_.SetAutofillWalletImportEnabled(true);
   }
diff --git a/ios/chrome/browser/payments/payment_request_unittest.mm b/ios/chrome/browser/payments/payment_request_unittest.mm
index c2fc995..f3d20018 100644
--- a/ios/chrome/browser/payments/payment_request_unittest.mm
+++ b/ios/chrome/browser/payments/payment_request_unittest.mm
@@ -42,6 +42,7 @@
 class MockTestPersonalDataManager : public autofill::TestPersonalDataManager {
  public:
   MockTestPersonalDataManager() : TestPersonalDataManager() {
+    SetAutofillProfileEnabled(true);
     SetAutofillCreditCardEnabled(true);
     SetAutofillWalletImportEnabled(true);
   }
@@ -72,6 +73,7 @@
  protected:
   PaymentRequestTest()
       : chrome_browser_state_(TestChromeBrowserState::Builder().Build()) {
+    test_personal_data_manager_.SetAutofillProfileEnabled(true);
     test_personal_data_manager_.SetAutofillCreditCardEnabled(true);
     test_personal_data_manager_.SetAutofillWalletImportEnabled(true);
   }
diff --git a/ios/chrome/browser/payments/payment_response_helper_unittest.mm b/ios/chrome/browser/payments/payment_response_helper_unittest.mm
index 638cac6..2622e1b 100644
--- a/ios/chrome/browser/payments/payment_response_helper_unittest.mm
+++ b/ios/chrome/browser/payments/payment_response_helper_unittest.mm
@@ -66,6 +66,7 @@
       : profile_(autofill::test::GetFullProfile()),
         credit_card_(autofill::test::GetCreditCard()),
         chrome_browser_state_(TestChromeBrowserState::Builder().Build()) {
+    personal_data_manager_.SetAutofillProfileEnabled(true);
     personal_data_manager_.SetAutofillCreditCardEnabled(true);
     personal_data_manager_.SetAutofillWalletImportEnabled(true);
     personal_data_manager_.AddProfile(profile_);
diff --git a/ios/chrome/browser/ui/payments/credit_card_edit_coordinator_unittest.mm b/ios/chrome/browser/ui/payments/credit_card_edit_coordinator_unittest.mm
index 6633fff..f6c2b37 100644
--- a/ios/chrome/browser/ui/payments/credit_card_edit_coordinator_unittest.mm
+++ b/ios/chrome/browser/ui/payments/credit_card_edit_coordinator_unittest.mm
@@ -114,6 +114,7 @@
       public PlatformTest {
  protected:
   PaymentRequestCreditCardEditCoordinatorTest() {
+    personal_data_manager_.SetAutofillProfileEnabled(true);
     personal_data_manager_.SetAutofillCreditCardEnabled(true);
     personal_data_manager_.SetAutofillWalletImportEnabled(true);
   }
diff --git a/ios/web_view/internal/autofill/cwv_autofill_data_manager_unittest.mm b/ios/web_view/internal/autofill/cwv_autofill_data_manager_unittest.mm
index a406874..10e6cb9a 100644
--- a/ios/web_view/internal/autofill/cwv_autofill_data_manager_unittest.mm
+++ b/ios/web_view/internal/autofill/cwv_autofill_data_manager_unittest.mm
@@ -50,6 +50,7 @@
 
     // Set to stub out behavior inside PersonalDataManager.
     personal_data_manager_->SetAutofillEnabled(true);
+    personal_data_manager_->SetAutofillProfileEnabled(true);
     personal_data_manager_->SetAutofillCreditCardEnabled(true);
     personal_data_manager_->SetAutofillWalletImportEnabled(true);