Index: ui/base/resource/resource_bundle.cc |
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc |
index 7e66615fa1b4f0490b78f17dfcd0c6c077f27776..372d3302e133c266429ea49ac449055a8ab4de87 100644 |
--- a/ui/base/resource/resource_bundle.cc |
+++ b/ui/base/resource/resource_bundle.cc |
@@ -211,9 +211,10 @@ void ResourceBundle::InitSharedInstanceWithPakFileRegion( |
base::File pak_file, |
const base::MemoryMappedFile::Region& region) { |
InitSharedInstance(NULL); |
- std::unique_ptr<DataPack> data_pack(new DataPack(SCALE_FACTOR_100P)); |
+ auto data_pack = base::MakeUnique<DataPack>(SCALE_FACTOR_100P); |
if (!data_pack->LoadFromFileRegion(std::move(pak_file), region)) { |
- NOTREACHED() << "failed to load pak file"; |
+ LOG(WARNING) << "failed to load pak file"; |
+ NOTREACHED(); |
return; |
} |
g_shared_instance_->locale_resources_data_ = std::move(data_pack); |
@@ -248,6 +249,18 @@ ResourceBundle& ResourceBundle::GetSharedInstance() { |
return *g_shared_instance_; |
} |
+void ResourceBundle::LoadSecondaryLocaleDataWithPakFileRegion( |
+ base::File pak_file, |
+ const base::MemoryMappedFile::Region& region) { |
+ auto data_pack = base::MakeUnique<DataPack>(SCALE_FACTOR_100P); |
+ if (!data_pack->LoadFromFileRegion(std::move(pak_file), region)) { |
+ LOG(WARNING) << "failed to load secondary pak file"; |
+ NOTREACHED(); |
+ return; |
+ } |
+ secondary_locale_resources_data_ = std::move(data_pack); |
+} |
+ |
#if !defined(OS_ANDROID) |
bool ResourceBundle::LocaleDataPakExists(const std::string& locale) { |
return !GetLocaleFilePath(locale, true).empty(); |
@@ -389,6 +402,7 @@ void ResourceBundle::LoadTestResources(const base::FilePath& path, |
void ResourceBundle::UnloadLocaleResources() { |
locale_resources_data_.reset(); |
+ secondary_locale_resources_data_.reset(); |
} |
void ResourceBundle::OverrideLocalePakForTest(const base::FilePath& pak_path) { |
@@ -551,20 +565,28 @@ base::string16 ResourceBundle::GetLocalizedString(int message_id) { |
} |
base::StringPiece data; |
+ ResourceHandle::TextEncodingType encoding = |
+ locale_resources_data_->GetTextEncodingType(); |
if (!locale_resources_data_->GetStringPiece(static_cast<uint16_t>(message_id), |
&data)) { |
- // Fall back on the main data pack (shouldn't be any strings here except in |
- // unittests). |
- data = GetRawDataResource(message_id); |
- if (data.empty()) { |
- NOTREACHED() << "unable to find resource: " << message_id; |
- return base::string16(); |
+ if (secondary_locale_resources_data_.get() && |
+ secondary_locale_resources_data_->GetStringPiece( |
+ static_cast<uint16_t>(message_id), &data)) { |
+ // Fall back on the secondary locale pak if it exists. |
+ encoding = secondary_locale_resources_data_->GetTextEncodingType(); |
+ } else { |
+ // Fall back on the main data pack (shouldn't be any strings here except |
+ // in unittests). |
+ data = GetRawDataResource(message_id); |
+ if (data.empty()) { |
+ LOG(WARNING) << "unable to find resource: " << message_id; |
+ NOTREACHED(); |
+ return base::string16(); |
+ } |
} |
} |
// Strings should not be loaded from a data pack that contains binary data. |
- ResourceHandle::TextEncodingType encoding = |
- locale_resources_data_->GetTextEncodingType(); |
DCHECK(encoding == ResourceHandle::UTF16 || encoding == ResourceHandle::UTF8) |
<< "requested localized string from binary pack file"; |
@@ -584,12 +606,20 @@ base::RefCountedMemory* ResourceBundle::LoadLocalizedResourceBytes( |
{ |
base::AutoLock lock_scope(*locale_resources_data_lock_); |
base::StringPiece data; |
+ |
if (locale_resources_data_.get() && |
locale_resources_data_->GetStringPiece( |
static_cast<uint16_t>(resource_id), &data) && |
!data.empty()) { |
return new base::RefCountedStaticMemory(data.data(), data.length()); |
} |
+ |
+ if (secondary_locale_resources_data_.get() && |
+ secondary_locale_resources_data_->GetStringPiece( |
+ static_cast<uint16_t>(resource_id), &data) && |
+ !data.empty()) { |
+ return new base::RefCountedStaticMemory(data.data(), data.length()); |
+ } |
} |
// Release lock_scope and fall back to main data pack. |
return LoadDataResourceBytes(resource_id); |