| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // Check to see if the image is already in the cache. | 112 // Check to see if the image is already in the cache. |
| 113 { | 113 { |
| 114 base::AutoLock lock_scope(*lock_); | 114 base::AutoLock lock_scope(*lock_); |
| 115 ImageMap::const_iterator found = images_.find(resource_id); | 115 ImageMap::const_iterator found = images_.find(resource_id); |
| 116 if (found != images_.end()) | 116 if (found != images_.end()) |
| 117 return *found->second; | 117 return *found->second; |
| 118 } | 118 } |
| 119 | 119 |
| 120 scoped_ptr<SkBitmap> bitmap(LoadBitmap(resources_data_, resource_id)); | 120 scoped_ptr<SkBitmap> bitmap(LoadBitmap(resources_data_, resource_id)); |
| 121 if (bitmap.get()) { | 121 if (bitmap.get()) { |
| 122 // Check if there's a large version of the image as well. |
| 123 scoped_ptr<SkBitmap> large_bitmap(LoadBitmap( |
| 124 large_icon_resources_data_, resource_id)); |
| 125 |
| 122 // The load was successful, so cache the image. | 126 // The load was successful, so cache the image. |
| 123 base::AutoLock lock_scope(*lock_); | 127 base::AutoLock lock_scope(*lock_); |
| 124 | 128 |
| 125 // Another thread raced the load and has already cached the image. | 129 // Another thread raced the load and has already cached the image. |
| 126 if (images_.count(resource_id)) | 130 if (images_.count(resource_id)) |
| 127 return *images_[resource_id]; | 131 return *images_[resource_id]; |
| 128 | 132 |
| 129 gfx::Image* image = new gfx::Image(bitmap.release()); | 133 std::vector<const SkBitmap*> bitmaps; |
| 134 bitmaps.push_back(bitmap.release()); |
| 135 if (large_bitmap.get()) |
| 136 bitmaps.push_back(large_bitmap.release()); |
| 137 gfx::Image* image = new gfx::Image(bitmaps); |
| 130 images_[resource_id] = image; | 138 images_[resource_id] = image; |
| 131 return *image; | 139 return *image; |
| 132 } | 140 } |
| 133 | 141 |
| 134 // The load failed to retrieve the image; show a debugging red square. | 142 // The load failed to retrieve the image; show a debugging red square. |
| 135 LOG(WARNING) << "Unable to load image with id " << resource_id; | 143 LOG(WARNING) << "Unable to load image with id " << resource_id; |
| 136 NOTREACHED(); // Want to assert in debug mode. | 144 NOTREACHED(); // Want to assert in debug mode. |
| 137 return *GetEmptyImage(); | 145 return *GetEmptyImage(); |
| 138 } | 146 } |
| 139 | 147 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 int resource_id, base::StringPiece* data) const { | 288 int resource_id, base::StringPiece* data) const { |
| 281 return data_pack_->GetStringPiece(static_cast<uint32>(resource_id), data); | 289 return data_pack_->GetStringPiece(static_cast<uint32>(resource_id), data); |
| 282 } | 290 } |
| 283 | 291 |
| 284 RefCountedStaticMemory* ResourceBundle::LoadedDataPack::GetStaticMemory( | 292 RefCountedStaticMemory* ResourceBundle::LoadedDataPack::GetStaticMemory( |
| 285 int resource_id) const { | 293 int resource_id) const { |
| 286 return data_pack_->GetStaticMemory(resource_id); | 294 return data_pack_->GetStaticMemory(resource_id); |
| 287 } | 295 } |
| 288 | 296 |
| 289 } // namespace ui | 297 } // namespace ui |
| OLD | NEW |