Commit 83221ad0 authored by Jared Saul's avatar Jared Saul Committed by Commit Bot

Refactor duplicate code into single method

Bug: 772483
Change-Id: I752b22807c89b44e3d5629239ad9aad582fc6493
Reviewed-on: https://chromium-review.googlesource.com/742127
Commit-Queue: Jared Saul <jsaul@google.com>
Reviewed-by: default avatarMathieu Perreault <mathp@chromium.org>
Reviewed-by: default avatarRoger McFarlane <rogerm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512710}
parent f1b58d6a
......@@ -407,43 +407,38 @@ int CreditCardSaveManager::SetProfilesForCreditCardUpload(
void CreditCardSaveManager::OnUserDidAcceptUpload() {
user_did_accept_upload_prompt_ = true;
if (!upload_request_.risk_data.empty()) {
upload_request_.app_locale = app_locale_;
// If the upload request does not have card CVC, populate it with the
// value provided by the user:
if (upload_request_.cvc.empty()) {
DCHECK(client_->GetSaveCardBubbleController());
upload_request_.cvc =
client_->GetSaveCardBubbleController()->GetCvcEnteredByUser();
}
if (IsAutofillSendBillingCustomerNumberExperimentEnabled()) {
upload_request_.billing_customer_number =
static_cast<int64_t>(payments_client_->GetPrefService()->GetDouble(
prefs::kAutofillBillingCustomerNumber));
}
payments_client_->UploadCard(upload_request_);
}
// Populating risk data and offering upload occur asynchronously.
// If |risk_data| has already been loaded, send the upload card request.
// Otherwise, continue to wait and let OnDidGetUploadRiskData handle it.
if (!upload_request_.risk_data.empty())
SendUploadCardRequest();
}
void CreditCardSaveManager::OnDidGetUploadRiskData(
const std::string& risk_data) {
upload_request_.risk_data = risk_data;
if (user_did_accept_upload_prompt_) {
upload_request_.app_locale = app_locale_;
// If the upload request does not have card CVC, populate it with the
// value provided by the user:
if (upload_request_.cvc.empty()) {
DCHECK(client_->GetSaveCardBubbleController());
upload_request_.cvc =
client_->GetSaveCardBubbleController()->GetCvcEnteredByUser();
}
if (IsAutofillSendBillingCustomerNumberExperimentEnabled()) {
upload_request_.billing_customer_number =
static_cast<int64_t>(payments_client_->GetPrefService()->GetDouble(
prefs::kAutofillBillingCustomerNumber));
}
payments_client_->UploadCard(upload_request_);
// Populating risk data and offering upload occur asynchronously.
// If the dialog has already been accepted, send the upload card request.
// Otherwise, continue to wait for the user to accept the save dialog.
if (user_did_accept_upload_prompt_)
SendUploadCardRequest();
}
void CreditCardSaveManager::SendUploadCardRequest() {
upload_request_.app_locale = app_locale_;
// If the upload request does not have card CVC, populate it with the value
// provided by the user:
if (upload_request_.cvc.empty()) {
DCHECK(client_->GetSaveCardBubbleController());
upload_request_.cvc =
client_->GetSaveCardBubbleController()->GetCvcEnteredByUser();
}
if (IsAutofillSendBillingCustomerNumberExperimentEnabled()) {
upload_request_.billing_customer_number =
static_cast<int64_t>(payments_client_->GetPrefService()->GetDouble(
prefs::kAutofillBillingCustomerNumber));
}
payments_client_->UploadCard(upload_request_);
}
AutofillMetrics::CardUploadDecisionMetric
......
......@@ -70,14 +70,17 @@ class CreditCardSaveManager : public payments::PaymentsClientSaveDelegate {
const CreditCard& card,
payments::PaymentsClient::UploadRequestDetails* upload_request) const;
// Sets |user_did_accept_upload_prompt_| and calls UploadCard if the risk data
// is available.
// Sets |user_did_accept_upload_prompt_| and calls SendUploadCardRequest if
// the risk data is available.
void OnUserDidAcceptUpload();
// Saves risk data in |uploading_risk_data_| and calls UploadCard if the user
// has accepted the prompt.
// Saves risk data in |uploading_risk_data_| and calls SendUploadCardRequest
// if the user has accepted the prompt.
void OnDidGetUploadRiskData(const std::string& risk_data);
// Finalizes the upload request and calls PaymentsClient::UploadCard().
void SendUploadCardRequest();
// Returns metric relevant to the CVC field based on values in
// |found_cvc_field_|, |found_value_in_cvc_field_| and
// |found_cvc_value_in_non_cvc_field_|.
......
......@@ -122,16 +122,17 @@ void FormDataImporter::ImportFormData(const FormStructure& submitted_form,
if (!credit_card_save_manager_->IsCreditCardUploadEnabled() ||
imported_credit_card_matches_masked_server_credit_card) {
// This block will only be reached if we have observed a new card or a card
// whose |TypeAndLastFourDigits| matches a masked server card.
// |ImportFormData| will return false if the card matches a full card that
// we have already stored.
// Offer local save. This block will only be reached if we have observed a
// new card or a card whose |TypeAndLastFourDigits| matches a masked server
// card. |ImportFormData| will return false if the card matches a full card
// that we have already stored.
credit_card_save_manager_->OfferCardLocalSave(*imported_credit_card);
} else {
// Whereas, because we pass IsCreditCardUploadEnabled() to ImportFormData,
// this block can be reached on observing either a new card or one already
// stored locally and whose |TypeAndLastFourDigits| do not match a masked
// server card. We will offer to upload either kind.
// Attempt to offer upload save. Because we pass IsCreditCardUploadEnabled()
// to ImportFormData, this block can be reached on observing either a new
// card or one already stored locally and whose |TypeAndLastFourDigits| do
// not match a masked server card. We can offer to upload either kind, but
// note that they must pass address/name/CVC validation requirements first.
credit_card_save_manager_->AttemptToOfferCardUploadSave(
submitted_form, *imported_credit_card);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment