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

Side by Side Diff: chrome/browser/extensions/image_loading_tracker.h

Issue 9428025: Add support for multiple icon sizes for Mac platform apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_
6 #define CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "chrome/common/extensions/extension_resource.h"
13 #include "content/public/browser/notification_observer.h" 14 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h" 15 #include "content/public/browser/notification_registrar.h"
16 #include "ui/gfx/size.h"
15 17
16 class Extension; 18 class Extension;
17 class ExtensionResource;
18 class SkBitmap; 19 class SkBitmap;
19 20
20 namespace gfx { 21 namespace gfx {
21 class Size; 22 class Image;
22 } 23 }
23 24
24 // The views need to load their icons asynchronously but might be deleted before 25 // The views need to load their icons asynchronously but might be deleted before
25 // the images have loaded. This class encapsulates a loader class that stays 26 // the images have loaded. This class encapsulates a loader class that stays
26 // alive while the request is in progress (manages its own lifetime) and keeps 27 // alive while the request is in progress (manages its own lifetime) and keeps
27 // track of whether the view still cares about the icon loading. 28 // track of whether the view still cares about the icon loading.
28 // 29 //
29 // To use this class, have your class derive from ImageLoadingTracker::Observer, 30 // To use this class, have your class derive from ImageLoadingTracker::Observer,
30 // and add a member variable ImageLoadingTracker tracker_. Then override 31 // and add a member variable ImageLoadingTracker tracker_. Then override
31 // Observer::OnImageLoaded and call: 32 // Observer::OnImageLoaded and call:
(...skipping 13 matching lines...) Expand all
45 46
46 class Observer { 47 class Observer {
47 public: 48 public:
48 // Will be called when the image with the given index has loaded. 49 // Will be called when the image with the given index has loaded.
49 // The |image| is owned by the tracker, so the observer should make a copy 50 // The |image| is owned by the tracker, so the observer should make a copy
50 // if they need to access it after this call. |image| can be null if a valid 51 // if they need to access it after this call. |image| can be null if a valid
51 // image was not found or it failed to decode. |resource| is the 52 // image was not found or it failed to decode. |resource| is the
52 // ExtensionResource where the |image| came from and the |index| represents 53 // ExtensionResource where the |image| came from and the |index| represents
53 // the index of the image just loaded (starts at 0 and increments every 54 // the index of the image just loaded (starts at 0 and increments every
54 // time LoadImage is called). 55 // time LoadImage is called).
55 virtual void OnImageLoaded(SkBitmap* image, 56 virtual void OnImageLoaded(const gfx::Image* image,
56 const ExtensionResource& resource, 57 const std::string& extension_id,
57 int index) = 0; 58 int index) = 0;
58 59
59 protected: 60 protected:
60 virtual ~Observer(); 61 virtual ~Observer();
61 }; 62 };
62 63
64 struct ImageInfo {
65 ImageInfo(const ExtensionResource resource, gfx::Size max_size);
66 ExtensionResource resource;
67 gfx::Size max_size;
68 };
69
63 explicit ImageLoadingTracker(Observer* observer); 70 explicit ImageLoadingTracker(Observer* observer);
64 virtual ~ImageLoadingTracker(); 71 virtual ~ImageLoadingTracker();
65 72
66 // Specify image resource to load. If the loaded image is larger than 73 // Specify image resource to load. If the loaded image is larger than
67 // |max_size| it will be resized to those dimensions. IMPORTANT NOTE: this 74 // |max_size| it will be resized to those dimensions. IMPORTANT NOTE: this
68 // function may call back your observer synchronously (ie before it returns) 75 // function may call back your observer synchronously (ie before it returns)
69 // if the image was found in the cache. 76 // if the image was found in the cache.
70 void LoadImage(const Extension* extension, 77 void LoadImage(const Extension* extension,
71 const ExtensionResource& resource, 78 const ExtensionResource& resource,
72 const gfx::Size& max_size, 79 const gfx::Size& max_size,
73 CacheParam cache); 80 CacheParam cache);
74 81
82 // Same as LoadImage() above except it loads multiple images. This is used
Mihai Parparita -not on Chrome 2012/02/23 00:19:41 "loads multiple images from the same extension" se
sail 2012/02/23 02:54:27 Done.
83 // to load multiple resolutions of the same image type.
84 void LoadImages(const Extension* extension,
85 const std::vector<ImageInfo>& info_list,
86 CacheParam cache);
87
75 // Returns the ID used for the next image that is loaded. That is, the return 88 // Returns the ID used for the next image that is loaded. That is, the return
76 // value from this method corresponds to the int that is passed to 89 // value from this method corresponds to the int that is passed to
77 // OnImageLoaded() the next time LoadImage() is invoked. 90 // OnImageLoaded() the next time LoadImage() is invoked.
78 int next_id() const { return next_id_; } 91 int next_id() const { return next_id_; }
79 92
80 private: 93 private:
81 typedef std::map<int, const Extension*> LoadMap; 94 struct PendingLoadInfo {
95 PendingLoadInfo();
96 ~PendingLoadInfo();
97
98 const Extension* extension;
99 std::string extension_id;
100 CacheParam cache;
101 size_t pending_count;
102 std::vector<SkBitmap> bitmaps;
103 };
104
105 typedef std::map<int, PendingLoadInfo> LoadMap;
82 106
83 class ImageLoader; 107 class ImageLoader;
84 108
85 // When an image has finished loaded and been resized on the file thread, it 109 // When an image has finished loaded and been resized on the file thread, it
86 // is posted back to this method on the original thread. This method then 110 // is posted back to this method on the original thread. This method then
87 // calls the observer's OnImageLoaded and deletes the ImageLoadingTracker if 111 // calls the observer's OnImageLoaded and deletes the ImageLoadingTracker if
88 // it was the last image in the list. The |original_size| should be the size 112 // it was the last image in the list. The |original_size| should be the size
89 // of the image before any resizing was done. 113 // of the image before any resizing was done.
90 // |image| may be null if the file failed to decode. 114 // |image| may be null if the file failed to decode.
91 void OnImageLoaded(SkBitmap* image, const ExtensionResource& resource, 115 void OnImageLoaded(SkBitmap* image, const ExtensionResource& resource,
(...skipping 18 matching lines...) Expand all
110 // integer identifies the id assigned to the request. If the extension is 134 // integer identifies the id assigned to the request. If the extension is
111 // deleted while fetching the image the entry is removed from the map. 135 // deleted while fetching the image the entry is removed from the map.
112 LoadMap load_map_; 136 LoadMap load_map_;
113 137
114 content::NotificationRegistrar registrar_; 138 content::NotificationRegistrar registrar_;
115 139
116 DISALLOW_COPY_AND_ASSIGN(ImageLoadingTracker); 140 DISALLOW_COPY_AND_ASSIGN(ImageLoadingTracker);
117 }; 141 };
118 142
119 #endif // CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ 143 #endif // CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698