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 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 ResizeCondition resize_method; | 89 ResizeCondition resize_method; |
90 | 90 |
91 // When |resize_method| is ALWAYS_RESIZE or when the loaded image is larger | 91 // When |resize_method| is ALWAYS_RESIZE or when the loaded image is larger |
92 // than |desired_size| it will be resized to these dimensions. | 92 // than |desired_size| it will be resized to these dimensions. |
93 gfx::Size desired_size; | 93 gfx::Size desired_size; |
94 | 94 |
95 // |scale_factor| is used to construct the loaded gfx::ImageSkia. | 95 // |scale_factor| is used to construct the loaded gfx::ImageSkia. |
96 ui::ScaleFactor scale_factor; | 96 ui::ScaleFactor scale_factor; |
97 }; | 97 }; |
98 | 98 |
99 // Returns true if given extension id is a special component extension that | |
100 // has its resource bundled. | |
101 // TODO(xiyuan): Move this out of this class. | |
102 static bool IsSpecialBundledExtensionId(const std::string& extension_id); | |
103 | |
104 explicit ImageLoadingTracker(Observer* observer); | 99 explicit ImageLoadingTracker(Observer* observer); |
105 virtual ~ImageLoadingTracker(); | 100 virtual ~ImageLoadingTracker(); |
106 | 101 |
107 // Specify image resource to load. If the loaded image is larger than | 102 // Specify image resource to load. If the loaded image is larger than |
108 // |max_size| it will be resized to those dimensions. IMPORTANT NOTE: this | 103 // |max_size| it will be resized to those dimensions. IMPORTANT NOTE: this |
109 // function may call back your observer synchronously (ie before it returns) | 104 // function may call back your observer synchronously (ie before it returns) |
110 // if the image was found in the cache. | 105 // if the image was found in the cache. |
111 // Note this method loads a raw bitmap from the resource. All sizes given are | 106 // Note this method loads a raw bitmap from the resource. All sizes given are |
112 // assumed to be in pixels. | 107 // assumed to be in pixels. |
113 void LoadImage(const extensions::Extension* extension, | 108 void LoadImage(const extensions::Extension* extension, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 const ImageRepresentation& image_info, | 149 const ImageRepresentation& image_info, |
155 const gfx::Size& original_size, | 150 const gfx::Size& original_size, |
156 int id, | 151 int id, |
157 bool should_cache); | 152 bool should_cache); |
158 | 153 |
159 // Checks whether image is a component extension resource. Returns false | 154 // Checks whether image is a component extension resource. Returns false |
160 // if a given |resource| does not have a corresponding image in bundled | 155 // if a given |resource| does not have a corresponding image in bundled |
161 // resources. Otherwise fills |resource_id|. | 156 // resources. Otherwise fills |resource_id|. |
162 bool IsComponentExtensionResource(const extensions::Extension* extension, | 157 bool IsComponentExtensionResource(const extensions::Extension* extension, |
163 const ExtensionResource& resource, | 158 const ExtensionResource& resource, |
164 int& resource_id) const; | 159 int* resource_id) const; |
165 | 160 |
166 // content::NotificationObserver method. If an extension is uninstalled while | 161 // content::NotificationObserver method. If an extension is uninstalled while |
167 // we're waiting for the image we remove the entry from load_map_. | 162 // we're waiting for the image we remove the entry from load_map_. |
168 virtual void Observe(int type, | 163 virtual void Observe(int type, |
169 const content::NotificationSource& source, | 164 const content::NotificationSource& source, |
170 const content::NotificationDetails& details) OVERRIDE; | 165 const content::NotificationDetails& details) OVERRIDE; |
171 | 166 |
172 // The view that is waiting for the image to load. | 167 // The view that is waiting for the image to load. |
173 Observer* observer_; | 168 Observer* observer_; |
174 | 169 |
175 // ID to use for next image requested. This is an ever increasing integer. | 170 // ID to use for next image requested. This is an ever increasing integer. |
176 int next_id_; | 171 int next_id_; |
177 | 172 |
178 // The object responsible for loading the image on the File thread. | 173 // The object responsible for loading the image on the File thread. |
179 scoped_refptr<ImageLoader> loader_; | 174 scoped_refptr<ImageLoader> loader_; |
180 | 175 |
181 // Information for each LoadImage request is cached here. The integer | 176 // Information for each LoadImage request is cached here. The integer |
182 // identifies the id assigned to the request. | 177 // identifies the id assigned to the request. |
183 LoadMap load_map_; | 178 LoadMap load_map_; |
184 | 179 |
185 content::NotificationRegistrar registrar_; | 180 content::NotificationRegistrar registrar_; |
186 | 181 |
187 FRIEND_TEST_ALL_PREFIXES(ImageLoadingTrackerTest, | 182 FRIEND_TEST_ALL_PREFIXES(ImageLoadingTrackerTest, |
188 IsComponentExtensionResource); | 183 IsComponentExtensionResource); |
189 | 184 |
190 DISALLOW_COPY_AND_ASSIGN(ImageLoadingTracker); | 185 DISALLOW_COPY_AND_ASSIGN(ImageLoadingTracker); |
191 }; | 186 }; |
192 | 187 |
193 #endif // CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ | 188 #endif // CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ |
OLD | NEW |