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 if (images_.count(resource_id)) { |
sky
2017/02/21 18:01:05
Use an iterator to avoid the repeated access? e.g.
tzik
2017/02/22 07:19:21
Done.
| |
95 base::AutoLock lock(*images_and_fonts_lock_); | 96 if (!images_[resource_id].HasRepresentation(gfx::Image::kImageRepCocoa)) { |
96 if (images_.count(resource_id)) { | 97 DLOG(WARNING) |
97 if (!images_[resource_id].HasRepresentation(gfx::Image::kImageRepCocoa)) { | 98 << "ResourceBundle::GetNativeImageNamed() is returning a" |
98 DLOG(WARNING) << "ResourceBundle::GetNativeImageNamed() is returning a" | |
99 << " cached gfx::Image that isn't backed by an NSImage. The image" | 99 << " cached gfx::Image that isn't backed by an NSImage. The image" |
100 << " will be converted, rather than going through the NSImage loader." | 100 << " will be converted, rather than going through the NSImage loader." |
101 << " resource_id = " << resource_id; | 101 << " resource_id = " << resource_id; |
102 } | |
103 return images_[resource_id]; | |
104 } | 102 } |
103 return images_[resource_id]; | |
105 } | 104 } |
106 | 105 |
107 gfx::Image image; | 106 gfx::Image image; |
108 if (delegate_) | 107 if (delegate_) |
109 image = delegate_->GetNativeImageNamed(resource_id); | 108 image = delegate_->GetNativeImageNamed(resource_id); |
110 | 109 |
111 if (image.IsEmpty()) { | 110 if (image.IsEmpty()) { |
112 base::scoped_nsobject<NSImage> ns_image; | 111 base::scoped_nsobject<NSImage> ns_image; |
113 for (size_t i = 0; i < data_packs_.size(); ++i) { | 112 for (size_t i = 0; i < data_packs_.size(); ++i) { |
114 scoped_refptr<base::RefCountedStaticMemory> data( | 113 scoped_refptr<base::RefCountedStaticMemory> data( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 | 152 |
154 if (!ns_image.get()) { | 153 if (!ns_image.get()) { |
155 LOG(WARNING) << "Unable to load image with id " << resource_id; | 154 LOG(WARNING) << "Unable to load image with id " << resource_id; |
156 NOTREACHED(); // Want to assert in debug mode. | 155 NOTREACHED(); // Want to assert in debug mode. |
157 return GetEmptyImage(); | 156 return GetEmptyImage(); |
158 } | 157 } |
159 | 158 |
160 image = gfx::Image(ns_image.release()); | 159 image = gfx::Image(ns_image.release()); |
161 } | 160 } |
162 | 161 |
163 base::AutoLock lock(*images_and_fonts_lock_); | 162 DCHECK(sequence_checker_.CalledOnValidSequence()); |
164 | 163 |
165 // Another thread raced the load and has already cached the image. | 164 // Another thread raced the load and has already cached the image. |
166 if (images_.count(resource_id)) | 165 if (images_.count(resource_id)) |
167 return images_[resource_id]; | 166 return images_[resource_id]; |
168 | 167 |
169 images_[resource_id] = image; | 168 images_[resource_id] = image; |
170 return images_[resource_id]; | 169 return images_[resource_id]; |
171 } | 170 } |
172 | 171 |
173 } // namespace ui | 172 } // namespace ui |
OLD | NEW |