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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_H_ 7 8 #include <vector> 9 10 #include "ui/gfx/image/image_skia.h" 11 #include "url/gurl.h" 12 13 namespace chromeos { 14 15 // Wrapper class storing a still image and it's raw representation. Could be 16 // used for storing profile images (including animated profile images) and user 17 // wallpapers. 18 class UserImage { 19 public: 20 // TODO(ivankr): replace with RefCountedMemory to prevent copying. 21 typedef std::vector<unsigned char> RawImage; 22 23 // Creates a new instance from a given still frame and tries to encode raw 24 // representation for it. 25 // TODO(ivankr): remove eventually. 26 static UserImage CreateAndEncode(const gfx::ImageSkia& image); 27 28 // Create instance with an empty still frame and no raw data. 29 UserImage(); 30 31 // Creates a new instance from a given still frame without any raw data. 32 explicit UserImage(const gfx::ImageSkia& image); 33 34 // Creates a new instance from a given still frame and raw representation. 35 // |raw_image| can be animated, in which case animated_image() will return the 36 // original |raw_image| and raw_image() will return the encoded representation 37 // of |image|. 38 UserImage(const gfx::ImageSkia& image, const RawImage& raw_image); 39 40 virtual ~UserImage(); 41 42 const gfx::ImageSkia& image() const { return image_; } 43 44 // Optional raw representation of the still image. 45 bool has_raw_image() const { return has_raw_image_; } 46 const RawImage& raw_image() const { return raw_image_; } 47 48 // Discards the stored raw image, freeing used memory. 49 void DiscardRawImage(); 50 51 // Optional raw representation of the animated image. 52 bool has_animated_image() const { return has_animated_image_; } 53 const RawImage& animated_image() const { return animated_image_; } 54 55 // URL from which this image was originally downloaded, if any. 56 void set_url(const GURL& url) { url_ = url; } 57 GURL url() const { return url_; } 58 59 // Whether |raw_image| contains data in format that is considered safe to 60 // decode in sensitive environment (on Login screen). 61 bool is_safe_format() const { return is_safe_format_; } 62 void MarkAsSafe(); 63 64 private: 65 gfx::ImageSkia image_; 66 bool has_raw_image_; 67 RawImage raw_image_; 68 bool has_animated_image_; 69 RawImage animated_image_; 70 GURL url_; 71 bool is_safe_format_; 72 }; 73 74 } // namespace chromeos 75 76 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_H_ 77