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_USER_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "ash/session/user_info.h" 12 #include "base/basictypes.h" 13 #include "base/strings/string16.h" 14 #include "chrome/browser/chromeos/login/users/avatar/user_image.h" 15 #include "third_party/skia/include/core/SkBitmap.h" 16 #include "ui/gfx/image/image_skia.h" 17 18 namespace chromeos { 19 20 extern const int kDefaultImagesCount; 21 22 // A class representing information about a previously logged in user. 23 // Each user has a canonical email (username), returned by |email()| and 24 // may have a different displayed email (in the raw form as entered by user), 25 // returned by |displayed_email()|. 26 // Displayed emails are for use in UI only, anywhere else users must be referred 27 // to by |email()|. 28 class User : public ash::UserInfo { 29 public: 30 // The user type. Used in a histogram; do not modify existing types. 31 typedef enum { 32 // Regular user, has a user name and password. 33 USER_TYPE_REGULAR = 0, 34 // Guest user, logs in without authentication. 35 USER_TYPE_GUEST = 1, 36 // Retail mode user, logs in without authentication. This is a special user 37 // type used in retail mode only. 38 USER_TYPE_RETAIL_MODE = 2, 39 // Public account user, logs in without authentication. Available only if 40 // enabled through policy. 41 USER_TYPE_PUBLIC_ACCOUNT = 3, 42 // Supervised (aka locally managed) user, logs in only with local 43 // authentication. 44 USER_TYPE_LOCALLY_MANAGED = 4, 45 // Kiosk app robot, logs in without authentication. 46 USER_TYPE_KIOSK_APP = 5, 47 // Maximum histogram value. 48 NUM_USER_TYPES = 6 49 } UserType; 50 51 // User OAuth token status according to the last check. 52 // Please note that enum values 1 and 2 were used for OAuth1 status and are 53 // deprecated now. 54 typedef enum { 55 OAUTH_TOKEN_STATUS_UNKNOWN = 0, 56 OAUTH2_TOKEN_STATUS_INVALID = 3, 57 OAUTH2_TOKEN_STATUS_VALID = 4, 58 } OAuthTokenStatus; 59 60 // Returned as |image_index| when user-selected file or photo is used as 61 // user image. 62 static const int kExternalImageIndex = -1; 63 // Returned as |image_index| when user profile image is used as user image. 64 static const int kProfileImageIndex = -2; 65 static const int kInvalidImageIndex = -3; 66 67 enum WallpaperType { 68 /* DAILY = 0 */ // Removed. Do not re-use the id! 69 CUSTOMIZED = 1, // Selected by user. 70 DEFAULT = 2, // Default. 71 /* UNKNOWN = 3 */ // Removed. Do not re-use the id! 72 ONLINE = 4, // WallpaperInfo.file denotes an URL. 73 POLICY = 5, // Controlled by policy, can't be changed by the user. 74 WALLPAPER_TYPE_COUNT = 6 75 }; 76 77 // Returns the user type. 78 virtual UserType GetType() const = 0; 79 80 // The email the user used to log in. 81 const std::string& email() const { return email_; } 82 83 // The displayed user name. 84 base::string16 display_name() const { return display_name_; } 85 86 // ash::UserInfo 87 virtual std::string GetEmail() const OVERRIDE; 88 virtual base::string16 GetDisplayName() const OVERRIDE; 89 virtual base::string16 GetGivenName() const OVERRIDE; 90 virtual const gfx::ImageSkia& GetImage() const OVERRIDE; 91 virtual std::string GetUserID() const OVERRIDE; 92 93 // Returns the account name part of the email. Use the display form of the 94 // email if available and use_display_name == true. Otherwise use canonical. 95 std::string GetAccountName(bool use_display_email) const; 96 97 // Whether the user has a default image. 98 bool HasDefaultImage() const; 99 100 // True if user image can be synced. 101 virtual bool CanSyncImage() const; 102 103 int image_index() const { return image_index_; } 104 bool has_raw_image() const { return user_image_.has_raw_image(); } 105 // Returns raw representation of static user image. 106 const UserImage::RawImage& raw_image() const { 107 return user_image_.raw_image(); 108 } 109 bool has_animated_image() const { return user_image_.has_animated_image(); } 110 // Returns raw representation of animated user image. 111 const UserImage::RawImage& animated_image() const { 112 return user_image_.animated_image(); 113 } 114 115 // Whether |raw_image| contains data in format that is considered safe to 116 // decode in sensitive environment (on Login screen). 117 bool image_is_safe_format() const { return user_image_.is_safe_format(); } 118 119 // Returns the URL of user image, if there is any. Currently only the profile 120 // image has a URL, for other images empty URL is returned. 121 GURL image_url() const { return user_image_.url(); } 122 123 // True if user image is a stub (while real image is being loaded from file). 124 bool image_is_stub() const { return image_is_stub_; } 125 126 // True if image is being loaded from file. 127 bool image_is_loading() const { return image_is_loading_; } 128 129 // The displayed (non-canonical) user email. 130 virtual std::string display_email() const; 131 132 // OAuth token status for this user. 133 OAuthTokenStatus oauth_token_status() const { return oauth_token_status_; } 134 135 // Whether online authentication against GAIA should be enforced during the 136 // user's next sign-in. 137 bool force_online_signin() const { return force_online_signin_; } 138 139 // True if the user's session can be locked (i.e. the user has a password with 140 // which to unlock the session). 141 virtual bool can_lock() const; 142 143 virtual std::string username_hash() const; 144 145 // True if current user is logged in. 146 virtual bool is_logged_in() const; 147 148 // True if current user is active within the current session. 149 virtual bool is_active() const; 150 151 // True if the user Profile is created. 152 bool is_profile_created() const { 153 return profile_is_created_; 154 } 155 156 protected: 157 friend class SupervisedUserManagerImpl; 158 friend class UserManagerImpl; 159 friend class UserImageManagerImpl; 160 // For testing: 161 friend class MockUserManager; 162 friend class FakeLoginUtils; 163 friend class FakeUserManager; 164 friend class UserAddingScreenTest; 165 166 // Do not allow anyone else to create new User instances. 167 static User* CreateRegularUser(const std::string& email); 168 static User* CreateGuestUser(); 169 static User* CreateKioskAppUser(const std::string& kiosk_app_username); 170 static User* CreateLocallyManagedUser(const std::string& username); 171 static User* CreateRetailModeUser(); 172 static User* CreatePublicAccountUser(const std::string& email); 173 174 explicit User(const std::string& email); 175 virtual ~User(); 176 177 const std::string* GetAccountLocale() const { 178 return account_locale_.get(); 179 } 180 181 // Setters are private so only UserManager can call them. 182 void SetAccountLocale(const std::string& resolved_account_locale); 183 184 void SetImage(const UserImage& user_image, int image_index); 185 186 void SetImageURL(const GURL& image_url); 187 188 // Sets a stub image until the next |SetImage| call. |image_index| may be 189 // one of |kExternalImageIndex| or |kProfileImageIndex|. 190 // If |is_loading| is |true|, that means user image is being loaded from file. 191 void SetStubImage(int image_index, bool is_loading); 192 193 void set_display_name(const base::string16& display_name) { 194 display_name_ = display_name; 195 } 196 197 void set_given_name(const base::string16& given_name) { 198 given_name_ = given_name; 199 } 200 201 void set_display_email(const std::string& display_email) { 202 display_email_ = display_email; 203 } 204 205 const UserImage& user_image() const { return user_image_; } 206 207 void set_oauth_token_status(OAuthTokenStatus status) { 208 oauth_token_status_ = status; 209 } 210 211 void set_force_online_signin(bool force_online_signin) { 212 force_online_signin_ = force_online_signin; 213 } 214 215 void set_username_hash(const std::string& username_hash) { 216 username_hash_ = username_hash; 217 } 218 219 void set_is_logged_in(bool is_logged_in) { 220 is_logged_in_ = is_logged_in; 221 } 222 223 void set_can_lock(bool can_lock) { 224 can_lock_ = can_lock; 225 } 226 227 void set_is_active(bool is_active) { 228 is_active_ = is_active; 229 } 230 231 void set_profile_is_created() { 232 profile_is_created_ = true; 233 } 234 235 // True if user has google account (not a guest or managed user). 236 bool has_gaia_account() const; 237 238 private: 239 std::string email_; 240 base::string16 display_name_; 241 base::string16 given_name_; 242 // The displayed user email, defaults to |email_|. 243 std::string display_email_; 244 UserImage user_image_; 245 OAuthTokenStatus oauth_token_status_; 246 bool force_online_signin_; 247 248 // This is set to chromeos locale if account data has been downloaded. 249 // (Or failed to download, but at least one download attempt finished). 250 // An empty string indicates error in data load, or in 251 // translation of Account locale to chromeos locale. 252 scoped_ptr<std::string> account_locale_; 253 254 // Used to identify homedir mount point. 255 std::string username_hash_; 256 257 // Either index of a default image for the user, |kExternalImageIndex| or 258 // |kProfileImageIndex|. 259 int image_index_; 260 261 // True if current user image is a stub set by a |SetStubImage| call. 262 bool image_is_stub_; 263 264 // True if current user image is being loaded from file. 265 bool image_is_loading_; 266 267 // True if user is able to lock screen. 268 bool can_lock_; 269 270 // True if user is currently logged in in current session. 271 bool is_logged_in_; 272 273 // True if user is currently logged in and active in current session. 274 bool is_active_; 275 276 // True if user Profile is created 277 bool profile_is_created_; 278 279 DISALLOW_COPY_AND_ASSIGN(User); 280 }; 281 282 // List of known users. 283 typedef std::vector<User*> UserList; 284 285 } // namespace chromeos 286 287 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_H_ 288