| 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 #include "components/payments/android/currency_formatter_android.h" | 5 #include "components/payments/android/currency_formatter_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
| 8 #include "base/optional.h" | 8 #include "base/optional.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "components/payments/currency_formatter.h" | 10 #include "components/payments/currency_formatter.h" |
| 11 #include "jni/CurrencyFormatter_jni.h" | 11 #include "jni/CurrencyFormatter_jni.h" |
| 12 | 12 |
| 13 using base::android::JavaParamRef; | 13 using base::android::JavaParamRef; |
| 14 using base::android::ConvertJavaStringToUTF8; | 14 using base::android::ConvertJavaStringToUTF8; |
| 15 | 15 |
| 16 namespace payments { | 16 namespace payments { |
| 17 | 17 |
| 18 CurrencyFormatterAndroid::CurrencyFormatterAndroid( | 18 CurrencyFormatterAndroid::CurrencyFormatterAndroid( |
| 19 JNIEnv* env, | 19 JNIEnv* env, |
| 20 jobject unused_obj, | 20 jobject unused_obj, |
| 21 const JavaParamRef<jstring>& currency_code, | 21 const JavaParamRef<jstring>& currency_code, |
| 22 const JavaParamRef<jstring>& currency_system, | 22 const JavaParamRef<jstring>& currency_system, |
| 23 const JavaParamRef<jstring>& locale_name) { | 23 const JavaParamRef<jstring>& locale_name) { |
| 24 std::string currency_system_str = | 24 std::string currency_system_str = |
| 25 ConvertJavaStringToUTF8(env, currency_system); | 25 ConvertJavaStringToUTF8(env, currency_system); |
| 26 | 26 |
| 27 currency_formatter_.reset(new CurrencyFormatter( | 27 currency_formatter_.reset(new CurrencyFormatter( |
| 28 ConvertJavaStringToUTF8(env, currency_code), | 28 ConvertJavaStringToUTF8(env, currency_code), currency_system_str, |
| 29 currency_system_str.empty() | |
| 30 ? base::Optional<std::string>() | |
| 31 : base::Optional<std::string>(currency_system_str), | |
| 32 ConvertJavaStringToUTF8(env, locale_name))); | 29 ConvertJavaStringToUTF8(env, locale_name))); |
| 33 } | 30 } |
| 34 | 31 |
| 35 CurrencyFormatterAndroid::~CurrencyFormatterAndroid() {} | 32 CurrencyFormatterAndroid::~CurrencyFormatterAndroid() {} |
| 36 | 33 |
| 37 void CurrencyFormatterAndroid::Destroy(JNIEnv* env, | 34 void CurrencyFormatterAndroid::Destroy(JNIEnv* env, |
| 38 const JavaParamRef<jobject>& obj) { | 35 const JavaParamRef<jobject>& obj) { |
| 39 delete this; | 36 delete this; |
| 40 } | 37 } |
| 41 | 38 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 67 const JavaParamRef<jstring>& currency_code, | 64 const JavaParamRef<jstring>& currency_code, |
| 68 const JavaParamRef<jstring>& currency_system, | 65 const JavaParamRef<jstring>& currency_system, |
| 69 const JavaParamRef<jstring>& locale_name) { | 66 const JavaParamRef<jstring>& locale_name) { |
| 70 CurrencyFormatterAndroid* currency_formatter_android = | 67 CurrencyFormatterAndroid* currency_formatter_android = |
| 71 new CurrencyFormatterAndroid(env, obj, currency_code, currency_system, | 68 new CurrencyFormatterAndroid(env, obj, currency_code, currency_system, |
| 72 locale_name); | 69 locale_name); |
| 73 return reinterpret_cast<intptr_t>(currency_formatter_android); | 70 return reinterpret_cast<intptr_t>(currency_formatter_android); |
| 74 } | 71 } |
| 75 | 72 |
| 76 } // namespace payments | 73 } // namespace payments |
| OLD | NEW |