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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/CurrencyFormatter.java

Issue 2649143003: PaymentRequest: The currencySystem should be non-nullable. (Closed)
Patch Set: PaymentRequest: The currencySystem should be non-nullable. 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/payments/CurrencyFormatterTest.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 package org.chromium.chrome.browser.payments; 5 package org.chromium.chrome.browser.payments;
6 6
7 import android.support.annotation.Nullable;
8
9 import org.chromium.base.annotations.JNINamespace; 7 import org.chromium.base.annotations.JNINamespace;
10 8
11 import java.util.Locale; 9 import java.util.Locale;
12 10
13 /** 11 /**
14 * Formatter for currency amounts. 12 * Formatter for currency amounts.
15 * https://w3c.github.io/browser-payment-api/specs/paymentrequest.html#currencya mount 13 * https://w3c.github.io/browser-payment-api/specs/paymentrequest.html#currencya mount
16 */ 14 */
17 @JNINamespace("payments") 15 @JNINamespace("payments")
18 public class CurrencyFormatter { 16 public class CurrencyFormatter {
19 /** 17 /**
20 * Pointer to the native implementation. 18 * Pointer to the native implementation.
21 */ 19 */
22 private long mCurrencyFormatterAndroid; 20 private long mCurrencyFormatterAndroid;
23 21
24 /** 22 /**
25 * Builds the formatter for the given currency code and the current user loc ale. 23 * Builds the formatter for the given currency code and the current user loc ale.
26 * 24 *
27 * @param currencyCode The currency code. Most commonly, this follows ISO 4 217 format: 3 upper 25 * @param currencyCode The currency code. Most commonly, this follows ISO 4 217 format: 3 upper
28 * case ASCII letters. For example, "USD". Format is no t restricted. Should 26 * case ASCII letters. For example, "USD". Format is no t restricted. Should
29 * not be null. 27 * not be null.
30 * @param currencySystem URI specifying the ISO4217 currency code specificat ion. See for 28 * @param currencySystem URI specifying the ISO4217 currency code specificat ion. See for
31 * details: https://w3c.github.io/browser-payment-api/#paymentcurre ncyamount-dictionary 29 * details: https://w3c.github.io/browser-payment-api/#paymentcurre ncyamount-dictionary
32 * Can be null, in which case "urn:iso:std:iso:4217" is assumed. 30 * By default, the value is "urn:iso:std:iso:4217".
33 * @param userLocale User's current locale. Should not be null. 31 * @param userLocale User's current locale. Should not be null.
34 */ 32 */
35 public CurrencyFormatter( 33 public CurrencyFormatter(String currencyCode, String currencySystem, Locale userLocale) {
36 String currencyCode, @Nullable String currencySystem, Locale userLoc ale) {
37 assert currencyCode != null : "currencyCode should not be null"; 34 assert currencyCode != null : "currencyCode should not be null";
35 assert currencySystem != null : "currencySystem should not be null";
38 assert userLocale != null : "userLocale should not be null"; 36 assert userLocale != null : "userLocale should not be null";
39 37
40 // Note that this pointer could leak the native object. The called must call destroy() to 38 // Note that this pointer could leak the native object. The called must call destroy() to
41 // ensure that the native object is destroyed. 39 // ensure that the native object is destroyed.
42 mCurrencyFormatterAndroid = nativeInitCurrencyFormatterAndroid( 40 mCurrencyFormatterAndroid = nativeInitCurrencyFormatterAndroid(
43 currencyCode, currencySystem == null ? "" : currencySystem, user Locale.toString()); 41 currencyCode, currencySystem, userLocale.toString());
44 } 42 }
45 43
46 /** Will destroy the native object. This class shouldn't be used afterwards. */ 44 /** Will destroy the native object. This class shouldn't be used afterwards. */
47 public void destroy() { 45 public void destroy() {
48 if (mCurrencyFormatterAndroid != 0) { 46 if (mCurrencyFormatterAndroid != 0) {
49 nativeDestroy(mCurrencyFormatterAndroid); 47 nativeDestroy(mCurrencyFormatterAndroid);
50 mCurrencyFormatterAndroid = 0; 48 mCurrencyFormatterAndroid = 0;
51 } 49 }
52 } 50 }
53 51
(...skipping 17 matching lines...) Expand all
71 69
72 return nativeFormat(mCurrencyFormatterAndroid, amountValue); 70 return nativeFormat(mCurrencyFormatterAndroid, amountValue);
73 } 71 }
74 72
75 private native long nativeInitCurrencyFormatterAndroid( 73 private native long nativeInitCurrencyFormatterAndroid(
76 String currencyCode, String currencySystem, String localeName); 74 String currencyCode, String currencySystem, String localeName);
77 private native void nativeDestroy(long nativeCurrencyFormatterAndroid); 75 private native void nativeDestroy(long nativeCurrencyFormatterAndroid);
78 private native String nativeFormat(long nativeCurrencyFormatterAndroid, Stri ng amountValue); 76 private native String nativeFormat(long nativeCurrencyFormatterAndroid, Stri ng amountValue);
79 private native String nativeGetFormattedCurrencyCode(long nativeCurrencyForm atterAndroid); 77 private native String nativeGetFormattedCurrencyCode(long nativeCurrencyForm atterAndroid);
80 } 78 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/payments/CurrencyFormatterTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698