Chromium Code Reviews| 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/synchronization/lock.h" | |
| 15 #include "base/threading/sequenced_worker_pool.h" | |
| 14 #include "chrome/browser/image_decoder.h" | 16 #include "chrome/browser/image_decoder.h" |
| 15 | 17 |
| 16 class MessageLoop; | 18 class MessageLoop; |
| 17 class SkBitmap; | 19 class SkBitmap; |
| 18 | 20 |
| 19 namespace chromeos { | 21 namespace chromeos { |
| 20 | 22 |
| 21 class UserImage; | 23 class UserImage; |
| 22 | 24 |
| 23 // A facility to read a file containing user image asynchronously in the IO | 25 // A facility to read a file containing user image asynchronously in the IO |
| 24 // thread. Returns the image in the form of an SkBitmap. | 26 // thread. Returns the image in the form of an SkBitmap. |
| 25 class UserImageLoader : public base::RefCountedThreadSafe<UserImageLoader>, | 27 class UserImageLoader : public base::RefCountedThreadSafe<UserImageLoader>, |
| 26 public ImageDecoder::Delegate { | 28 public ImageDecoder::Delegate { |
| 27 public: | 29 public: |
| 28 // Callback used to indicate that image has been loaded. | 30 // Callback used to indicate that image has been loaded. |
| 29 typedef base::Callback<void(const UserImage& user_image)> LoadedCallback; | 31 typedef base::Callback<void(const UserImage& user_image)> LoadedCallback; |
| 30 | 32 |
| 33 typedef base::SequencedWorkerPool::SequenceToken SequenceToken; | |
|
Joao da Silva
2013/01/22 10:04:12
This can be moved to the .cc file.
bshe
2013/01/22 15:36:26
Done.
| |
| 34 | |
| 31 explicit UserImageLoader(ImageDecoder::ImageCodec image_codec); | 35 explicit UserImageLoader(ImageDecoder::ImageCodec image_codec); |
| 32 | 36 |
| 33 // Start reading the image from |filepath| on the file thread. Calls | 37 // Start reading the image from |filepath| on the file thread. Calls |
|
Nikita (slow)
2013/01/22 11:30:54
nit: Comment should be updated now.
bshe
2013/01/22 15:36:26
Done.
| |
| 34 // |loaded_cb| when image has been successfully loaded. | 38 // |loaded_cb| when image has been successfully loaded. |
| 35 // If |size| is positive, image is cropped and (if needed) downsized to | 39 // If |size| is positive, image is cropped and (if needed) downsized to |
| 36 // |size|x|size| pixels. | 40 // |size|x|size| pixels. |
| 37 void Start(const std::string& filepath, int size, | 41 void Start(const std::string& filepath, int size, |
| 38 const LoadedCallback& loaded_cb); | 42 const LoadedCallback& loaded_cb); |
| 39 | 43 |
| 40 private: | 44 private: |
| 41 friend class base::RefCountedThreadSafe<UserImageLoader>; | 45 friend class base::RefCountedThreadSafe<UserImageLoader>; |
| 42 | 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; |
| 53 | 57 |
| 54 virtual ~UserImageLoader(); | 58 virtual ~UserImageLoader(); |
| 55 | 59 |
| 56 // Method that reads the file on the file thread and starts decoding it in | 60 // Method that reads the file on the file thread and starts decoding it in |
|
Nikita (slow)
2013/01/22 11:30:54
nit: Comment should be updated now.
bshe
2013/01/22 15:36:26
Done.
| |
| 57 // sandboxed process. | 61 // sandboxed process. |
| 58 void LoadImage(const std::string& filepath, const ImageInfo& image_info); | 62 void LoadImage(const std::string& filepath, |
| 63 const ImageInfo& image_info, | |
| 64 scoped_refptr<base::SequencedTaskRunner> task_runner); | |
| 59 | 65 |
| 60 // ImageDecoder::Delegate implementation. | 66 // ImageDecoder::Delegate implementation. |
| 61 virtual void OnImageDecoded(const ImageDecoder* decoder, | 67 virtual void OnImageDecoded(const ImageDecoder* decoder, |
| 62 const SkBitmap& decoded_image) OVERRIDE; | 68 const SkBitmap& decoded_image) OVERRIDE; |
| 63 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; | 69 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; |
| 64 | 70 |
| 65 // The message loop object of the thread in which we notify the delegate. | 71 // The message loop object of the thread in which we notify the delegate. |
| 66 MessageLoop* target_message_loop_; | 72 MessageLoop* target_message_loop_; |
| 67 | 73 |
| 68 // Specify how the file should be decoded in the utility process. | 74 // Specify how the file should be decoded in the utility process. |
| 69 const ImageDecoder::ImageCodec image_codec_; | 75 const ImageDecoder::ImageCodec image_codec_; |
| 70 | 76 |
| 77 // Proctect image_info_map_ | |
| 78 base::Lock lock_; | |
| 79 | |
| 71 // Holds info structures about all images we're trying to decode. | 80 // Holds info structures about all images we're trying to decode. |
| 72 // Accessed only on FILE thread. | 81 // Accessed only on FILE thread. |
|
Nikita (slow)
2013/01/22 11:30:54
nit: Comment should be updated now.
bshe
2013/01/22 15:36:26
Done.
| |
| 73 ImageInfoMap image_info_map_; | 82 ImageInfoMap image_info_map_; |
| 74 | 83 |
| 75 DISALLOW_COPY_AND_ASSIGN(UserImageLoader); | 84 DISALLOW_COPY_AND_ASSIGN(UserImageLoader); |
| 76 }; | 85 }; |
| 77 | 86 |
| 78 } // namespace chromeos | 87 } // namespace chromeos |
| 79 | 88 |
| 80 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_LOADER_H_ | 89 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_LOADER_H_ |
| OLD | NEW |