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

Unified Diff: components/payments/android/currency_formatter_android.cc

Issue 2629883004: [Payment Request] Update the CurrencyStringFormatter to call the native impl. (Closed)
Patch Set: CurrencyStringFormatter -> CurrencyFormatter Created 3 years, 11 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
« no previous file with comments | « components/payments/android/currency_formatter_android.h ('k') | components/payments/currency_formatter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/payments/android/currency_formatter_android.cc
diff --git a/components/payments/android/currency_formatter_android.cc b/components/payments/android/currency_formatter_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..00143f3214e59766fa6e2880b76ff4387f11111e
--- /dev/null
+++ b/components/payments/android/currency_formatter_android.cc
@@ -0,0 +1,76 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/payments/android/currency_formatter_android.h"
+
+#include "base/android/jni_string.h"
+#include "base/optional.h"
+#include "base/strings/string16.h"
+#include "components/payments/currency_formatter.h"
+#include "jni/CurrencyFormatter_jni.h"
+
+using base::android::JavaParamRef;
+using base::android::ConvertJavaStringToUTF8;
+
+namespace payments {
+
+CurrencyFormatterAndroid::CurrencyFormatterAndroid(
+ JNIEnv* env,
+ jobject unused_obj,
+ const JavaParamRef<jstring>& currency_code,
+ const JavaParamRef<jstring>& currency_system,
+ const JavaParamRef<jstring>& locale_name) {
+ std::string currency_system_str =
+ ConvertJavaStringToUTF8(env, currency_system);
+
+ currency_formatter_.reset(new CurrencyFormatter(
+ ConvertJavaStringToUTF8(env, currency_code),
+ currency_system_str.empty()
+ ? base::Optional<std::string>()
+ : base::Optional<std::string>(currency_system_str),
+ ConvertJavaStringToUTF8(env, locale_name)));
+}
+
+CurrencyFormatterAndroid::~CurrencyFormatterAndroid() {}
+
+void CurrencyFormatterAndroid::Destroy(JNIEnv* env,
+ const JavaParamRef<jobject>& obj) {
+ delete this;
+}
+
+base::android::ScopedJavaLocalRef<jstring> CurrencyFormatterAndroid::Format(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& unused_obj,
+ const JavaParamRef<jstring>& amount) {
+ base::string16 result =
+ currency_formatter_->Format(ConvertJavaStringToUTF8(env, amount));
+ return base::android::ConvertUTF16ToJavaString(env, result);
+}
+
+base::android::ScopedJavaLocalRef<jstring>
+CurrencyFormatterAndroid::GetFormattedCurrencyCode(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& unused_obj) {
+ return base::android::ConvertUTF8ToJavaString(
+ env, currency_formatter_->formatted_currency_code());
+}
+
+// static
+bool CurrencyFormatterAndroid::Register(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+static jlong InitCurrencyFormatterAndroid(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& obj,
+ const JavaParamRef<jstring>& currency_code,
+ const JavaParamRef<jstring>& currency_system,
+ const JavaParamRef<jstring>& locale_name) {
+ CurrencyFormatterAndroid* currency_formatter_android =
+ new CurrencyFormatterAndroid(env, obj, currency_code, currency_system,
+ locale_name);
+ return reinterpret_cast<intptr_t>(currency_formatter_android);
+}
+
+} // namespace payments
« no previous file with comments | « components/payments/android/currency_formatter_android.h ('k') | components/payments/currency_formatter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698