Chromium Code Reviews| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "components/user_manager/user_manager_export.h" | 12 #include "components/user_manager/user_manager_export.h" |
| 13 #include "ui/gfx/image/image_skia.h" | 13 #include "ui/gfx/image/image_skia.h" |
| 14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 15 | 15 |
| 16 namespace user_manager { | 16 namespace user_manager { |
| 17 | 17 |
| 18 // Wrapper class storing a still image and it's raw representation. Could be | 18 // Wrapper class storing a still image and its bytes representation for |
| 19 // used for storing profile images and user wallpapers. | 19 // WebUI in a web-compatible format such as JPEG. Could be used for storing |
| 20 // profile images and user wallpapers. | |
| 20 class USER_MANAGER_EXPORT UserImage { | 21 class USER_MANAGER_EXPORT UserImage { |
| 21 public: | 22 public: |
| 23 // Used to store bytes representation for WebUI. | |
| 22 // TODO(ivankr): replace with RefCountedMemory to prevent copying. | 24 // TODO(ivankr): replace with RefCountedMemory to prevent copying. |
| 23 typedef std::vector<unsigned char> RawImage; | 25 typedef std::vector<unsigned char> Bytes; |
| 24 | 26 |
| 25 // Creates a new instance from a given still frame and tries to encode raw | 27 // Creates a new instance from a given still frame and tries to encode it |
| 26 // representation for it. | 28 // to bytes representation for WebUI. |
| 27 // TODO(ivankr): remove eventually. | 29 // TODO(ivankr): remove eventually. |
| 28 static UserImage CreateAndEncode(const gfx::ImageSkia& image); | 30 static UserImage CreateAndEncode(const gfx::ImageSkia& image); |
| 29 | 31 |
| 30 // Create instance with an empty still frame and no raw data. | 32 // Create instance with an empty still frame and no bytes |
| 33 // representation for WebUI. | |
| 31 UserImage(); | 34 UserImage(); |
| 32 | 35 |
| 33 // Creates a new instance from a given still frame without any raw data. | 36 // Creates a new instance from a given still frame without any bytes |
| 37 // representation for WebUI. | |
| 34 explicit UserImage(const gfx::ImageSkia& image); | 38 explicit UserImage(const gfx::ImageSkia& image); |
| 35 | 39 |
| 36 // Creates a new instance from a given still frame and raw representation. | 40 // Creates a new instance from a given still frame and bytes |
| 37 UserImage(const gfx::ImageSkia& image, const RawImage& raw_image); | 41 // representation for WebUI. |
| 42 UserImage(const gfx::ImageSkia& image, const Bytes& image_bytes); | |
| 38 | 43 |
| 39 virtual ~UserImage(); | 44 virtual ~UserImage(); |
| 40 | 45 |
| 41 const gfx::ImageSkia& image() const { return image_; } | 46 const gfx::ImageSkia& image() const { return image_; } |
| 42 | 47 |
| 43 // Optional raw representation of the still image. | 48 // Optional bytes representation of the still image for WebUI. |
| 44 bool has_raw_image() const { return has_raw_image_; } | 49 bool has_image_bytes() const { return has_image_bytes_; } |
| 45 const RawImage& raw_image() const { return raw_image_; } | 50 const Bytes& image_bytes() const { return image_bytes_; } |
| 46 | 51 |
| 47 // Discards the stored raw image, freeing used memory. | 52 // Discards the stored bytes representation, freeing used memory. |
| 48 void DiscardRawImage(); | 53 void DiscardBytes(); |
|
hashimoto
2016/03/01 08:04:22
Is this needed?
satorux1
2016/03/01 08:11:09
good catch. not used at all. removed!
| |
| 49 | 54 |
| 50 // URL from which this image was originally downloaded, if any. | 55 // URL from which this image was originally downloaded, if any. |
| 51 void set_url(const GURL& url) { url_ = url; } | 56 void set_url(const GURL& url) { url_ = url; } |
| 52 GURL url() const { return url_; } | 57 GURL url() const { return url_; } |
| 53 | 58 |
| 54 // Whether |raw_image| contains data in format that is considered safe to | 59 // Whether |image_bytes| contains data in format that is considered safe to |
| 55 // decode in sensitive environment (on Login screen). | 60 // decode in sensitive environment (on Login screen). |
| 56 bool is_safe_format() const { return is_safe_format_; } | 61 bool is_safe_format() const { return is_safe_format_; } |
| 57 void MarkAsSafe(); | 62 void MarkAsSafe(); |
| 58 | 63 |
| 59 const base::FilePath& file_path() const { return file_path_; } | 64 const base::FilePath& file_path() const { return file_path_; } |
| 60 void set_file_path(const base::FilePath& file_path) { | 65 void set_file_path(const base::FilePath& file_path) { |
| 61 file_path_ = file_path; | 66 file_path_ = file_path; |
| 62 } | 67 } |
| 63 | 68 |
| 64 private: | 69 private: |
| 65 gfx::ImageSkia image_; | 70 gfx::ImageSkia image_; |
| 66 bool has_raw_image_; | 71 bool has_image_bytes_; |
| 67 RawImage raw_image_; | 72 Bytes image_bytes_; |
| 68 GURL url_; | 73 GURL url_; |
| 69 | 74 |
| 70 // If image was loaded from the local file, file path is stored here. | 75 // If image was loaded from the local file, file path is stored here. |
| 71 base::FilePath file_path_; | 76 base::FilePath file_path_; |
| 72 bool is_safe_format_; | 77 bool is_safe_format_; |
| 73 }; | 78 }; |
| 74 | 79 |
| 75 } // namespace user_manager | 80 } // namespace user_manager |
| 76 | 81 |
| 77 #endif // COMPONENTS_USER_MANAGER_USER_IMAGE_USER_IMAGE_H_ | 82 #endif // COMPONENTS_USER_MANAGER_USER_IMAGE_USER_IMAGE_H_ |
| OLD | NEW |