diff options
author | glotov@google.com <glotov@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-14 17:58:52 +0000 |
---|---|---|
committer | glotov@google.com <glotov@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-14 17:58:52 +0000 |
commit | 4549b0c7c309791cec499dc858609a07ae95a207 (patch) | |
tree | a74f5d1ec77227d1c903a6d3952e5c88ba8f7be7 /app | |
parent | 2abf2acb3ab6c5a5a1f25f8a586e4385d5f9a125 (diff) | |
download | chromium_src-4549b0c7c309791cec499dc858609a07ae95a207.zip chromium_src-4549b0c7c309791cec499dc858609a07ae95a207.tar.gz chromium_src-4549b0c7c309791cec499dc858609a07ae95a207.tar.bz2 |
ReloadSharedInstance() added to change the locale on the live system.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/1648004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44498 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/resource_bundle.cc | 14 | ||||
-rw-r--r-- | app/resource_bundle.h | 23 | ||||
-rw-r--r-- | app/resource_bundle_posix.cc | 15 | ||||
-rw-r--r-- | app/resource_bundle_win.cc | 15 |
4 files changed, 54 insertions, 13 deletions
diff --git a/app/resource_bundle.cc b/app/resource_bundle.cc index 5ca0408..a2058ec 100644 --- a/app/resource_bundle.cc +++ b/app/resource_bundle.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -38,7 +38,17 @@ std::string ResourceBundle::InitSharedInstance( DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice"; g_shared_instance_ = new ResourceBundle(); - return g_shared_instance_->LoadResources(pref_locale); + g_shared_instance_->LoadCommonResources(); + return g_shared_instance_->LoadLocaleResources(pref_locale); +} + +/* static */ +std::string ResourceBundle::ReloadSharedInstance( + const std::wstring& pref_locale) { + DCHECK(g_shared_instance_ != NULL) << "ResourceBundle not initialized"; + + g_shared_instance_->UnloadLocaleResources(); + return g_shared_instance_->LoadLocaleResources(pref_locale); } /* static */ diff --git a/app/resource_bundle.h b/app/resource_bundle.h index a76a426..2150437 100644 --- a/app/resource_bundle.h +++ b/app/resource_bundle.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -70,6 +70,14 @@ class ResourceBundle { // defined by the Cocoa UI (ie-NSBundle does the langange work). static std::string InitSharedInstance(const std::wstring& pref_locale); + // Changes the locale for an already-initialized ResourceBundle. Future + // calls to get strings will return the strings for this new locale. This + // has no effect on existing or future image resources. This has no effect + // on existing or future image resources, and thus does not use the lock to + // guarantee thread-safety, since all string access is expected to happen on + // the UI thread. + static std::string ReloadSharedInstance(const std::wstring& pref_locale); + // Delete the ResourceBundle for this process if it exists. static void CleanupSharedInstance(); @@ -172,9 +180,16 @@ class ResourceBundle { void FreeGdkPixBufs(); #endif - // Try to load the main resources and the locale specific strings from an - // external data module. Returns the locale that is loaded. - std::string LoadResources(const std::wstring& pref_locale); + // Load the main resources. + void LoadCommonResources(); + + // Try to load the locale specific strings from an external data module. + // Returns the locale that is loaded. + std::string LoadLocaleResources(const std::wstring& pref_locale); + + // Unload the locale specific strings and prepares to load new ones. See + // comments for ReloadSharedInstance(). + void UnloadLocaleResources(); // Initialize all the gfx::Font members if they haven't yet been initialized. void LoadFontsIfNecessary(); diff --git a/app/resource_bundle_posix.cc b/app/resource_bundle_posix.cc index 5b1fb3c..1246087 100644 --- a/app/resource_bundle_posix.cc +++ b/app/resource_bundle_posix.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -30,12 +30,16 @@ ResourceBundle::~ResourceBundle() { #if defined(OS_POSIX) && !defined(OS_MACOSX) FreeGdkPixBufs(); #endif - delete locale_resources_data_; - locale_resources_data_ = NULL; + UnloadLocaleResources(); delete resources_data_; resources_data_ = NULL; } +void ResourceBundle::UnloadLocaleResources() { + delete locale_resources_data_; + locale_resources_data_ = NULL; +} + // static RefCountedStaticMemory* ResourceBundle::LoadResourceBytes( DataHandle module, int resource_id) { @@ -80,13 +84,16 @@ string16 ResourceBundle::GetLocalizedString(int message_id) { return msg; } -std::string ResourceBundle::LoadResources(const std::wstring& pref_locale) { +void ResourceBundle::LoadCommonResources() { DCHECK(!resources_data_) << "chrome.pak already loaded"; FilePath resources_file_path = GetResourcesFilePath(); CHECK(!resources_file_path.empty()) << "chrome.pak not found"; resources_data_ = LoadResourcesDataPak(resources_file_path); CHECK(resources_data_) << "failed to load chrome.pak"; +} +std::string ResourceBundle::LoadLocaleResources( + const std::wstring& pref_locale) { DCHECK(!locale_resources_data_) << "locale.pak already loaded"; std::string app_locale = l10n_util::GetApplicationLocale(pref_locale); FilePath locale_file_path = GetLocaleFilePath(app_locale); diff --git a/app/resource_bundle_win.cc b/app/resource_bundle_win.cc index 72cfb38..6161e71 100644 --- a/app/resource_bundle_win.cc +++ b/app/resource_bundle_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -31,19 +31,28 @@ DWORD GetDataDllLoadFlags() { ResourceBundle::~ResourceBundle() { FreeImages(); + UnloadLocaleResources(); + resources_data_ = NULL; +} +void ResourceBundle::UnloadLocaleResources() { if (locale_resources_data_) { BOOL rv = FreeLibrary(locale_resources_data_); DCHECK(rv); + locale_resources_data_ = NULL; } } -std::string ResourceBundle::LoadResources(const std::wstring& pref_locale) { +void ResourceBundle::LoadCommonResources() { // As a convenience, set resources_data_ to the current resource module. + DCHECK(NULL == resources_data_) << "common resources already loaded"; resources_data_ = _AtlBaseModule.GetResourceInstance(); +} +std::string ResourceBundle::LoadLocaleResources( + const std::wstring& pref_locale) { DCHECK(NULL == locale_resources_data_) << "locale dll already loaded"; - std::string app_locale = l10n_util::GetApplicationLocale(pref_locale); + const 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 |