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

Unified Diff: ui/base/resource/resource_bundle_mac.mm

Issue 6849030: Add support for multi resolution icons (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: ui/base/resource/resource_bundle_mac.mm
diff --git a/ui/base/resource/resource_bundle_mac.mm b/ui/base/resource/resource_bundle_mac.mm
index 1a238a72c08d230a14f6863ce180027f2fd76086..3e04df9cd5b5a9f1022f7a5c2cfcb8768ddc2838 100644
--- a/ui/base/resource/resource_bundle_mac.mm
+++ b/ui/base/resource/resource_bundle_mac.mm
@@ -62,19 +62,9 @@ FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale) {
gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) {
// Check to see if the image is already in the cache.
- {
- base::AutoLock lock(*lock_);
- ImageMap::const_iterator found = images_.find(resource_id);
- if (found != images_.end()) {
- if (!found->second->HasRepresentation(gfx::Image::kNSImageRep)) {
- DLOG(WARNING) << "ResourceBundle::GetNativeImageNamed() is returning a"
- << " cached gfx::Image that isn't backed by an NSImage. The image"
- << " will be converted, rather than going through the NSImage loader."
- << " resource_id = " << resource_id;
- }
- return *found->second;
- }
- }
+ std::vector<gfx::Image*> images;
+ if (GetImagesFromCacheNamed(resource_id, images) && !images.empty())
+ return **images.begin();
// Load the raw data from the resource pack.
scoped_refptr<RefCountedStaticMemory> data(
@@ -89,16 +79,21 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) {
// Cache the converted image.
if (ns_image.get()) {
- base::AutoLock lock(*lock_);
-
- // Another thread raced the load and has already cached the image.
- if (images_.count(resource_id)) {
- return *images_[resource_id];
+ {
+ base::AutoLock lock(*lock_);
+
+ // Has another thread raced the load and has already cached the image?
+ if (!images_.count(resource_id)) {
+ gfx::Image* image = new gfx::Image(ns_image.release());
+ std::vector<gfx::Image*>* images_ptr = new std::vector<gfx::Image*>;
+ images_ptr->push_back(image);
+ images_[resource_id] = images_ptr;
+ return *image;
+ }
}
- gfx::Image* image = new gfx::Image(ns_image.release());
- images_[resource_id] = image;
- return *image;
+ if (GetImagesFromCacheNamed(resource_id, images) && !images.empty())
+ return **images.begin();
}
LOG(WARNING) << "Unable to load image with id " << resource_id;

Powered by Google App Engine
This is Rietveld 408576698