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. | |
23 // See http://crbug.com/558625. | |
24 bool success = U_SUCCESS(error) ? true : false; | |
Mathieu
2015/11/20 18:40:46
This is not elegant, but I had to do it to fix a c
Evan Stade
2015/11/20 19:49:47
normally I use !! for this, or you can probably do
Mathieu
2015/11/20 21:16:42
Done.
| |
25 if (success) { | |
26 collator_->setStrength(icu::Collator::PRIMARY); | |
27 } else { | |
28 // NOTE(mathp): Developers hitting this should either report their device | |
29 // information in the bug linked above, or contact me directly. | |
30 LOG(ERROR) << "Failed to initialize the ICU Collator for " | |
31 << "CaseInsensitiveCompare."; | |
32 } | |
33 | |
34 UMA_HISTOGRAM_BOOLEAN("Autofill.IcuCollatorCreationSuccess", success); | |
18 } | 35 } |
19 | 36 |
20 CaseInsensitiveCompare::~CaseInsensitiveCompare() { | 37 CaseInsensitiveCompare::~CaseInsensitiveCompare() { |
21 } | 38 } |
22 | 39 |
23 bool CaseInsensitiveCompare::StringsEqual(const base::string16& lhs, | 40 bool CaseInsensitiveCompare::StringsEqual(const base::string16& lhs, |
24 const base::string16& rhs) const { | 41 const base::string16& rhs) const { |
25 return base::i18n::CompareString16WithCollator(*collator_, lhs, rhs) == | 42 if (collator_.get()) { |
26 UCOL_EQUAL; | 43 return base::i18n::CompareString16WithCollator(*collator_, lhs, rhs) == |
44 UCOL_EQUAL; | |
45 } | |
46 return lhs == rhs; | |
27 } | 47 } |
28 | 48 |
29 } // namespace l10n | 49 } // namespace l10n |
30 } // namespace autofill | 50 } // namespace autofill |
OLD | NEW |