OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "chrome/browser/image_decoder.h" | 15 #include "chrome/browser/image_decoder.h" |
16 | 16 |
17 class MessageLoop; | 17 class MessageLoop; |
18 class SkBitmap; | 18 class SkBitmap; |
19 | 19 |
20 namespace chromeos { | 20 namespace chromeos { |
21 | 21 |
22 class UserImage; | |
23 | |
24 // A facility to read a file containing user image asynchronously in the IO | 22 // A facility to read a file containing user image asynchronously in the IO |
25 // thread. Returns the image in the form of an SkBitmap. | 23 // thread. Returns the image in the form of an SkBitmap. |
26 class UserImageLoader : public base::RefCountedThreadSafe<UserImageLoader>, | 24 class UserImageLoader : public base::RefCountedThreadSafe<UserImageLoader>, |
27 public ImageDecoder::Delegate { | 25 public ImageDecoder::Delegate { |
28 public: | 26 public: |
29 // Callback used to inidicate that image has been loaded. | 27 // Callback used to inidicate that image has been loaded. |
30 typedef base::Callback<void(const UserImage& user_image)> LoadedCallback; | 28 typedef base::Callback<void(const SkBitmap& image)> LoadedCallback; |
31 | 29 |
32 UserImageLoader(); | 30 UserImageLoader(); |
33 | 31 |
34 // Start reading the image from |filepath| on the file thread. Calls | 32 // Start reading the image from |filepath| on the file thread. Calls |
35 // |loaded_cb| when image has been successfully loaded. | 33 // |loaded_cb| when image has been successfully loaded. |
36 // If |size| is positive, image is resized to |size|x|size| pixels. | 34 // If |size| is positive, image is resized to |size|x|size| pixels. |
37 // If |load_raw_image| is true, raw image is also passed to callback. | 35 void Start(const std::string& filepath, int size, |
38 void Start(const std::string& filepath, int size, bool load_raw_image, | |
39 const LoadedCallback& loaded_cb); | 36 const LoadedCallback& loaded_cb); |
40 | 37 |
41 private: | 38 private: |
42 friend class base::RefCountedThreadSafe<UserImageLoader>; | 39 friend class base::RefCountedThreadSafe<UserImageLoader>; |
43 | 40 |
44 // Contains attributes we need to know about each image we decode. | 41 // Contains attributes we need to know about each image we decode. |
45 struct ImageInfo { | 42 struct ImageInfo { |
46 ImageInfo(int size, bool load_raw_image, const LoadedCallback& loaded_cb); | 43 ImageInfo(int size, const LoadedCallback& loaded_cb); |
47 ~ImageInfo(); | 44 ~ImageInfo(); |
48 | 45 |
49 int size; | 46 int size; |
50 bool load_raw_image; | |
51 LoadedCallback loaded_cb; | 47 LoadedCallback loaded_cb; |
52 }; | 48 }; |
53 | 49 |
54 typedef std::map<const ImageDecoder*, ImageInfo> ImageInfoMap; | 50 typedef std::map<const ImageDecoder*, ImageInfo> ImageInfoMap; |
55 | 51 |
56 virtual ~UserImageLoader(); | 52 virtual ~UserImageLoader(); |
57 | 53 |
58 // Method that reads the file on the file thread and starts decoding it in | 54 // Method that reads the file on the file thread and starts decoding it in |
59 // sandboxed process. | 55 // sandboxed process. |
60 void LoadImage(const std::string& filepath, const ImageInfo& image_info); | 56 void LoadImage(const std::string& filepath, const ImageInfo& image_info); |
61 | 57 |
62 // ImageDecoder::Delegate implementation. | 58 // ImageDecoder::Delegate implementation. |
63 virtual void OnImageDecoded(const ImageDecoder* decoder, | 59 virtual void OnImageDecoded(const ImageDecoder* decoder, |
64 const SkBitmap& decoded_image) OVERRIDE; | 60 const SkBitmap& decoded_image) OVERRIDE; |
65 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; | 61 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; |
66 | 62 |
67 // The message loop object of the thread in which we notify the delegate. | 63 // The message loop object of the thread in which we notify the delegate. |
68 MessageLoop* target_message_loop_; | 64 MessageLoop* target_message_loop_; |
69 | 65 |
70 // Holds info structures about all images we're trying to decode. | 66 // Holds info structures about all images we're trying to decode. |
71 // Accessed only on FILE thread. | 67 // Accessed only on FILE thread. |
72 ImageInfoMap image_info_map_; | 68 ImageInfoMap image_info_map_; |
73 | 69 |
74 DISALLOW_COPY_AND_ASSIGN(UserImageLoader); | 70 DISALLOW_COPY_AND_ASSIGN(UserImageLoader); |
75 }; | 71 }; |
76 | 72 |
77 } // namespace chromeos | 73 } // namespace chromeos |
78 | 74 |
79 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_LOADER_H_ | 75 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_LOADER_H_ |
OLD | NEW |