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() { |
14 UErrorCode error = U_ZERO_ERROR; | 15 UErrorCode error = U_ZERO_ERROR; |
15 collator_.reset(icu::Collator::createInstance(error)); | 16 collator_.reset(icu::Collator::createInstance(error)); |
16 DCHECK(U_SUCCESS(error)); | 17 // On some systems, the default locale is invalid to the eyes of the ICU |
17 collator_->setStrength(icu::Collator::PRIMARY); | 18 // library. This could be due to a device-specific issue (has been seen in the |
19 // wild on Android devices). | |
Ilya Sherman
2015/11/19 21:04:06
Please add a crbug reference to this comment.
Mathieu
2015/11/19 21:53:02
Done.
| |
20 bool success = U_SUCCESS(error); | |
21 DCHECK(success); | |
Ilya Sherman
2015/11/19 21:04:06
nit: It's not appropriate to DCHECK a statement th
Mathieu
2015/11/19 21:53:01
My idea there was that a developer with a faulty d
Ilya Sherman
2015/11/19 22:31:20
If you think it's useful for random developers to
Mathieu
2015/11/20 16:19:38
It hits me that I can't test the failure codepath
| |
22 if (success) | |
23 collator_->setStrength(icu::Collator::PRIMARY); | |
24 | |
25 UMA_HISTOGRAM_BOOLEAN("Autofill.IcuCollatorCreationSuccess", success); | |
Mathieu
2015/11/19 20:50:51
I thought it was simpler to have the macro here, l
Ilya Sherman
2015/11/19 21:04:06
I think it's been helpful in the past to funnel al
Mathieu
2015/11/19 21:53:02
Done. Created an explicit constructor for testing,
Mathieu
2015/11/20 16:19:38
It turns out that there is no dependency path betw
| |
18 } | 26 } |
19 | 27 |
20 CaseInsensitiveCompare::~CaseInsensitiveCompare() { | 28 CaseInsensitiveCompare::~CaseInsensitiveCompare() { |
21 } | 29 } |
22 | 30 |
23 bool CaseInsensitiveCompare::StringsEqual(const base::string16& lhs, | 31 bool CaseInsensitiveCompare::StringsEqual(const base::string16& lhs, |
24 const base::string16& rhs) const { | 32 const base::string16& rhs) const { |
25 return base::i18n::CompareString16WithCollator(*collator_, lhs, rhs) == | 33 if (collator_.get()) { |
Ilya Sherman
2015/11/19 21:04:06
Hmm, when might the collator be unset? The code o
Mathieu
2015/11/19 21:53:01
On line 16, the constructor can return NULL on err
Ilya Sherman
2015/11/19 22:31:19
I see -- I'd misunderstood what the failure case w
Mathieu
2015/11/20 16:19:38
Acknowledged.
| |
26 UCOL_EQUAL; | 34 return base::i18n::CompareString16WithCollator(*collator_, lhs, rhs) == |
35 UCOL_EQUAL; | |
36 } | |
37 return lhs == rhs; | |
27 } | 38 } |
28 | 39 |
29 } // namespace l10n | 40 } // namespace l10n |
30 } // namespace autofill | 41 } // namespace autofill |
OLD | NEW |