Chromium Code Reviews| Index: chrome/browser/extensions/extension_icon_image.h |
| diff --git a/chrome/browser/extensions/extension_icon_image.h b/chrome/browser/extensions/extension_icon_image.h |
| index c2f98526e4224985aa7fdbe983876f76b9af956e..5c15504b7f43acd163ab9112d4c3b69eac7c8e0b 100644 |
| --- a/chrome/browser/extensions/extension_icon_image.h |
| +++ b/chrome/browser/extensions/extension_icon_image.h |
| @@ -9,6 +9,7 @@ |
| #include <string> |
| #include "base/basictypes.h" |
| +#include "base/memory/weak_ptr.h" |
| #include "chrome/browser/extensions/image_loading_tracker.h" |
| #include "chrome/common/extensions/extension_icon_set.h" |
| #include "content/public/browser/notification_observer.h" |
| @@ -31,7 +32,10 @@ namespace extensions { |
| // should be outlived by the observer. In painting code, UI code paints with the |
| // ImageSkia provided by this class. If required extension icon resource is not |
| // present, this class uses ImageLoadingTracker to load it and call on its |
| -// observer interface when the resource is loaded. |
| +// observer interface when the resource is loaded. Until the resource is loaded, |
| +// the UI code will be provided image representations from the default icon |
| +// supplied in the constructor. If no default icon is supplied, UI code must |
| +// make sure null ImageSkiaReps are handled well. |
|
pkotwicz
2012/08/22 23:17:55
An idea: Can we have a default 'default icon' whic
tbarzic
2012/08/22 23:46:08
Yeah, I had the same idea (just about to upload th
|
| class IconImage : public ImageLoadingTracker::Observer, |
| public content::NotificationObserver { |
| public: |
| @@ -41,7 +45,8 @@ class IconImage : public ImageLoadingTracker::Observer, |
| // is loaded and added to |image|. |
| virtual void OnExtensionIconImageChanged(IconImage* image) = 0; |
| - // Invoked when the icon image couldn't be loaded. |
| + // Invoked when the icon image couldn't be loaded. This will always be |
| + // called asynchronously. |
| virtual void OnIconImageLoadFailed(IconImage* image, |
| ui::ScaleFactor scale_factor) = 0; |
| @@ -52,6 +57,7 @@ class IconImage : public ImageLoadingTracker::Observer, |
| IconImage(const Extension* extension, |
| const ExtensionIconSet& icon_set, |
| int resource_size_in_dip, |
| + const gfx::ImageSkia& default_icon, |
| Observer* observer); |
| virtual ~IconImage(); |
| @@ -60,10 +66,15 @@ class IconImage : public ImageLoadingTracker::Observer, |
| private: |
| class Source; |
| - typedef std::map<int, ui::ScaleFactor> LoadMap; |
| + struct LoadRequest { |
| + ui::ScaleFactor scale_factor; |
| + bool is_async; |
| + }; |
| + |
| + typedef std::map<int, LoadRequest> LoadMap; |
| // Loads bitmap for additional scale factor. |
| - void LoadImageForScaleFactor(ui::ScaleFactor scale_factor); |
| + gfx::ImageSkiaRep LoadImageForScaleFactor(ui::ScaleFactor scale_factor); |
| // ImageLoadingTracker::Observer overrides: |
| virtual void OnImageLoaded(const gfx::Image& image, |
| @@ -75,6 +86,8 @@ class IconImage : public ImageLoadingTracker::Observer, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) OVERRIDE; |
| + void NotifyFail(ui::ScaleFactor scale_factor); |
| + |
| const Extension* extension_; |
| const ExtensionIconSet& icon_set_; |
| const int resource_size_in_dip_; |
| @@ -88,6 +101,8 @@ class IconImage : public ImageLoadingTracker::Observer, |
| ImageLoadingTracker tracker_; |
| content::NotificationRegistrar registrar_; |
| + base::WeakPtrFactory<IconImage> weak_ptr_factory_; |
| + |
| LoadMap load_map_; |
| DISALLOW_COPY_AND_ASSIGN(IconImage); |