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..841fc8886bd6c2ab1322d48f7ff2a758eac01a5e 100644 |
| --- a/chrome/browser/extensions/extension_icon_image.h |
| +++ b/chrome/browser/extensions/extension_icon_image.h |
| @@ -25,13 +25,25 @@ class Size; |
| namespace extensions { |
| -// A class that provides an ImageSkia for UI code to use. It handles extension |
| -// icon resource loading, screen scale factor change etc. UI code that uses |
| -// extension icon should host this class and be its observer. ExtensionIconImage |
| -// 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. |
| +/** |
|
Jeffrey Yasskin
2012/09/01 01:10:27
I haven't noticed this style comment elsewhere in
tbarzic
2012/09/04 21:07:09
Done.
|
| + * A class that provides an ImageSkia for UI code to use. It handles extension |
| + * icon resource loading, screen scale factor change etc. UI code that uses |
| + * extension icon should host this class and be its observer. ExtensionIconImage |
| + * 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 |
| + * already present, this class tries to load it and calls its observer interface |
| + * when the image get updated. Until the resource is loaded, the UI code will be |
| + * provided with blank, transparent image. |
| + * If the requesetd resource doesn't exist or can't be loaded and a default icon |
|
Jeffrey Yasskin
2012/09/01 01:10:27
sp: requesetd
tbarzic
2012/09/04 21:07:09
Done.
|
| + * was supplied in the constructor, icon image will be updated with the default |
| + * icon's resource. |
| + * The default icon doesn't need to be supplied, but in that case, icon image |
| + * representation will be left blank if the resource loading fails. |
| + * If default icon is supplied, it is assumed that it contains or can |
| + * syncronously create (when |GetRepresentation| is called on it) |
| + * representations for all the scale factors supported by the current platform. |
| + * Note that |IconImage| is not thread safe. |
| +**/ |
| class IconImage : public ImageLoadingTracker::Observer, |
| public content::NotificationObserver { |
| public: |
| @@ -41,10 +53,6 @@ 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. |
| - virtual void OnIconImageLoadFailed(IconImage* image, |
| - ui::ScaleFactor scale_factor) = 0; |
| - |
| protected: |
| virtual ~Observer() {} |
| }; |
| @@ -52,6 +60,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 +69,20 @@ 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); |
| + // Loads a image representation for the scale factor. |
| + // If the representation gets loaded syncronously, it is returned by this |
|
Jeffrey Yasskin
2012/09/01 01:10:27
sp: syncronously
tbarzic
2012/09/04 21:07:09
Done.
|
| + // method. |
| + // If representation loading is asynchronous, an empty image |
| + // representation is returned. When the representation gets loaded the |
| + // observer's |OnExtensionIconImageLoaded| will be called. |
| + gfx::ImageSkiaRep LoadImageForScaleFactor(ui::ScaleFactor scale_factor); |
| // ImageLoadingTracker::Observer overrides: |
| virtual void OnImageLoaded(const gfx::Image& image, |
| @@ -78,12 +97,14 @@ class IconImage : public ImageLoadingTracker::Observer, |
| const Extension* extension_; |
| const ExtensionIconSet& icon_set_; |
| const int resource_size_in_dip_; |
| - const gfx::Size desired_size_in_dip_; |
| Observer* observer_; |
| Source* source_; // Owned by ImageSkia storage. |
| gfx::ImageSkia image_skia_; |
| + // The icon with whose representation |image_skia_| should be updated if |
| + // its own representation load fails. |
| + gfx::ImageSkia default_icon_; |
| ImageLoadingTracker tracker_; |
| content::NotificationRegistrar registrar_; |