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

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) {
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 if (overridden_strings_.find(message_id) != overridden_strings_.end())
grt (UTC plus 2) 2014/06/09 16:54:44 avoid doing two O(logN) scans when there's a hit w
jwd 2014/06/10 20:59:25 Done.
448 return overridden_strings_[message_id];
449
442 // Ensure that ReloadLocaleResources() doesn't drop the resources while 450 // Ensure that ReloadLocaleResources() doesn't drop the resources while
443 // we're using them. 451 // we're using them.
444 base::AutoLock lock_scope(*locale_resources_data_lock_); 452 base::AutoLock lock_scope(*locale_resources_data_lock_);
445 453
446 // If for some reason we were unable to load the resources , return an empty 454 // If for some reason we were unable to load the resources , return an empty
447 // string (better than crashing). 455 // string (better than crashing).
448 if (!locale_resources_data_.get()) { 456 if (!locale_resources_data_.get()) {
449 LOG(WARNING) << "locale resources are not loaded"; 457 LOG(WARNING) << "locale resources are not loaded";
450 return base::string16(); 458 return base::string16();
451 } 459 }
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 // static 803 // static
796 bool ResourceBundle::DecodePNG(const unsigned char* buf, 804 bool ResourceBundle::DecodePNG(const unsigned char* buf,
797 size_t size, 805 size_t size,
798 SkBitmap* bitmap, 806 SkBitmap* bitmap,
799 bool* fell_back_to_1x) { 807 bool* fell_back_to_1x) {
800 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); 808 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size);
801 return gfx::PNGCodec::Decode(buf, size, bitmap); 809 return gfx::PNGCodec::Decode(buf, size, bitmap);
802 } 810 }
803 811
804 } // namespace ui 812 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698