#include "components/autofill/core/browser/payments/credit_card_save_manager.h"
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <limits>
#include <map>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/check_deref.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "client_behavior_constants.h"
#include "components/autofill/core/browser/address_data_manager.h"
#include "components/autofill/core/browser/autofill_client.h"
#include "components/autofill/core/browser/autofill_experiments.h"
#include "components/autofill/core/browser/autofill_type.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/form_data_importer.h"
#include "components/autofill/core/browser/form_structure.h"
#include "components/autofill/core/browser/logging/log_manager.h"
#include "components/autofill/core/browser/metrics/autofill_metrics.h"
#include "components/autofill/core/browser/metrics/payments/credit_card_save_metrics.h"
#include "components/autofill/core/browser/payments/autofill_payments_feature_availability.h"
#include "components/autofill/core/browser/payments/client_behavior_constants.h"
#include "components/autofill/core/browser/payments/payments_autofill_client.h"
#include "components/autofill/core/browser/payments/payments_network_interface.h"
#include "components/autofill/core/browser/payments/payments_util.h"
#include "components/autofill/core/browser/payments/virtual_card_enrollment_manager.h"
#include "components/autofill/core/browser/payments_data_manager.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/strike_databases/strike_database.h"
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_internals/log_message.h"
#include "components/autofill/core/common/autofill_internals/logging_scope.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/autofill/core/common/autofill_util.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "url/gurl.h"
namespace autofill {
namespace {
PaymentsRpcResult;
SaveCardOfferUserDecision;
std::u16string RemoveMiddleInitial(const std::u16string& name) { … }
std::optional<
payments::PaymentsNetworkInterface::GetDetailsForEnrollmentResponseDetails>
PrepareForVirtualCardEnroll(
bool card_saved,
payments::PaymentsNetworkInterface::UploadCardResponseDetails
upload_card_response_details,
CreditCard* uploaded_card) { … }
}
CreditCardSaveManager::CreditCardSaveManager(AutofillClient* client,
const std::string& app_locale)
: … { … }
CreditCardSaveManager::~CreditCardSaveManager() = default;
bool CreditCardSaveManager::AttemptToOfferCardLocalSave(
const CreditCard& card) { … }
bool CreditCardSaveManager::AttemptToOfferCvcLocalSave(const CreditCard& card) { … }
bool CreditCardSaveManager::ShouldOfferCvcSave(
const CreditCard& card,
FormDataImporter::CreditCardImportType credit_card_import_type,
bool is_credit_card_upstream_enabled) { … }
bool CreditCardSaveManager::ProceedWithSavingIfApplicable(
const FormStructure& submitted_form,
const CreditCard& card,
FormDataImporter::CreditCardImportType credit_card_import_type,
bool is_credit_card_upstream_enabled) { … }
void CreditCardSaveManager::AttemptToOfferCardUploadSave(
const FormStructure& submitted_form,
const CreditCard& card,
const bool uploading_local_card) { … }
void CreditCardSaveManager::AttemptToOfferCvcUploadSave(
const CreditCard& card) { … }
bool CreditCardSaveManager::IsCreditCardUploadEnabled() { … }
void CreditCardSaveManager::OnDidUploadCard(
PaymentsRpcResult result,
const payments::PaymentsNetworkInterface::UploadCardResponseDetails&
upload_card_response_details) { … }
void CreditCardSaveManager::InitVirtualCardEnroll(
const CreditCard& credit_card,
std::optional<payments::PaymentsNetworkInterface::
GetDetailsForEnrollmentResponseDetails>
get_details_for_enrollment_response_details) { … }
CreditCardSaveStrikeDatabase*
CreditCardSaveManager::GetCreditCardSaveStrikeDatabase() { … }
CvcStorageStrikeDatabase* CreditCardSaveManager::GetCvcStorageStrikeDatabase() { … }
bool CreditCardSaveManager::
DetermineAndLogCvcSaveStrikeDatabaseBlockDecision() { … }
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
LocalCardMigrationStrikeDatabase*
CreditCardSaveManager::GetLocalCardMigrationStrikeDatabase() { … }
#endif
void CreditCardSaveManager::OnDidGetUploadDetails(
PaymentsRpcResult result,
const std::u16string& context_token,
std::unique_ptr<base::Value::Dict> legal_message,
std::vector<std::pair<int, int>> supported_card_bin_ranges) { … }
void CreditCardSaveManager::OfferCardLocalSave() { … }
void CreditCardSaveManager::OfferCvcLocalSave() { … }
void CreditCardSaveManager::OfferCardUploadSave() { … }
void CreditCardSaveManager::OnUserDidDecideOnLocalSave(
SaveCardOfferUserDecision user_decision) { … }
void CreditCardSaveManager::OnUserDidDecideOnCvcLocalSave(
SaveCardOfferUserDecision user_decision) { … }
void CreditCardSaveManager::LogStrikesPresentWhenCardSaved(
bool is_local,
const int num_strikes) { … }
void CreditCardSaveManager::SetProfilesForCreditCardUpload(
const CreditCard& card,
payments::PaymentsNetworkInterface::UploadCardRequestDetails*
upload_request) { … }
int CreditCardSaveManager::GetDetectedValues() const { … }
void CreditCardSaveManager::OnUserDidDecideOnUploadSave(
SaveCardOfferUserDecision user_decision,
const payments::PaymentsAutofillClient::UserProvidedCardDetails&
user_provided_card_details) { … }
void CreditCardSaveManager::OnUserDidDecideOnCvcUploadSave(
SaveCardOfferUserDecision user_decision,
const payments::PaymentsAutofillClient::UserProvidedCardDetails&
user_provided_card_details) { … }
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
void CreditCardSaveManager::OnUserDidAcceptAccountNameFixFlow(
const std::u16string& cardholder_name) {
DCHECK(should_request_name_from_user_);
OnUserDidAcceptUploadHelper({cardholder_name,
std::u16string(),
std::u16string()});
}
void CreditCardSaveManager::OnUserDidAcceptExpirationDateFixFlow(
const std::u16string& month,
const std::u16string& year) {
OnUserDidAcceptUploadHelper(
{std::u16string(), month, year});
}
#endif
void CreditCardSaveManager::OnUserDidAcceptUploadHelper(
const payments::PaymentsAutofillClient::UserProvidedCardDetails&
user_provided_card_details) { … }
void CreditCardSaveManager::OnDidGetUploadRiskData(
const std::string& risk_data) { … }
void CreditCardSaveManager::SendUploadCardRequest() { … }
void CreditCardSaveManager::OnUserDidIgnoreOrDeclineSave(
const std::u16string& card_last_four_digits) { … }
void CreditCardSaveManager::OnStrikeChangeComplete(const int num_strikes) { … }
autofill_metrics::CardUploadDecision
CreditCardSaveManager::GetCVCCardUploadDecisionMetric() const { … }
void CreditCardSaveManager::LogCardUploadDecisions(
int upload_decision_metrics) { … }
void CreditCardSaveManager::LogCardUploadDecisionsToAutofillInternals(
int upload_decision_metrics) { … }
void CreditCardSaveManager::LogSaveCardRequestExpirationDateReasonMetric() { … }
PaymentsDataManager& CreditCardSaveManager::payments_data_manager() { … }
const PaymentsDataManager& CreditCardSaveManager::payments_data_manager()
const { … }
}