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

Unified Diff: components/autofill/core/browser/autofill_country.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/autofill/core/common/autofill_l10n_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/core/browser/autofill_country.cc
diff --git a/components/autofill/core/browser/autofill_country.cc b/components/autofill/core/browser/autofill_country.cc
index b45719b791be8b1807eabca69329433027f9ac88..75e9901eee72aa17f2dc865f046e2384912c0cc0 100644
--- a/components/autofill/core/browser/autofill_country.cc
+++ b/components/autofill/core/browser/autofill_country.cc
@@ -871,7 +871,7 @@ class CountryNames {
// Returns an ICU collator -- i.e. string comparator -- appropriate for the
// given |locale|, or null if no collator is available.
- icu::Collator* GetCollatorForLocale(const std::string& locale);
+ const icu::Collator* GetCollatorForLocale(const std::string& locale);
// Returns the ICU sort key corresponding to |str| for the given |collator|.
// Uses |buffer| as temporary storage, and might resize |buffer| as a side-
@@ -895,7 +895,7 @@ class CountryNames {
locales_to_localized_names_;
// Maps ICU locale names to their corresponding collators.
- std::map<std::string, icu::Collator*> collators_;
+ std::map<std::string, scoped_ptr<icu::Collator>> collators_;
DISALLOW_COPY_AND_ASSIGN(CountryNames);
};
@@ -930,10 +930,7 @@ CountryNames::CountryNames() {
common_names_.insert(std::make_pair("DEUTSCHLAND", "DE"));
}
-CountryNames::~CountryNames() {
- STLDeleteContainerPairSecondPointers(collators_.begin(),
- collators_.end());
-}
+CountryNames::~CountryNames() {}
const std::string CountryNames::GetCountryCode(const base::string16& country,
const std::string& locale) {
@@ -985,7 +982,7 @@ const std::string CountryNames::GetCountryCodeForLocalizedName(
const std::string& locale) {
AddLocalizedNamesForLocale(locale);
- icu::Collator* collator = GetCollatorForLocale(locale);
+ const icu::Collator* collator = GetCollatorForLocale(locale);
// In very rare cases, the collator fails to initialize.
if (!collator)
return std::string();
@@ -1011,9 +1008,10 @@ const std::string CountryNames::GetCountryCodeForLocalizedName(
return std::string();
}
-icu::Collator* CountryNames::GetCollatorForLocale(const std::string& locale) {
- if (!collators_.count(locale)) {
- icu::Collator* collator(
+const icu::Collator* CountryNames::GetCollatorForLocale(
+ const std::string& locale) {
+ if (!ContainsKey(collators_, locale)) {
+ scoped_ptr<icu::Collator> collator(
autofill::l10n::GetCollatorForLocale(icu::Locale(locale.c_str())));
if (!collator)
return nullptr;
@@ -1024,10 +1022,10 @@ icu::Collator* CountryNames::GetCollatorForLocale(const std::string& locale) {
ignored = U_ZERO_ERROR;
collator->setAttribute(UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, ignored);
- collators_.insert(std::make_pair(locale, collator));
+ collators_[locale] = std::move(collator);
}
- return collators_[locale];
+ return collators_[locale].get();
}
const std::string CountryNames::GetSortKey(const icu::Collator& collator,
« no previous file with comments | « no previous file | components/autofill/core/common/autofill_l10n_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698