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

Side by Side Diff: ui/base/resource/resource_bundle.cc

Issue 322523002: Adding OverrideStringResource API to ResourceBundle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Threading and reset Created 6 years, 5 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/base/resource/resource_bundle.h" 5 #include "ui/base/resource/resource_bundle.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/big_endian.h" 9 #include "base/big_endian.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 304 }
305 305
306 void ResourceBundle::UnloadLocaleResources() { 306 void ResourceBundle::UnloadLocaleResources() {
307 locale_resources_data_.reset(); 307 locale_resources_data_.reset();
308 } 308 }
309 309
310 void ResourceBundle::OverrideLocalePakForTest(const base::FilePath& pak_path) { 310 void ResourceBundle::OverrideLocalePakForTest(const base::FilePath& pak_path) {
311 overridden_pak_path_ = pak_path; 311 overridden_pak_path_ = pak_path;
312 } 312 }
313 313
314 void ResourceBundle::OverrideLocaleStringResource(
315 int message_id,
316 const base::string16& string) {
317 overridden_locale_strings_[message_id] = string;
318 }
319
314 const base::FilePath& ResourceBundle::GetOverriddenPakPath() { 320 const base::FilePath& ResourceBundle::GetOverriddenPakPath() {
315 return overridden_pak_path_; 321 return overridden_pak_path_;
316 } 322 }
317 323
318 std::string ResourceBundle::ReloadLocaleResources( 324 std::string ResourceBundle::ReloadLocaleResources(
319 const std::string& pref_locale) { 325 const std::string& pref_locale) {
320 base::AutoLock lock_scope(*locale_resources_data_lock_); 326 base::AutoLock lock_scope(*locale_resources_data_lock_);
327
328 // Remove all overriden strings, as they will not be valid for the new locale.
329 overridden_locale_strings_.clear();
330
321 UnloadLocaleResources(); 331 UnloadLocaleResources();
322 return LoadLocaleResources(pref_locale); 332 return LoadLocaleResources(pref_locale);
323 } 333 }
324 334
325 gfx::ImageSkia* ResourceBundle::GetImageSkiaNamed(int resource_id) { 335 gfx::ImageSkia* ResourceBundle::GetImageSkiaNamed(int resource_id) {
326 const gfx::ImageSkia* image = GetImageNamed(resource_id).ToImageSkia(); 336 const gfx::ImageSkia* image = GetImageNamed(resource_id).ToImageSkia();
327 return const_cast<gfx::ImageSkia*>(image); 337 return const_cast<gfx::ImageSkia*>(image);
328 } 338 }
329 339
330 gfx::Image& ResourceBundle::GetImageNamed(int resource_id) { 340 gfx::Image& ResourceBundle::GetImageNamed(int resource_id) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 446
437 base::string16 ResourceBundle::GetLocalizedString(int message_id) { 447 base::string16 ResourceBundle::GetLocalizedString(int message_id) {
438 base::string16 string; 448 base::string16 string;
439 if (delegate_ && delegate_->GetLocalizedString(message_id, &string)) 449 if (delegate_ && delegate_->GetLocalizedString(message_id, &string))
440 return string; 450 return string;
441 451
442 // Ensure that ReloadLocaleResources() doesn't drop the resources while 452 // Ensure that ReloadLocaleResources() doesn't drop the resources while
443 // we're using them. 453 // we're using them.
444 base::AutoLock lock_scope(*locale_resources_data_lock_); 454 base::AutoLock lock_scope(*locale_resources_data_lock_);
445 455
456 IdToStringMap::const_iterator it =
457 overridden_locale_strings_.find(message_id);
458 if (it != overridden_locale_strings_.end())
459 return it->second;
460
446 // If for some reason we were unable to load the resources , return an empty 461 // If for some reason we were unable to load the resources , return an empty
447 // string (better than crashing). 462 // string (better than crashing).
448 if (!locale_resources_data_.get()) { 463 if (!locale_resources_data_.get()) {
449 LOG(WARNING) << "locale resources are not loaded"; 464 LOG(WARNING) << "locale resources are not loaded";
450 return base::string16(); 465 return base::string16();
451 } 466 }
452 467
453 base::StringPiece data; 468 base::StringPiece data;
454 if (!locale_resources_data_->GetStringPiece(message_id, &data)) { 469 if (!locale_resources_data_->GetStringPiece(message_id, &data)) {
455 // Fall back on the main data pack (shouldn't be any strings here except in 470 // Fall back on the main data pack (shouldn't be any strings here except in
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 // static 810 // static
796 bool ResourceBundle::DecodePNG(const unsigned char* buf, 811 bool ResourceBundle::DecodePNG(const unsigned char* buf,
797 size_t size, 812 size_t size,
798 SkBitmap* bitmap, 813 SkBitmap* bitmap,
799 bool* fell_back_to_1x) { 814 bool* fell_back_to_1x) {
800 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); 815 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size);
801 return gfx::PNGCodec::Decode(buf, size, bitmap); 816 return gfx::PNGCodec::Decode(buf, size, bitmap);
802 } 817 }
803 818
804 } // namespace ui 819 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698