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