| 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 #ifndef COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_ | 5 #ifndef COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_ |
| 6 #define COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_ | 6 #define COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 // Returns the CurrencyFormatter instance for this PaymentRequest. | 61 // Returns the CurrencyFormatter instance for this PaymentRequest. |
| 62 // |locale_name| should be the result of the browser's GetApplicationLocale(). | 62 // |locale_name| should be the result of the browser's GetApplicationLocale(). |
| 63 // Note: Having multiple currencies per PaymentRequest is not supported; hence | 63 // Note: Having multiple currencies per PaymentRequest is not supported; hence |
| 64 // the CurrencyFormatter is cached here. | 64 // the CurrencyFormatter is cached here. |
| 65 CurrencyFormatter* GetOrCreateCurrencyFormatter( | 65 CurrencyFormatter* GetOrCreateCurrencyFormatter( |
| 66 const std::string& currency_code, | 66 const std::string& currency_code, |
| 67 const std::string& currency_system, | 67 const std::string& currency_system, |
| 68 const std::string& locale_name); | 68 const std::string& locale_name); |
| 69 | 69 |
| 70 // Returns the Autofill Profile, representing the shipping address and contact | 70 // Returns the appropriate Autofill Profiles for this user. On the first |
| 71 // information, currently selected for this PaymentRequest flow. If | 71 // invocation of either getter, the profiles are fetched from the |
| 72 // unpopulated, populates with and returns the 0th profile on record for this | 72 // PersonalDataManager; on subsequent invocations, a cached version is |
| 73 // user, if it exists; or nullptr otherwise. Profile is owned by the request | 73 // returned. The profiles returned are owned by the request object. |
| 74 // object, not the caller. | 74 const std::vector<autofill::AutofillProfile*>& shipping_profiles(); |
| 75 autofill::AutofillProfile* GetCurrentlySelectedProfile(); | 75 const std::vector<autofill::AutofillProfile*>& contact_profiles(); |
| 76 |
| 77 // Gets/sets the Autofill Profile representing the shipping address or contact |
| 78 // information currently selected for this PaymentRequest flow. Can return |
| 79 // null. |
| 80 autofill::AutofillProfile* selected_shipping_profile() const { |
| 81 return selected_shipping_profile_; |
| 82 } |
| 83 void set_selected_shipping_profile(autofill::AutofillProfile* profile) { |
| 84 selected_shipping_profile_ = profile; |
| 85 } |
| 86 autofill::AutofillProfile* selected_contact_profile() const { |
| 87 return selected_contact_profile_; |
| 88 } |
| 89 void set_selected_contact_profile(autofill::AutofillProfile* profile) { |
| 90 selected_contact_profile_ = profile; |
| 91 } |
| 76 | 92 |
| 77 // Returns the currently selected credit card for this PaymentRequest flow. | 93 // Returns the currently selected credit card for this PaymentRequest flow. |
| 78 // It's not guaranteed to be complete. Returns nullptr if there is no selected | 94 // It's not guaranteed to be complete. Returns nullptr if there is no selected |
| 79 // card. | 95 // card. |
| 80 autofill::CreditCard* GetCurrentlySelectedCreditCard(); | 96 autofill::CreditCard* GetCurrentlySelectedCreditCard(); |
| 81 | 97 |
| 82 payments::mojom::PaymentDetails* details() { return details_.get(); } | 98 payments::mojom::PaymentDetails* details() { return details_.get(); } |
| 83 content::WebContents* web_contents() { return web_contents_; } | 99 content::WebContents* web_contents() { return web_contents_; } |
| 84 | 100 |
| 85 private: | 101 private: |
| 102 // Fetches the Autofill Profiles for this user from the PersonalDataManager, |
| 103 // and stores copies of them, owned by this Request, in profile_cache_. |
| 104 void PopulateProfileCache(); |
| 105 |
| 106 // Sets the default values for the selected Shipping and Contact profiles. |
| 107 void SetDefaultProfileSelections(); |
| 108 |
| 86 content::WebContents* web_contents_; | 109 content::WebContents* web_contents_; |
| 87 std::unique_ptr<PaymentRequestDelegate> delegate_; | 110 std::unique_ptr<PaymentRequestDelegate> delegate_; |
| 88 // |manager_| owns this PaymentRequest. | 111 // |manager_| owns this PaymentRequest. |
| 89 PaymentRequestWebContentsManager* manager_; | 112 PaymentRequestWebContentsManager* manager_; |
| 90 mojo::Binding<payments::mojom::PaymentRequest> binding_; | 113 mojo::Binding<payments::mojom::PaymentRequest> binding_; |
| 91 payments::mojom::PaymentRequestClientPtr client_; | 114 payments::mojom::PaymentRequestClientPtr client_; |
| 92 payments::mojom::PaymentDetailsPtr details_; | 115 payments::mojom::PaymentDetailsPtr details_; |
| 93 std::unique_ptr<CurrencyFormatter> currency_formatter_; | 116 std::unique_ptr<CurrencyFormatter> currency_formatter_; |
| 94 std::unique_ptr<autofill::AutofillProfile> profile_; | 117 |
| 118 // Profiles may change due to (e.g.) sync events, so profiles are cached after |
| 119 // loading and owned here. They are populated once only, and ordered by |
| 120 // frecency. |
| 121 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_; |
| 122 std::vector<autofill::AutofillProfile*> shipping_profiles_; |
| 123 std::vector<autofill::AutofillProfile*> contact_profiles_; |
| 124 autofill::AutofillProfile* selected_shipping_profile_; |
| 125 autofill::AutofillProfile* selected_contact_profile_; |
| 95 | 126 |
| 96 DISALLOW_COPY_AND_ASSIGN(PaymentRequest); | 127 DISALLOW_COPY_AND_ASSIGN(PaymentRequest); |
| 97 }; | 128 }; |
| 98 | 129 |
| 99 } // namespace payments | 130 } // namespace payments |
| 100 | 131 |
| 101 #endif // COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_ | 132 #endif // COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_ |
| OLD | NEW |