OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.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()); |
| 94 |
93 // Check to see if the image is already in the cache. | 95 // Check to see if the image is already in the cache. |
94 { | 96 ImageMap::iterator found = images_.find(resource_id); |
95 base::AutoLock lock(*images_and_fonts_lock_); | 97 if (found != images_.end()) { |
96 ImageMap::iterator found = images_.find(resource_id); | 98 return found->second; |
97 if (found != images_.end()) { | |
98 return found->second; | |
99 } | |
100 } | 99 } |
101 | 100 |
102 gfx::Image image; | 101 gfx::Image image; |
103 if (delegate_) | 102 if (delegate_) |
104 image = delegate_->GetNativeImageNamed(resource_id); | 103 image = delegate_->GetNativeImageNamed(resource_id); |
105 | 104 |
106 if (image.IsEmpty()) { | 105 if (image.IsEmpty()) { |
107 // Load the raw data from the resource pack at the current supported scale | 106 // Load the raw data from the resource pack at the current supported scale |
108 // factor. This code assumes that only one of the possible scale factors is | 107 // factor. This code assumes that only one of the possible scale factors is |
109 // supported at runtime, based on the device resolution. | 108 // supported at runtime, based on the device resolution. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 if (!ui_image.get()) { | 158 if (!ui_image.get()) { |
160 LOG(WARNING) << "Unable to load image with id " << resource_id; | 159 LOG(WARNING) << "Unable to load image with id " << resource_id; |
161 NOTREACHED(); // Want to assert in debug mode. | 160 NOTREACHED(); // Want to assert in debug mode. |
162 return GetEmptyImage(); | 161 return GetEmptyImage(); |
163 } | 162 } |
164 | 163 |
165 // The gfx::Image takes ownership. | 164 // The gfx::Image takes ownership. |
166 image = gfx::Image(ui_image, base::scoped_policy::RETAIN); | 165 image = gfx::Image(ui_image, base::scoped_policy::RETAIN); |
167 } | 166 } |
168 | 167 |
169 base::AutoLock lock(*images_and_fonts_lock_); | 168 DCHECK(sequence_checker_.CalledOnValidSequence()); |
170 | 169 |
171 // Another thread raced the load and has already cached the image. | 170 // Another thread raced the load and has already cached the image. |
172 if (images_.count(resource_id)) | 171 if (images_.count(resource_id)) |
173 return images_[resource_id]; | 172 return images_[resource_id]; |
174 | 173 |
175 images_[resource_id] = image; | 174 images_[resource_id] = image; |
176 return images_[resource_id]; | 175 return images_[resource_id]; |
177 } | 176 } |
178 | 177 |
179 } // namespace ui | 178 } // namespace ui |
OLD | NEW |