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( ...@@ -407,43 +407,38 @@ int CreditCardSaveManager::SetProfilesForCreditCardUpload(
void CreditCardSaveManager::OnUserDidAcceptUpload() { void CreditCardSaveManager::OnUserDidAcceptUpload() {
user_did_accept_upload_prompt_ = true; user_did_accept_upload_prompt_ = true;
if (!upload_request_.risk_data.empty()) { // Populating risk data and offering upload occur asynchronously.
upload_request_.app_locale = app_locale_; // If |risk_data| has already been loaded, send the upload card request.
// If the upload request does not have card CVC, populate it with the // Otherwise, continue to wait and let OnDidGetUploadRiskData handle it.
// value provided by the user: if (!upload_request_.risk_data.empty())
if (upload_request_.cvc.empty()) { SendUploadCardRequest();
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_);
}
} }
void CreditCardSaveManager::OnDidGetUploadRiskData( void CreditCardSaveManager::OnDidGetUploadRiskData(
const std::string& risk_data) { const std::string& risk_data) {
upload_request_.risk_data = risk_data; upload_request_.risk_data = risk_data;
if (user_did_accept_upload_prompt_) { // Populating risk data and offering upload occur asynchronously.
upload_request_.app_locale = app_locale_; // If the dialog has already been accepted, send the upload card request.
// If the upload request does not have card CVC, populate it with the // Otherwise, continue to wait for the user to accept the save dialog.
// value provided by the user: if (user_did_accept_upload_prompt_)
if (upload_request_.cvc.empty()) { SendUploadCardRequest();
DCHECK(client_->GetSaveCardBubbleController()); }
upload_request_.cvc =
client_->GetSaveCardBubbleController()->GetCvcEnteredByUser(); void CreditCardSaveManager::SendUploadCardRequest() {
} upload_request_.app_locale = app_locale_;
if (IsAutofillSendBillingCustomerNumberExperimentEnabled()) { // If the upload request does not have card CVC, populate it with the value
upload_request_.billing_customer_number = // provided by the user:
static_cast<int64_t>(payments_client_->GetPrefService()->GetDouble( if (upload_request_.cvc.empty()) {
prefs::kAutofillBillingCustomerNumber)); DCHECK(client_->GetSaveCardBubbleController());
} upload_request_.cvc =
payments_client_->UploadCard(upload_request_); 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 AutofillMetrics::CardUploadDecisionMetric
......
...@@ -70,14 +70,17 @@ class CreditCardSaveManager : public payments::PaymentsClientSaveDelegate { ...@@ -70,14 +70,17 @@ class CreditCardSaveManager : public payments::PaymentsClientSaveDelegate {
const CreditCard& card, const CreditCard& card,
payments::PaymentsClient::UploadRequestDetails* upload_request) const; payments::PaymentsClient::UploadRequestDetails* upload_request) const;
// Sets |user_did_accept_upload_prompt_| and calls UploadCard if the risk data // Sets |user_did_accept_upload_prompt_| and calls SendUploadCardRequest if
// is available. // the risk data is available.
void OnUserDidAcceptUpload(); void OnUserDidAcceptUpload();
// Saves risk data in |uploading_risk_data_| and calls UploadCard if the user // Saves risk data in |uploading_risk_data_| and calls SendUploadCardRequest
// has accepted the prompt. // if the user has accepted the prompt.
void OnDidGetUploadRiskData(const std::string& risk_data); 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 // Returns metric relevant to the CVC field based on values in
// |found_cvc_field_|, |found_value_in_cvc_field_| and // |found_cvc_field_|, |found_value_in_cvc_field_| and
// |found_cvc_value_in_non_cvc_field_|. // |found_cvc_value_in_non_cvc_field_|.
......
...@@ -122,16 +122,17 @@ void FormDataImporter::ImportFormData(const FormStructure& submitted_form, ...@@ -122,16 +122,17 @@ void FormDataImporter::ImportFormData(const FormStructure& submitted_form,
if (!credit_card_save_manager_->IsCreditCardUploadEnabled() || if (!credit_card_save_manager_->IsCreditCardUploadEnabled() ||
imported_credit_card_matches_masked_server_credit_card) { imported_credit_card_matches_masked_server_credit_card) {
// This block will only be reached if we have observed a new card or a card // Offer local save. This block will only be reached if we have observed a
// whose |TypeAndLastFourDigits| matches a masked server card. // new card or a card whose |TypeAndLastFourDigits| matches a masked server
// |ImportFormData| will return false if the card matches a full card that // card. |ImportFormData| will return false if the card matches a full card
// we have already stored. // that we have already stored.
credit_card_save_manager_->OfferCardLocalSave(*imported_credit_card); credit_card_save_manager_->OfferCardLocalSave(*imported_credit_card);
} else { } else {
// Whereas, because we pass IsCreditCardUploadEnabled() to ImportFormData, // Attempt to offer upload save. Because we pass IsCreditCardUploadEnabled()
// this block can be reached on observing either a new card or one already // to ImportFormData, this block can be reached on observing either a new
// stored locally and whose |TypeAndLastFourDigits| do not match a masked // card or one already stored locally and whose |TypeAndLastFourDigits| do
// server card. We will offer to upload either kind. // 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( credit_card_save_manager_->AttemptToOfferCardUploadSave(
submitted_form, *imported_credit_card); 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