diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-10 00:04:48 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-10 00:04:48 +0000 |
commit | ce4b6a9dbb6ac14810294205185d385f066457fc (patch) | |
tree | 6c152e7d0e6ffc89b5c80eadbab5f24ec6ed7424 /app | |
parent | a437e4c7a38a959f3412df30b9b066c5d869ccc4 (diff) | |
download | chromium_src-ce4b6a9dbb6ac14810294205185d385f066457fc.zip chromium_src-ce4b6a9dbb6ac14810294205185d385f066457fc.tar.gz chromium_src-ce4b6a9dbb6ac14810294205185d385f066457fc.tar.bz2 |
Make BrowserProcess::GetApplicationLocale thread safe and migrate
callers of l10n_util::GetApplicationLocale to use this instead.
In the browser process, it's wrong to call
l10n_util::GetApplicationLocale with an empty string because then
it won't consider the user pref value when resolving the locale.
On Linux, it's also wrong to call l10n_util::GetApplicationLocale
after startup because the call touches disk and on Linux, we assume
that all of the program files can be deleted after startup (so
updates in place can work).
Review URL: http://codereview.chromium.org/476002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34206 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/l10n_util.h | 2 | ||||
-rw-r--r-- | app/resource_bundle.cc | 5 | ||||
-rw-r--r-- | app/resource_bundle.h | 11 | ||||
-rw-r--r-- | app/resource_bundle_dummy.cc | 4 | ||||
-rw-r--r-- | app/resource_bundle_linux.cc | 3 | ||||
-rw-r--r-- | app/resource_bundle_mac.mm | 4 | ||||
-rw-r--r-- | app/resource_bundle_posix.cc | 9 | ||||
-rw-r--r-- | app/resource_bundle_win.cc | 11 |
8 files changed, 28 insertions, 21 deletions
diff --git a/app/l10n_util.h b/app/l10n_util.h index 4675156..0c65934 100644 --- a/app/l10n_util.h +++ b/app/l10n_util.h @@ -27,7 +27,7 @@ #include "unicode/uchar.h" #if defined(OS_MACOSX) -#include "app/l10n_util.h" +#include "app/l10n_util_mac.h" #endif // OS_MACOSX class FilePath; diff --git a/app/resource_bundle.cc b/app/resource_bundle.cc index e3174d8..4c13e01 100644 --- a/app/resource_bundle.cc +++ b/app/resource_bundle.cc @@ -31,11 +31,12 @@ const SkColor ResourceBundle::toolbar_separator_color = SkColorSetRGB(182, 186, 192); /* static */ -void ResourceBundle::InitSharedInstance(const std::wstring& pref_locale) { +std::string ResourceBundle::InitSharedInstance( + const std::wstring& pref_locale) { DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice"; g_shared_instance_ = new ResourceBundle(); - g_shared_instance_->LoadResources(pref_locale); + return g_shared_instance_->LoadResources(pref_locale); } /* static */ diff --git a/app/resource_bundle.h b/app/resource_bundle.h index 550fb72..0273494 100644 --- a/app/resource_bundle.h +++ b/app/resource_bundle.h @@ -63,10 +63,11 @@ class ResourceBundle { LargeFont, }; - // Initialize the ResourceBundle for this process. + // Initialize the ResourceBundle for this process. Returns the language + // selected. // NOTE: Mac ignores this and always loads up resources for the language // defined by the Cocoa UI (ie-NSBundle does the langange work). - static void InitSharedInstance(const std::wstring& pref_locale); + static std::string InitSharedInstance(const std::wstring& pref_locale); // Delete the ResourceBundle for this process if it exists. static void CleanupSharedInstance(); @@ -169,8 +170,8 @@ class ResourceBundle { #endif // Try to load the main resources and the locale specific strings from an - // external data module. - void LoadResources(const std::wstring& pref_locale); + // external data module. Returns the locale that is loaded. + std::string LoadResources(const std::wstring& pref_locale); // Initialize all the gfx::Font members if they haven't yet been initialized. void LoadFontsIfNecessary(); @@ -183,7 +184,7 @@ class ResourceBundle { // Returns the full pathname of the locale file to load. May return an empty // string if no locale data files are found. - static FilePath GetLocaleFilePath(const std::wstring& pref_locale); + static FilePath GetLocaleFilePath(const std::string& app_locale); // Returns a handle to bytes from the resource |module|, without doing any // processing or interpretation of the resource. Returns whether we diff --git a/app/resource_bundle_dummy.cc b/app/resource_bundle_dummy.cc index 77479f6..1dd65ed 100644 --- a/app/resource_bundle_dummy.cc +++ b/app/resource_bundle_dummy.cc @@ -24,9 +24,11 @@ namespace gfx { /* static */ -void ResourceBundle::InitSharedInstance(const std::wstring& pref_locale) { +std::string ResourceBundle::InitSharedInstance( + const std::wstring& pref_locale) { DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice"; g_shared_instance_ = new ResourceBundle(); + return std::string(); } /* static */ diff --git a/app/resource_bundle_linux.cc b/app/resource_bundle_linux.cc index e8c53d3..95d5ceb 100644 --- a/app/resource_bundle_linux.cc +++ b/app/resource_bundle_linux.cc @@ -74,12 +74,11 @@ FilePath ResourceBundle::GetResourcesFilePath() { } // static -FilePath ResourceBundle::GetLocaleFilePath(const std::wstring& pref_locale) { +FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale) { FilePath locale_file_path; PathService::Get(app::DIR_LOCALES, &locale_file_path); if (locale_file_path.empty()) return locale_file_path; - const std::string app_locale = l10n_util::GetApplicationLocale(pref_locale); if (app_locale.empty()) return FilePath(); locale_file_path = locale_file_path.AppendASCII(app_locale + ".pak"); diff --git a/app/resource_bundle_mac.mm b/app/resource_bundle_mac.mm index 94ef31a..9d14440 100644 --- a/app/resource_bundle_mac.mm +++ b/app/resource_bundle_mac.mm @@ -29,8 +29,8 @@ FilePath ResourceBundle::GetResourcesFilePath() { } // static -FilePath ResourceBundle::GetLocaleFilePath(const std::wstring& pref_locale) { - DLOG_IF(WARNING, !pref_locale.empty()) +FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale) { + DLOG_IF(WARNING, !app_locale.empty()) << "ignoring requested locale in favor of NSBundle's selection"; return GetResourcesPakFilePath(@"locale"); } diff --git a/app/resource_bundle_posix.cc b/app/resource_bundle_posix.cc index ec6893a..044bc3d 100644 --- a/app/resource_bundle_posix.cc +++ b/app/resource_bundle_posix.cc @@ -5,6 +5,7 @@ #include "app/resource_bundle.h" #include "app/gfx/font.h" +#include "app/l10n_util.h" #include "base/data_pack.h" #include "base/logging.h" #include "base/string16.h" @@ -79,7 +80,7 @@ string16 ResourceBundle::GetLocalizedString(int message_id) { return msg; } -void ResourceBundle::LoadResources(const std::wstring& pref_locale) { +std::string ResourceBundle::LoadResources(const std::wstring& pref_locale) { DCHECK(!resources_data_) << "chrome.pak already loaded"; FilePath resources_file_path = GetResourcesFilePath(); DCHECK(!resources_file_path.empty()) << "chrome.pak not found"; @@ -87,12 +88,14 @@ void ResourceBundle::LoadResources(const std::wstring& pref_locale) { DCHECK(resources_data_) << "failed to load chrome.pak"; DCHECK(!locale_resources_data_) << "locale.pak already loaded"; - FilePath locale_file_path = GetLocaleFilePath(pref_locale); + std::string app_locale = l10n_util::GetApplicationLocale(pref_locale); + FilePath locale_file_path = GetLocaleFilePath(app_locale); if (locale_file_path.empty()) { // It's possible that there is no locale.pak. NOTREACHED(); - return; + return std::string(); } locale_resources_data_ = LoadResourcesDataPak(locale_file_path); DCHECK(locale_resources_data_) << "failed to load locale.pak"; + return app_locale; } diff --git a/app/resource_bundle_win.cc b/app/resource_bundle_win.cc index 9a0f7eb..ae420b8 100644 --- a/app/resource_bundle_win.cc +++ b/app/resource_bundle_win.cc @@ -38,17 +38,18 @@ ResourceBundle::~ResourceBundle() { } } -void ResourceBundle::LoadResources(const std::wstring& pref_locale) { +std::string ResourceBundle::LoadResources(const std::wstring& pref_locale) { // As a convenience, set resources_data_ to the current resource module. resources_data_ = _AtlBaseModule.GetResourceInstance(); DCHECK(NULL == locale_resources_data_) << "locale dll already loaded"; - const FilePath& locale_path = GetLocaleFilePath(pref_locale); + std::string app_locale = l10n_util::GetApplicationLocale(pref_locale); + const FilePath& locale_path = GetLocaleFilePath(app_locale); if (locale_path.value().empty()) { // It's possible that there are no locale dlls found, in which case we just // return. NOTREACHED(); - return; + return std::string(); } // The dll should only have resources, not executable code. @@ -56,14 +57,14 @@ void ResourceBundle::LoadResources(const std::wstring& pref_locale) { GetDataDllLoadFlags()); DCHECK(locale_resources_data_ != NULL) << "unable to load generated resources"; + return app_locale; } // static -FilePath ResourceBundle::GetLocaleFilePath(const std::wstring& pref_locale) { +FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale) { FilePath locale_path; PathService::Get(app::DIR_LOCALES, &locale_path); - const std::string app_locale = l10n_util::GetApplicationLocale(pref_locale); if (app_locale.empty()) return FilePath(); |