diff options
author | tbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-07 05:42:21 +0000 |
---|---|---|
committer | tbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-07 05:42:21 +0000 |
commit | 99d300519d94cc747a7deb414dd000ff7aea6354 (patch) | |
tree | f04c81667496000d12477a0029b41b9197a17699 /chrome/browser/extensions/extension_icon_image.h | |
parent | d4e8827c1e5c91d5ec30679b49e3c40e31a574dd (diff) | |
download | chromium_src-99d300519d94cc747a7deb414dd000ff7aea6354.zip chromium_src-99d300519d94cc747a7deb414dd000ff7aea6354.tar.gz chromium_src-99d300519d94cc747a7deb414dd000ff7aea6354.tar.bz2 |
Supply default icon to extension icon image.
Icon image shuld return default representation until actual image is loaded
instead of the empty representation.
Also, handle the case when image loading tracker returns synchronously.
BUG=138025
TEST=IconImageTests
Review URL: https://chromiumcodereview.appspot.com/10861034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155330 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_icon_image.h')
-rw-r--r-- | chrome/browser/extensions/extension_icon_image.h | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/chrome/browser/extensions/extension_icon_image.h b/chrome/browser/extensions/extension_icon_image.h index c2f9852..a8ee983 100644 --- a/chrome/browser/extensions/extension_icon_image.h +++ b/chrome/browser/extensions/extension_icon_image.h @@ -30,8 +30,18 @@ namespace extensions { // 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. +// 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 requested resource doesn't exist or can't be loaded and a default +// icon 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 +// synchronously 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 +51,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 +58,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 +67,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 an image representation for the scale factor. + // If the representation gets loaded synchronously, it is returned by this + // 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 +95,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_; |