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

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: Created 6 years, 6 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::OverrideStringResource(
315 int message_id, const base::string16& overridding_string) {
grt (UTC plus 2) 2014/06/11 01:51:18 did "git cl format" do this wrapping? if not, i be
grt (UTC plus 2) 2014/06/11 01:51:18 overridding_string -> string to match the declarat
jwd 2014/07/03 17:41:31 Done.
jwd 2014/07/03 17:41:31 Done.
316 overridden_strings_[message_id] = overridding_string;
317 }
318
314 const base::FilePath& ResourceBundle::GetOverriddenPakPath() { 319 const base::FilePath& ResourceBundle::GetOverriddenPakPath() {
315 return overridden_pak_path_; 320 return overridden_pak_path_;
316 } 321 }
317 322
318 std::string ResourceBundle::ReloadLocaleResources( 323 std::string ResourceBundle::ReloadLocaleResources(
319 const std::string& pref_locale) { 324 const std::string& pref_locale) {
320 base::AutoLock lock_scope(*locale_resources_data_lock_); 325 base::AutoLock lock_scope(*locale_resources_data_lock_);
321 UnloadLocaleResources(); 326 UnloadLocaleResources();
322 return LoadLocaleResources(pref_locale); 327 return LoadLocaleResources(pref_locale);
323 } 328 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 } 437 }
433 438
434 return base::StringPiece(); 439 return base::StringPiece();
435 } 440 }
436 441
437 base::string16 ResourceBundle::GetLocalizedString(int message_id) { 442 base::string16 ResourceBundle::GetLocalizedString(int message_id) {
438 base::string16 string; 443 base::string16 string;
439 if (delegate_ && delegate_->GetLocalizedString(message_id, &string)) 444 if (delegate_ && delegate_->GetLocalizedString(message_id, &string))
440 return string; 445 return string;
441 446
447 IdToStringMap::const_iterator it = overridden_strings_.find(message_id);
448 if (it != overridden_strings_.end())
449 return it->second;
450
442 // Ensure that ReloadLocaleResources() doesn't drop the resources while 451 // Ensure that ReloadLocaleResources() doesn't drop the resources while
443 // we're using them. 452 // we're using them.
444 base::AutoLock lock_scope(*locale_resources_data_lock_); 453 base::AutoLock lock_scope(*locale_resources_data_lock_);
445 454
446 // If for some reason we were unable to load the resources , return an empty 455 // If for some reason we were unable to load the resources , return an empty
447 // string (better than crashing). 456 // string (better than crashing).
448 if (!locale_resources_data_.get()) { 457 if (!locale_resources_data_.get()) {
449 LOG(WARNING) << "locale resources are not loaded"; 458 LOG(WARNING) << "locale resources are not loaded";
450 return base::string16(); 459 return base::string16();
451 } 460 }
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 // static 804 // static
796 bool ResourceBundle::DecodePNG(const unsigned char* buf, 805 bool ResourceBundle::DecodePNG(const unsigned char* buf,
797 size_t size, 806 size_t size,
798 SkBitmap* bitmap, 807 SkBitmap* bitmap,
799 bool* fell_back_to_1x) { 808 bool* fell_back_to_1x) {
800 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); 809 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size);
801 return gfx::PNGCodec::Decode(buf, size, bitmap); 810 return gfx::PNGCodec::Decode(buf, size, bitmap);
802 } 811 }
803 812
804 } // namespace ui 813 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698