| 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 CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_LOADER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_LOADER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_LOADER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_LOADER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <queue> |
| 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 "chrome/browser/image_decoder.h" | 14 #include "chrome/browser/image_decoder.h" |
| 15 | 15 |
| 16 class SkBitmap; | 16 class SkBitmap; |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 ImageInfo(const std::string& file_path, | 60 ImageInfo(const std::string& file_path, |
| 61 int pixels_per_side, | 61 int pixels_per_side, |
| 62 const LoadedCallback& loaded_cb); | 62 const LoadedCallback& loaded_cb); |
| 63 ~ImageInfo(); | 63 ~ImageInfo(); |
| 64 | 64 |
| 65 const std::string file_path; | 65 const std::string file_path; |
| 66 const int pixels_per_side; | 66 const int pixels_per_side; |
| 67 const LoadedCallback loaded_cb; | 67 const LoadedCallback loaded_cb; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 typedef std::map<const ImageDecoder*, ImageInfo> ImageInfoMap; | 70 typedef std::queue<ImageInfo> ImageInfoQueue; |
| 71 typedef std::queue<std::vector<unsigned char>> ImageDataQueue; |
| 71 | 72 |
| 72 ~UserImageLoader() override; | 73 ~UserImageLoader() override; |
| 73 | 74 |
| 74 // Reads the image from |image_info.file_path| and starts the decoding | 75 // Reads the image from |image_info.file_path| and starts the decoding |
| 75 // process. This method may only be invoked via the |background_task_runner_|. | 76 // process. This method may only be invoked via the |background_task_runner_|. |
| 76 void ReadAndDecodeImage(const ImageInfo& image_info); | 77 void ReadAndDecodeImage(const ImageInfo& image_info); |
| 77 | 78 |
| 78 // Decodes the image |data|. This method may only be invoked via the | 79 // Decodes the image |data|. This method may only be invoked via the |
| 79 // |background_task_runner_|. | 80 // |background_task_runner_|. |
| 80 void DecodeImage(const scoped_ptr<std::string> data, | 81 void DecodeImage(const scoped_ptr<std::string> data, |
| 81 const ImageInfo& image_info); | 82 const ImageInfo& image_info); |
| 82 | 83 |
| 83 // ImageDecoder::Delegate implementation. These callbacks will only be invoked | 84 // ImageDecoder::Delegate implementation. These callbacks will only be invoked |
| 84 // via the |background_task_runner_|. | 85 // via the |background_task_runner_|. |
| 85 void OnImageDecoded(const ImageDecoder* decoder, | 86 void OnImageDecoded(const SkBitmap& decoded_image) override; |
| 86 const SkBitmap& decoded_image) override; | 87 void OnDecodeImageFailed() override; |
| 87 void OnDecodeImageFailed(const ImageDecoder* decoder) override; | |
| 88 | 88 |
| 89 // The foreground task runner on which |this| is instantiated, Start() is | 89 // The foreground task runner on which |this| is instantiated, Start() is |
| 90 // called and LoadedCallbacks are invoked. | 90 // called and LoadedCallbacks are invoked. |
| 91 scoped_refptr<base::SequencedTaskRunner> foreground_task_runner_; | 91 scoped_refptr<base::SequencedTaskRunner> foreground_task_runner_; |
| 92 | 92 |
| 93 // The background task runner on which file I/O, image decoding and resizing | 93 // The background task runner on which file I/O, image decoding and resizing |
| 94 // are done. | 94 // are done. |
| 95 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; | 95 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; |
| 96 | 96 |
| 97 // Specify how the file should be decoded in the utility process. | 97 // Specify how the file should be decoded in the utility process. |
| 98 const ImageDecoder::ImageCodec image_codec_; | 98 const ImageDecoder::ImageCodec image_codec_; |
| 99 | 99 |
| 100 // Holds information about the images currently being decoded. Accessed via | 100 // Holds information about the images currently being decoded. Accessed via |
| 101 // |background_task_runner_| only. | 101 // |background_task_runner_| only. |
| 102 ImageInfoMap image_info_map_; | 102 ImageInfoQueue image_info_queue_; |
| 103 ImageDataQueue image_data_queue_; |
| 103 | 104 |
| 104 DISALLOW_COPY_AND_ASSIGN(UserImageLoader); | 105 DISALLOW_COPY_AND_ASSIGN(UserImageLoader); |
| 105 }; | 106 }; |
| 106 | 107 |
| 107 } // namespace chromeos | 108 } // namespace chromeos |
| 108 | 109 |
| 109 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_LOADER_H_ | 110 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_LOADER_H_ |
| OLD | NEW |