Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: components/user_manager/user.cc

Issue 1425093004: Revert of This CL replaces user_manager::UserID with AccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@468875--Chrome-OS-handles-deletion-of-Gmail-account-poorly--Create-AccountID-structure-part2--user_names
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/user_manager/user.h ('k') | components/user_manager/user_id.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "components/user_manager/user.h" 5 #include "components/user_manager/user.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
11 #include "chromeos/login/user_names.h" 11 #include "chromeos/login/user_names.h"
12 #include "components/signin/core/account_id/account_id.h"
13 #include "components/user_manager/user_image/default_user_images.h" 12 #include "components/user_manager/user_image/default_user_images.h"
14 #include "google_apis/gaia/gaia_auth_util.h" 13 #include "google_apis/gaia/gaia_auth_util.h"
15 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
16 15
17 namespace user_manager { 16 namespace user_manager {
18 17
19 namespace { 18 namespace {
20 19
21 // Returns account name portion of an email. 20 // Returns account name portion of an email.
22 std::string GetUserName(const std::string& email) { 21 std::string GetUserName(const std::string& email) {
23 std::string::size_type i = email.find('@'); 22 std::string::size_type i = email.find('@');
24 if (i == 0 || i == std::string::npos) { 23 if (i == 0 || i == std::string::npos) {
25 return email; 24 return email;
26 } 25 }
27 return email.substr(0, i); 26 return email.substr(0, i);
28 } 27 }
29 28
30 } // namespace 29 } // namespace
31 30
32 // static 31 // static
33 bool User::TypeHasGaiaAccount(UserType user_type) { 32 bool User::TypeHasGaiaAccount(UserType user_type) {
34 return user_type == USER_TYPE_REGULAR || 33 return user_type == USER_TYPE_REGULAR ||
35 user_type == USER_TYPE_CHILD; 34 user_type == USER_TYPE_CHILD;
36 } 35 }
37 36
38 const std::string& User::email() const {
39 return account_id_.GetUserEmail();
40 }
41
42 // Also used for regular supervised users. 37 // Also used for regular supervised users.
43 class RegularUser : public User { 38 class RegularUser : public User {
44 public: 39 public:
45 explicit RegularUser(const AccountId& account_id); 40 explicit RegularUser(const std::string& email);
46 ~RegularUser() override; 41 ~RegularUser() override;
47 42
48 // Overridden from User: 43 // Overridden from User:
49 UserType GetType() const override; 44 UserType GetType() const override;
50 bool CanSyncImage() const override; 45 bool CanSyncImage() const override;
51 void SetIsChild(bool is_child) override; 46 void SetIsChild(bool is_child) override;
52 47
53 private: 48 private:
54 bool is_child_ = false; 49 bool is_child_;
55 50
56 DISALLOW_COPY_AND_ASSIGN(RegularUser); 51 DISALLOW_COPY_AND_ASSIGN(RegularUser);
57 }; 52 };
58 53
59 class GuestUser : public User { 54 class GuestUser : public User {
60 public: 55 public:
61 GuestUser(); 56 GuestUser();
62 ~GuestUser() override; 57 ~GuestUser() override;
63 58
64 // Overridden from User: 59 // Overridden from User:
65 UserType GetType() const override; 60 UserType GetType() const override;
66 61
67 private: 62 private:
68 DISALLOW_COPY_AND_ASSIGN(GuestUser); 63 DISALLOW_COPY_AND_ASSIGN(GuestUser);
69 }; 64 };
70 65
71 class KioskAppUser : public User { 66 class KioskAppUser : public User {
72 public: 67 public:
73 explicit KioskAppUser(const AccountId& kiosk_app_account_id); 68 explicit KioskAppUser(const std::string& app_id);
74 ~KioskAppUser() override; 69 ~KioskAppUser() override;
75 70
76 // Overridden from User: 71 // Overridden from User:
77 UserType GetType() const override; 72 UserType GetType() const override;
78 73
79 private: 74 private:
80 DISALLOW_COPY_AND_ASSIGN(KioskAppUser); 75 DISALLOW_COPY_AND_ASSIGN(KioskAppUser);
81 }; 76 };
82 77
83 class SupervisedUser : public User { 78 class SupervisedUser : public User {
84 public: 79 public:
85 explicit SupervisedUser(const AccountId& account_id); 80 explicit SupervisedUser(const std::string& username);
86 ~SupervisedUser() override; 81 ~SupervisedUser() override;
87 82
88 // Overridden from User: 83 // Overridden from User:
89 UserType GetType() const override; 84 UserType GetType() const override;
90 std::string display_email() const override; 85 std::string display_email() const override;
91 86
92 private: 87 private:
93 DISALLOW_COPY_AND_ASSIGN(SupervisedUser); 88 DISALLOW_COPY_AND_ASSIGN(SupervisedUser);
94 }; 89 };
95 90
96 class PublicAccountUser : public User { 91 class PublicAccountUser : public User {
97 public: 92 public:
98 explicit PublicAccountUser(const AccountId& account_id); 93 explicit PublicAccountUser(const std::string& email);
99 ~PublicAccountUser() override; 94 ~PublicAccountUser() override;
100 95
101 // Overridden from User: 96 // Overridden from User:
102 UserType GetType() const override; 97 UserType GetType() const override;
103 98
104 private: 99 private:
105 DISALLOW_COPY_AND_ASSIGN(PublicAccountUser); 100 DISALLOW_COPY_AND_ASSIGN(PublicAccountUser);
106 }; 101 };
107 102
108 std::string User::GetEmail() const { 103 std::string User::GetEmail() const {
109 return display_email(); 104 return display_email();
110 } 105 }
111 106
112 base::string16 User::GetDisplayName() const { 107 base::string16 User::GetDisplayName() const {
113 // Fallback to the email account name in case display name haven't been set. 108 // Fallback to the email account name in case display name haven't been set.
114 return display_name_.empty() ? base::UTF8ToUTF16(GetAccountName(true)) 109 return display_name_.empty() ? base::UTF8ToUTF16(GetAccountName(true))
115 : display_name_; 110 : display_name_;
116 } 111 }
117 112
118 base::string16 User::GetGivenName() const { 113 base::string16 User::GetGivenName() const {
119 return given_name_; 114 return given_name_;
120 } 115 }
121 116
122 const gfx::ImageSkia& User::GetImage() const { 117 const gfx::ImageSkia& User::GetImage() const {
123 return user_image_.image(); 118 return user_image_.image();
124 } 119 }
125 120
126 AccountId User::GetAccountId() const { 121 UserID User::GetUserID() const {
127 return AccountId::FromUserEmail( 122 return gaia::CanonicalizeEmail(gaia::SanitizeEmail(email()));
128 gaia::CanonicalizeEmail(gaia::SanitizeEmail(email())));
129 } 123 }
130 124
131 void User::SetIsChild(bool is_child) { 125 void User::SetIsChild(bool is_child) {
132 VLOG(1) << "Ignoring SetIsChild call with param " << is_child; 126 VLOG(1) << "Ignoring SetIsChild call with param " << is_child;
133 if (is_child) { 127 if (is_child) {
134 NOTREACHED() << "Calling SetIsChild(true) for base User class." 128 NOTREACHED() << "Calling SetIsChild(true) for base User class."
135 << "Base class cannot be set as child"; 129 << "Base class cannot be set as child";
136 } 130 }
137 } 131 }
138 132
139 bool User::HasGaiaAccount() const { 133 bool User::HasGaiaAccount() const {
140 return TypeHasGaiaAccount(GetType()); 134 return TypeHasGaiaAccount(GetType());
141 } 135 }
142 136
143 bool User::IsSupervised() const { 137 bool User::IsSupervised() const {
144 UserType type = GetType(); 138 UserType type = GetType();
145 return type == USER_TYPE_SUPERVISED || 139 return type == USER_TYPE_SUPERVISED ||
146 type == USER_TYPE_CHILD; 140 type == USER_TYPE_CHILD;
147 } 141 }
148 142
149 std::string User::GetAccountName(bool use_display_email) const { 143 std::string User::GetAccountName(bool use_display_email) const {
150 if (use_display_email && !display_email_.empty()) 144 if (use_display_email && !display_email_.empty())
151 return GetUserName(display_email_); 145 return GetUserName(display_email_);
152 else 146 else
153 return GetUserName(account_id_.GetUserEmail()); 147 return GetUserName(email_);
154 } 148 }
155 149
156 bool User::HasDefaultImage() const { 150 bool User::HasDefaultImage() const {
157 return image_index_ >= 0 && image_index_ < kDefaultImagesCount; 151 return image_index_ >= 0 && image_index_ < kDefaultImagesCount;
158 } 152 }
159 153
160 bool User::CanSyncImage() const { 154 bool User::CanSyncImage() const {
161 return false; 155 return false;
162 } 156 }
163 157
(...skipping 10 matching lines...) Expand all
174 } 168 }
175 169
176 bool User::is_logged_in() const { 170 bool User::is_logged_in() const {
177 return is_logged_in_; 171 return is_logged_in_;
178 } 172 }
179 173
180 bool User::is_active() const { 174 bool User::is_active() const {
181 return is_active_; 175 return is_active_;
182 } 176 }
183 177
184 User* User::CreateRegularUser(const AccountId& account_id) { 178 User* User::CreateRegularUser(const std::string& email) {
185 return new RegularUser(account_id); 179 return new RegularUser(email);
186 } 180 }
187 181
188 User* User::CreateGuestUser() { 182 User* User::CreateGuestUser() {
189 return new GuestUser; 183 return new GuestUser;
190 } 184 }
191 185
192 User* User::CreateKioskAppUser(const AccountId& kiosk_app_account_id) { 186 User* User::CreateKioskAppUser(const std::string& kiosk_app_username) {
193 return new KioskAppUser(kiosk_app_account_id); 187 return new KioskAppUser(kiosk_app_username);
194 } 188 }
195 189
196 User* User::CreateSupervisedUser(const AccountId& account_id) { 190 User* User::CreateSupervisedUser(const std::string& username) {
197 return new SupervisedUser(account_id); 191 return new SupervisedUser(username);
198 } 192 }
199 193
200 User* User::CreatePublicAccountUser(const AccountId& account_id) { 194 User* User::CreatePublicAccountUser(const std::string& email) {
201 return new PublicAccountUser(account_id); 195 return new PublicAccountUser(email);
202 } 196 }
203 197
204 User::User(const AccountId& account_id) : account_id_(account_id) {} 198 User::User(const std::string& email)
199 : email_(email),
200 oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN),
201 force_online_signin_(false),
202 image_index_(USER_IMAGE_INVALID),
203 image_is_stub_(false),
204 image_is_loading_(false),
205 can_lock_(false),
206 is_logged_in_(false),
207 is_active_(false),
208 profile_is_created_(false),
209 is_affiliated_(false){
210 }
205 211
206 User::~User() { 212 User::~User() {
207 } 213 }
208 214
209 void User::SetAccountLocale(const std::string& resolved_account_locale) { 215 void User::SetAccountLocale(const std::string& resolved_account_locale) {
210 account_locale_.reset(new std::string(resolved_account_locale)); 216 account_locale_.reset(new std::string(resolved_account_locale));
211 } 217 }
212 218
213 void User::SetImage(const UserImage& user_image, int image_index) { 219 void User::SetImage(const UserImage& user_image, int image_index) {
214 user_image_ = user_image; 220 user_image_ = user_image;
215 image_index_ = image_index; 221 image_index_ = image_index;
216 image_is_stub_ = false; 222 image_is_stub_ = false;
217 image_is_loading_ = false; 223 image_is_loading_ = false;
218 DCHECK(HasDefaultImage() || user_image.has_raw_image()); 224 DCHECK(HasDefaultImage() || user_image.has_raw_image());
219 } 225 }
220 226
221 void User::SetImageURL(const GURL& image_url) { 227 void User::SetImageURL(const GURL& image_url) {
222 user_image_.set_url(image_url); 228 user_image_.set_url(image_url);
223 } 229 }
224 230
225 void User::SetStubImage(const UserImage& stub_user_image, 231 void User::SetStubImage(const UserImage& stub_user_image,
226 int image_index, 232 int image_index,
227 bool is_loading) { 233 bool is_loading) {
228 user_image_ = stub_user_image; 234 user_image_ = stub_user_image;
229 image_index_ = image_index; 235 image_index_ = image_index;
230 image_is_stub_ = true; 236 image_is_stub_ = true;
231 image_is_loading_ = is_loading; 237 image_is_loading_ = is_loading;
232 } 238 }
233 239
234 RegularUser::RegularUser(const AccountId& account_id) : User(account_id) { 240 RegularUser::RegularUser(const std::string& email)
241 : User(email), is_child_(false) {
235 set_can_lock(true); 242 set_can_lock(true);
236 set_display_email(account_id.GetUserEmail()); 243 set_display_email(email);
237 } 244 }
238 245
239 RegularUser::~RegularUser() { 246 RegularUser::~RegularUser() {
240 } 247 }
241 248
242 UserType RegularUser::GetType() const { 249 UserType RegularUser::GetType() const {
243 return is_child_ ? user_manager::USER_TYPE_CHILD : 250 return is_child_ ? user_manager::USER_TYPE_CHILD :
244 user_manager::USER_TYPE_REGULAR; 251 user_manager::USER_TYPE_REGULAR;
245 } 252 }
246 253
247 bool RegularUser::CanSyncImage() const { 254 bool RegularUser::CanSyncImage() const {
248 return true; 255 return true;
249 } 256 }
250 257
251 void RegularUser::SetIsChild(bool is_child) { 258 void RegularUser::SetIsChild(bool is_child) {
252 VLOG(1) << "Setting user is child to " << is_child; 259 VLOG(1) << "Setting user is child to " << is_child;
253 is_child_ = is_child; 260 is_child_ = is_child;
254 } 261 }
255 262
256 GuestUser::GuestUser() : User(chromeos::login::GuestAccountId()) { 263 GuestUser::GuestUser() : User(chromeos::login::kGuestUserName) {
257 set_display_email(std::string()); 264 set_display_email(std::string());
258 } 265 }
259 266
260 GuestUser::~GuestUser() { 267 GuestUser::~GuestUser() {
261 } 268 }
262 269
263 UserType GuestUser::GetType() const { 270 UserType GuestUser::GetType() const {
264 return user_manager::USER_TYPE_GUEST; 271 return user_manager::USER_TYPE_GUEST;
265 } 272 }
266 273
267 KioskAppUser::KioskAppUser(const AccountId& kiosk_app_account_id) 274 KioskAppUser::KioskAppUser(const std::string& kiosk_app_username)
268 : User(kiosk_app_account_id) { 275 : User(kiosk_app_username) {
269 set_display_email(kiosk_app_account_id.GetUserEmail()); 276 set_display_email(kiosk_app_username);
270 } 277 }
271 278
272 KioskAppUser::~KioskAppUser() { 279 KioskAppUser::~KioskAppUser() {
273 } 280 }
274 281
275 UserType KioskAppUser::GetType() const { 282 UserType KioskAppUser::GetType() const {
276 return user_manager::USER_TYPE_KIOSK_APP; 283 return user_manager::USER_TYPE_KIOSK_APP;
277 } 284 }
278 285
279 SupervisedUser::SupervisedUser(const AccountId& account_id) : User(account_id) { 286 SupervisedUser::SupervisedUser(const std::string& username) : User(username) {
280 set_can_lock(true); 287 set_can_lock(true);
281 } 288 }
282 289
283 SupervisedUser::~SupervisedUser() { 290 SupervisedUser::~SupervisedUser() {
284 } 291 }
285 292
286 UserType SupervisedUser::GetType() const { 293 UserType SupervisedUser::GetType() const {
287 return user_manager::USER_TYPE_SUPERVISED; 294 return user_manager::USER_TYPE_SUPERVISED;
288 } 295 }
289 296
290 std::string SupervisedUser::display_email() const { 297 std::string SupervisedUser::display_email() const {
291 return base::UTF16ToUTF8(display_name()); 298 return base::UTF16ToUTF8(display_name());
292 } 299 }
293 300
294 PublicAccountUser::PublicAccountUser(const AccountId& account_id) 301 PublicAccountUser::PublicAccountUser(const std::string& email) : User(email) {
295 : User(account_id) {} 302 }
296 303
297 PublicAccountUser::~PublicAccountUser() { 304 PublicAccountUser::~PublicAccountUser() {
298 } 305 }
299 306
300 UserType PublicAccountUser::GetType() const { 307 UserType PublicAccountUser::GetType() const {
301 return user_manager::USER_TYPE_PUBLIC_ACCOUNT; 308 return user_manager::USER_TYPE_PUBLIC_ACCOUNT;
302 } 309 }
303 310
304 bool User::has_gaia_account() const { 311 bool User::has_gaia_account() const {
305 static_assert(user_manager::NUM_USER_TYPES == 7, 312 static_assert(user_manager::NUM_USER_TYPES == 7,
306 "NUM_USER_TYPES should equal 7"); 313 "NUM_USER_TYPES should equal 7");
307 switch (GetType()) { 314 switch (GetType()) {
308 case user_manager::USER_TYPE_REGULAR: 315 case user_manager::USER_TYPE_REGULAR:
309 case user_manager::USER_TYPE_CHILD: 316 case user_manager::USER_TYPE_CHILD:
310 return true; 317 return true;
311 case user_manager::USER_TYPE_GUEST: 318 case user_manager::USER_TYPE_GUEST:
312 case user_manager::USER_TYPE_PUBLIC_ACCOUNT: 319 case user_manager::USER_TYPE_PUBLIC_ACCOUNT:
313 case user_manager::USER_TYPE_SUPERVISED: 320 case user_manager::USER_TYPE_SUPERVISED:
314 case user_manager::USER_TYPE_KIOSK_APP: 321 case user_manager::USER_TYPE_KIOSK_APP:
315 return false; 322 return false;
316 default: 323 default:
317 NOTREACHED(); 324 NOTREACHED();
318 } 325 }
319 return false; 326 return false;
320 } 327 }
321 328
322 } // namespace user_manager 329 } // namespace user_manager
OLDNEW
« no previous file with comments | « components/user_manager/user.h ('k') | components/user_manager/user_id.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698