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

Side by Side Diff: chrome/common/extensions/extension_l10n_util.cc

Issue 8468018: chrome: Remove 10 exit time destructors and 2 static initializers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: duh Created 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/extension_file_util.cc ('k') | chrome/common/mac/objc_zombie.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/common/extensions/extension_l10n_util.h" 5 #include "chrome/common/extensions/extension_l10n_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/json/json_value_serializer.h" 13 #include "base/json/json_value_serializer.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/linked_ptr.h" 15 #include "base/memory/linked_ptr.h"
16 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
19 #include "chrome/common/extensions/extension_constants.h" 19 #include "chrome/common/extensions/extension_constants.h"
20 #include "chrome/common/extensions/extension_file_util.h" 20 #include "chrome/common/extensions/extension_file_util.h"
21 #include "chrome/common/extensions/extension_message_bundle.h" 21 #include "chrome/common/extensions/extension_message_bundle.h"
22 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
23 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
24 #include "unicode/uloc.h" 24 #include "unicode/uloc.h"
25 25
26 namespace errors = extension_manifest_errors; 26 namespace errors = extension_manifest_errors;
27 namespace keys = extension_manifest_keys; 27 namespace keys = extension_manifest_keys;
28 28
29 static std::string* GetProcessLocale() { 29 static std::string& GetProcessLocale() {
30 static std::string locale; 30 CR_DEFINE_STATIC_LOCAL(std::string, locale, ());
31 return &locale; 31 return locale;
32 } 32 }
33 33
34 namespace extension_l10n_util { 34 namespace extension_l10n_util {
35 35
36 void SetProcessLocale(const std::string& locale) { 36 void SetProcessLocale(const std::string& locale) {
37 *(GetProcessLocale()) = locale; 37 GetProcessLocale() = locale;
38 } 38 }
39 39
40 std::string GetDefaultLocaleFromManifest(const DictionaryValue& manifest, 40 std::string GetDefaultLocaleFromManifest(const DictionaryValue& manifest,
41 std::string* error) { 41 std::string* error) {
42 std::string default_locale; 42 std::string default_locale;
43 if (manifest.GetString(keys::kDefaultLocale, &default_locale)) 43 if (manifest.GetString(keys::kDefaultLocale, &default_locale))
44 return default_locale; 44 return default_locale;
45 45
46 *error = errors::kInvalidDefaultLocale; 46 *error = errors::kInvalidDefaultLocale;
47 return ""; 47 return "";
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } else { 176 } else {
177 *error = base::StringPrintf("Catalog file is missing for locale %s.", 177 *error = base::StringPrintf("Catalog file is missing for locale %s.",
178 locale_name.c_str()); 178 locale_name.c_str());
179 return false; 179 return false;
180 } 180 }
181 181
182 return true; 182 return true;
183 } 183 }
184 184
185 std::string CurrentLocaleOrDefault() { 185 std::string CurrentLocaleOrDefault() {
186 std::string current_locale = l10n_util::NormalizeLocale(*GetProcessLocale()); 186 std::string current_locale = l10n_util::NormalizeLocale(GetProcessLocale());
187 if (current_locale.empty()) 187 if (current_locale.empty())
188 current_locale = "en"; 188 current_locale = "en";
189 189
190 return current_locale; 190 return current_locale;
191 } 191 }
192 192
193 void GetAllLocales(std::set<std::string>* all_locales) { 193 void GetAllLocales(std::set<std::string>* all_locales) {
194 const std::vector<std::string>& available_locales = 194 const std::vector<std::string>& available_locales =
195 l10n_util::GetAvailableLocales(); 195 l10n_util::GetAvailableLocales();
196 // Add all parents of the current locale to the available locales set. 196 // Add all parents of the current locale to the available locales set.
197 // I.e. for sr_Cyrl_RS we add sr_Cyrl_RS, sr_Cyrl and sr. 197 // I.e. for sr_Cyrl_RS we add sr_Cyrl_RS, sr_Cyrl and sr.
198 for (size_t i = 0; i < available_locales.size(); ++i) { 198 for (size_t i = 0; i < available_locales.size(); ++i) {
199 std::vector<std::string> result; 199 std::vector<std::string> result;
200 l10n_util::GetParentLocales(available_locales[i], &result); 200 l10n_util::GetParentLocales(available_locales[i], &result);
201 all_locales->insert(result.begin(), result.end()); 201 all_locales->insert(result.begin(), result.end());
202 } 202 }
203 } 203 }
204 204
205 bool GetValidLocales(const FilePath& locale_path, 205 bool GetValidLocales(const FilePath& locale_path,
206 std::set<std::string>* valid_locales, 206 std::set<std::string>* valid_locales,
207 std::string* error) { 207 std::string* error) {
208 static std::set<std::string> chrome_locales; 208 std::set<std::string> chrome_locales;
209 GetAllLocales(&chrome_locales); 209 GetAllLocales(&chrome_locales);
210 210
211 // Enumerate all supplied locales in the extension. 211 // Enumerate all supplied locales in the extension.
212 file_util::FileEnumerator locales(locale_path, 212 file_util::FileEnumerator locales(locale_path,
213 false, 213 false,
214 file_util::FileEnumerator::DIRECTORIES); 214 file_util::FileEnumerator::DIRECTORIES);
215 FilePath locale_folder; 215 FilePath locale_folder;
216 while (!(locale_folder = locales.Next()).empty()) { 216 while (!(locale_folder = locales.Next()).empty()) {
217 std::string locale_name = locale_folder.BaseName().MaybeAsASCII(); 217 std::string locale_name = locale_folder.BaseName().MaybeAsASCII();
218 if (locale_name.empty()) { 218 if (locale_name.empty()) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 if (std::find(subdir.begin(), subdir.end(), '.') != subdir.end()) 306 if (std::find(subdir.begin(), subdir.end(), '.') != subdir.end())
307 return true; 307 return true;
308 308
309 if (all_locales.find(subdir) == all_locales.end()) 309 if (all_locales.find(subdir) == all_locales.end())
310 return true; 310 return true;
311 311
312 return false; 312 return false;
313 } 313 }
314 314
315 } // namespace extension_l10n_util 315 } // namespace extension_l10n_util
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_file_util.cc ('k') | chrome/common/mac/objc_zombie.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698