OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/autofill/core/common/autofill_l10n_util.h" | 5 #include "components/autofill/core/common/autofill_l10n_util.h" |
6 | 6 |
7 #include "base/i18n/string_compare.h" | 7 #include "base/i18n/string_compare.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram_macros.h" | |
9 | 10 |
10 namespace autofill { | 11 namespace autofill { |
11 namespace l10n { | 12 namespace l10n { |
12 | 13 |
13 CaseInsensitiveCompare::CaseInsensitiveCompare() { | 14 CaseInsensitiveCompare::CaseInsensitiveCompare() |
15 : CaseInsensitiveCompare(icu::Locale::getDefault()) {} | |
16 | |
17 CaseInsensitiveCompare::CaseInsensitiveCompare(const icu::Locale& locale) { | |
14 UErrorCode error = U_ZERO_ERROR; | 18 UErrorCode error = U_ZERO_ERROR; |
15 collator_.reset(icu::Collator::createInstance(error)); | 19 collator_.reset(icu::Collator::createInstance(locale, error)); |
16 DCHECK(U_SUCCESS(error)); | 20 // On some systems, the default locale is invalid to the eyes of the ICU |
17 collator_->setStrength(icu::Collator::PRIMARY); | 21 // library. This could be due to a device-specific issue (has been seen in the |
22 // wild on Android devices). In the failure case, |collator_| will be null. | |
Evan Stade
2015/11/25 20:05:45
if collator_ is null for failure it seems easier t
Mathieu
2015/11/27 01:05:28
Acknowledged.
| |
23 // See http://crbug.com/558625. | |
24 bool success = !!U_SUCCESS(error); | |
Evan Stade
2015/11/25 20:05:45
nit: this might be clearer and give better logging
Mathieu
2015/11/27 01:05:28
Thanks
| |
25 if (success) { | |
26 collator_->setStrength(icu::Collator::PRIMARY); | |
27 } else { | |
28 // Attempt to load the English locale. | |
29 collator_.reset(icu::Collator::createInstance(icu::Locale::getEnglish(), | |
Evan Stade
2015/11/25 20:05:45
I think you forgot to setStrength in the success c
Mathieu
2015/11/27 01:05:28
Done.
| |
30 error)); | |
31 success = !!U_SUCCESS(error); | |
32 if (!success) { | |
33 // NOTE(mathp): Developers hitting this should either report their device | |
34 // information in the bug linked above, or contact me directly. | |
35 icu_54::UnicodeString name; | |
Evan Stade
2015/11/25 20:06:59
can you inline |name|?
Mathieu
2015/11/27 01:05:28
They have a strange API where you pass the ref and
| |
36 std::string locale_name; | |
37 locale.getDisplayName(name).toUTF8String(locale_name); | |
38 LOG(ERROR) << "Failed to initialize the ICU Collator for " | |
39 << "CaseInsensitiveCompare with locale: " | |
40 << locale_name << ", as well as the English locale."; | |
41 } | |
42 } | |
43 | |
44 UMA_HISTOGRAM_BOOLEAN("Autofill.IcuCollatorCreationSuccess", success); | |
18 } | 45 } |
19 | 46 |
20 CaseInsensitiveCompare::~CaseInsensitiveCompare() { | 47 CaseInsensitiveCompare::~CaseInsensitiveCompare() { |
21 } | 48 } |
22 | 49 |
23 bool CaseInsensitiveCompare::StringsEqual(const base::string16& lhs, | 50 bool CaseInsensitiveCompare::StringsEqual(const base::string16& lhs, |
24 const base::string16& rhs) const { | 51 const base::string16& rhs) const { |
25 return base::i18n::CompareString16WithCollator(*collator_, lhs, rhs) == | 52 if (collator_) { |
26 UCOL_EQUAL; | 53 return base::i18n::CompareString16WithCollator(*collator_, lhs, rhs) == |
54 UCOL_EQUAL; | |
55 } | |
56 return lhs == rhs; | |
27 } | 57 } |
28 | 58 |
29 } // namespace l10n | 59 } // namespace l10n |
30 } // namespace autofill | 60 } // namespace autofill |
OLD | NEW |