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

Side by Side Diff: components/autofill/core/common/autofill_l10n_util.cc

Issue 1457393003: [Autofill] Guard against the initialization failure of ICU Collator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments Created 5 years, 1 month 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
OLDNEW
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 "components/autofill/core/browser/autofill_metrics.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). crbug.com/558625.
Ilya Sherman 2015/11/19 22:31:20 nit: Please prepend "http://" to the link URL.
Ilya Sherman 2015/11/19 22:31:20 Please document that in the failure case, collator
Mathieu 2015/11/20 16:19:38 Done.
Mathieu 2015/11/20 16:19:38 Done.
23 bool success = U_SUCCESS(error);
24 if (success)
25 collator_->setStrength(icu::Collator::PRIMARY);
26
27 AutofillMetrics::LogIcuCollatorCreationSuccess(success);
18 } 28 }
19 29
20 CaseInsensitiveCompare::~CaseInsensitiveCompare() { 30 CaseInsensitiveCompare::~CaseInsensitiveCompare() {
21 } 31 }
22 32
23 bool CaseInsensitiveCompare::StringsEqual(const base::string16& lhs, 33 bool CaseInsensitiveCompare::StringsEqual(const base::string16& lhs,
24 const base::string16& rhs) const { 34 const base::string16& rhs) const {
25 return base::i18n::CompareString16WithCollator(*collator_, lhs, rhs) == 35 if (collator_.get()) {
26 UCOL_EQUAL; 36 return base::i18n::CompareString16WithCollator(*collator_, lhs, rhs) ==
37 UCOL_EQUAL;
38 }
39 return lhs == rhs;
27 } 40 }
28 41
29 } // namespace l10n 42 } // namespace l10n
30 } // namespace autofill 43 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698