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

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: Initial 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..8c82a12185089d8aeba594ca37a9b8f456815b13 100644
--- a/components/autofill/core/common/autofill_l10n_util.cc
+++ b/components/autofill/core/common/autofill_l10n_util.cc
@@ -6,6 +6,7 @@
#include "base/i18n/string_compare.h"
#include "base/logging.h"
+#include "base/metrics/histogram_macros.h"
namespace autofill {
namespace l10n {
@@ -13,8 +14,15 @@ namespace l10n {
CaseInsensitiveCompare::CaseInsensitiveCompare() {
UErrorCode error = U_ZERO_ERROR;
collator_.reset(icu::Collator::createInstance(error));
- DCHECK(U_SUCCESS(error));
- collator_->setStrength(icu::Collator::PRIMARY);
+ // 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).
Ilya Sherman 2015/11/19 21:04:06 Please add a crbug reference to this comment.
Mathieu 2015/11/19 21:53:02 Done.
+ bool success = U_SUCCESS(error);
+ 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
+ if (success)
+ collator_->setStrength(icu::Collator::PRIMARY);
+
+ 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
}
CaseInsensitiveCompare::~CaseInsensitiveCompare() {
@@ -22,8 +30,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()) {
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.
+ return base::i18n::CompareString16WithCollator(*collator_, lhs, rhs) ==
+ UCOL_EQUAL;
+ }
+ return lhs == rhs;
}
} // namespace l10n
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698