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