OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_RESPONSE_HELPER_H_ | 5 #ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_RESPONSE_HELPER_H_ |
6 #define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_RESPONSE_HELPER_H_ | 6 #define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_RESPONSE_HELPER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "components/autofill/core/browser/autofill_profile.h" | |
10 #include "components/payments/core/address_normalizer.h" | |
9 #include "components/payments/core/payment_instrument.h" | 11 #include "components/payments/core/payment_instrument.h" |
10 #include "components/payments/mojom/payment_request.mojom.h" | 12 #include "components/payments/mojom/payment_request.mojom.h" |
11 | 13 |
12 namespace autofill { | 14 namespace autofill { |
13 class AutofillProfile; | 15 class AutofillProfile; |
please use gerrit instead
2017/04/20 20:15:20
Remove the forward decl.
sebsg
2017/04/20 21:06:19
Done.
| |
14 } // namespace autofill | 16 } // namespace autofill |
15 | 17 |
16 namespace payments { | 18 namespace payments { |
17 | 19 |
20 class PaymentRequestDelegate; | |
18 class PaymentRequestSpec; | 21 class PaymentRequestSpec; |
19 | 22 |
20 // TODO(sebsg): Asynchronously normalize the billing and shipping addresses | 23 // TODO(sebsg): Asynchronously normalize the billing and shipping addresses |
21 // before adding them to the PaymentResponse. | 24 // before adding them to the PaymentResponse. |
22 // A helper class to facilitate the creation of the PaymentResponse. | 25 // A helper class to facilitate the creation of the PaymentResponse. |
23 class PaymentResponseHelper : public PaymentInstrument::Delegate { | 26 class PaymentResponseHelper : public PaymentInstrument::Delegate, |
27 AddressNormalizer::Delegate { | |
24 public: | 28 public: |
25 class Delegate { | 29 class Delegate { |
26 public: | 30 public: |
27 virtual ~Delegate() {} | 31 virtual ~Delegate() {} |
28 | 32 |
29 virtual void OnPaymentResponseReady( | 33 virtual void OnPaymentResponseReady( |
30 mojom::PaymentResponsePtr payment_response) = 0; | 34 mojom::PaymentResponsePtr payment_response) = 0; |
31 }; | 35 }; |
32 | 36 |
33 // The spec, selected_instrument and delegate cannot be null. | 37 // The spec, selected_instrument and delegate cannot be null. |
34 PaymentResponseHelper(const std::string& app_locale, | 38 PaymentResponseHelper(const std::string& app_locale, |
35 PaymentRequestSpec* spec, | 39 PaymentRequestSpec* spec, |
36 PaymentInstrument* selected_instrument, | 40 PaymentInstrument* selected_instrument, |
41 PaymentRequestDelegate* payment_request_delegate, | |
37 autofill::AutofillProfile* selected_shipping_profile, | 42 autofill::AutofillProfile* selected_shipping_profile, |
38 autofill::AutofillProfile* selected_contact_profile, | 43 autofill::AutofillProfile* selected_contact_profile, |
39 Delegate* delegate); | 44 Delegate* delegate); |
40 ~PaymentResponseHelper() override; | 45 ~PaymentResponseHelper() override; |
41 | 46 |
42 // Returns a new mojo PaymentAddress based on the specified | 47 // Returns a new mojo PaymentAddress based on the specified |
43 // |profile| and |app_locale|. | 48 // |profile| and |app_locale|. |
44 static mojom::PaymentAddressPtr GetMojomPaymentAddressFromAutofillProfile( | 49 static mojom::PaymentAddressPtr GetMojomPaymentAddressFromAutofillProfile( |
45 const autofill::AutofillProfile* const profile, | 50 const autofill::AutofillProfile* const profile, |
46 const std::string& app_locale); | 51 const std::string& app_locale); |
47 | 52 |
48 // PaymentInstrument::Delegate | 53 // PaymentInstrument::Delegate |
49 void OnInstrumentDetailsReady( | 54 void OnInstrumentDetailsReady( |
50 const std::string& method_name, | 55 const std::string& method_name, |
51 const std::string& stringified_details) override; | 56 const std::string& stringified_details) override; |
52 void OnInstrumentDetailsError() override {} | 57 void OnInstrumentDetailsError() override {} |
53 | 58 |
59 // AddressNormalizer::Delegate | |
60 void OnAddressNormalized( | |
61 const autofill::AutofillProfile& normalized_profile) override; | |
62 void OnCouldNotNormalize(const autofill::AutofillProfile& profile) override; | |
63 | |
54 private: | 64 private: |
65 // Generates the Payment Response and sends it to the delegate. | |
66 void GeneratePaymentResponse(); | |
67 | |
55 const std::string& app_locale_; | 68 const std::string& app_locale_; |
69 bool is_waiting_for_shipping_address_normalization_; | |
70 bool is_waiting_for_instrument_details_; | |
56 | 71 |
57 // Not owned, cannot be null. | 72 // Not owned, cannot be null. |
58 PaymentRequestSpec* spec_; | 73 PaymentRequestSpec* spec_; |
59 Delegate* delegate_; | 74 Delegate* delegate_; |
60 PaymentInstrument* selected_instrument_; | 75 PaymentInstrument* selected_instrument_; |
76 PaymentRequestDelegate* payment_request_delegate_; | |
61 | 77 |
62 // Not owned, can be null (dependent on the spec). | 78 // Not owned, can be null (dependent on the spec). |
63 autofill::AutofillProfile* selected_shipping_profile_; | |
64 autofill::AutofillProfile* selected_contact_profile_; | 79 autofill::AutofillProfile* selected_contact_profile_; |
65 | 80 |
81 autofill::AutofillProfile shipping_address_; | |
82 | |
83 // Instrument Details. | |
84 std::string method_name_; | |
85 std::string stringified_details_; | |
86 | |
66 DISALLOW_COPY_AND_ASSIGN(PaymentResponseHelper); | 87 DISALLOW_COPY_AND_ASSIGN(PaymentResponseHelper); |
67 }; | 88 }; |
68 | 89 |
69 } // namespace payments | 90 } // namespace payments |
70 | 91 |
71 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_RESPONSE_HELPER_H_ | 92 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_RESPONSE_HELPER_H_ |
OLD | NEW |