OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/extension_icon_image.h" | 5 #include "extensions/browser/extension_icon_image.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 image_in.IsEmpty() ? &default_icon_ : image_in.ToImageSkia(); | 216 image_in.IsEmpty() ? &default_icon_ : image_in.ToImageSkia(); |
217 | 217 |
218 // Maybe default icon was not set. | 218 // Maybe default icon was not set. |
219 if (image->isNull()) | 219 if (image->isNull()) |
220 return; | 220 return; |
221 | 221 |
222 gfx::ImageSkiaRep rep = image->GetRepresentation(scale); | 222 gfx::ImageSkiaRep rep = image->GetRepresentation(scale); |
223 DCHECK(!rep.is_null()); | 223 DCHECK(!rep.is_null()); |
224 DCHECK_EQ(scale, rep.scale()); | 224 DCHECK_EQ(scale, rep.scale()); |
225 | 225 |
226 // Remove old representation if there is one. | 226 // Remove all old representations. This will ensure that stale image caches |
227 image_skia_.RemoveRepresentation(scale); | 227 // are invalidated. |
228 // A better approach might be to set the |image_| member using the ImageSkia | |
oshima
2015/03/24 01:19:05
can you add TODO(oshima): here?
ananta
2015/03/24 02:12:23
Done.
| |
229 // copy from the image passed in and set the |image_skia_| member using | |
230 // image_.ToImageSkia(). However that does not work correctly as the | |
231 // ImageSkia from the image does not contain a source which breaks requests | |
232 // for scaled images. | |
233 std::vector<gfx::ImageSkiaRep> reps = image_skia_.image_reps(); | |
234 for (size_t rep_index = 0; rep_index < reps.size(); ++rep_index) { | |
oshima
2015/03/24 01:19:05
range based for-loop, and nuke {}
ananta
2015/03/24 02:12:23
Removed the loop and replaced with image_skia_ = g
| |
235 image_skia_.RemoveRepresentation(reps[rep_index].scale()); | |
236 } | |
oshima
2015/03/24 01:22:22
actually, you should be able to do:
image_skia_ =
ananta
2015/03/24 02:12:23
Done.
| |
237 | |
228 image_skia_.AddRepresentation(rep); | 238 image_skia_.AddRepresentation(rep); |
229 | 239 |
230 // Update the image to use the updated image skia. | 240 // Update the image to use the updated image skia. |
231 // It's a shame we have to do this because it means that all the other | 241 // It's a shame we have to do this because it means that all the other |
232 // representations stored on |image_| will be deleted, but unfortunately | 242 // representations stored on |image_| will be deleted, but unfortunately |
233 // there's no way to combine the storage of two images. | 243 // there's no way to combine the storage of two images. |
234 image_ = gfx::Image(image_skia_); | 244 image_ = gfx::Image(image_skia_); |
235 | 245 |
236 FOR_EACH_OBSERVER(Observer, observers_, OnExtensionIconImageChanged(this)); | 246 FOR_EACH_OBSERVER(Observer, observers_, OnExtensionIconImageChanged(this)); |
237 } | 247 } |
238 | 248 |
239 void IconImage::Observe(int type, | 249 void IconImage::Observe(int type, |
240 const content::NotificationSource& source, | 250 const content::NotificationSource& source, |
241 const content::NotificationDetails& details) { | 251 const content::NotificationDetails& details) { |
242 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_REMOVED); | 252 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_REMOVED); |
243 | 253 |
244 const Extension* extension = content::Details<const Extension>(details).ptr(); | 254 const Extension* extension = content::Details<const Extension>(details).ptr(); |
245 | 255 |
246 if (extension_ == extension) | 256 if (extension_ == extension) |
247 extension_ = NULL; | 257 extension_ = NULL; |
248 } | 258 } |
249 | 259 |
250 } // namespace extensions | 260 } // namespace extensions |
OLD | NEW |