| 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 COMPONENTS_USER_MANAGER_USER_IMAGE_USER_IMAGE_H_ | 5 #ifndef COMPONENTS_USER_MANAGER_USER_IMAGE_USER_IMAGE_H_ |
| 6 #define COMPONENTS_USER_MANAGER_USER_IMAGE_USER_IMAGE_H_ | 6 #define COMPONENTS_USER_MANAGER_USER_IMAGE_USER_IMAGE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/ref_counted_memory.h" |
| 13 #include "components/user_manager/user_manager_export.h" | 14 #include "components/user_manager/user_manager_export.h" |
| 14 #include "ui/gfx/image/image_skia.h" | 15 #include "ui/gfx/image/image_skia.h" |
| 15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 16 | 17 |
| 17 namespace user_manager { | 18 namespace user_manager { |
| 18 | 19 |
| 19 // Wrapper class storing a still image and its bytes representation for | 20 // Wrapper class storing a still image and its bytes representation for |
| 20 // WebUI in a web-compatible format such as JPEG. Could be used for storing | 21 // WebUI in a web-compatible format such as JPEG. Could be used for storing |
| 21 // profile images and user wallpapers. | 22 // profile images and user wallpapers. |
| 22 class USER_MANAGER_EXPORT UserImage { | 23 class USER_MANAGER_EXPORT UserImage { |
| 23 public: | 24 public: |
| 24 // Used to store bytes representation for WebUI. | |
| 25 // TODO(ivankr): replace with RefCountedMemory to prevent copying. | |
| 26 typedef std::vector<unsigned char> Bytes; | |
| 27 | |
| 28 // Encodes the given bitmap to bytes representation for WebUI. Returns null | 25 // Encodes the given bitmap to bytes representation for WebUI. Returns null |
| 29 // on failure. | 26 // on failure. |
| 30 static std::unique_ptr<Bytes> Encode(const SkBitmap& bitmap); | 27 static scoped_refptr<base::RefCountedBytes> Encode(const SkBitmap& bitmap); |
| 31 | 28 |
| 32 // Creates a new instance from a given still frame and tries to encode it | 29 // Creates a new instance from a given still frame and tries to encode it |
| 33 // to bytes representation for WebUI. Always returns a non-null result. | 30 // to bytes representation for WebUI. Always returns a non-null result. |
| 34 // TODO(ivankr): remove eventually. | 31 // TODO(ivankr): remove eventually. |
| 35 static std::unique_ptr<UserImage> CreateAndEncode( | 32 static std::unique_ptr<UserImage> CreateAndEncode( |
| 36 const gfx::ImageSkia& image); | 33 const gfx::ImageSkia& image); |
| 37 | 34 |
| 38 // Create instance with an empty still frame and no bytes | 35 // Create instance with an empty still frame and no bytes |
| 39 // representation for WebUI. | 36 // representation for WebUI. |
| 40 UserImage(); | 37 UserImage(); |
| 41 | 38 |
| 42 // Creates a new instance from a given still frame without any bytes | 39 // Creates a new instance from a given still frame without any bytes |
| 43 // representation for WebUI. | 40 // representation for WebUI. |
| 44 explicit UserImage(const gfx::ImageSkia& image); | 41 explicit UserImage(const gfx::ImageSkia& image); |
| 45 | 42 |
| 46 // Creates a new instance from a given still frame and bytes | 43 // Creates a new instance from a given still frame and bytes |
| 47 // representation for WebUI. | 44 // representation for WebUI. |
| 48 // TODO(crbug.com/593251): Remove the data copy via |image_bytes|. | 45 UserImage(const gfx::ImageSkia& image, |
| 49 UserImage(const gfx::ImageSkia& image, const Bytes& image_bytes); | 46 scoped_refptr<base::RefCountedBytes> image_bytes); |
| 50 | 47 |
| 51 virtual ~UserImage(); | 48 virtual ~UserImage(); |
| 52 | 49 |
| 53 const gfx::ImageSkia& image() const { return image_; } | 50 const gfx::ImageSkia& image() const { return image_; } |
| 54 | 51 |
| 55 // Optional bytes representation of the still image for WebUI. | 52 // Optional bytes representation of the still image for WebUI. |
| 56 bool has_image_bytes() const { return has_image_bytes_; } | 53 bool has_image_bytes() const { return image_bytes_ != nullptr; } |
| 57 const Bytes& image_bytes() const { return image_bytes_; } | 54 scoped_refptr<base::RefCountedBytes> image_bytes() const { |
| 55 return image_bytes_; |
| 56 } |
| 58 | 57 |
| 59 // URL from which this image was originally downloaded, if any. | 58 // URL from which this image was originally downloaded, if any. |
| 60 void set_url(const GURL& url) { url_ = url; } | 59 void set_url(const GURL& url) { url_ = url; } |
| 61 GURL url() const { return url_; } | 60 GURL url() const { return url_; } |
| 62 | 61 |
| 63 // Whether |image_bytes| contains data in format that is considered safe to | 62 // Whether |image_bytes| contains data in format that is considered safe to |
| 64 // decode in sensitive environment (on Login screen). | 63 // decode in sensitive environment (on Login screen). |
| 65 bool is_safe_format() const { return is_safe_format_; } | 64 bool is_safe_format() const { return is_safe_format_; } |
| 66 void MarkAsSafe(); | 65 void MarkAsSafe(); |
| 67 | 66 |
| 68 const base::FilePath& file_path() const { return file_path_; } | 67 const base::FilePath& file_path() const { return file_path_; } |
| 69 void set_file_path(const base::FilePath& file_path) { | 68 void set_file_path(const base::FilePath& file_path) { |
| 70 file_path_ = file_path; | 69 file_path_ = file_path; |
| 71 } | 70 } |
| 72 | 71 |
| 73 private: | 72 private: |
| 74 gfx::ImageSkia image_; | 73 gfx::ImageSkia image_; |
| 75 bool has_image_bytes_; | 74 scoped_refptr<base::RefCountedBytes> image_bytes_; |
| 76 Bytes image_bytes_; | |
| 77 GURL url_; | 75 GURL url_; |
| 78 | 76 |
| 79 // If image was loaded from the local file, file path is stored here. | 77 // If image was loaded from the local file, file path is stored here. |
| 80 base::FilePath file_path_; | 78 base::FilePath file_path_; |
| 81 bool is_safe_format_; | 79 bool is_safe_format_ = false; |
| 82 | 80 |
| 83 DISALLOW_COPY_AND_ASSIGN(UserImage); | 81 DISALLOW_COPY_AND_ASSIGN(UserImage); |
| 84 }; | 82 }; |
| 85 | 83 |
| 86 } // namespace user_manager | 84 } // namespace user_manager |
| 87 | 85 |
| 88 #endif // COMPONENTS_USER_MANAGER_USER_IMAGE_USER_IMAGE_H_ | 86 #endif // COMPONENTS_USER_MANAGER_USER_IMAGE_USER_IMAGE_H_ |
| OLD | NEW |