OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_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/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 // Information that is passed around while authentication is in progress. The | |
23 // credentials may consist of a |user_id|, |password| pair or a GAIA | |
24 // |auth_code|. The |user_id_hash| is used to locate the user's home directory | |
25 // mount point for the user. It is set when the mount has been completed. | |
26 class UserContext { | |
27 public: | |
28 // The authentication flow used during sign-in. | |
29 enum AuthFlow { | |
30 // Online authentication against GAIA. GAIA did not redirect to a SAML IdP. | |
31 AUTH_FLOW_GAIA_WITHOUT_SAML, | |
32 // Online authentication against GAIA. GAIA redirected to a SAML IdP. | |
33 AUTH_FLOW_GAIA_WITH_SAML, | |
34 // Offline authentication against a cached key. | |
35 AUTH_FLOW_OFFLINE | |
36 }; | |
37 | |
38 UserContext(); | |
39 UserContext(const std::string& user_id, | |
40 const std::string& password, | |
41 const std::string& auth_code); | |
42 UserContext(const std::string& user_id, | |
43 const std::string& password, | |
44 const std::string& auth_code, | |
45 const std::string& user_id_hash); | |
46 UserContext(const std::string& user_id, | |
47 const std::string& password, | |
48 const std::string& auth_code, | |
49 const std::string& user_id_hash, | |
50 bool is_using_oauth, | |
51 AuthFlow auth_flow); | |
52 ~UserContext(); | |
53 bool operator==(const UserContext& context) const; | |
54 | |
55 void CopyFrom(const UserContext& other); | |
56 | |
57 const std::string& GetUserID() const; | |
58 const std::string& GetPassword() const; | |
59 bool DoesNeedPasswordHashing() const; | |
60 const std::string& GetKeyLabel() const; | |
61 const std::string& GetAuthCode() const; | |
62 const std::string& GetUserIDHash() const; | |
63 bool IsUsingOAuth() const; | |
64 AuthFlow GetAuthFlow() const; | |
65 | |
66 bool HasCredentials() const; | |
67 | |
68 void SetUserID(const std::string& user_id); | |
69 void SetPassword(const std::string& password); | |
70 void SetDoesNeedPasswordHashing(bool does_need_password_hashing); | |
71 void SetKeyLabel(const std::string& key_label); | |
72 void SetAuthCode(const std::string& auth_code); | |
73 void SetUserIDHash(const std::string& user_id_hash); | |
74 void SetIsUsingOAuth(bool is_using_oauth); | |
75 | |
76 private: | |
77 std::string user_id_; | |
78 std::string password_; | |
79 bool does_need_password_hashing_; | |
80 std::string key_label_; | |
81 std::string auth_code_; | |
82 std::string user_id_hash_; | |
83 bool is_using_oauth_; | |
84 AuthFlow auth_flow_; | |
85 }; | |
86 | |
87 // A class representing information about a previously logged in user. | |
88 // Each user has a canonical email (username), returned by |email()| and | |
89 // may have a different displayed email (in the raw form as entered by user), | |
90 // returned by |displayed_email()|. | |
91 // Displayed emails are for use in UI only, anywhere else users must be referred | |
92 // to by |email()|. | |
93 class User : public ash::UserInfo { | |
94 public: | |
95 // The user type. Used in a histogram; do not modify existing types. | |
96 typedef enum { | |
97 // Regular user, has a user name and password. | |
98 USER_TYPE_REGULAR = 0, | |
99 // Guest user, logs in without authentication. | |
100 USER_TYPE_GUEST = 1, | |
101 // Retail mode user, logs in without authentication. This is a special user | |
102 // type used in retail mode only. | |
103 USER_TYPE_RETAIL_MODE = 2, | |
104 // Public account user, logs in without authentication. Available only if | |
105 // enabled through policy. | |
106 USER_TYPE_PUBLIC_ACCOUNT = 3, | |
107 // Locally managed user, logs in only with local authentication. | |
108 USER_TYPE_LOCALLY_MANAGED = 4, | |
109 // Kiosk app robot, logs in without authentication. | |
110 USER_TYPE_KIOSK_APP = 5, | |
111 // Maximum histogram value. | |
112 NUM_USER_TYPES = 6 | |
113 } UserType; | |
114 | |
115 // User OAuth token status according to the last check. | |
116 // Please note that enum values 1 and 2 were used for OAuth1 status and are | |
117 // deprecated now. | |
118 typedef enum { | |
119 OAUTH_TOKEN_STATUS_UNKNOWN = 0, | |
120 OAUTH2_TOKEN_STATUS_INVALID = 3, | |
121 OAUTH2_TOKEN_STATUS_VALID = 4, | |
122 } OAuthTokenStatus; | |
123 | |
124 // Returned as |image_index| when user-selected file or photo is used as | |
125 // user image. | |
126 static const int kExternalImageIndex = -1; | |
127 // Returned as |image_index| when user profile image is used as user image. | |
128 static const int kProfileImageIndex = -2; | |
129 static const int kInvalidImageIndex = -3; | |
130 | |
131 enum WallpaperType { | |
132 /* DAILY = 0 */ // Removed. Do not re-use the id! | |
133 CUSTOMIZED = 1, // Selected by user. | |
134 DEFAULT = 2, // Default. | |
135 /* UNKNOWN = 3 */ // Removed. Do not re-use the id! | |
136 ONLINE = 4, // WallpaperInfo.file denotes an URL. | |
137 POLICY = 5, // Controlled by policy, can't be changed by the user. | |
138 WALLPAPER_TYPE_COUNT = 6 | |
139 }; | |
140 | |
141 // Returns the user type. | |
142 virtual UserType GetType() const = 0; | |
143 | |
144 // The email the user used to log in. | |
145 const std::string& email() const { return email_; } | |
146 | |
147 // The displayed user name. | |
148 base::string16 display_name() const { return display_name_; } | |
149 | |
150 // ash::UserInfo | |
151 virtual std::string GetEmail() const OVERRIDE; | |
152 virtual base::string16 GetDisplayName() const OVERRIDE; | |
153 virtual base::string16 GetGivenName() const OVERRIDE; | |
154 virtual const gfx::ImageSkia& GetImage() const OVERRIDE; | |
155 virtual std::string GetUserID() const OVERRIDE; | |
156 | |
157 // Returns the account name part of the email. Use the display form of the | |
158 // email if available and use_display_name == true. Otherwise use canonical. | |
159 std::string GetAccountName(bool use_display_email) const; | |
160 | |
161 // Whether the user has a default image. | |
162 bool HasDefaultImage() const; | |
163 | |
164 // True if user image can be synced. | |
165 virtual bool CanSyncImage() const; | |
166 | |
167 int image_index() const { return image_index_; } | |
168 bool has_raw_image() const { return user_image_.has_raw_image(); } | |
169 // Returns raw representation of static user image. | |
170 const UserImage::RawImage& raw_image() const { | |
171 return user_image_.raw_image(); | |
172 } | |
173 bool has_animated_image() const { return user_image_.has_animated_image(); } | |
174 // Returns raw representation of animated user image. | |
175 const UserImage::RawImage& animated_image() const { | |
176 return user_image_.animated_image(); | |
177 } | |
178 | |
179 // Whether |raw_image| contains data in format that is considered safe to | |
180 // decode in sensitive environment (on Login screen). | |
181 bool image_is_safe_format() const { return user_image_.is_safe_format(); } | |
182 | |
183 // Returns the URL of user image, if there is any. Currently only the profile | |
184 // image has a URL, for other images empty URL is returned. | |
185 GURL image_url() const { return user_image_.url(); } | |
186 | |
187 // True if user image is a stub (while real image is being loaded from file). | |
188 bool image_is_stub() const { return image_is_stub_; } | |
189 | |
190 // True if image is being loaded from file. | |
191 bool image_is_loading() const { return image_is_loading_; } | |
192 | |
193 // The displayed (non-canonical) user email. | |
194 virtual std::string display_email() const; | |
195 | |
196 // OAuth token status for this user. | |
197 OAuthTokenStatus oauth_token_status() const { return oauth_token_status_; } | |
198 | |
199 // Whether online authentication against GAIA should be enforced during the | |
200 // user's next sign-in. | |
201 bool force_online_signin() const { return force_online_signin_; } | |
202 | |
203 // True if the user's session can be locked (i.e. the user has a password with | |
204 // which to unlock the session). | |
205 virtual bool can_lock() const; | |
206 | |
207 virtual std::string username_hash() const; | |
208 | |
209 // True if current user is logged in. | |
210 virtual bool is_logged_in() const; | |
211 | |
212 // True if current user is active within the current session. | |
213 virtual bool is_active() const; | |
214 | |
215 // True if the user Profile is created. | |
216 bool is_profile_created() const { | |
217 return profile_is_created_; | |
218 } | |
219 | |
220 protected: | |
221 friend class SupervisedUserManagerImpl; | |
222 friend class UserManagerImpl; | |
223 friend class UserImageManagerImpl; | |
224 // For testing: | |
225 friend class MockUserManager; | |
226 friend class FakeLoginUtils; | |
227 friend class FakeUserManager; | |
228 friend class UserAddingScreenTest; | |
229 | |
230 // Do not allow anyone else to create new User instances. | |
231 static User* CreateRegularUser(const std::string& email); | |
232 static User* CreateGuestUser(); | |
233 static User* CreateKioskAppUser(const std::string& kiosk_app_username); | |
234 static User* CreateLocallyManagedUser(const std::string& username); | |
235 static User* CreateRetailModeUser(); | |
236 static User* CreatePublicAccountUser(const std::string& email); | |
237 | |
238 explicit User(const std::string& email); | |
239 virtual ~User(); | |
240 | |
241 const std::string* GetAccountLocale() const { | |
242 return account_locale_.get(); | |
243 } | |
244 | |
245 // Setters are private so only UserManager can call them. | |
246 void SetAccountLocale(const std::string& resolved_account_locale); | |
247 | |
248 void SetImage(const UserImage& user_image, int image_index); | |
249 | |
250 void SetImageURL(const GURL& image_url); | |
251 | |
252 // Sets a stub image until the next |SetImage| call. |image_index| may be | |
253 // one of |kExternalImageIndex| or |kProfileImageIndex|. | |
254 // If |is_loading| is |true|, that means user image is being loaded from file. | |
255 void SetStubImage(int image_index, bool is_loading); | |
256 | |
257 void set_display_name(const base::string16& display_name) { | |
258 display_name_ = display_name; | |
259 } | |
260 | |
261 void set_given_name(const base::string16& given_name) { | |
262 given_name_ = given_name; | |
263 } | |
264 | |
265 void set_display_email(const std::string& display_email) { | |
266 display_email_ = display_email; | |
267 } | |
268 | |
269 const UserImage& user_image() const { return user_image_; } | |
270 | |
271 void set_oauth_token_status(OAuthTokenStatus status) { | |
272 oauth_token_status_ = status; | |
273 } | |
274 | |
275 void set_force_online_signin(bool force_online_signin) { | |
276 force_online_signin_ = force_online_signin; | |
277 } | |
278 | |
279 void set_username_hash(const std::string& username_hash) { | |
280 username_hash_ = username_hash; | |
281 } | |
282 | |
283 void set_is_logged_in(bool is_logged_in) { | |
284 is_logged_in_ = is_logged_in; | |
285 } | |
286 | |
287 void set_can_lock(bool can_lock) { | |
288 can_lock_ = can_lock; | |
289 } | |
290 | |
291 void set_is_active(bool is_active) { | |
292 is_active_ = is_active; | |
293 } | |
294 | |
295 void set_profile_is_created() { | |
296 profile_is_created_ = true; | |
297 } | |
298 | |
299 // True if user has google account (not a guest or managed user). | |
300 bool has_gaia_account() const; | |
301 | |
302 private: | |
303 std::string email_; | |
304 base::string16 display_name_; | |
305 base::string16 given_name_; | |
306 // The displayed user email, defaults to |email_|. | |
307 std::string display_email_; | |
308 UserImage user_image_; | |
309 OAuthTokenStatus oauth_token_status_; | |
310 bool force_online_signin_; | |
311 | |
312 // This is set to chromeos locale if account data has been downloaded. | |
313 // (Or failed to download, but at least one download attempt finished). | |
314 // An empty string indicates error in data load, or in | |
315 // translation of Account locale to chromeos locale. | |
316 scoped_ptr<std::string> account_locale_; | |
317 | |
318 // Used to identify homedir mount point. | |
319 std::string username_hash_; | |
320 | |
321 // Either index of a default image for the user, |kExternalImageIndex| or | |
322 // |kProfileImageIndex|. | |
323 int image_index_; | |
324 | |
325 // True if current user image is a stub set by a |SetStubImage| call. | |
326 bool image_is_stub_; | |
327 | |
328 // True if current user image is being loaded from file. | |
329 bool image_is_loading_; | |
330 | |
331 // True if user is able to lock screen. | |
332 bool can_lock_; | |
333 | |
334 // True if user is currently logged in in current session. | |
335 bool is_logged_in_; | |
336 | |
337 // True if user is currently logged in and active in current session. | |
338 bool is_active_; | |
339 | |
340 // True if user Profile is created | |
341 bool profile_is_created_; | |
342 | |
343 DISALLOW_COPY_AND_ASSIGN(User); | |
344 }; | |
345 | |
346 // List of known users. | |
347 typedef std::vector<User*> UserList; | |
348 | |
349 } // namespace chromeos | |
350 | |
351 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_H_ | |
OLD | NEW |