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