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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/common/autofill_l10n_util.cc
diff --git a/components/autofill/core/common/autofill_l10n_util.cc b/components/autofill/core/common/autofill_l10n_util.cc
index 6f063a85f4f7821d0e962b3d26680b26d075d151..52ab4e1c6d83994e1994a9593b127264c82f6bd8 100644
--- a/components/autofill/core/common/autofill_l10n_util.cc
+++ b/components/autofill/core/common/autofill_l10n_util.cc
@@ -6,15 +6,25 @@
#include "base/i18n/string_compare.h"
#include "base/logging.h"
+#include "components/autofill/core/browser/autofill_metrics.h"
namespace autofill {
namespace l10n {
-CaseInsensitiveCompare::CaseInsensitiveCompare() {
+CaseInsensitiveCompare::CaseInsensitiveCompare()
+ : CaseInsensitiveCompare(icu::Locale::getDefault()) {}
+
+CaseInsensitiveCompare::CaseInsensitiveCompare(const icu::Locale& locale) {
UErrorCode error = U_ZERO_ERROR;
- collator_.reset(icu::Collator::createInstance(error));
- DCHECK(U_SUCCESS(error));
- collator_->setStrength(icu::Collator::PRIMARY);
+ collator_.reset(icu::Collator::createInstance(locale, error));
+ // On some systems, the default locale is invalid to the eyes of the ICU
+ // library. This could be due to a device-specific issue (has been seen in the
+ // 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.
+ bool success = U_SUCCESS(error);
+ if (success)
+ collator_->setStrength(icu::Collator::PRIMARY);
+
+ AutofillMetrics::LogIcuCollatorCreationSuccess(success);
}
CaseInsensitiveCompare::~CaseInsensitiveCompare() {
@@ -22,8 +32,11 @@ CaseInsensitiveCompare::~CaseInsensitiveCompare() {
bool CaseInsensitiveCompare::StringsEqual(const base::string16& lhs,
const base::string16& rhs) const {
- return base::i18n::CompareString16WithCollator(*collator_, lhs, rhs) ==
- UCOL_EQUAL;
+ if (collator_.get()) {
+ return base::i18n::CompareString16WithCollator(*collator_, lhs, rhs) ==
+ UCOL_EQUAL;
+ }
+ return lhs == rhs;
}
} // namespace l10n

Powered by Google App Engine
This is Rietveld 408576698