OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/browser/country_names.h" | 5 #include "components/autofill/core/browser/country_names.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | |
9 | 8 |
10 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
11 #include "base/logging.h" | 10 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
14 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
15 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
17 #include "components/autofill/core/browser/country_data.h" | 16 #include "components/autofill/core/browser/country_data.h" |
18 #include "components/autofill/core/common/autofill_l10n_util.h" | 17 #include "components/autofill/core/common/autofill_l10n_util.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 134 } |
136 | 135 |
137 } // namespace | 136 } // namespace |
138 | 137 |
139 // static | 138 // static |
140 CountryNames* CountryNames::GetInstance() { | 139 CountryNames* CountryNames::GetInstance() { |
141 return base::Singleton<CountryNames>::get(); | 140 return base::Singleton<CountryNames>::get(); |
142 } | 141 } |
143 | 142 |
144 // static | 143 // static |
145 void CountryNames::SetLocaleString(std::string locale) { | 144 void CountryNames::SetLocaleString(const std::string& locale) { |
146 DCHECK(!locale.empty()); | 145 DCHECK(!locale.empty()); |
147 // Application locale should never be empty. The empty value of | 146 // Application locale should never be empty. The empty value of |
148 // |g_application_locale| means that it has not been initialized yet. | 147 // |g_application_locale| means that it has not been initialized yet. |
149 std::string* storage = g_application_locale.Pointer(); | 148 std::string* storage = g_application_locale.Pointer(); |
150 if (storage->empty()) { | 149 if (storage->empty()) { |
151 *storage = std::move(locale); | 150 *storage = locale; |
152 } | 151 } |
153 // TODO(crbug.com/579971) CountryNames currently cannot adapt to changed | 152 // TODO(crbug.com/579971) CountryNames currently cannot adapt to changed |
154 // locale without Chrome's restart. | 153 // locale without Chrome's restart. |
155 } | 154 } |
156 | 155 |
157 CountryNames::CountryNames(const std::string& locale_name) | 156 CountryNames::CountryNames(const std::string& locale_name) |
158 : locale_(locale_name.c_str()), | 157 : locale_(locale_name.c_str()), |
159 collator_(CreateCollator(locale_)), | 158 collator_(CreateCollator(locale_)), |
160 default_collator_(CreateDefaultCollator(locale_)), | 159 default_collator_(CreateDefaultCollator(locale_)), |
161 common_names_(GetCommonNames()), | 160 common_names_(GetCommonNames()), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 204 |
206 auto result = localized_names.find(sort_key); | 205 auto result = localized_names.find(sort_key); |
207 | 206 |
208 if (result != localized_names.end()) | 207 if (result != localized_names.end()) |
209 return result->second; | 208 return result->second; |
210 | 209 |
211 return std::string(); | 210 return std::string(); |
212 } | 211 } |
213 | 212 |
214 } // namespace autofill | 213 } // namespace autofill |
OLD | NEW |