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