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 e59371d08ca376d246e47e212ae01b98bb9613c9..0dad085c6ca5d9ad55632737eb68ded613d78f95 100644 |
| --- a/chrome/browser/extensions/image_loading_tracker.h |
| +++ b/chrome/browser/extensions/image_loading_tracker.h |
| @@ -10,15 +10,16 @@ |
| #include "base/compiler_specific.h" |
| #include "base/memory/ref_counted.h" |
| +#include "chrome/common/extensions/extension_resource.h" |
| #include "content/public/browser/notification_observer.h" |
| #include "content/public/browser/notification_registrar.h" |
| +#include "ui/gfx/size.h" |
| class Extension; |
| -class ExtensionResource; |
| class SkBitmap; |
| namespace gfx { |
| - class Size; |
| +class Image; |
| } |
| // The views need to load their icons asynchronously but might be deleted before |
| @@ -46,20 +47,28 @@ class ImageLoadingTracker : public content::NotificationObserver { |
| class Observer { |
| public: |
| // Will be called when the image with the given index has loaded. |
| - // The |image| is owned by the tracker, so the observer should make a copy |
| - // if they need to access it after this call. |image| can be null if a valid |
| - // image was not found or it failed to decode. |resource| is the |
| - // ExtensionResource where the |image| came from and the |index| represents |
| - // the index of the image just loaded (starts at 0 and increments every |
| - // time LoadImage is called). |
| - virtual void OnImageLoaded(SkBitmap* image, |
| - const ExtensionResource& resource, |
| + // |image| can be empty if a valid image was not found or it failed to |
| + // decode. |extension_id| is the ID of the extension the images are loaded |
| + // from. |index| represents the index of the image just loaded (starts at 0 |
| + // and increments every time LoadImage is called). |
| + virtual void OnImageLoaded(const gfx::Image& image, |
| + const std::string& extension_id, |
| int index) = 0; |
| protected: |
| virtual ~Observer(); |
| }; |
| + // Information about a single image to load from a extension resource. |
| + struct ImageInfo { |
| + ImageInfo(const ExtensionResource resource, gfx::Size max_size); |
| + ~ImageInfo(); |
|
Robert Sesek
2012/03/05 15:18:32
nit: blank line after
|
| + ExtensionResource resource; |
| + // If the loaded image is larger than |max_size| it will be resized to those |
| + // dimensions. |
| + gfx::Size max_size; |
| + }; |
| + |
| explicit ImageLoadingTracker(Observer* observer); |
| virtual ~ImageLoadingTracker(); |
| @@ -72,13 +81,35 @@ class ImageLoadingTracker : public content::NotificationObserver { |
| 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. |
| + void LoadImages(const Extension* extension, |
| + const std::vector<ImageInfo>& info_list, |
| + CacheParam cache); |
| + |
| // Returns the ID used for the next image that is loaded. That is, the return |
| // value from this method corresponds to the int that is passed to |
| // OnImageLoaded() the next time LoadImage() is invoked. |
| int next_id() const { return next_id_; } |
| private: |
| - typedef std::map<int, const Extension*> LoadMap; |
| + // Information for pending image load operation for one or more images. |
| + struct PendingLoadInfo { |
| + PendingLoadInfo(); |
| + ~PendingLoadInfo(); |
| + |
| + const Extension* extension; |
| + // This is cached separate from |extension| in case the extension in |
| + // unloaded. |
| + std::string extension_id; |
| + CacheParam cache; |
| + size_t pending_count; |
| + std::vector<SkBitmap> bitmaps; |
| + }; |
| + |
| + // Maps an integer identifying a load request to a PendingLoadInfo. |
| + typedef std::map<int, PendingLoadInfo> LoadMap; |
| class ImageLoader; |
| @@ -106,9 +137,8 @@ class ImageLoadingTracker : public content::NotificationObserver { |
| // The object responsible for loading the image on the File thread. |
| scoped_refptr<ImageLoader> loader_; |
| - // If LoadImage is told to cache the result an entry is added here. The |
| - // integer identifies the id assigned to the request. If the extension is |
| - // deleted while fetching the image the entry is removed from the map. |
| + // Information for each LoadImage request is cached here. The integer |
| + // identifies the id assigned to the request. |
| LoadMap load_map_; |
| content::NotificationRegistrar registrar_; |