Mac: Fix performance issues with remote CoreAnimation
[chromium-blink-merge.git] / components / user_manager / user.h
blob907c365af991b5e6357e6b80c6f4d84128314dbe
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_H_
6 #define COMPONENTS_USER_MANAGER_USER_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/strings/string16.h"
13 #include "components/user_manager/user_image/user_image.h"
14 #include "components/user_manager/user_info.h"
15 #include "components/user_manager/user_manager_export.h"
16 #include "components/user_manager/user_type.h"
17 #include "third_party/skia/include/core/SkBitmap.h"
18 #include "ui/gfx/image/image_skia.h"
20 namespace chromeos {
21 class ChromeUserManagerImpl;
22 class FakeLoginUtils;
23 class FakeUserManager;
24 class MockUserManager;
25 class SupervisedUserManagerImpl;
26 class UserAddingScreenTest;
27 class UserImageManagerImpl;
28 class UserSessionManager;
31 namespace user_manager {
33 class UserManagerBase;
35 // A class representing information about a previously logged in user.
36 // Each user has a canonical email (username), returned by |email()| and
37 // may have a different displayed email (in the raw form as entered by user),
38 // returned by |displayed_email()|.
39 // Displayed emails are for use in UI only, anywhere else users must be referred
40 // to by |email()|.
41 class USER_MANAGER_EXPORT User : public UserInfo {
42 public:
43 // User OAuth token status according to the last check.
44 // Please note that enum values 1 and 2 were used for OAuth1 status and are
45 // deprecated now.
46 typedef enum {
47 OAUTH_TOKEN_STATUS_UNKNOWN = 0,
48 OAUTH2_TOKEN_STATUS_INVALID = 3,
49 OAUTH2_TOKEN_STATUS_VALID = 4,
50 } OAuthTokenStatus;
52 // These special values are used instead of actual default image indices.
53 typedef enum {
54 USER_IMAGE_INVALID = -3,
56 // Returned as |image_index| when user profile image is used as user image.
57 USER_IMAGE_PROFILE = -2,
59 // Returned as |image_index| when user-selected file or photo is used as
60 // user image.
61 USER_IMAGE_EXTERNAL = -1,
62 } UserImageType;
64 // This enum is used to define the buckets for an enumerated UMA histogram.
65 // Hence,
66 // (a) existing enumerated constants should never be deleted or reordered,
67 // (b) new constants should only be appended at the end of the enumeration.
68 enum WallpaperType {
69 /* DAILY = 0 */ // Removed.
70 CUSTOMIZED = 1, // Selected by user.
71 DEFAULT = 2, // Default.
72 /* UNKNOWN = 3 */ // Removed.
73 ONLINE = 4, // WallpaperInfo.location denotes an URL.
74 POLICY = 5, // Controlled by policy, can't be changed by the user.
75 WALLPAPER_TYPE_COUNT = 6
78 // Returns true if user type has gaia account.
79 static bool TypeHasGaiaAccount(UserType user_type);
81 // Returns the user type.
82 virtual UserType GetType() const = 0;
84 // The email the user used to log in.
85 const std::string& email() const { return email_; }
87 // The displayed user name.
88 base::string16 display_name() const { return display_name_; }
90 // UserInfo
91 std::string GetEmail() const override;
92 base::string16 GetDisplayName() const override;
93 base::string16 GetGivenName() const override;
94 const gfx::ImageSkia& GetImage() const override;
95 std::string GetUserID() const override;
97 // Allows managing supervised status of the user. Used for RegularUser.
98 virtual void SetIsSupervised(bool is_supervised);
100 // Returns true if user has gaia account. True for users of types
101 // USER_TYPE_REGULAR and USER_TYPE_REGULAR_SUPERVISED.
102 virtual bool HasGaiaAccount() const;
104 // Returns true if user is supervised.
105 virtual bool IsSupervised() const;
107 // Returns the account name part of the email. Use the display form of the
108 // email if available and use_display_name == true. Otherwise use canonical.
109 std::string GetAccountName(bool use_display_email) const;
111 // Whether the user has a default image.
112 bool HasDefaultImage() const;
114 // True if user image can be synced.
115 virtual bool CanSyncImage() const;
117 int image_index() const { return image_index_; }
118 bool has_raw_image() const { return user_image_.has_raw_image(); }
119 // Returns raw representation of static user image.
120 const UserImage::RawImage& raw_image() const {
121 return user_image_.raw_image();
124 // Whether |raw_image| contains data in format that is considered safe to
125 // decode in sensitive environment (on Login screen).
126 bool image_is_safe_format() const { return user_image_.is_safe_format(); }
128 // Returns the URL of user image, if there is any. Currently only the profile
129 // image has a URL, for other images empty URL is returned.
130 GURL image_url() const { return user_image_.url(); }
132 // True if user image is a stub (while real image is being loaded from file).
133 bool image_is_stub() const { return image_is_stub_; }
135 // True if image is being loaded from file.
136 bool image_is_loading() const { return image_is_loading_; }
138 // The displayed (non-canonical) user email.
139 virtual std::string display_email() const;
141 // OAuth token status for this user.
142 OAuthTokenStatus oauth_token_status() const { return oauth_token_status_; }
144 // Whether online authentication against GAIA should be enforced during the
145 // user's next sign-in.
146 bool force_online_signin() const { return force_online_signin_; }
148 // True if the user's session can be locked (i.e. the user has a password with
149 // which to unlock the session).
150 bool can_lock() const;
152 // Returns empty string when home dir hasn't been mounted yet.
153 std::string username_hash() const;
155 // True if current user is logged in.
156 bool is_logged_in() const;
158 // True if current user is active within the current session.
159 bool is_active() const;
161 // True if the user Profile is created.
162 bool is_profile_created() const { return profile_is_created_; }
164 protected:
165 friend class UserManagerBase;
166 friend class chromeos::ChromeUserManagerImpl;
167 friend class chromeos::SupervisedUserManagerImpl;
168 friend class chromeos::UserImageManagerImpl;
169 friend class chromeos::UserSessionManager;
171 // For testing:
172 friend class chromeos::MockUserManager;
173 friend class chromeos::FakeLoginUtils;
174 friend class chromeos::FakeUserManager;
175 friend class chromeos::UserAddingScreenTest;
177 // Do not allow anyone else to create new User instances.
178 static User* CreateRegularUser(const std::string& email);
179 static User* CreateGuestUser();
180 static User* CreateKioskAppUser(const std::string& kiosk_app_username);
181 static User* CreateSupervisedUser(const std::string& username);
182 static User* CreateRetailModeUser();
183 static User* CreatePublicAccountUser(const std::string& email);
185 explicit User(const std::string& email);
186 ~User() override;
188 const std::string* GetAccountLocale() const { return account_locale_.get(); }
190 // Setters are private so only UserManager can call them.
191 void SetAccountLocale(const std::string& resolved_account_locale);
193 void SetImage(const UserImage& user_image, int image_index);
195 void SetImageURL(const GURL& image_url);
197 // Sets a stub image until the next |SetImage| call. |image_index| may be
198 // one of |USER_IMAGE_EXTERNAL| or |USER_IMAGE_PROFILE|.
199 // If |is_loading| is |true|, that means user image is being loaded from file.
200 void SetStubImage(const UserImage& stub_user_image,
201 int image_index,
202 bool is_loading);
204 void set_display_name(const base::string16& display_name) {
205 display_name_ = display_name;
208 void set_given_name(const base::string16& given_name) {
209 given_name_ = given_name;
212 void set_display_email(const std::string& display_email) {
213 display_email_ = display_email;
216 const UserImage& user_image() const { return user_image_; }
218 void set_oauth_token_status(OAuthTokenStatus status) {
219 oauth_token_status_ = status;
222 void set_force_online_signin(bool force_online_signin) {
223 force_online_signin_ = force_online_signin;
226 void set_username_hash(const std::string& username_hash) {
227 username_hash_ = username_hash;
230 void set_is_logged_in(bool is_logged_in) { is_logged_in_ = is_logged_in; }
232 void set_can_lock(bool can_lock) { can_lock_ = can_lock; }
234 void set_is_active(bool is_active) { is_active_ = is_active; }
236 void set_profile_is_created() { profile_is_created_ = true; }
238 // True if user has google account (not a guest or managed user).
239 bool has_gaia_account() const;
241 private:
242 std::string email_;
243 base::string16 display_name_;
244 base::string16 given_name_;
245 // The displayed user email, defaults to |email_|.
246 std::string display_email_;
247 UserImage user_image_;
248 OAuthTokenStatus oauth_token_status_;
249 bool force_online_signin_;
251 // This is set to chromeos locale if account data has been downloaded.
252 // (Or failed to download, but at least one download attempt finished).
253 // An empty string indicates error in data load, or in
254 // translation of Account locale to chromeos locale.
255 scoped_ptr<std::string> account_locale_;
257 // Used to identify homedir mount point.
258 std::string username_hash_;
260 // Either index of a default image for the user, |USER_IMAGE_EXTERNAL| or
261 // |USER_IMAGE_PROFILE|.
262 int image_index_;
264 // True if current user image is a stub set by a |SetStubImage| call.
265 bool image_is_stub_;
267 // True if current user image is being loaded from file.
268 bool image_is_loading_;
270 // True if user is able to lock screen.
271 bool can_lock_;
273 // True if user is currently logged in in current session.
274 bool is_logged_in_;
276 // True if user is currently logged in and active in current session.
277 bool is_active_;
279 // True if user Profile is created
280 bool profile_is_created_;
282 DISALLOW_COPY_AND_ASSIGN(User);
285 // List of known users.
286 typedef std::vector<User*> UserList;
288 } // namespace user_manager
290 #endif // COMPONENTS_USER_MANAGER_USER_H_