Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4947)

Unified Diff: chrome/browser/extensions/image_loading_tracker.h

Issue 9586018: Add support for multiple icon sizes for Mac platform apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix build Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/extension_web_ui.cc ('k') | chrome/browser/extensions/image_loading_tracker.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..6363877d32473b9f87b7a6783148a1df30106f12 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();
+ 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;
@@ -89,7 +120,7 @@ class ImageLoadingTracker : public content::NotificationObserver {
// 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,
- const gfx::Size& original_size, int id);
+ const gfx::Size& original_size, int id, bool should_cache);
// content::NotificationObserver method. If an extension is uninstalled while
// we're waiting for the image we remove the entry from load_map_.
@@ -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_;
« no previous file with comments | « chrome/browser/extensions/extension_web_ui.cc ('k') | chrome/browser/extensions/image_loading_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698