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

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

Issue 56833003: Use base::PostTaskAndReplyWithResults() in more places. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, fix clang error Created 7 years 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_LOADER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_IMAGE_LOADER_H_
6 #define CHROME_BROWSER_EXTENSIONS_IMAGE_LOADER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_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 10 matching lines...) Expand all
21 } 21 }
22 22
23 namespace gfx { 23 namespace gfx {
24 class Image; 24 class Image;
25 } 25 }
26 26
27 namespace extensions { 27 namespace extensions {
28 28
29 class Extension; 29 class Extension;
30 30
31 typedef base::Callback<void(const gfx::Image&)> ImageLoaderCallback;
32
31 // This class is responsible for asynchronously loading extension images and 33 // This class is responsible for asynchronously loading extension images and
32 // calling a callback when an image is loaded. 34 // calling a callback when an image is loaded.
33 // The views need to load their icons asynchronously might be deleted before 35 // The views need to load their icons asynchronously might be deleted before
34 // the images have loaded. If you pass your callback using a weak_ptr, this 36 // the images have loaded. If you pass your callback using a weak_ptr, this
35 // will make sure the callback won't be called after the view is deleted. 37 // will make sure the callback won't be called after the view is deleted.
36 class ImageLoader : public BrowserContextKeyedService { 38 class ImageLoader : public BrowserContextKeyedService {
37 public: 39 public:
38 // Information about a singe image representation to load from an extension 40 // Information about a singe image representation to load from an extension
39 // resource. 41 // resource.
40 struct ImageRepresentation { 42 struct ImageRepresentation {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 86
85 // Specify image resource to load. If the loaded image is larger than 87 // Specify image resource to load. If the loaded image is larger than
86 // |max_size| it will be resized to those dimensions. IMPORTANT NOTE: this 88 // |max_size| it will be resized to those dimensions. IMPORTANT NOTE: this
87 // function may call back your callback synchronously (ie before it returns) 89 // function may call back your callback synchronously (ie before it returns)
88 // if the image was found in the cache. 90 // if the image was found in the cache.
89 // Note this method loads a raw bitmap from the resource. All sizes given are 91 // Note this method loads a raw bitmap from the resource. All sizes given are
90 // assumed to be in pixels. 92 // assumed to be in pixels.
91 void LoadImageAsync(const extensions::Extension* extension, 93 void LoadImageAsync(const extensions::Extension* extension,
92 const ExtensionResource& resource, 94 const ExtensionResource& resource,
93 const gfx::Size& max_size, 95 const gfx::Size& max_size,
94 const base::Callback<void(const gfx::Image&)>& callback); 96 const ImageLoaderCallback& callback);
95 97
96 // Same as LoadImage() above except it loads multiple images from the same 98 // Same as LoadImage() above except it loads multiple images from the same
97 // extension. This is used to load multiple resolutions of the same image 99 // extension. This is used to load multiple resolutions of the same image
98 // type. 100 // type.
99 void LoadImagesAsync(const extensions::Extension* extension, 101 void LoadImagesAsync(const extensions::Extension* extension,
100 const std::vector<ImageRepresentation>& info_list, 102 const std::vector<ImageRepresentation>& info_list,
101 const base::Callback<void(const gfx::Image&)>& callback); 103 const ImageLoaderCallback& callback);
102 104
103 private: 105 private:
106 void ReplyBack(const ImageLoaderCallback& callback,
107 const std::vector<LoadResult>& load_result);
108
104 base::WeakPtrFactory<ImageLoader> weak_ptr_factory_; 109 base::WeakPtrFactory<ImageLoader> weak_ptr_factory_;
105 110
106 static void LoadImagesOnBlockingPool( 111 DISALLOW_COPY_AND_ASSIGN(ImageLoader);
107 const std::vector<ImageRepresentation>& info_list,
108 const std::vector<SkBitmap>& bitmaps,
109 std::vector<LoadResult>* load_result);
110
111 void ReplyBack(
112 const std::vector<LoadResult>* load_result,
113 const base::Callback<void(const gfx::Image&)>& callback);
114 }; 112 };
115 113
116 } // namespace extensions 114 } // namespace extensions
117 115
118 #endif // CHROME_BROWSER_EXTENSIONS_IMAGE_LOADER_H_ 116 #endif // CHROME_BROWSER_EXTENSIONS_IMAGE_LOADER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_protocols.cc ('k') | chrome/browser/extensions/image_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698