Don't preload rarely seen large images
[chromium-blink-merge.git] / components / user_manager / user_image / user_image.h
blob03da41b633353efb64d9282d540262a647a4bcfd
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.
5 #ifndef COMPONENTS_USER_MANAGER_USER_IMAGE_USER_IMAGE_H_
6 #define COMPONENTS_USER_MANAGER_USER_IMAGE_USER_IMAGE_H_
8 #include <string>
9 #include <vector>
11 #include "components/user_manager/user_manager_export.h"
12 #include "ui/gfx/image/image_skia.h"
13 #include "url/gurl.h"
15 namespace user_manager {
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;
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);
29 // Create instance with an empty still frame and no raw data.
30 UserImage();
32 // Creates a new instance from a given still frame without any raw data.
33 explicit UserImage(const gfx::ImageSkia& image);
35 // Creates a new instance from a given still frame and raw representation.
36 UserImage(const gfx::ImageSkia& image, const RawImage& raw_image);
38 virtual ~UserImage();
40 const gfx::ImageSkia& image() const { return image_; }
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_; }
46 // Discards the stored raw image, freeing used memory.
47 void DiscardRawImage();
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_; }
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();
58 const std::string& file_path() const { return file_path_; }
59 void set_file_path(const std::string& file_path) { file_path_ = file_path; }
61 private:
62 gfx::ImageSkia image_;
63 bool has_raw_image_;
64 RawImage raw_image_;
65 GURL url_;
67 // If image was loaded from the local file, file path is stored here.
68 std::string file_path_;
69 bool is_safe_format_;
72 } // namespace user_manager
74 #endif // COMPONENTS_USER_MANAGER_USER_IMAGE_USER_IMAGE_H_