| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/browser/payments/full_card_request.h" | 5 #include "components/autofill/core/browser/payments/full_card_request.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 void FullCardRequest::GetFullCard(const CreditCard& card, | 35 void FullCardRequest::GetFullCard(const CreditCard& card, |
| 36 AutofillClient::UnmaskCardReason reason, | 36 AutofillClient::UnmaskCardReason reason, |
| 37 base::WeakPtr<Delegate> delegate) { | 37 base::WeakPtr<Delegate> delegate) { |
| 38 DCHECK(delegate); | 38 DCHECK(delegate); |
| 39 | 39 |
| 40 // Only request can be active a time. If the member variable |delegate_| is | 40 // Only request can be active a time. If the member variable |delegate_| is |
| 41 // already set, then immediately reject the new request through the method | 41 // already set, then immediately reject the new request through the method |
| 42 // parameter |delegate|. | 42 // parameter |delegate|. |
| 43 if (delegate_) { | 43 if (delegate_) { |
| 44 delegate->OnFullCardError(); | 44 delegate->OnFullCardRequestFailed(); |
| 45 return; | 45 return; |
| 46 } | 46 } |
| 47 | 47 |
| 48 delegate_ = delegate; | 48 delegate_ = delegate; |
| 49 request_.reset(new payments::PaymentsClient::UnmaskRequestDetails); | 49 request_.reset(new payments::PaymentsClient::UnmaskRequestDetails); |
| 50 request_->card = card; | 50 request_->card = card; |
| 51 should_unmask_card_ = card.record_type() == CreditCard::MASKED_SERVER_CARD || | 51 should_unmask_card_ = card.record_type() == CreditCard::MASKED_SERVER_CARD || |
| 52 (card.record_type() == CreditCard::FULL_SERVER_CARD && | 52 (card.record_type() == CreditCard::FULL_SERVER_CARD && |
| 53 card.ShouldUpdateExpiration(base::Time::Now())); | 53 card.ShouldUpdateExpiration(base::Time::Now())); |
| 54 if (should_unmask_card_) | 54 if (should_unmask_card_) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 76 request_->card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, response.exp_year); | 76 request_->card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, response.exp_year); |
| 77 | 77 |
| 78 if (request_->card.record_type() == CreditCard::LOCAL_CARD && | 78 if (request_->card.record_type() == CreditCard::LOCAL_CARD && |
| 79 !request_->card.guid().empty() && | 79 !request_->card.guid().empty() && |
| 80 (!response.exp_month.empty() || !response.exp_year.empty())) { | 80 (!response.exp_month.empty() || !response.exp_year.empty())) { |
| 81 personal_data_manager_->UpdateCreditCard(request_->card); | 81 personal_data_manager_->UpdateCreditCard(request_->card); |
| 82 } | 82 } |
| 83 | 83 |
| 84 if (!should_unmask_card_) { | 84 if (!should_unmask_card_) { |
| 85 if (delegate_) | 85 if (delegate_) |
| 86 delegate_->OnFullCardDetails(request_->card, response.cvc); | 86 delegate_->OnFullCardRequestSucceeded(request_->card, response.cvc); |
| 87 Reset(); | 87 Reset(); |
| 88 autofill_client_->OnUnmaskVerificationResult(AutofillClient::SUCCESS); | 88 autofill_client_->OnUnmaskVerificationResult(AutofillClient::SUCCESS); |
| 89 return; | 89 return; |
| 90 } | 90 } |
| 91 | 91 |
| 92 request_->user_response = response; | 92 request_->user_response = response; |
| 93 if (!request_->risk_data.empty()) { | 93 if (!request_->risk_data.empty()) { |
| 94 real_pan_request_timestamp_ = base::Time::Now(); | 94 real_pan_request_timestamp_ = base::Time::Now(); |
| 95 payments_client_->UnmaskCard(*request_); | 95 payments_client_->UnmaskCard(*request_); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 void FullCardRequest::OnUnmaskPromptClosed() { | 99 void FullCardRequest::OnUnmaskPromptClosed() { |
| 100 if (delegate_) | 100 if (delegate_) |
| 101 delegate_->OnFullCardError(); | 101 delegate_->OnFullCardRequestFailed(); |
| 102 | 102 |
| 103 Reset(); | 103 Reset(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void FullCardRequest::OnDidGetUnmaskRiskData(const std::string& risk_data) { | 106 void FullCardRequest::OnDidGetUnmaskRiskData(const std::string& risk_data) { |
| 107 request_->risk_data = risk_data; | 107 request_->risk_data = risk_data; |
| 108 if (!request_->user_response.cvc.empty()) { | 108 if (!request_->user_response.cvc.empty()) { |
| 109 real_pan_request_timestamp_ = base::Time::Now(); | 109 real_pan_request_timestamp_ = base::Time::Now(); |
| 110 payments_client_->UnmaskCard(*request_); | 110 payments_client_->UnmaskCard(*request_); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 void FullCardRequest::OnDidGetRealPan(AutofillClient::PaymentsRpcResult result, | 114 void FullCardRequest::OnDidGetRealPan(AutofillClient::PaymentsRpcResult result, |
| 115 const std::string& real_pan) { | 115 const std::string& real_pan) { |
| 116 AutofillMetrics::LogRealPanDuration( | 116 AutofillMetrics::LogRealPanDuration( |
| 117 base::Time::Now() - real_pan_request_timestamp_, result); | 117 base::Time::Now() - real_pan_request_timestamp_, result); |
| 118 | 118 |
| 119 switch (result) { | 119 switch (result) { |
| 120 // Wait for user retry. | 120 // Wait for user retry. |
| 121 case AutofillClient::TRY_AGAIN_FAILURE: | 121 case AutofillClient::TRY_AGAIN_FAILURE: |
| 122 break; | 122 break; |
| 123 | 123 |
| 124 // Neither PERMANENT_FAILURE nor NETWORK_ERROR allow retry. | 124 // Neither PERMANENT_FAILURE nor NETWORK_ERROR allow retry. |
| 125 case AutofillClient::PERMANENT_FAILURE: | 125 case AutofillClient::PERMANENT_FAILURE: |
| 126 // Intentional fall through. | 126 // Intentional fall through. |
| 127 case AutofillClient::NETWORK_ERROR: { | 127 case AutofillClient::NETWORK_ERROR: { |
| 128 if (delegate_) | 128 if (delegate_) |
| 129 delegate_->OnFullCardError(); | 129 delegate_->OnFullCardRequestFailed(); |
| 130 Reset(); | 130 Reset(); |
| 131 break; | 131 break; |
| 132 } | 132 } |
| 133 | 133 |
| 134 case AutofillClient::SUCCESS: { | 134 case AutofillClient::SUCCESS: { |
| 135 DCHECK(!real_pan.empty()); | 135 DCHECK(!real_pan.empty()); |
| 136 request_->card.set_record_type(CreditCard::FULL_SERVER_CARD); | 136 request_->card.set_record_type(CreditCard::FULL_SERVER_CARD); |
| 137 request_->card.SetNumber(base::UTF8ToUTF16(real_pan)); | 137 request_->card.SetNumber(base::UTF8ToUTF16(real_pan)); |
| 138 request_->card.SetServerStatus(CreditCard::OK); | 138 request_->card.SetServerStatus(CreditCard::OK); |
| 139 | 139 |
| 140 if (request_->user_response.should_store_pan) | 140 if (request_->user_response.should_store_pan) |
| 141 personal_data_manager_->UpdateServerCreditCard(request_->card); | 141 personal_data_manager_->UpdateServerCreditCard(request_->card); |
| 142 | 142 |
| 143 if (delegate_) | 143 if (delegate_) |
| 144 delegate_->OnFullCardDetails(request_->card, | 144 delegate_->OnFullCardRequestSucceeded(request_->card, |
| 145 request_->user_response.cvc); | 145 request_->user_response.cvc); |
| 146 Reset(); | 146 Reset(); |
| 147 break; | 147 break; |
| 148 } | 148 } |
| 149 | 149 |
| 150 case AutofillClient::NONE: | 150 case AutofillClient::NONE: |
| 151 NOTREACHED(); | 151 NOTREACHED(); |
| 152 break; | 152 break; |
| 153 } | 153 } |
| 154 | 154 |
| 155 autofill_client_->OnUnmaskVerificationResult(result); | 155 autofill_client_->OnUnmaskVerificationResult(result); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void FullCardRequest::Reset() { | 158 void FullCardRequest::Reset() { |
| 159 weak_ptr_factory_.InvalidateWeakPtrs(); | 159 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 160 payments_client_->CancelRequest(); | 160 payments_client_->CancelRequest(); |
| 161 delegate_ = nullptr; | 161 delegate_ = nullptr; |
| 162 request_.reset(); | 162 request_.reset(); |
| 163 should_unmask_card_ = false; | 163 should_unmask_card_ = false; |
| 164 } | 164 } |
| 165 | 165 |
| 166 } // namespace payments | 166 } // namespace payments |
| 167 } // namespace autofill | 167 } // namespace autofill |
| OLD | NEW |