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

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

Issue 1541843002: Autofill's CountryCode should use scoped_ptr for owned pointers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « components/autofill/core/common/autofill_l10n_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <utility>
8
7 #include "base/i18n/string_compare.h" 9 #include "base/i18n/string_compare.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
9 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
10 12
11 namespace autofill { 13 namespace autofill {
12 namespace l10n { 14 namespace l10n {
13 15
14 icu::Collator* GetCollatorForLocale(const icu::Locale& locale) { 16 scoped_ptr<icu::Collator> GetCollatorForLocale(const icu::Locale& locale) {
15 UErrorCode ignored = U_ZERO_ERROR; 17 UErrorCode ignored = U_ZERO_ERROR;
16 icu::Collator* collator(icu::Collator::createInstance(locale, ignored)); 18 scoped_ptr<icu::Collator> collator(
19 icu::Collator::createInstance(locale, ignored));
17 if (!collator) { 20 if (!collator) {
18 // On some systems, the default locale is invalid to the eyes of the ICU 21 // On some systems, the default locale is invalid to the eyes of the ICU
19 // library. This could be due to a device-specific issue (has been seen in 22 // library. This could be due to a device-specific issue (has been seen in
20 // the wild on Android and iOS devices). In the failure case, |collator| 23 // the wild on Android and iOS devices). In the failure case, |collator|
21 // will be null. See http://crbug.com/558625. 24 // will be null. See http://crbug.com/558625.
22 icu::UnicodeString name; 25 icu::UnicodeString name;
23 std::string locale_name; 26 std::string locale_name;
24 locale.getDisplayName(name).toUTF8String(locale_name); 27 locale.getDisplayName(name).toUTF8String(locale_name);
25 LOG(ERROR) << "Failed to initialize the ICU Collator with locale " 28 LOG(ERROR) << "Failed to initialize the ICU Collator with locale "
26 << locale_name; 29 << locale_name;
27 30
28 // Attempt to load the English locale. 31 // Attempt to load the English locale.
29 collator = 32 collator = make_scoped_ptr(
30 icu::Collator::createInstance(icu::Locale::getEnglish(), ignored); 33 icu::Collator::createInstance(icu::Locale::getEnglish(), ignored));
31 if (!collator) { 34 if (!collator) {
32 LOG(ERROR) << "Failed to initialize the ICU Collator with the English " 35 LOG(ERROR) << "Failed to initialize the ICU Collator with the English "
33 << "locale."; 36 << "locale.";
34 } 37 }
35 } 38 }
36 39
37 UMA_HISTOGRAM_BOOLEAN("Autofill.IcuCollatorCreationSuccess", !!collator); 40 UMA_HISTOGRAM_BOOLEAN("Autofill.IcuCollatorCreationSuccess", !!collator);
38 return collator; 41 return collator;
39 } 42 }
40 43
(...skipping 13 matching lines...) Expand all
54 const base::string16& rhs) const { 57 const base::string16& rhs) const {
55 if (collator_) { 58 if (collator_) {
56 return base::i18n::CompareString16WithCollator(*collator_, lhs, rhs) == 59 return base::i18n::CompareString16WithCollator(*collator_, lhs, rhs) ==
57 UCOL_EQUAL; 60 UCOL_EQUAL;
58 } 61 }
59 return lhs == rhs; 62 return lhs == rhs;
60 } 63 }
61 64
62 } // namespace l10n 65 } // namespace l10n
63 } // namespace autofill 66 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/common/autofill_l10n_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698