Chromium Code Reviews| Index: chrome/browser/extensions/image_loading_tracker.h |
| diff --git a/chrome/browser/extensions/image_loading_tracker.h b/chrome/browser/extensions/image_loading_tracker.h |
| index b163651e9a551d4ae3b53533f4596a181d350ea6..a47c47512b0500d0d5a30aa1e887262744bcc4b8 100644 |
| --- a/chrome/browser/extensions/image_loading_tracker.h |
| +++ b/chrome/browser/extensions/image_loading_tracker.h |
| @@ -6,13 +6,18 @@ |
| #define CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ |
| #include <map> |
| +#include <string> |
| +#include <vector> |
| #include "base/compiler_specific.h" |
| #include "base/gtest_prod_util.h" |
| #include "base/memory/ref_counted.h" |
| +#include "chrome/common/extensions/extension_icon_set.h" |
| #include "chrome/common/extensions/extension_resource.h" |
| #include "content/public/browser/notification_observer.h" |
| #include "content/public/browser/notification_registrar.h" |
| +#include "ui/base/layout.h" |
| +#include "ui/gfx/image/image_skia.h" |
| #include "ui/gfx/size.h" |
| class SkBitmap; |
| @@ -35,7 +40,16 @@ class Image; |
| // Observer::OnImageLoaded and call: |
| // tracker_.LoadImage(extension, resource, max_size, false); |
| // ... and wait for OnImageLoaded to be called back on you with a pointer to the |
| -// SkBitmap loaded. |
| +// ImageSkia loaded. |
| +// |
| +// To supports DIP, the returned ImageSkia has all representations for scale |
| +// factors in use when LoadImage is called. And if you care about DIP change |
| +// after that, you need to keep this class around. And when screen scale factor |
| +// is change and ImageSkia requests a representation for the new scale factor, |
|
oshima
2012/07/16 17:22:33
"and Image" (space)
xiyuan
2012/07/16 20:11:28
Done.
|
| +// ImageLoadingTracker::ImageSource would get the request, finds a relevant |
| +// extension resource and loads it. After the new resource is loaded, |
| +// ImageLoadingTracker::Observer would be notified again with updated image. |
| +// |
| // NOTE: if the image is available already (or the resource is not valid), the |
| // Observer is notified immediately from the call to LoadImage. In other words, |
| // by the time LoadImage returns the observer has been notified. |
| @@ -64,12 +78,17 @@ class ImageLoadingTracker : public content::NotificationObserver { |
| // Information about a single image to load from a extension resource. |
|
pkotwicz
2012/07/16 17:33:52
image->bitmap/image rep
xiyuan
2012/07/16 20:11:28
Done.
|
| struct ImageInfo { |
| - ImageInfo(const ExtensionResource& resource, gfx::Size max_size); |
| + ImageInfo(const ExtensionResource& resource, |
| + const gfx::Size& max_size, |
| + ui::ScaleFactor scale_factor); |
| ~ImageInfo(); |
| + |
| ExtensionResource resource; |
| // If the loaded image is larger than |max_size| it will be resized to those |
| // dimensions. |
| gfx::Size max_size; |
| + // |scale_factor| is used to construct loaded gfx::ImageSkia. |
| + ui::ScaleFactor scale_factor; |
| }; |
| explicit ImageLoadingTracker(Observer* observer); |
| @@ -84,6 +103,14 @@ class ImageLoadingTracker : public content::NotificationObserver { |
| const gfx::Size& max_size, |
| CacheParam cache); |
| + // Similar to LoadImage above but loads an ImageSkia that supports DIP. |
| + // |resource_size| and |max_size| are in DIP coordinates. |
| + void LoadImageInDIP(const extensions::Extension* extension, |
|
pkotwicz
2012/07/16 17:33:52
Can you call this simply "LoadImageSkia"?
xiyuan
2012/07/16 20:11:28
Done.
|
| + int resource_size, |
| + ExtensionIconSet::MatchType resource_match_type, |
| + const gfx::Size& max_size, |
| + CacheParam cache); |
| + |
| // Same as LoadImage() above except it loads multiple images from the same |
| // extension. This is used to load multiple resolutions of the same image |
| // type. |
| @@ -97,24 +124,42 @@ class ImageLoadingTracker : public content::NotificationObserver { |
| int next_id() const { return next_id_; } |
| private: |
| + class ImageLoader; |
| + class ImageSource; |
| + |
| // Information for pending image load operation for one or more images. |
| struct PendingLoadInfo { |
| PendingLoadInfo(); |
| ~PendingLoadInfo(); |
| const extensions::Extension* extension; |
| - // This is cached separate from |extension| in case the extension in |
| + // This is cached separate from |extension| in case the extension is |
| // unloaded. |
| std::string extension_id; |
| + |
| + // Size info from a LoadImage call. |
| + int resource_size_in_dip; |
| + ExtensionIconSet::MatchType resource_match_type; |
| + gfx::Size max_size_in_dip; |
| + |
| + // ImageSource loads image for additional scale factor. This is only set if |
| + // above size info is valid. |
| + ImageSource* image_source; // Owned by ImageSkiaStorage. |
| + |
| CacheParam cache; |
| size_t pending_count; |
| - std::vector<SkBitmap> bitmaps; |
| + |
| + gfx::ImageSkia images; |
|
pkotwicz
2012/07/16 17:33:52
Can you call this variable image_skia? I think it
xiyuan
2012/07/16 20:11:28
Done.
|
| }; |
| // Maps an integer identifying a load request to a PendingLoadInfo. |
| typedef std::map<int, PendingLoadInfo> LoadMap; |
| - class ImageLoader; |
| + // Loads image resources in |info_list| for load request identified by |id|. |
| + void DoLoadImages(int id, const std::vector<ImageInfo>& info_list); |
| + |
| + // Loads image for additional scale factor for given load id. |
| + void LoadImageForScaleFactor(int id, ui::ScaleFactor scale_factor); |
| // When an image has finished loaded and been resized on the file thread, it |
| // is posted back to this method on the original thread. This method then |
| @@ -122,7 +167,7 @@ class ImageLoadingTracker : public content::NotificationObserver { |
| // it was the last image in the list. The |original_size| should be the size |
| // of the image before any resizing was done. |
| // |image| may be null if the file failed to decode. |
| - void OnImageLoaded(SkBitmap* image, const ExtensionResource& resource, |
| + void OnImageLoaded(SkBitmap* image, const ImageInfo& image_info, |
| const gfx::Size& original_size, int id, bool should_cache); |
| // Checks whether image is a component extension resource. Returns false |