Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1677)

Unified Diff: components/payments/content/payment_request_spec.cc

Issue 2741343011: [Payments] Move PersonalDataManager and locale to PaymentRequestState (Closed)
Patch Set: Initial Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/payments/content/payment_request_spec.cc
diff --git a/components/payments/content/payment_request_spec.cc b/components/payments/content/payment_request_spec.cc
index 7509a76a1ccce6b77cc86bed05bff8cc6df22c1c..3d3211204c8199585714b466049d8bd3344d3bbb 100644
--- a/components/payments/content/payment_request_spec.cc
+++ b/components/payments/content/payment_request_spec.cc
@@ -19,8 +19,11 @@ PaymentRequestSpec::PaymentRequestSpec(
mojom::PaymentOptionsPtr options,
mojom::PaymentDetailsPtr details,
std::vector<mojom::PaymentMethodDataPtr> method_data,
- Observer* observer)
- : options_(std::move(options)), details_(std::move(details)) {
+ Observer* observer,
+ const std::string& app_locale)
+ : options_(std::move(options)),
+ details_(std::move(details)),
+ app_locale_(app_locale) {
if (observer)
AddObserver(observer);
PopulateValidatedMethodData(method_data);
@@ -36,6 +39,22 @@ void PaymentRequestSpec::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
+base::string16 PaymentRequestSpec::GetFormattedCurrencyAmount(
+ const std::string& amount) {
+ CurrencyFormatter* formatter = GetOrCreateCurrencyFormatter(
+ details_->total->amount->currency,
+ details_->total->amount->currency_system, app_locale_);
+ return formatter->Format(amount);
+}
+
+std::string PaymentRequestSpec::GetFormattedCurrencyCode() {
+ CurrencyFormatter* formatter = GetOrCreateCurrencyFormatter(
+ details_->total->amount->currency,
+ details_->total->amount->currency_system, app_locale_);
+
+ return formatter->formatted_currency_code();
+}
+
void PaymentRequestSpec::PopulateValidatedMethodData(
const std::vector<mojom::PaymentMethodDataPtr>& method_data) {
if (method_data.empty()) {
@@ -112,4 +131,15 @@ void PaymentRequestSpec::NotifyOnInvalidSpecProvided() {
observer.OnInvalidSpecProvided();
}
+CurrencyFormatter* PaymentRequestSpec::GetOrCreateCurrencyFormatter(
+ const std::string& currency_code,
+ const std::string& currency_system,
+ const std::string& locale_name) {
+ if (!currency_formatter_) {
+ currency_formatter_.reset(
+ new CurrencyFormatter(currency_code, currency_system, locale_name));
+ }
+ return currency_formatter_.get();
+}
+
} // namespace payments
« no previous file with comments | « components/payments/content/payment_request_spec.h ('k') | components/payments/content/payment_request_spec_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698