summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authortony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-10 00:04:48 +0000
committertony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-10 00:04:48 +0000
commitce4b6a9dbb6ac14810294205185d385f066457fc (patch)
tree6c152e7d0e6ffc89b5c80eadbab5f24ec6ed7424 /chrome/browser
parenta437e4c7a38a959f3412df30b9b066c5d869ccc4 (diff)
downloadchromium_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 'chrome/browser')
-rw-r--r--chrome/browser/browser_main.cc19
-rw-r--r--chrome/browser/browser_process.h1
-rw-r--r--chrome/browser/browser_process_impl.cc9
-rw-r--r--chrome/browser/browser_process_impl.h8
-rw-r--r--chrome/browser/extensions/extension_file_util.cc5
-rw-r--r--chrome/browser/utility_process_host.cc4
6 files changed, 23 insertions, 23 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 766fb91..9878994 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -559,15 +559,20 @@ int BrowserMain(const MainFunctionParams& parameters) {
// If we're running tests (ui_task is non-null), then the ResourceBundle
// has already been initialized.
- // Mac starts it earlier in Platform::WillInitializeMainMessageLoop (because
- // it is needed when loading the MainMenu.nib and the language doesn't depend
- // on anything since it comes from Cocoa.
-#if !defined(OS_MACOSX)
- if (!parameters.ui_task) {
- ResourceBundle::InitSharedInstance(
+ if (parameters.ui_task) {
+ g_browser_process->set_application_locale("en-US");
+ } else {
+ // Mac starts it earlier in Platform::WillInitializeMainMessageLoop (because
+ // it is needed when loading the MainMenu.nib and the language doesn't depend
+ // on anything since it comes from Cocoa.
+#if defined(OS_MACOSX)
+ g_browser_process->set_application_locale(l10n_util::GetLocaleOverride());
+#else
+ std::string app_locale = ResourceBundle::InitSharedInstance(
local_state->GetString(prefs::kApplicationLocale));
- }
+ g_browser_process->set_application_locale(app_locale);
#endif // !defined(OS_MACOSX)
+ }
#if defined(OS_LINUX)
gtk_util::SetDefaultWindowIcon();
diff --git a/chrome/browser/browser_process.h b/chrome/browser/browser_process.h
index 3283318..d826321 100644
--- a/chrome/browser/browser_process.h
+++ b/chrome/browser/browser_process.h
@@ -125,6 +125,7 @@ class BrowserProcess {
// Returns the locale used by the application.
virtual const std::string& GetApplicationLocale() = 0;
+ virtual void set_application_locale(const std::string& locale) = 0;
DownloadRequestManager* download_request_manager();
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 9b110a65..54d7858 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -290,15 +290,6 @@ printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
return print_job_manager_.get();
}
-const std::string& BrowserProcessImpl::GetApplicationLocale() {
- DCHECK(CalledOnValidThread());
- if (locale_.empty()) {
- locale_ = l10n_util::GetApplicationLocale(
- local_state()->GetString(prefs::kApplicationLocale));
- }
- return locale_;
-}
-
void BrowserProcessImpl::CreateResourceDispatcherHost() {
DCHECK(!created_resource_dispatcher_host_ &&
resource_dispatcher_host_.get() == NULL);
diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h
index 3d1bbcd..f4b0e7d 100644
--- a/chrome/browser/browser_process_impl.h
+++ b/chrome/browser/browser_process_impl.h
@@ -194,7 +194,13 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe {
return google_url_tracker_.get();
}
- virtual const std::string& GetApplicationLocale();
+ virtual const std::string& GetApplicationLocale() {
+ DCHECK(!locale_.empty());
+ return locale_;
+ }
+ virtual void set_application_locale(const std::string& locale) {
+ locale_ = locale;
+ }
virtual base::WaitableEvent* shutdown_event() {
return shutdown_event_.get();
diff --git a/chrome/browser/extensions/extension_file_util.cc b/chrome/browser/extensions/extension_file_util.cc
index a1cace7..0c16ecd 100644
--- a/chrome/browser/extensions/extension_file_util.cc
+++ b/chrome/browser/extensions/extension_file_util.cc
@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "base/scoped_temp_dir.h"
#include "base/string_util.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_prefs.h"
#include "chrome/browser/privacy_blacklist/blacklist.h"
#include "chrome/browser/privacy_blacklist/blacklist_io.h"
@@ -414,9 +415,7 @@ ExtensionMessageBundle* LoadLocaleInfo(const FilePath& extension_path,
return NULL;
}
- // We can't call g_browser_process->GetApplicationLocale() since we are not
- // on the main thread.
- static std::string app_locale = l10n_util::GetApplicationLocale(L"");
+ std::string app_locale = g_browser_process->GetApplicationLocale();
if (locales.find(app_locale) == locales.end())
app_locale = "";
ExtensionMessageBundle* message_bundle =
diff --git a/chrome/browser/utility_process_host.cc b/chrome/browser/utility_process_host.cc
index 9b03634..76d24f2 100644
--- a/chrome/browser/utility_process_host.cc
+++ b/chrome/browser/utility_process_host.cc
@@ -74,9 +74,7 @@ bool UtilityProcessHost::StartProcess(const FilePath& exposed_dir) {
switches::kUtilityProcess);
cmd_line->AppendSwitchWithValue(switches::kProcessChannelID,
ASCIIToWide(channel_id()));
- // Pass on the browser locale. TODO(tony): This touches the disk and
- // checks for locale dlls/pak files. It shouldn't need to.
- std::string locale = l10n_util::GetApplicationLocale(L"");
+ std::string locale = g_browser_process->GetApplicationLocale();
cmd_line->AppendSwitchWithValue(switches::kLang, locale);
SetCrashReporterCommandLine(cmd_line);