OLD | NEW |
---|---|
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 #include <string> | |
11 #include <vector> | |
10 | 12 |
11 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
12 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
13 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
14 #include "chrome/common/extensions/extension_resource.h" | 16 #include "chrome/common/extensions/extension_resource.h" |
15 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
19 #include "ui/base/layout.h" | |
20 #include "ui/gfx/image/image_skia.h" | |
17 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
18 | 22 |
19 class SkBitmap; | 23 class SkBitmap; |
20 | 24 |
21 namespace extensions { | 25 namespace extensions { |
22 class Extension; | 26 class Extension; |
23 } | 27 } |
24 | 28 |
25 namespace gfx { | 29 namespace gfx { |
26 class Image; | 30 class Image; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 virtual void OnImageLoaded(const gfx::Image& image, | 62 virtual void OnImageLoaded(const gfx::Image& image, |
59 const std::string& extension_id, | 63 const std::string& extension_id, |
60 int index) = 0; | 64 int index) = 0; |
61 | 65 |
62 protected: | 66 protected: |
63 virtual ~Observer(); | 67 virtual ~Observer(); |
64 }; | 68 }; |
65 | 69 |
66 // Information about a single image to load from a extension resource. | 70 // Information about a single image to load from a extension resource. |
67 struct ImageInfo { | 71 struct ImageInfo { |
68 ImageInfo(const ExtensionResource& resource, gfx::Size max_size); | 72 ImageInfo(const ExtensionResource& resource, |
73 const gfx::Size& max_size, | |
74 ui::ScaleFactor scale_factor); | |
69 ~ImageInfo(); | 75 ~ImageInfo(); |
76 | |
70 ExtensionResource resource; | 77 ExtensionResource resource; |
71 // If the loaded image is larger than |max_size| it will be resized to those | 78 // If the loaded image is larger than |max_size| it will be resized to those |
72 // dimensions. | 79 // dimensions. |
73 gfx::Size max_size; | 80 gfx::Size max_size; |
81 // |scale_factor| is used to construct loaded gfx::ImageSkia. | |
82 ui::ScaleFactor scale_factor; | |
74 }; | 83 }; |
75 | 84 |
76 explicit ImageLoadingTracker(Observer* observer); | 85 explicit ImageLoadingTracker(Observer* observer); |
77 virtual ~ImageLoadingTracker(); | 86 virtual ~ImageLoadingTracker(); |
78 | 87 |
79 // Specify image resource to load. If the loaded image is larger than | 88 // Specify image resource to load. If the loaded image is larger than |
80 // |max_size| it will be resized to those dimensions. IMPORTANT NOTE: this | 89 // |max_size| it will be resized to those dimensions. IMPORTANT NOTE: this |
81 // function may call back your observer synchronously (ie before it returns) | 90 // function may call back your observer synchronously (ie before it returns) |
82 // if the image was found in the cache. | 91 // if the image was found in the cache. |
83 void LoadImage(const extensions::Extension* extension, | 92 void LoadImage(const extensions::Extension* extension, |
84 const ExtensionResource& resource, | 93 const ExtensionResource& resource, |
85 const gfx::Size& max_size, | 94 const gfx::Size& max_size, |
86 CacheParam cache); | 95 CacheParam cache); |
87 | 96 |
97 // Loads an extension image for given DIP size. On non-DIP enabled screen, | |
98 // this is the same as above LoadImage. On DIP screen, this function would try | |
99 // to load hi-res icons with proper scale factor. | |
100 void LoadDIPImage(const extensions::Extension* extension, | |
pkotwicz
2012/07/11 21:02:25
Nit: I am not a fan of this method name, but I don
oshima
2012/07/11 21:09:33
LoadImageInDIP is better
xiyuan
2012/07/13 18:35:46
Changed name to LoadImageInDIP and pass in match_t
| |
101 int preferred_dip_size, | |
102 gfx::Size max_dip_size, | |
103 CacheParam cache); | |
104 | |
88 // Same as LoadImage() above except it loads multiple images from the same | 105 // Same as LoadImage() above except it loads multiple images from the same |
89 // extension. This is used to load multiple resolutions of the same image | 106 // extension. This is used to load multiple resolutions of the same image |
90 // type. | 107 // type. |
91 void LoadImages(const extensions::Extension* extension, | 108 void LoadImages(const extensions::Extension* extension, |
92 const std::vector<ImageInfo>& info_list, | 109 const std::vector<ImageInfo>& info_list, |
pkotwicz
2012/07/11 21:02:25
Can you please write a multires version of this me
xiyuan
2012/07/13 18:35:46
I take this function as a low-level function that
| |
93 CacheParam cache); | 110 CacheParam cache); |
94 | 111 |
95 // Returns the ID used for the next image that is loaded. That is, the return | 112 // Returns the ID used for the next image that is loaded. That is, the return |
96 // value from this method corresponds to the int that is passed to | 113 // value from this method corresponds to the int that is passed to |
97 // OnImageLoaded() the next time LoadImage() is invoked. | 114 // OnImageLoaded() the next time LoadImage() is invoked. |
98 int next_id() const { return next_id_; } | 115 int next_id() const { return next_id_; } |
99 | 116 |
100 private: | 117 private: |
101 // Information for pending image load operation for one or more images. | 118 // Information for pending image load operation for one or more images. |
102 struct PendingLoadInfo { | 119 struct PendingLoadInfo { |
103 PendingLoadInfo(); | 120 PendingLoadInfo(); |
104 ~PendingLoadInfo(); | 121 ~PendingLoadInfo(); |
105 | 122 |
106 const extensions::Extension* extension; | 123 const extensions::Extension* extension; |
107 // This is cached separate from |extension| in case the extension in | 124 // This is cached separate from |extension| in case the extension in |
108 // unloaded. | 125 // unloaded. |
109 std::string extension_id; | 126 std::string extension_id; |
110 CacheParam cache; | 127 CacheParam cache; |
111 size_t pending_count; | 128 size_t pending_count; |
112 std::vector<SkBitmap> bitmaps; | 129 gfx::ImageSkia images; |
113 }; | 130 }; |
114 | 131 |
115 // Maps an integer identifying a load request to a PendingLoadInfo. | 132 // Maps an integer identifying a load request to a PendingLoadInfo. |
116 typedef std::map<int, PendingLoadInfo> LoadMap; | 133 typedef std::map<int, PendingLoadInfo> LoadMap; |
117 | 134 |
118 class ImageLoader; | 135 class ImageLoader; |
119 | 136 |
120 // When an image has finished loaded and been resized on the file thread, it | 137 // When an image has finished loaded and been resized on the file thread, it |
121 // is posted back to this method on the original thread. This method then | 138 // is posted back to this method on the original thread. This method then |
122 // calls the observer's OnImageLoaded and deletes the ImageLoadingTracker if | 139 // calls the observer's OnImageLoaded and deletes the ImageLoadingTracker if |
123 // it was the last image in the list. The |original_size| should be the size | 140 // it was the last image in the list. The |original_size| should be the size |
124 // of the image before any resizing was done. | 141 // of the image before any resizing was done. |
125 // |image| may be null if the file failed to decode. | 142 // |image| may be null if the file failed to decode. |
126 void OnImageLoaded(SkBitmap* image, const ExtensionResource& resource, | 143 void OnImageLoaded(SkBitmap* image, const ImageInfo& image_info, |
127 const gfx::Size& original_size, int id, bool should_cache); | 144 const gfx::Size& original_size, int id, bool should_cache); |
128 | 145 |
129 // Checks whether image is a component extension resource. Returns false | 146 // Checks whether image is a component extension resource. Returns false |
130 // if a given |resource| does not have a corresponding image in bundled | 147 // if a given |resource| does not have a corresponding image in bundled |
131 // resources. Otherwise fills |resource_id|. | 148 // resources. Otherwise fills |resource_id|. |
132 bool IsComponentExtensionResource(const extensions::Extension* extension, | 149 bool IsComponentExtensionResource(const extensions::Extension* extension, |
133 const ExtensionResource& resource, | 150 const ExtensionResource& resource, |
134 int& resource_id) const; | 151 int& resource_id) const; |
135 | 152 |
136 // content::NotificationObserver method. If an extension is uninstalled while | 153 // content::NotificationObserver method. If an extension is uninstalled while |
(...skipping 17 matching lines...) Expand all Loading... | |
154 | 171 |
155 content::NotificationRegistrar registrar_; | 172 content::NotificationRegistrar registrar_; |
156 | 173 |
157 FRIEND_TEST_ALL_PREFIXES(ImageLoadingTrackerTest, | 174 FRIEND_TEST_ALL_PREFIXES(ImageLoadingTrackerTest, |
158 IsComponentExtensionResource); | 175 IsComponentExtensionResource); |
159 | 176 |
160 DISALLOW_COPY_AND_ASSIGN(ImageLoadingTracker); | 177 DISALLOW_COPY_AND_ASSIGN(ImageLoadingTracker); |
161 }; | 178 }; |
162 | 179 |
163 #endif // CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ | 180 #endif // CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ |
OLD | NEW |