OLD | NEW |
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 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 if (locale_file_path.empty() || !locale_file_path.IsAbsolute()) | 83 if (locale_file_path.empty() || !locale_file_path.IsAbsolute()) |
84 return base::FilePath(); | 84 return base::FilePath(); |
85 | 85 |
86 if (test_file_exists && !base::PathExists(locale_file_path)) | 86 if (test_file_exists && !base::PathExists(locale_file_path)) |
87 return base::FilePath(); | 87 return base::FilePath(); |
88 | 88 |
89 return locale_file_path; | 89 return locale_file_path; |
90 } | 90 } |
91 | 91 |
92 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) { | 92 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) { |
| 93 DCHECK(sequence_checker_.CalledOnValidSequence()); |
93 // Check to see if the image is already in the cache. | 94 // Check to see if the image is already in the cache. |
94 { | 95 auto found = images_.find(resource_id); |
95 base::AutoLock lock(*images_and_fonts_lock_); | 96 if (found != images_.end()) { |
96 if (images_.count(resource_id)) { | 97 if (!found->second.HasRepresentation(gfx::Image::kImageRepCocoa)) { |
97 if (!images_[resource_id].HasRepresentation(gfx::Image::kImageRepCocoa)) { | 98 DLOG(WARNING) |
98 DLOG(WARNING) << "ResourceBundle::GetNativeImageNamed() is returning a" | 99 << "ResourceBundle::GetNativeImageNamed() is returning a" |
99 << " cached gfx::Image that isn't backed by an NSImage. The image" | 100 << " cached gfx::Image that isn't backed by an NSImage. The image" |
100 << " will be converted, rather than going through the NSImage loader." | 101 << " will be converted, rather than going through the NSImage loader." |
101 << " resource_id = " << resource_id; | 102 << " resource_id = " << resource_id; |
102 } | |
103 return images_[resource_id]; | |
104 } | 103 } |
| 104 return found->second; |
105 } | 105 } |
106 | 106 |
107 gfx::Image image; | 107 gfx::Image image; |
108 if (delegate_) | 108 if (delegate_) |
109 image = delegate_->GetNativeImageNamed(resource_id); | 109 image = delegate_->GetNativeImageNamed(resource_id); |
110 | 110 |
111 if (image.IsEmpty()) { | 111 if (image.IsEmpty()) { |
112 base::scoped_nsobject<NSImage> ns_image; | 112 base::scoped_nsobject<NSImage> ns_image; |
113 for (size_t i = 0; i < data_packs_.size(); ++i) { | 113 for (size_t i = 0; i < data_packs_.size(); ++i) { |
114 scoped_refptr<base::RefCountedStaticMemory> data( | 114 scoped_refptr<base::RefCountedStaticMemory> data( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 153 |
154 if (!ns_image.get()) { | 154 if (!ns_image.get()) { |
155 LOG(WARNING) << "Unable to load image with id " << resource_id; | 155 LOG(WARNING) << "Unable to load image with id " << resource_id; |
156 NOTREACHED(); // Want to assert in debug mode. | 156 NOTREACHED(); // Want to assert in debug mode. |
157 return GetEmptyImage(); | 157 return GetEmptyImage(); |
158 } | 158 } |
159 | 159 |
160 image = gfx::Image(ns_image.release()); | 160 image = gfx::Image(ns_image.release()); |
161 } | 161 } |
162 | 162 |
163 base::AutoLock lock(*images_and_fonts_lock_); | 163 DCHECK(sequence_checker_.CalledOnValidSequence()); |
164 | 164 |
165 // Another thread raced the load and has already cached the image. | 165 // Another thread raced the load and has already cached the image. |
166 if (images_.count(resource_id)) | 166 if (images_.count(resource_id)) |
167 return images_[resource_id]; | 167 return images_[resource_id]; |
168 | 168 |
169 images_[resource_id] = image; | 169 images_[resource_id] = image; |
170 return images_[resource_id]; | 170 return images_[resource_id]; |
171 } | 171 } |
172 | 172 |
173 } // namespace ui | 173 } // namespace ui |
OLD | NEW |