Chromium Code Reviews| 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 // TODO(oshima) | |
| 229 // A better approach might be to set the |image_| member using the ImageSkia | |
| 230 // copy from the image passed in and set the |image_skia_| member using | |
| 231 // image_.ToImageSkia(). However that does not work correctly as the | |
| 232 // ImageSkia from the image does not contain a source which breaks requests | |
| 233 // for scaled images. | |
| 234 image_skia_ = gfx::ImageSkia(); | |
|
pkotwicz
2015/03/24 21:43:08
Drive by: Why don't you use the ImageSkia construc
ananta
2015/03/24 21:50:38
Please take a peek at the updated patch. We cannot
| |
| 235 | |
| 228 image_skia_.AddRepresentation(rep); | 236 image_skia_.AddRepresentation(rep); |
| 229 | 237 |
| 230 // Update the image to use the updated image skia. | 238 // 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 | 239 // 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 | 240 // representations stored on |image_| will be deleted, but unfortunately |
| 233 // there's no way to combine the storage of two images. | 241 // there's no way to combine the storage of two images. |
| 234 image_ = gfx::Image(image_skia_); | 242 image_ = gfx::Image(image_skia_); |
| 235 | 243 |
| 236 FOR_EACH_OBSERVER(Observer, observers_, OnExtensionIconImageChanged(this)); | 244 FOR_EACH_OBSERVER(Observer, observers_, OnExtensionIconImageChanged(this)); |
| 237 } | 245 } |
| 238 | 246 |
| 239 void IconImage::Observe(int type, | 247 void IconImage::Observe(int type, |
| 240 const content::NotificationSource& source, | 248 const content::NotificationSource& source, |
| 241 const content::NotificationDetails& details) { | 249 const content::NotificationDetails& details) { |
| 242 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_REMOVED); | 250 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_REMOVED); |
| 243 | 251 |
| 244 const Extension* extension = content::Details<const Extension>(details).ptr(); | 252 const Extension* extension = content::Details<const Extension>(details).ptr(); |
| 245 | 253 |
| 246 if (extension_ == extension) | 254 if (extension_ == extension) |
| 247 extension_ = NULL; | 255 extension_ = NULL; |
| 248 } | 256 } |
| 249 | 257 |
| 250 } // namespace extensions | 258 } // namespace extensions |
| OLD | NEW |