Skip to content

Commit

Permalink
Clean up code for cloud token virtual cards (1/ n + 4)
Browse files Browse the repository at this point in the history
The project is cancelled so remove dead code from the code base.
The cleaning will take at least 4 CLs to finish as how I see it.

This first CL will clean up code for triggering the suggestion of
"Use a virtual card number" in the card autofill dropdown.

CL2: gstatic reader
CL3: UI related code, autofill client, virtualcardselectiondialog, test.
CL4: Cloud token data model & sync (maybe sync will be a standalone CL)

Bug: 1020740, 1419097
Change-Id: Ie847fc415d2d3a20d80d85c9aefbc36603758fb8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4779365
Reviewed-by: Olivia Saul <jsaul@google.com>
Reviewed-by: Florian Leimgruber <fleimgruber@google.com>
Commit-Queue: Siyu An <siyua@chromium.org>
Reviewed-by: Jan Keitel <jkeitel@google.com>
Cr-Commit-Position: refs/heads/main@{#1186880}
  • Loading branch information
Siyu authored and Chromium LUCI CQ committed Aug 22, 2023
1 parent 03457a3 commit 04d41cc
Show file tree
Hide file tree
Showing 15 changed files with 0 additions and 431 deletions.
5 changes: 0 additions & 5 deletions chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8126,11 +8126,6 @@ const FeatureEntry kFeatureEntries[] = {
FEATURE_VALUE_TYPE(ash::features::kUseWallpaperStagingUrl)},
#endif // BUILDFLAG(IS_CHROMEOS_ASH)

{"autofill-enable-virtual-card",
flag_descriptions::kAutofillEnableVirtualCardName,
flag_descriptions::kAutofillEnableVirtualCardDescription, kOsDesktop,
FEATURE_VALUE_TYPE(autofill::features::kAutofillEnableVirtualCard)},

#if BUILDFLAG(IS_ANDROID)
{"autofill-enable-manual-fallback-for-virtual-cards",
flag_descriptions::kAutofillEnableManualFallbackForVirtualCardsName,
Expand Down
5 changes: 0 additions & 5 deletions chrome/browser/flag-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,6 @@
"expiry_milestone": 120
},
{
"name": "autofill-enable-virtual-card",
"owners": [ "siyua", "jsaul@google.com", "aneeshali@google.com" ],
"expiry_milestone": 112
},
{
"name": "autofill-enable-virtual-card-fido-enrollment",
"owners": [ "siyua", "jsaul@google.com"],
"expiry_milestone": 120
Expand Down
6 changes: 0 additions & 6 deletions chrome/browser/flag_descriptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,6 @@ const char kAutofillEnableVirtualCardFidoEnrollmentDescription[] =
"card is FIDO eligible the user will be prompted to register the virtual "
"card into FIDO.";

const char kAutofillEnableVirtualCardName[] =
"Offer to use cloud token virtual card in Autofill";
const char kAutofillEnableVirtualCardDescription[] =
"When enabled, if all requirements are met, Autofill will offer to use "
"virtual credit cards in form filling.";

const char kAutofillEnableNewSaveCardBubbleUiName[] =
"Update UI messaging and banner image for credit card upload save";
const char kAutofillEnableNewSaveCardBubbleUiDescription[] =
Expand Down
3 changes: 0 additions & 3 deletions chrome/browser/flag_descriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,6 @@ extern const char kAutofillEnableUpdateVirtualCardEnrollmentDescription[];
extern const char kAutofillEnableVirtualCardFidoEnrollmentName[];
extern const char kAutofillEnableVirtualCardFidoEnrollmentDescription[];

extern const char kAutofillEnableVirtualCardName[];
extern const char kAutofillEnableVirtualCardDescription[];

extern const char kAutofillEnableNewSaveCardBubbleUiName[];
extern const char kAutofillEnableNewSaveCardBubbleUiDescription[];

Expand Down
1 change: 0 additions & 1 deletion chrome/browser/ui/views/autofill/popup/popup_view_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ bool IsFooterPopupItemId(PopupItemId popup_item_id) {
case PopupItemId::kPasswordAccountStorageReSignin:
case PopupItemId::kPasswordAccountStorageOptInAndGenerate:
case PopupItemId::kShowAccountCards:
case PopupItemId::kUseVirtualCard:
case PopupItemId::kAllSavedPasswordsEntry:
case PopupItemId::kFillEverythingFromAddressProfile:
case PopupItemId::kClearForm:
Expand Down
16 changes: 0 additions & 16 deletions components/autofill/core/browser/autofill_browser_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,4 @@ bool ShouldAllowCreditCardFallbacks(const AutofillClient& client,
return !IsFormOrClientNonSecure(client, form);
}

bool IsCompleteCreditCardFormIncludingCvcField(
const FormStructure& form_structure) {
// If card number field or expiration date field is not detected, return
// false.
if (!form_structure.IsCompleteCreditCardForm())
return false;

// If CVC field is detected, then all requirements are met, otherwise return
// false.
for (auto& field : form_structure) {
if (field->Type().GetStorableType() == CREDIT_CARD_VERIFICATION_CODE)
return true;
}
return false;
}

} // namespace autofill
5 changes: 0 additions & 5 deletions components/autofill/core/browser/autofill_browser_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ bool IsFormMixedContent(const AutofillClient& client, const FormData& form);
bool ShouldAllowCreditCardFallbacks(const AutofillClient& client,
const FormData& form);

// Returns whether the form is a complete credit card form with card number
// field, card expiration date field and card CVC field detected.
bool IsCompleteCreditCardFormIncludingCvcField(
const FormStructure& form_structure);

} // namespace autofill

#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_BROWSER_UTIL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,6 @@ void AutofillExternalDelegate::DidAcceptSuggestion(
case PopupItemId::kShowAccountCards:
manager_->OnUserAcceptedCardsFromAccountOption();
break;
case PopupItemId::kUseVirtualCard:
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
manager_->FetchVirtualCardCandidates();
#else
NOTREACHED();
#endif
break;
case PopupItemId::kVirtualCreditCardEntry:
// There can be multiple virtual credit cards that all rely on
// PopupItemId::kVirtualCreditCardEntry as a `popup_item_id`. In this
Expand Down
101 changes: 0 additions & 101 deletions components/autofill/core/browser/browser_autofill_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ FillDataType GetEventTypeFromSingleFieldSuggestionPopupItemId(
case PopupItemId::kGeneratePasswordEntry:
case PopupItemId::kShowAccountCards:
case PopupItemId::kPasswordAccountStorageOptIn:
case PopupItemId::kUseVirtualCard:
case PopupItemId::kPasswordAccountStorageOptInAndGenerate:
case PopupItemId::kAccountStoragePasswordEntry:
case PopupItemId::kAccountStorageUsernameEntry:
Expand Down Expand Up @@ -459,39 +458,6 @@ bool ContainsAutofillableValue(const FormStructure& form) {
});
}

#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
// Retrieves all valid credit card candidates for virtual card selection. A
// valid candidate must have exactly one cloud token.
std::vector<CreditCard*> GetVirtualCardCandidates(
PersonalDataManager* personal_data_manager) {
DCHECK(personal_data_manager);
std::vector<CreditCard*> candidates =
personal_data_manager->GetServerCreditCards();
const std::vector<CreditCardCloudTokenData*> cloud_token_data =
personal_data_manager->GetCreditCardCloudTokenData();

// Constructs map.
std::unordered_map<std::string, int> id_count;
for (CreditCardCloudTokenData* data : cloud_token_data) {
const auto& iterator = id_count.find(data->masked_card_id);
if (iterator == id_count.end())
id_count.emplace(data->masked_card_id, 1);
else
iterator->second += 1;
}

// Remove the card from the vector that either has multiple cloud token data
// or has no cloud token data.
base::EraseIf(candidates, [&](const auto& card) {
const auto& iterator = id_count.find(card->server_id());
return iterator == id_count.end() || iterator->second > 1;
});

// Returns the remaining valid cards.
return candidates;
}
#endif

const char* SubmissionSourceToString(SubmissionSource source) {
switch (source) {
case SubmissionSource::NONE:
Expand Down Expand Up @@ -760,29 +726,6 @@ void BrowserAutofillManager::RefetchCardsAndUpdatePopup(
should_display_gpay_logo);
}

#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
void BrowserAutofillManager::FetchVirtualCardCandidates() {
const std::vector<CreditCard*>& candidates =
GetVirtualCardCandidates(client().GetPersonalDataManager());
// Make sure the |candidates| is not empty, otherwise the check in
// ShouldShowVirtualCardOption() should fail.
DCHECK(!candidates.empty());

client().OfferVirtualCardOptions(
candidates,
base::BindOnce(&BrowserAutofillManager::OnVirtualCardCandidateSelected,
weak_ptr_factory_.GetWeakPtr()));
}

void BrowserAutofillManager::OnVirtualCardCandidateSelected(
const std::string& selected_card_id) {
// TODO(crbug.com/1020740): Implement this and the following flow in a
// separate CL. The following flow will be sending a request to Payments
// to fetched the up-to-date cloud token data for the selected card and fill
// the information in the form.
}
#endif

bool BrowserAutofillManager::ShouldParseForms() {
bool autofill_enabled = IsAutofillEnabled();
// If autofill is disabled but the password manager is enabled, we still
Expand Down Expand Up @@ -3634,16 +3577,6 @@ void BrowserAutofillManager::GetAvailableSuggestions(
if (suggestions->empty() || !context->is_filling_credit_card)
return;

#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
// This section adds the "Use a virtual card number" option in the autofill
// dropdown menu, if applicable.
if (ShouldShowVirtualCardOption(context->form_structure)) {
suggestions->emplace_back(l10n_util::GetStringUTF16(
IDS_AUTOFILL_CLOUD_TOKEN_DROPDOWN_OPTION_LABEL));
suggestions->back().popup_item_id = PopupItemId::kUseVirtualCard;
}
#endif

// Don't provide credit card suggestions for non-secure pages, but do
// provide them for secure pages with passive mixed content (see
// implementation of IsContextSecure).
Expand All @@ -3659,40 +3592,6 @@ void BrowserAutofillManager::GetAvailableSuggestions(
}
}

#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
// TODO(crbug.com/1020740): Add metrics logging.
bool BrowserAutofillManager::ShouldShowVirtualCardOption(
FormStructure* form_structure) {
// If experiment is disabled, return false.
if (!base::FeatureList::IsEnabled(features::kAutofillEnableVirtualCard))
return false;

// If credit card upload is disabled, return false.
if (!IsAutofillCreditCardEnabled())
return false;

// If merchant is not allowed, return false.
std::vector<std::string> allowed_merchants =
client().GetAllowedMerchantsForVirtualCards();
if (!base::Contains(allowed_merchants, form_structure->source_url().spec())) {
return false;
}

// If no credit card candidate has related cloud token data available,
// return false.
if (GetVirtualCardCandidates(client().GetPersonalDataManager()).empty()) {
return false;
}

// If not all of card number field, expiration date field and CVC field are
// detected, return false.
if (!IsCompleteCreditCardFormIncludingCvcField(*form_structure))
return false;

return true;
}
#endif

autofill_metrics::FormEventLoggerBase*
BrowserAutofillManager::GetEventFormLogger(const AutofillField& field) const {
if (field.ShouldSuppressSuggestionsAndFillingByDefault()) {
Expand Down
19 changes: 0 additions & 19 deletions components/autofill/core/browser/browser_autofill_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,6 @@ class BrowserAutofillManager : public AutofillManager,
virtual void RefetchCardsAndUpdatePopup(const FormData& form,
const FormFieldData& field_data);

#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
// Returns the list of credit cards that have associated cloud token data.
virtual void FetchVirtualCardCandidates();

// Callback invoked when an actual card is selected. |selected_card_id| will
// be used to identify the card. The selected card's cloud token data will be
// fetched from the server.
// TODO(crbug.com/1020740): Passes card server id for now. In the future when
// one actual credit card can have multiple virtual cards, passes instrument
// token instead. Design TBD.
virtual void OnVirtualCardCandidateSelected(
const std::string& selected_card_id);
#endif

// Called from our external delegate so they cannot be private.
// TODO(crbug.com/1330108): Clean up the API.
virtual void FillOrPreviewForm(
Expand Down Expand Up @@ -703,11 +689,6 @@ class BrowserAutofillManager : public AutofillManager,
const std::vector<AutofillProfile>& profiles,
FormStructure* form_structure);

#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
// Whether to show the option to use virtual card in the autofill popup.
bool ShouldShowVirtualCardOption(FormStructure* form_structure);
#endif

// Returns an appropriate EventFormLogger, depending on the given `field`'s
// type. May return nullptr.
autofill_metrics::FormEventLoggerBase* GetEventFormLogger(
Expand Down

0 comments on commit 04d41cc

Please sign in to comment.