| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 EXTENSIONS_BROWSER_IMAGE_LOADER_H_ | 5 #ifndef EXTENSIONS_BROWSER_IMAGE_LOADER_H_ |
| 6 #define EXTENSIONS_BROWSER_IMAGE_LOADER_H_ | 6 #define EXTENSIONS_BROWSER_IMAGE_LOADER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 // Information about a singe image representation to load from an extension | 42 // Information about a singe image representation to load from an extension |
| 43 // resource. | 43 // resource. |
| 44 struct ImageRepresentation { | 44 struct ImageRepresentation { |
| 45 // Enum values to indicate whether to resize loaded bitmap when it is larger | 45 // Enum values to indicate whether to resize loaded bitmap when it is larger |
| 46 // than |desired_size| or always resize it. | 46 // than |desired_size| or always resize it. |
| 47 enum ResizeCondition { RESIZE_WHEN_LARGER, ALWAYS_RESIZE, NEVER_RESIZE }; | 47 enum ResizeCondition { RESIZE_WHEN_LARGER, ALWAYS_RESIZE, NEVER_RESIZE }; |
| 48 | 48 |
| 49 ImageRepresentation(const ExtensionResource& resource, | 49 ImageRepresentation(const ExtensionResource& resource, |
| 50 ResizeCondition resize_condition, | 50 ResizeCondition resize_condition, |
| 51 const gfx::Size& desired_size, | 51 const gfx::Size& desired_size, |
| 52 ui::ScaleFactor scale_factor); | 52 float scale_factor); |
| 53 ~ImageRepresentation(); | 53 ~ImageRepresentation(); |
| 54 | 54 |
| 55 // Extension resource to load. | 55 // Extension resource to load. |
| 56 ExtensionResource resource; | 56 ExtensionResource resource; |
| 57 | 57 |
| 58 ResizeCondition resize_condition; | 58 ResizeCondition resize_condition; |
| 59 | 59 |
| 60 // When |resize_method| is ALWAYS_RESIZE or when the loaded image is larger | 60 // When |resize_method| is ALWAYS_RESIZE or when the loaded image is larger |
| 61 // than |desired_size| it will be resized to these dimensions. | 61 // than |desired_size| it will be resized to these dimensions. |
| 62 gfx::Size desired_size; | 62 gfx::Size desired_size; |
| 63 | 63 |
| 64 // |scale_factor| is used to construct the loaded gfx::ImageSkia. | 64 // |scale_factor| is used to construct the loaded gfx::ImageSkia. |
| 65 ui::ScaleFactor scale_factor; | 65 float scale_factor; |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 struct LoadResult; | 68 struct LoadResult; |
| 69 | 69 |
| 70 // Returns the instance for the given |context| or NULL if none. This is | 70 // Returns the instance for the given |context| or NULL if none. This is |
| 71 // a convenience wrapper around ImageLoaderFactory::GetForBrowserContext. | 71 // a convenience wrapper around ImageLoaderFactory::GetForBrowserContext. |
| 72 static ImageLoader* Get(content::BrowserContext* context); | 72 static ImageLoader* Get(content::BrowserContext* context); |
| 73 | 73 |
| 74 ImageLoader(); | 74 ImageLoader(); |
| 75 ~ImageLoader() override; | 75 ~ImageLoader() override; |
| 76 | 76 |
| 77 // Specify image resource to load. If the loaded image is larger than | 77 // Specify image resource to load. If the loaded image is larger than |
| 78 // |max_size| it will be resized to those dimensions. IMPORTANT NOTE: this | 78 // |max_size| it will be resized to those dimensions. IMPORTANT NOTE: this |
| 79 // function may call back your callback synchronously (ie before it returns) | 79 // function may call back your callback synchronously (ie before it returns) |
| 80 // if the image was found in the cache. | 80 // if the image was found in the cache. |
| 81 // Note this method loads a raw bitmap from the resource. All sizes given are | 81 // Note this method loads a raw bitmap from the resource. All sizes given are |
| 82 // assumed to be in pixels. | 82 // assumed to be in pixels. |
| 83 // TODO(estade): remove this in favor of LoadImageAtEveryScaleFactorAsync, | 83 // TODO(estade): remove this in favor of LoadImageAtEveryScaleFactorAsync, |
| 84 // and rename the latter to LoadImageAsync. | 84 // and rename the latter to LoadImageAsync. |
| 85 void LoadImageAsync(const Extension* extension, | 85 void LoadImageAsync(const Extension* extension, |
| 86 const ExtensionResource& resource, | 86 const ExtensionResource& resource, |
| 87 const gfx::Size& max_size, | 87 const gfx::Size& max_size, |
| 88 const ImageLoaderImageCallback& callback); | 88 const ImageLoaderImageCallback& callback); |
| 89 | 89 |
| 90 // Loads and returns a gfx::Image that has representations at all supported | 90 // Loads a gfx::Image that has representations at all scale factors we are |
| 91 // scale factors. | 91 // likely to care about. That includes every scale for which we pack resources |
| 92 // in ResourceBundle plus the scale for all currently attached displays. The |
| 93 // image is returned via |callback|. |
| 92 void LoadImageAtEveryScaleFactorAsync( | 94 void LoadImageAtEveryScaleFactorAsync( |
| 93 const Extension* extension, | 95 const Extension* extension, |
| 94 const gfx::Size& dip_size, | 96 const gfx::Size& dip_size, |
| 95 const ImageLoaderImageCallback& callback); | 97 const ImageLoaderImageCallback& callback); |
| 96 | 98 |
| 97 // Same as LoadImageAsync() above except it loads multiple images from the | 99 // Same as LoadImageAsync() above except it loads multiple images from the |
| 98 // same extension. This is used to load multiple resolutions of the same image | 100 // same extension. This is used to load multiple resolutions of the same image |
| 99 // type. | 101 // type. |
| 100 void LoadImagesAsync(const Extension* extension, | 102 void LoadImagesAsync(const Extension* extension, |
| 101 const std::vector<ImageRepresentation>& info_list, | 103 const std::vector<ImageRepresentation>& info_list, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 120 const std::vector<LoadResult>& load_result); | 122 const std::vector<LoadResult>& load_result); |
| 121 | 123 |
| 122 base::WeakPtrFactory<ImageLoader> weak_ptr_factory_; | 124 base::WeakPtrFactory<ImageLoader> weak_ptr_factory_; |
| 123 | 125 |
| 124 DISALLOW_COPY_AND_ASSIGN(ImageLoader); | 126 DISALLOW_COPY_AND_ASSIGN(ImageLoader); |
| 125 }; | 127 }; |
| 126 | 128 |
| 127 } // namespace extensions | 129 } // namespace extensions |
| 128 | 130 |
| 129 #endif // EXTENSIONS_BROWSER_IMAGE_LOADER_H_ | 131 #endif // EXTENSIONS_BROWSER_IMAGE_LOADER_H_ |
| OLD | NEW |