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