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_CHROMEOS_LOGIN_USER_IMAGE_LOADER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_LOADER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_LOADER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_LOADER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/threading/sequenced_worker_pool.h" | |
14 #include "chrome/browser/image_decoder.h" | 15 #include "chrome/browser/image_decoder.h" |
15 | 16 |
16 class MessageLoop; | 17 class MessageLoop; |
17 class SkBitmap; | 18 class SkBitmap; |
18 | 19 |
19 namespace chromeos { | 20 namespace chromeos { |
20 | 21 |
21 class UserImage; | 22 class UserImage; |
22 | 23 |
23 // A facility to read a file containing user image asynchronously in the IO | 24 // A facility to read a file containing user image asynchronously in the IO |
24 // thread. Returns the image in the form of an SkBitmap. | 25 // thread. Returns the image in the form of an SkBitmap. |
25 class UserImageLoader : public base::RefCountedThreadSafe<UserImageLoader>, | 26 class UserImageLoader : public base::RefCountedThreadSafe<UserImageLoader>, |
26 public ImageDecoder::Delegate { | 27 public ImageDecoder::Delegate { |
27 public: | 28 public: |
28 // Callback used to indicate that image has been loaded. | 29 // Callback used to indicate that image has been loaded. |
29 typedef base::Callback<void(const UserImage& user_image)> LoadedCallback; | 30 typedef base::Callback<void(const UserImage& user_image)> LoadedCallback; |
30 | 31 |
31 explicit UserImageLoader(ImageDecoder::ImageCodec image_codec); | 32 explicit UserImageLoader(ImageDecoder::ImageCodec image_codec); |
32 | 33 |
33 // Start reading the image from |filepath| on the file thread. Calls | 34 // Start reading the image from |filepath| on the file thread. Calls |
34 // |loaded_cb| when image has been successfully loaded. | 35 // |loaded_cb| when image has been successfully loaded. |
35 // If |size| is positive, image is cropped and (if needed) downsized to | 36 // If |size| is positive, image is cropped and (if needed) downsized to |
36 // |size|x|size| pixels. | 37 // |size|x|size| pixels. |
37 void Start(const std::string& filepath, int size, | 38 void Start(const std::string& filepath, int size, |
38 const LoadedCallback& loaded_cb); | 39 const LoadedCallback& loaded_cb); |
39 | 40 |
40 private: | 41 private: |
41 friend class base::RefCountedThreadSafe<UserImageLoader>; | 42 friend class base::RefCountedThreadSafe<UserImageLoader>; |
42 | 43 |
44 // Token name for user image loader. | |
45 static const char* kUserImageLoaderTokenName; | |
Nikita (slow)
2013/01/18 16:40:13
static const char kUserImageLoaderTokenName[]
Joao da Silva
2013/01/18 17:24:58
This could also be hidden in the .cc file, in an a
| |
46 | |
43 // Contains attributes we need to know about each image we decode. | 47 // Contains attributes we need to know about each image we decode. |
44 struct ImageInfo { | 48 struct ImageInfo { |
45 ImageInfo(int size, const LoadedCallback& loaded_cb); | 49 ImageInfo(int size, const LoadedCallback& loaded_cb); |
46 ~ImageInfo(); | 50 ~ImageInfo(); |
47 | 51 |
48 const int size; | 52 const int size; |
49 const LoadedCallback loaded_cb; | 53 const LoadedCallback loaded_cb; |
50 }; | 54 }; |
51 | 55 |
52 typedef std::map<const ImageDecoder*, ImageInfo> ImageInfoMap; | 56 typedef std::map<const ImageDecoder*, ImageInfo> ImageInfoMap; |
(...skipping 12 matching lines...) Expand all Loading... | |
65 // The message loop object of the thread in which we notify the delegate. | 69 // The message loop object of the thread in which we notify the delegate. |
66 MessageLoop* target_message_loop_; | 70 MessageLoop* target_message_loop_; |
67 | 71 |
68 // Specify how the file should be decoded in the utility process. | 72 // Specify how the file should be decoded in the utility process. |
69 const ImageDecoder::ImageCodec image_codec_; | 73 const ImageDecoder::ImageCodec image_codec_; |
70 | 74 |
71 // Holds info structures about all images we're trying to decode. | 75 // Holds info structures about all images we're trying to decode. |
72 // Accessed only on FILE thread. | 76 // Accessed only on FILE thread. |
73 ImageInfoMap image_info_map_; | 77 ImageInfoMap image_info_map_; |
74 | 78 |
79 base::SequencedWorkerPool::SequenceToken sequence_token_; | |
80 | |
75 DISALLOW_COPY_AND_ASSIGN(UserImageLoader); | 81 DISALLOW_COPY_AND_ASSIGN(UserImageLoader); |
76 }; | 82 }; |
77 | 83 |
78 } // namespace chromeos | 84 } // namespace chromeos |
79 | 85 |
80 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_LOADER_H_ | 86 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_LOADER_H_ |
OLD | NEW |