| 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" |
| 11 #include "components/autofill/core/browser/autofill_client.h" | 11 #include "components/autofill/core/browser/autofill_client.h" |
| 12 #include "components/autofill/core/browser/autofill_metrics.h" | 12 #include "components/autofill/core/browser/autofill_metrics.h" |
| 13 #include "components/autofill/core/browser/credit_card.h" | 13 #include "components/autofill/core/browser/credit_card.h" |
| 14 #include "components/autofill/core/browser/personal_data_manager.h" | 14 #include "components/autofill/core/browser/personal_data_manager.h" |
| 15 #include "components/autofill/core/common/autofill_clock.h" |
| 15 | 16 |
| 16 namespace autofill { | 17 namespace autofill { |
| 17 namespace payments { | 18 namespace payments { |
| 18 | 19 |
| 19 FullCardRequest::FullCardRequest(AutofillClient* autofill_client, | 20 FullCardRequest::FullCardRequest(AutofillClient* autofill_client, |
| 20 payments::PaymentsClient* payments_client, | 21 payments::PaymentsClient* payments_client, |
| 21 PersonalDataManager* personal_data_manager) | 22 PersonalDataManager* personal_data_manager) |
| 22 : autofill_client_(autofill_client), | 23 : autofill_client_(autofill_client), |
| 23 payments_client_(payments_client), | 24 payments_client_(payments_client), |
| 24 personal_data_manager_(personal_data_manager), | 25 personal_data_manager_(personal_data_manager), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 43 if (delegate_) { | 44 if (delegate_) { |
| 44 delegate->OnFullCardRequestFailed(); | 45 delegate->OnFullCardRequestFailed(); |
| 45 return; | 46 return; |
| 46 } | 47 } |
| 47 | 48 |
| 48 delegate_ = delegate; | 49 delegate_ = delegate; |
| 49 request_.reset(new payments::PaymentsClient::UnmaskRequestDetails); | 50 request_.reset(new payments::PaymentsClient::UnmaskRequestDetails); |
| 50 request_->card = card; | 51 request_->card = card; |
| 51 should_unmask_card_ = card.record_type() == CreditCard::MASKED_SERVER_CARD || | 52 should_unmask_card_ = card.record_type() == CreditCard::MASKED_SERVER_CARD || |
| 52 (card.record_type() == CreditCard::FULL_SERVER_CARD && | 53 (card.record_type() == CreditCard::FULL_SERVER_CARD && |
| 53 card.ShouldUpdateExpiration(base::Time::Now())); | 54 card.ShouldUpdateExpiration(AutofillClock::Now())); |
| 54 if (should_unmask_card_) | 55 if (should_unmask_card_) |
| 55 payments_client_->Prepare(); | 56 payments_client_->Prepare(); |
| 56 | 57 |
| 57 autofill_client_->ShowUnmaskPrompt(request_->card, reason, | 58 autofill_client_->ShowUnmaskPrompt(request_->card, reason, |
| 58 weak_ptr_factory_.GetWeakPtr()); | 59 weak_ptr_factory_.GetWeakPtr()); |
| 59 | 60 |
| 60 if (should_unmask_card_) { | 61 if (should_unmask_card_) { |
| 61 autofill_client_->LoadRiskData( | 62 autofill_client_->LoadRiskData( |
| 62 base::Bind(&FullCardRequest::OnDidGetUnmaskRiskData, | 63 base::Bind(&FullCardRequest::OnDidGetUnmaskRiskData, |
| 63 weak_ptr_factory_.GetWeakPtr())); | 64 weak_ptr_factory_.GetWeakPtr())); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 84 if (!should_unmask_card_) { | 85 if (!should_unmask_card_) { |
| 85 if (delegate_) | 86 if (delegate_) |
| 86 delegate_->OnFullCardRequestSucceeded(request_->card, response.cvc); | 87 delegate_->OnFullCardRequestSucceeded(request_->card, response.cvc); |
| 87 Reset(); | 88 Reset(); |
| 88 autofill_client_->OnUnmaskVerificationResult(AutofillClient::SUCCESS); | 89 autofill_client_->OnUnmaskVerificationResult(AutofillClient::SUCCESS); |
| 89 return; | 90 return; |
| 90 } | 91 } |
| 91 | 92 |
| 92 request_->user_response = response; | 93 request_->user_response = response; |
| 93 if (!request_->risk_data.empty()) { | 94 if (!request_->risk_data.empty()) { |
| 94 real_pan_request_timestamp_ = base::Time::Now(); | 95 real_pan_request_timestamp_ = AutofillClock::Now(); |
| 95 payments_client_->UnmaskCard(*request_); | 96 payments_client_->UnmaskCard(*request_); |
| 96 } | 97 } |
| 97 } | 98 } |
| 98 | 99 |
| 99 void FullCardRequest::OnUnmaskPromptClosed() { | 100 void FullCardRequest::OnUnmaskPromptClosed() { |
| 100 if (delegate_) | 101 if (delegate_) |
| 101 delegate_->OnFullCardRequestFailed(); | 102 delegate_->OnFullCardRequestFailed(); |
| 102 | 103 |
| 103 Reset(); | 104 Reset(); |
| 104 } | 105 } |
| 105 | 106 |
| 106 void FullCardRequest::OnDidGetUnmaskRiskData(const std::string& risk_data) { | 107 void FullCardRequest::OnDidGetUnmaskRiskData(const std::string& risk_data) { |
| 107 request_->risk_data = risk_data; | 108 request_->risk_data = risk_data; |
| 108 if (!request_->user_response.cvc.empty()) { | 109 if (!request_->user_response.cvc.empty()) { |
| 109 real_pan_request_timestamp_ = base::Time::Now(); | 110 real_pan_request_timestamp_ = AutofillClock::Now(); |
| 110 payments_client_->UnmaskCard(*request_); | 111 payments_client_->UnmaskCard(*request_); |
| 111 } | 112 } |
| 112 } | 113 } |
| 113 | 114 |
| 114 void FullCardRequest::OnDidGetRealPan(AutofillClient::PaymentsRpcResult result, | 115 void FullCardRequest::OnDidGetRealPan(AutofillClient::PaymentsRpcResult result, |
| 115 const std::string& real_pan) { | 116 const std::string& real_pan) { |
| 116 AutofillMetrics::LogRealPanDuration( | 117 AutofillMetrics::LogRealPanDuration( |
| 117 base::Time::Now() - real_pan_request_timestamp_, result); | 118 AutofillClock::Now() - real_pan_request_timestamp_, result); |
| 118 | 119 |
| 119 switch (result) { | 120 switch (result) { |
| 120 // Wait for user retry. | 121 // Wait for user retry. |
| 121 case AutofillClient::TRY_AGAIN_FAILURE: | 122 case AutofillClient::TRY_AGAIN_FAILURE: |
| 122 break; | 123 break; |
| 123 | 124 |
| 124 // Neither PERMANENT_FAILURE nor NETWORK_ERROR allow retry. | 125 // Neither PERMANENT_FAILURE nor NETWORK_ERROR allow retry. |
| 125 case AutofillClient::PERMANENT_FAILURE: | 126 case AutofillClient::PERMANENT_FAILURE: |
| 126 // Intentional fall through. | 127 // Intentional fall through. |
| 127 case AutofillClient::NETWORK_ERROR: { | 128 case AutofillClient::NETWORK_ERROR: { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 158 void FullCardRequest::Reset() { | 159 void FullCardRequest::Reset() { |
| 159 weak_ptr_factory_.InvalidateWeakPtrs(); | 160 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 160 payments_client_->CancelRequest(); | 161 payments_client_->CancelRequest(); |
| 161 delegate_ = nullptr; | 162 delegate_ = nullptr; |
| 162 request_.reset(); | 163 request_.reset(); |
| 163 should_unmask_card_ = false; | 164 should_unmask_card_ = false; |
| 164 } | 165 } |
| 165 | 166 |
| 166 } // namespace payments | 167 } // namespace payments |
| 167 } // namespace autofill | 168 } // namespace autofill |
| OLD | NEW |