OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_PAYMENTS_FULL_CARD_REQUEST_H_ |
| 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_PAYMENTS_FULL_CARD_REQUEST_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/strings/string16.h" |
| 14 #include "base/time/time.h" |
| 15 #include "components/autofill/core/browser/card_unmask_delegate.h" |
| 16 #include "components/autofill/core/browser/payments/payments_client.h" |
| 17 |
| 18 namespace autofill { |
| 19 |
| 20 class AutofillClient; |
| 21 class CreditCard; |
| 22 class PersonalDataManager; |
| 23 |
| 24 namespace payments { |
| 25 |
| 26 // Retrieves the full card details, including the pan and the cvc. |
| 27 class FullCardRequest : public CardUnmaskDelegate { |
| 28 public: |
| 29 // The interface for receiving the full card details. |
| 30 class Delegate { |
| 31 public: |
| 32 virtual void OnFullCardDetails(const CreditCard& card, |
| 33 const base::string16& cvc) = 0; |
| 34 virtual void OnFullCardError() = 0; |
| 35 }; |
| 36 |
| 37 // The parameters should outlive the FullCardRequest. |
| 38 FullCardRequest(AutofillClient* autofill_client, |
| 39 payments::PaymentsClient* payments_client, |
| 40 PersonalDataManager* personal_data_manager); |
| 41 ~FullCardRequest(); |
| 42 |
| 43 // Retrieves the pan and cvc for |card| and invokes |
| 44 // Delegate::OnFullCardDetails() or Delegate::OnFullCardError(). Only one |
| 45 // request should be active at a time. |
| 46 void GetFullCard(const CreditCard& card, |
| 47 AutofillClient::UnmaskCardReason reason, |
| 48 base::WeakPtr<Delegate> delegate); |
| 49 |
| 50 // Returns true if there's a pending request to get the full card. |
| 51 bool IsGettingFullCard() const; |
| 52 |
| 53 // Called by the payments client when a card has been unmasked. |
| 54 void OnDidGetRealPan(AutofillClient::PaymentsRpcResult result, |
| 55 const std::string& real_pan); |
| 56 private: |
| 57 // CardUnmaskDelegate: |
| 58 void OnUnmaskResponse(const UnmaskResponse& response) override; |
| 59 void OnUnmaskPromptClosed() override; |
| 60 |
| 61 // Called by autofill client when the risk data has been loaded. |
| 62 void OnDidGetUnmaskRiskData(const std::string& risk_data); |
| 63 |
| 64 // Responsible for showing the UI that prompts the user for the CVC and/or the |
| 65 // updated expiration date. |
| 66 AutofillClient* const autofill_client_; |
| 67 |
| 68 // Responsible for unmasking a masked server card. |
| 69 payments::PaymentsClient* const payments_client_; |
| 70 |
| 71 // Responsible for updating the server card on disk after it's been unmasked. |
| 72 PersonalDataManager* const personal_data_manager_; |
| 73 |
| 74 // Receiver of the full PAN and CVC. |
| 75 base::WeakPtr<Delegate> delegate_; |
| 76 |
| 77 // The pending request to get a card's full PAN and CVC. |
| 78 std::unique_ptr<payments::PaymentsClient::UnmaskRequestDetails> request_; |
| 79 |
| 80 // The timestamp when the full PAN was requested from a server. For |
| 81 // histograms. |
| 82 base::Time real_pan_request_timestamp_; |
| 83 |
| 84 // Enables destroying FullCardRequest while CVC prompt is showing or a server |
| 85 // communication is pending. |
| 86 base::WeakPtrFactory<FullCardRequest> weak_ptr_factory_; |
| 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(FullCardRequest); |
| 89 }; |
| 90 |
| 91 } // namespace payments |
| 92 } // namespace autofill |
| 93 |
| 94 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_PAYMENTS_FULL_CARD_REQUEST_H_ |
OLD | NEW |