Home | History | Annotate | Download | only in user_image
      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 COMPONENTS_USER_MANAGER_USER_IMAGE_USER_IMAGE_H_
      6 #define COMPONENTS_USER_MANAGER_USER_IMAGE_USER_IMAGE_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "components/user_manager/user_manager_export.h"
     12 #include "ui/gfx/image/image_skia.h"
     13 #include "url/gurl.h"
     14 
     15 namespace user_manager {
     16 
     17 // Wrapper class storing a still image and it's raw representation.  Could be
     18 // used for storing profile images and user wallpapers.
     19 class USER_MANAGER_EXPORT 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   UserImage(const gfx::ImageSkia& image, const RawImage& raw_image);
     37 
     38   virtual ~UserImage();
     39 
     40   const gfx::ImageSkia& image() const { return image_; }
     41 
     42   // Optional raw representation of the still image.
     43   bool has_raw_image() const { return has_raw_image_; }
     44   const RawImage& raw_image() const { return raw_image_; }
     45 
     46   // Discards the stored raw image, freeing used memory.
     47   void DiscardRawImage();
     48 
     49   // URL from which this image was originally downloaded, if any.
     50   void set_url(const GURL& url) { url_ = url; }
     51   GURL url() const { return url_; }
     52 
     53   // Whether |raw_image| contains data in format that is considered safe to
     54   // decode in sensitive environment (on Login screen).
     55   bool is_safe_format() const { return is_safe_format_; }
     56   void MarkAsSafe();
     57 
     58   const std::string& file_path() const { return file_path_; }
     59   void set_file_path(const std::string& file_path) { file_path_ = file_path; }
     60 
     61  private:
     62   gfx::ImageSkia image_;
     63   bool has_raw_image_;
     64   RawImage raw_image_;
     65   GURL url_;
     66 
     67   // If image was loaded from the local file, file path is stored here.
     68   std::string file_path_;
     69   bool is_safe_format_;
     70 };
     71 
     72 }  // namespace user_manager
     73 
     74 #endif  // COMPONENTS_USER_MANAGER_USER_IMAGE_USER_IMAGE_H_
     75