Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / user.h
blobc61c0bb8f6a2c8e02426e7e10a33862e84230c6d
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.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/strings/string16.h"
13 #include "chrome/browser/chromeos/login/user_image.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "ui/gfx/image/image_skia.h"
17 namespace chromeos {
19 extern const int kDefaultImagesCount;
21 // User context data that is being exchanged between part of ChromeOS
22 // authentication mechanism. Includes credentials:
23 // |username|, |password|, |auth_code| and |username_hash| which is returned
24 // back once user homedir is mounted. |username_hash| is used to identify
25 // user homedir mount point.
26 struct UserContext {
27 UserContext();
28 UserContext(const std::string& username,
29 const std::string& password,
30 const std::string& auth_code);
31 UserContext(const std::string& username,
32 const std::string& password,
33 const std::string& auth_code,
34 const std::string& username_hash);
35 UserContext(const std::string& username,
36 const std::string& password,
37 const std::string& auth_code,
38 const std::string& username_hash,
39 bool using_oauth);
40 virtual ~UserContext();
41 bool operator==(const UserContext& context) const;
42 std::string username;
43 std::string password;
44 std::string auth_code;
45 std::string username_hash;
46 bool using_oauth;
49 // A class representing information about a previously logged in user.
50 // Each user has a canonical email (username), returned by |email()| and
51 // may have a different displayed email (in the raw form as entered by user),
52 // returned by |displayed_email()|.
53 // Displayed emails are for use in UI only, anywhere else users must be referred
54 // to by |email()|.
55 class User {
56 public:
57 // The user type. Used in a histogram; do not modify existing types.
58 typedef enum {
59 // Regular user, has a user name and password.
60 USER_TYPE_REGULAR = 0,
61 // Guest user, logs in without authentication.
62 USER_TYPE_GUEST = 1,
63 // Retail mode user, logs in without authentication. This is a special user
64 // type used in retail mode only.
65 USER_TYPE_RETAIL_MODE = 2,
66 // Public account user, logs in without authentication. Available only if
67 // enabled through policy.
68 USER_TYPE_PUBLIC_ACCOUNT = 3,
69 // Locally managed user, logs in only with local authentication.
70 USER_TYPE_LOCALLY_MANAGED = 4,
71 // Kiosk app robot, logs in without authentication.
72 USER_TYPE_KIOSK_APP = 5,
73 // Maximum histogram value.
74 NUM_USER_TYPES = 6
75 } UserType;
77 // User OAuth token status according to the last check.
78 // Please note that enum values 1 and 2 were used for OAuth1 status and are
79 // deprecated now.
80 typedef enum {
81 OAUTH_TOKEN_STATUS_UNKNOWN = 0,
82 OAUTH2_TOKEN_STATUS_INVALID = 3,
83 OAUTH2_TOKEN_STATUS_VALID = 4,
84 } OAuthTokenStatus;
86 // Returned as |image_index| when user-selected file or photo is used as
87 // user image.
88 static const int kExternalImageIndex = -1;
89 // Returned as |image_index| when user profile image is used as user image.
90 static const int kProfileImageIndex = -2;
91 static const int kInvalidImageIndex = -3;
93 enum WallpaperType {
94 DAILY = 0,
95 CUSTOMIZED = 1,
96 DEFAULT = 2,
97 UNKNOWN = 3,
98 ONLINE = 4,
99 WALLPAPER_TYPE_COUNT = 5
102 // Returns the user type.
103 virtual UserType GetType() const = 0;
105 // The email the user used to log in.
106 const std::string& email() const { return email_; }
108 // Returns the human name to display for this user.
109 base::string16 GetDisplayName() const;
111 // Returns given name of user, or empty string if given name is unknown.
112 const base::string16& given_name() const { return given_name_; }
114 // Returns the account name part of the email. Use the display form of the
115 // email if available and use_display_name == true. Otherwise use canonical.
116 std::string GetAccountName(bool use_display_email) const;
118 // The image for this user.
119 const gfx::ImageSkia& image() const { return user_image_.image(); }
121 // Whether the user has a default image.
122 bool HasDefaultImage() const;
124 // True if user image can be synced.
125 virtual bool CanSyncImage() const;
127 int image_index() const { return image_index_; }
128 bool has_raw_image() const { return user_image_.has_raw_image(); }
129 // Returns raw representation of static user image.
130 const UserImage::RawImage& raw_image() const {
131 return user_image_.raw_image();
133 bool has_animated_image() const { return user_image_.has_animated_image(); }
134 // Returns raw representation of animated user image.
135 const UserImage::RawImage& animated_image() const {
136 return user_image_.animated_image();
139 // Whether |raw_image| contains data in format that is considered safe to
140 // decode in sensitive environment (on Login screen).
141 bool image_is_safe_format() const { return user_image_.is_safe_format(); }
143 // Returns the URL of user image, if there is any. Currently only the profile
144 // image has a URL, for other images empty URL is returned.
145 GURL image_url() const { return user_image_.url(); }
147 // True if user image is a stub (while real image is being loaded from file).
148 bool image_is_stub() const { return image_is_stub_; }
150 // True if image is being loaded from file.
151 bool image_is_loading() const { return image_is_loading_; }
153 // OAuth token status for this user.
154 OAuthTokenStatus oauth_token_status() const { return oauth_token_status_; }
156 // The displayed user name.
157 base::string16 display_name() const { return display_name_; }
159 // The displayed (non-canonical) user email.
160 virtual std::string display_email() const;
162 // True if the user's session can be locked (i.e. the user has a password with
163 // which to unlock the session).
164 virtual bool can_lock() const;
166 virtual std::string username_hash() const;
168 // True if current user is logged in.
169 virtual bool is_logged_in() const;
171 // True if current user is active within the current session.
172 virtual bool is_active() const;
174 // True if the user Profile is created.
175 bool is_profile_created() const {
176 return profile_is_created_;
179 protected:
180 friend class SupervisedUserManagerImpl;
181 friend class UserManagerImpl;
182 friend class UserImageManagerImpl;
183 // For testing:
184 friend class MockUserManager;
185 friend class FakeUserManager;
187 // Do not allow anyone else to create new User instances.
188 static User* CreateRegularUser(const std::string& email);
189 static User* CreateGuestUser();
190 static User* CreateKioskAppUser(const std::string& kiosk_app_username);
191 static User* CreateLocallyManagedUser(const std::string& username);
192 static User* CreateRetailModeUser();
193 static User* CreatePublicAccountUser(const std::string& email);
195 explicit User(const std::string& email);
196 virtual ~User();
198 const std::string* GetAccountLocale() const {
199 return account_locale_.get();
202 // Setters are private so only UserManager can call them.
203 void SetAccountLocale(const std::string& resolved_account_locale);
205 void SetImage(const UserImage& user_image, int image_index);
207 void SetImageURL(const GURL& image_url);
209 // Sets a stub image until the next |SetImage| call. |image_index| may be
210 // one of |kExternalImageIndex| or |kProfileImageIndex|.
211 // If |is_loading| is |true|, that means user image is being loaded from file.
212 void SetStubImage(int image_index, bool is_loading);
214 void set_oauth_token_status(OAuthTokenStatus status) {
215 oauth_token_status_ = status;
218 void set_display_name(const base::string16& display_name) {
219 display_name_ = display_name;
222 void set_given_name(const base::string16& given_name) { given_name_ = given_name; }
224 void set_display_email(const std::string& display_email) {
225 display_email_ = display_email;
228 const UserImage& user_image() const { return user_image_; }
230 void set_username_hash(const std::string& username_hash) {
231 username_hash_ = username_hash;
234 void set_is_logged_in(bool is_logged_in) {
235 is_logged_in_ = is_logged_in;
238 void set_is_active(bool is_active) {
239 is_active_ = is_active;
242 void set_profile_is_created() {
243 profile_is_created_ = true;
246 // True if user has google account (not a guest or managed user).
247 bool has_gaia_account() const;
249 private:
250 std::string email_;
251 base::string16 display_name_;
252 base::string16 given_name_;
253 // The displayed user email, defaults to |email_|.
254 std::string display_email_;
255 UserImage user_image_;
256 OAuthTokenStatus oauth_token_status_;
258 // This is set to chromeos locale if account data has been downloaded.
259 // (Or failed to download, but at least one download attempt finished).
260 // An empty string indicates error in data load, or in
261 // translation of Account locale to chromeos locale.
262 scoped_ptr<std::string> account_locale_;
264 // Used to identify homedir mount point.
265 std::string username_hash_;
267 // Either index of a default image for the user, |kExternalImageIndex| or
268 // |kProfileImageIndex|.
269 int image_index_;
271 // True if current user image is a stub set by a |SetStubImage| call.
272 bool image_is_stub_;
274 // True if current user image is being loaded from file.
275 bool image_is_loading_;
277 // True if user is currently logged in in current session.
278 bool is_logged_in_;
280 // True if user is currently logged in and active in current session.
281 bool is_active_;
283 // True if user Profile is created
284 bool profile_is_created_;
286 DISALLOW_COPY_AND_ASSIGN(User);
289 // List of known users.
290 typedef std::vector<User*> UserList;
292 } // namespace chromeos
294 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_H_