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 #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 Loading... | |
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 // static |
32 return false; | 32 bool User::TypeHasGaia(UserType user_type) { |
Nikita (slow)
2014/11/14 09:34:52
nit: TypeHasGaiaAccount
merkulova
2014/11/14 10:09:49
Done.
| |
33 return user_type == USER_TYPE_REGULAR || | |
34 user_type == USER_TYPE_REGULAR_SUPERVISED; | |
33 } | 35 } |
34 | 36 |
35 void User::SetIsSupervised(bool is_supervised) { | 37 // Also used for regular supervised users. |
36 VLOG(1) << "Ignoring SetIsSupervised call with param " << is_supervised; | |
37 } | |
38 | |
39 class RegularUser : public User { | 38 class RegularUser : public User { |
40 public: | 39 public: |
41 explicit RegularUser(const std::string& email); | 40 explicit RegularUser(const std::string& email); |
42 virtual ~RegularUser(); | 41 virtual ~RegularUser(); |
43 | 42 |
44 // Overridden from User: | 43 // Overridden from User: |
45 virtual UserType GetType() const override; | 44 virtual UserType GetType() const override; |
46 virtual bool CanSyncImage() const override; | 45 virtual bool CanSyncImage() const override; |
47 virtual void SetIsSupervised(bool is_supervised) override { | 46 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 { | |
52 return is_supervised_; | |
53 } | |
54 | 47 |
55 private: | 48 private: |
56 bool is_supervised_; | 49 bool is_supervised_; |
57 | 50 |
58 DISALLOW_COPY_AND_ASSIGN(RegularUser); | 51 DISALLOW_COPY_AND_ASSIGN(RegularUser); |
59 }; | 52 }; |
60 | 53 |
61 class GuestUser : public User { | 54 class GuestUser : public User { |
62 public: | 55 public: |
63 GuestUser(); | 56 GuestUser(); |
(...skipping 18 matching lines...) Expand all Loading... | |
82 DISALLOW_COPY_AND_ASSIGN(KioskAppUser); | 75 DISALLOW_COPY_AND_ASSIGN(KioskAppUser); |
83 }; | 76 }; |
84 | 77 |
85 class SupervisedUser : public User { | 78 class SupervisedUser : public User { |
86 public: | 79 public: |
87 explicit SupervisedUser(const std::string& username); | 80 explicit SupervisedUser(const std::string& username); |
88 virtual ~SupervisedUser(); | 81 virtual ~SupervisedUser(); |
89 | 82 |
90 // Overridden from User: | 83 // Overridden from User: |
91 virtual UserType GetType() const override; | 84 virtual UserType GetType() const override; |
92 virtual bool IsSupervised() const override; | |
93 virtual std::string display_email() const override; | 85 virtual std::string display_email() const override; |
94 | 86 |
95 private: | 87 private: |
96 DISALLOW_COPY_AND_ASSIGN(SupervisedUser); | 88 DISALLOW_COPY_AND_ASSIGN(SupervisedUser); |
97 }; | 89 }; |
98 | 90 |
99 class RetailModeUser : public User { | 91 class RetailModeUser : public User { |
100 public: | 92 public: |
101 RetailModeUser(); | 93 RetailModeUser(); |
102 virtual ~RetailModeUser(); | 94 virtual ~RetailModeUser(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 } | 127 } |
136 | 128 |
137 const gfx::ImageSkia& User::GetImage() const { | 129 const gfx::ImageSkia& User::GetImage() const { |
138 return user_image_.image(); | 130 return user_image_.image(); |
139 } | 131 } |
140 | 132 |
141 std::string User::GetUserID() const { | 133 std::string User::GetUserID() const { |
142 return gaia::CanonicalizeEmail(gaia::SanitizeEmail(email())); | 134 return gaia::CanonicalizeEmail(gaia::SanitizeEmail(email())); |
143 } | 135 } |
144 | 136 |
137 void User::SetIsSupervised(bool is_supervised) { | |
138 VLOG(1) << "Ignoring SetIsSupervised call with param " << is_supervised; | |
139 NOTREACHED() << "Calling SetIsSupervised for base User class."; | |
140 } | |
141 | |
142 bool User::HasGaiaAccount() const { | |
143 return TypeHasGaia(GetType()); | |
144 } | |
145 | |
146 bool User::IsSupervised() const { | |
147 UserType type = GetType(); | |
148 return type == USER_TYPE_SUPERVISED || | |
149 type == USER_TYPE_REGULAR_SUPERVISED; | |
150 } | |
151 | |
145 std::string User::GetAccountName(bool use_display_email) const { | 152 std::string User::GetAccountName(bool use_display_email) const { |
146 if (use_display_email && !display_email_.empty()) | 153 if (use_display_email && !display_email_.empty()) |
147 return GetUserName(display_email_); | 154 return GetUserName(display_email_); |
148 else | 155 else |
149 return GetUserName(email_); | 156 return GetUserName(email_); |
150 } | 157 } |
151 | 158 |
152 bool User::HasDefaultImage() const { | 159 bool User::HasDefaultImage() const { |
153 return image_index_ >= 0 && image_index_ < kDefaultImagesCount; | 160 return image_index_ >= 0 && image_index_ < kDefaultImagesCount; |
154 } | 161 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 RegularUser::RegularUser(const std::string& email) | 252 RegularUser::RegularUser(const std::string& email) |
246 : User(email), is_supervised_(false) { | 253 : User(email), is_supervised_(false) { |
247 set_can_lock(true); | 254 set_can_lock(true); |
248 set_display_email(email); | 255 set_display_email(email); |
249 } | 256 } |
250 | 257 |
251 RegularUser::~RegularUser() { | 258 RegularUser::~RegularUser() { |
252 } | 259 } |
253 | 260 |
254 UserType RegularUser::GetType() const { | 261 UserType RegularUser::GetType() const { |
255 return user_manager::USER_TYPE_REGULAR; | 262 return is_supervised_ ? user_manager::USER_TYPE_REGULAR_SUPERVISED : |
263 user_manager::USER_TYPE_REGULAR; | |
256 } | 264 } |
257 | 265 |
258 bool RegularUser::CanSyncImage() const { | 266 bool RegularUser::CanSyncImage() const { |
259 return true; | 267 return true; |
260 } | 268 } |
261 | 269 |
270 void RegularUser::SetIsSupervised(bool is_supervised) { | |
271 VLOG(1) << "Setting user is supervised to " << is_supervised; | |
272 is_supervised_ = is_supervised; | |
273 } | |
274 | |
262 GuestUser::GuestUser() : User(chromeos::login::kGuestUserName) { | 275 GuestUser::GuestUser() : User(chromeos::login::kGuestUserName) { |
263 set_display_email(std::string()); | 276 set_display_email(std::string()); |
264 } | 277 } |
265 | 278 |
266 GuestUser::~GuestUser() { | 279 GuestUser::~GuestUser() { |
267 } | 280 } |
268 | 281 |
269 UserType GuestUser::GetType() const { | 282 UserType GuestUser::GetType() const { |
270 return user_manager::USER_TYPE_GUEST; | 283 return user_manager::USER_TYPE_GUEST; |
271 } | 284 } |
(...skipping 18 matching lines...) Expand all Loading... | |
290 } | 303 } |
291 | 304 |
292 UserType SupervisedUser::GetType() const { | 305 UserType SupervisedUser::GetType() const { |
293 return user_manager::USER_TYPE_SUPERVISED; | 306 return user_manager::USER_TYPE_SUPERVISED; |
294 } | 307 } |
295 | 308 |
296 std::string SupervisedUser::display_email() const { | 309 std::string SupervisedUser::display_email() const { |
297 return base::UTF16ToUTF8(display_name()); | 310 return base::UTF16ToUTF8(display_name()); |
298 } | 311 } |
299 | 312 |
300 bool SupervisedUser::IsSupervised() const { | |
301 return true; | |
302 } | |
303 | |
304 RetailModeUser::RetailModeUser() : User(chromeos::login::kRetailModeUserName) { | 313 RetailModeUser::RetailModeUser() : User(chromeos::login::kRetailModeUserName) { |
305 set_display_email(std::string()); | 314 set_display_email(std::string()); |
306 } | 315 } |
307 | 316 |
308 RetailModeUser::~RetailModeUser() { | 317 RetailModeUser::~RetailModeUser() { |
309 } | 318 } |
310 | 319 |
311 UserType RetailModeUser::GetType() const { | 320 UserType RetailModeUser::GetType() const { |
312 return user_manager::USER_TYPE_RETAIL_MODE; | 321 return user_manager::USER_TYPE_RETAIL_MODE; |
313 } | 322 } |
314 | 323 |
315 PublicAccountUser::PublicAccountUser(const std::string& email) : User(email) { | 324 PublicAccountUser::PublicAccountUser(const std::string& email) : User(email) { |
316 } | 325 } |
317 | 326 |
318 PublicAccountUser::~PublicAccountUser() { | 327 PublicAccountUser::~PublicAccountUser() { |
319 } | 328 } |
320 | 329 |
321 UserType PublicAccountUser::GetType() const { | 330 UserType PublicAccountUser::GetType() const { |
322 return user_manager::USER_TYPE_PUBLIC_ACCOUNT; | 331 return user_manager::USER_TYPE_PUBLIC_ACCOUNT; |
323 } | 332 } |
324 | 333 |
325 bool User::has_gaia_account() const { | 334 bool User::has_gaia_account() const { |
326 COMPILE_ASSERT(user_manager::NUM_USER_TYPES == 6, num_user_types_unexpected); | 335 COMPILE_ASSERT(user_manager::NUM_USER_TYPES == 7, num_user_types_unexpected); |
327 switch (GetType()) { | 336 switch (GetType()) { |
328 case user_manager::USER_TYPE_REGULAR: | 337 case user_manager::USER_TYPE_REGULAR: |
338 case user_manager::USER_TYPE_REGULAR_SUPERVISED: | |
329 return true; | 339 return true; |
330 case user_manager::USER_TYPE_GUEST: | 340 case user_manager::USER_TYPE_GUEST: |
331 case user_manager::USER_TYPE_RETAIL_MODE: | 341 case user_manager::USER_TYPE_RETAIL_MODE: |
332 case user_manager::USER_TYPE_PUBLIC_ACCOUNT: | 342 case user_manager::USER_TYPE_PUBLIC_ACCOUNT: |
333 case user_manager::USER_TYPE_SUPERVISED: | 343 case user_manager::USER_TYPE_SUPERVISED: |
334 case user_manager::USER_TYPE_KIOSK_APP: | 344 case user_manager::USER_TYPE_KIOSK_APP: |
335 return false; | 345 return false; |
336 default: | 346 default: |
337 NOTREACHED(); | 347 NOTREACHED(); |
338 } | 348 } |
339 return false; | 349 return false; |
340 } | 350 } |
341 | 351 |
342 } // namespace user_manager | 352 } // namespace user_manager |
OLD | NEW |