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

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

Issue 718673002: New user type introduced. Combines regular and supervised features. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First comments addressed. Created 6 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
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"
(...skipping 10 matching lines...) Expand all
21 std::string GetUserName(const std::string& email) { 21 std::string GetUserName(const std::string& email) {
22 std::string::size_type i = email.find('@'); 22 std::string::size_type i = email.find('@');
23 if (i == 0 || i == std::string::npos) { 23 if (i == 0 || i == std::string::npos) {
24 return email; 24 return email;
25 } 25 }
26 return email.substr(0, i); 26 return email.substr(0, i);
27 } 27 }
28 28
29 } // namespace 29 } // namespace
30 30
31 bool User::IsSupervised() const { 31 void User::SetIsSupervised(bool is_supervised) {
bartfab (slow) 2014/11/11 19:42:07 The definition order does not match the declaratio
merkulova 2014/11/12 10:01:01 Done.
32 return false; 32 VLOG(1) << "Ignoring SetIsSupervised call with param " << is_supervised;
33 NOTREACHED() << "Calling SetIsSupervised for base User class.";
33 } 34 }
34 35
35 void User::SetIsSupervised(bool is_supervised) { 36 // static
36 VLOG(1) << "Ignoring SetIsSupervised call with param " << is_supervised; 37 bool User::TypeIsRegular(UserType user_type) {
38 return user_type == USER_TYPE_REGULAR ||
39 user_type == USER_TYPE_REGULAR_SUPERVISED;
37 } 40 }
38 41
42 // static
43 bool User::TypeIsSupervised(UserType user_type) {
Daniel Erat 2014/11/11 16:02:49 i don't see this static method getting called anyw
bartfab (slow) 2014/11/11 19:42:07 The definition order does not match the declaratio
merkulova 2014/11/12 10:01:01 Done.
merkulova 2014/11/12 10:01:02 Done.
44 return user_type == USER_TYPE_SUPERVISED ||
45 user_type == USER_TYPE_REGULAR_SUPERVISED;
46 }
47
48 bool User::IsRegular() const {
bartfab (slow) 2014/11/11 19:42:07 1: This should be implemented in the same way as t
merkulova 2014/11/12 10:01:02 Why would you prefer that approach? That would lea
bartfab (slow) 2014/11/12 16:20:25 The idea is that you have a class which encapsulat
49 return TypeIsRegular(GetType());
50 }
51
52 bool User::IsSupervised() const {
bartfab (slow) 2014/11/11 19:42:06 The definition order does not match the declaratio
merkulova 2014/11/12 10:01:01 Done.
53 return TypeIsSupervised(GetType());
54 }
55
56 // Also used for regular supervised users.
39 class RegularUser : public User { 57 class RegularUser : public User {
40 public: 58 public:
41 explicit RegularUser(const std::string& email); 59 explicit RegularUser(const std::string& email);
42 virtual ~RegularUser(); 60 virtual ~RegularUser();
43 61
44 // Overridden from User: 62 // Overridden from User:
45 virtual UserType GetType() const override; 63 virtual UserType GetType() const override;
46 virtual bool CanSyncImage() const override; 64 virtual bool CanSyncImage() const override;
47 virtual void SetIsSupervised(bool is_supervised) override { 65 virtual void SetIsSupervised(bool is_supervised) override;
48 VLOG(1) << "Setting user is supervised to " << is_supervised;
49 is_supervised_ = is_supervised;
50 }
51 virtual bool IsSupervised() const override {
bartfab (slow) 2014/11/11 19:42:07 This was the right way of doing things. Why did yo
merkulova 2014/11/12 10:01:01 Because new user type was introduced. Before there
52 return is_supervised_;
53 }
54 66
55 private: 67 private:
56 bool is_supervised_; 68 bool is_supervised_;
57 69
58 DISALLOW_COPY_AND_ASSIGN(RegularUser); 70 DISALLOW_COPY_AND_ASSIGN(RegularUser);
59 }; 71 };
60 72
61 class GuestUser : public User { 73 class GuestUser : public User {
62 public: 74 public:
63 GuestUser(); 75 GuestUser();
(...skipping 18 matching lines...) Expand all
82 DISALLOW_COPY_AND_ASSIGN(KioskAppUser); 94 DISALLOW_COPY_AND_ASSIGN(KioskAppUser);
83 }; 95 };
84 96
85 class SupervisedUser : public User { 97 class SupervisedUser : public User {
86 public: 98 public:
87 explicit SupervisedUser(const std::string& username); 99 explicit SupervisedUser(const std::string& username);
88 virtual ~SupervisedUser(); 100 virtual ~SupervisedUser();
89 101
90 // Overridden from User: 102 // Overridden from User:
91 virtual UserType GetType() const override; 103 virtual UserType GetType() const override;
92 virtual bool IsSupervised() const override;
93 virtual std::string display_email() const override; 104 virtual std::string display_email() const override;
94 105
95 private: 106 private:
96 DISALLOW_COPY_AND_ASSIGN(SupervisedUser); 107 DISALLOW_COPY_AND_ASSIGN(SupervisedUser);
97 }; 108 };
98 109
99 class RetailModeUser : public User { 110 class RetailModeUser : public User {
100 public: 111 public:
101 RetailModeUser(); 112 RetailModeUser();
102 virtual ~RetailModeUser(); 113 virtual ~RetailModeUser();
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 RegularUser::RegularUser(const std::string& email) 256 RegularUser::RegularUser(const std::string& email)
246 : User(email), is_supervised_(false) { 257 : User(email), is_supervised_(false) {
247 set_can_lock(true); 258 set_can_lock(true);
248 set_display_email(email); 259 set_display_email(email);
249 } 260 }
250 261
251 RegularUser::~RegularUser() { 262 RegularUser::~RegularUser() {
252 } 263 }
253 264
254 UserType RegularUser::GetType() const { 265 UserType RegularUser::GetType() const {
255 return user_manager::USER_TYPE_REGULAR; 266 return is_supervised_ ? user_manager::USER_TYPE_REGULAR_SUPERVISED :
267 user_manager::USER_TYPE_REGULAR;
256 } 268 }
257 269
258 bool RegularUser::CanSyncImage() const { 270 bool RegularUser::CanSyncImage() const {
259 return true; 271 return true;
260 } 272 }
261 273
274 void RegularUser::SetIsSupervised(bool is_supervised) {
275 VLOG(1) << "Setting user is supervised to " << is_supervised;
276 is_supervised_ = is_supervised;
277 }
278
262 GuestUser::GuestUser() : User(chromeos::login::kGuestUserName) { 279 GuestUser::GuestUser() : User(chromeos::login::kGuestUserName) {
263 set_display_email(std::string()); 280 set_display_email(std::string());
264 } 281 }
265 282
266 GuestUser::~GuestUser() { 283 GuestUser::~GuestUser() {
267 } 284 }
268 285
269 UserType GuestUser::GetType() const { 286 UserType GuestUser::GetType() const {
270 return user_manager::USER_TYPE_GUEST; 287 return user_manager::USER_TYPE_GUEST;
271 } 288 }
(...skipping 18 matching lines...) Expand all
290 } 307 }
291 308
292 UserType SupervisedUser::GetType() const { 309 UserType SupervisedUser::GetType() const {
293 return user_manager::USER_TYPE_SUPERVISED; 310 return user_manager::USER_TYPE_SUPERVISED;
294 } 311 }
295 312
296 std::string SupervisedUser::display_email() const { 313 std::string SupervisedUser::display_email() const {
297 return base::UTF16ToUTF8(display_name()); 314 return base::UTF16ToUTF8(display_name());
298 } 315 }
299 316
300 bool SupervisedUser::IsSupervised() const {
301 return true;
302 }
303
304 RetailModeUser::RetailModeUser() : User(chromeos::login::kRetailModeUserName) { 317 RetailModeUser::RetailModeUser() : User(chromeos::login::kRetailModeUserName) {
305 set_display_email(std::string()); 318 set_display_email(std::string());
306 } 319 }
307 320
308 RetailModeUser::~RetailModeUser() { 321 RetailModeUser::~RetailModeUser() {
309 } 322 }
310 323
311 UserType RetailModeUser::GetType() const { 324 UserType RetailModeUser::GetType() const {
312 return user_manager::USER_TYPE_RETAIL_MODE; 325 return user_manager::USER_TYPE_RETAIL_MODE;
313 } 326 }
314 327
315 PublicAccountUser::PublicAccountUser(const std::string& email) : User(email) { 328 PublicAccountUser::PublicAccountUser(const std::string& email) : User(email) {
316 } 329 }
317 330
318 PublicAccountUser::~PublicAccountUser() { 331 PublicAccountUser::~PublicAccountUser() {
319 } 332 }
320 333
321 UserType PublicAccountUser::GetType() const { 334 UserType PublicAccountUser::GetType() const {
322 return user_manager::USER_TYPE_PUBLIC_ACCOUNT; 335 return user_manager::USER_TYPE_PUBLIC_ACCOUNT;
323 } 336 }
324 337
325 bool User::has_gaia_account() const { 338 bool User::has_gaia_account() const {
326 COMPILE_ASSERT(user_manager::NUM_USER_TYPES == 6, num_user_types_unexpected); 339 COMPILE_ASSERT(user_manager::NUM_USER_TYPES == 7, num_user_types_unexpected);
327 switch (GetType()) { 340 switch (GetType()) {
328 case user_manager::USER_TYPE_REGULAR: 341 case user_manager::USER_TYPE_REGULAR:
342 case user_manager::USER_TYPE_REGULAR_SUPERVISED:
329 return true; 343 return true;
330 case user_manager::USER_TYPE_GUEST: 344 case user_manager::USER_TYPE_GUEST:
331 case user_manager::USER_TYPE_RETAIL_MODE: 345 case user_manager::USER_TYPE_RETAIL_MODE:
332 case user_manager::USER_TYPE_PUBLIC_ACCOUNT: 346 case user_manager::USER_TYPE_PUBLIC_ACCOUNT:
333 case user_manager::USER_TYPE_SUPERVISED: 347 case user_manager::USER_TYPE_SUPERVISED:
334 case user_manager::USER_TYPE_KIOSK_APP: 348 case user_manager::USER_TYPE_KIOSK_APP:
335 return false; 349 return false;
336 default: 350 default:
337 NOTREACHED(); 351 NOTREACHED();
338 } 352 }
339 return false; 353 return false;
340 } 354 }
341 355
342 } // namespace user_manager 356 } // namespace user_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698