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

Side by Side Diff: chrome/browser/chromeos/login/users/chrome_user_manager_impl.cc

Issue 1412813003: 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: Update after review. 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
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 "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h" 5 #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <set> 8 #include <set>
9 9
10 #include "ash/multi_profile_uma.h" 10 #include "ash/multi_profile_uma.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 BootstrapManager* ChromeUserManagerImpl::GetBootstrapManager() { 199 BootstrapManager* ChromeUserManagerImpl::GetBootstrapManager() {
200 return bootstrap_manager_.get(); 200 return bootstrap_manager_.get();
201 } 201 }
202 202
203 MultiProfileUserController* 203 MultiProfileUserController*
204 ChromeUserManagerImpl::GetMultiProfileUserController() { 204 ChromeUserManagerImpl::GetMultiProfileUserController() {
205 return multi_profile_user_controller_.get(); 205 return multi_profile_user_controller_.get();
206 } 206 }
207 207
208 UserImageManager* ChromeUserManagerImpl::GetUserImageManager( 208 UserImageManager* ChromeUserManagerImpl::GetUserImageManager(
209 const std::string& user_id) { 209 const AccountId& account_id) {
210 UserImageManagerMap::iterator ui = user_image_managers_.find(user_id); 210 UserImageManagerMap::iterator ui = user_image_managers_.find(account_id);
211 if (ui != user_image_managers_.end()) 211 if (ui != user_image_managers_.end())
212 return ui->second.get(); 212 return ui->second.get();
213 linked_ptr<UserImageManagerImpl> mgr(new UserImageManagerImpl(user_id, this)); 213 linked_ptr<UserImageManagerImpl> mgr(
214 user_image_managers_[user_id] = mgr; 214 new UserImageManagerImpl(account_id.GetUserEmail(), this));
215 user_image_managers_[account_id] = mgr;
215 return mgr.get(); 216 return mgr.get();
216 } 217 }
217 218
218 SupervisedUserManager* ChromeUserManagerImpl::GetSupervisedUserManager() { 219 SupervisedUserManager* ChromeUserManagerImpl::GetSupervisedUserManager() {
219 return supervised_user_manager_.get(); 220 return supervised_user_manager_.get();
220 } 221 }
221 222
222 user_manager::UserList ChromeUserManagerImpl::GetUsersAllowedForMultiProfile() 223 user_manager::UserList ChromeUserManagerImpl::GetUsersAllowedForMultiProfile()
223 const { 224 const {
224 // Supervised users are not allowed to use multi-profiles. 225 // Supervised users are not allowed to use multi-profiles.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 DCHECK_CURRENTLY_ON(BrowserThread::UI); 310 DCHECK_CURRENTLY_ON(BrowserThread::UI);
310 ChromeUserManager::SessionStarted(); 311 ChromeUserManager::SessionStarted();
311 312
312 content::NotificationService::current()->Notify( 313 content::NotificationService::current()->Notify(
313 chrome::NOTIFICATION_SESSION_STARTED, 314 chrome::NOTIFICATION_SESSION_STARTED,
314 content::Source<UserManager>(this), 315 content::Source<UserManager>(this),
315 content::Details<const user_manager::User>(GetActiveUser())); 316 content::Details<const user_manager::User>(GetActiveUser()));
316 } 317 }
317 318
318 void ChromeUserManagerImpl::RemoveUserInternal( 319 void ChromeUserManagerImpl::RemoveUserInternal(
319 const std::string& user_email, 320 const AccountId& account_id,
320 user_manager::RemoveUserDelegate* delegate) { 321 user_manager::RemoveUserDelegate* delegate) {
321 CrosSettings* cros_settings = CrosSettings::Get(); 322 CrosSettings* cros_settings = CrosSettings::Get();
322 323
323 const base::Closure& callback = 324 const base::Closure& callback =
324 base::Bind(&ChromeUserManagerImpl::RemoveUserInternal, 325 base::Bind(&ChromeUserManagerImpl::RemoveUserInternal,
325 weak_factory_.GetWeakPtr(), 326 weak_factory_.GetWeakPtr(), account_id, delegate);
326 user_email,
327 delegate);
328 327
329 // Ensure the value of owner email has been fetched. 328 // Ensure the value of owner email has been fetched.
330 if (CrosSettingsProvider::TRUSTED != 329 if (CrosSettingsProvider::TRUSTED !=
331 cros_settings->PrepareTrustedValues(callback)) { 330 cros_settings->PrepareTrustedValues(callback)) {
332 // Value of owner email is not fetched yet. RemoveUserInternal will be 331 // Value of owner email is not fetched yet. RemoveUserInternal will be
333 // called again after fetch completion. 332 // called again after fetch completion.
334 return; 333 return;
335 } 334 }
336 std::string owner; 335 std::string owner;
337 cros_settings->GetString(kDeviceOwner, &owner); 336 cros_settings->GetString(kDeviceOwner, &owner);
338 if (user_email == owner) { 337 if (account_id == AccountId::FromUserEmail(owner)) {
achuithb 2015/10/28 23:11:45 This is changing to GaiaId, right?
Alexander Alekseev 2015/10/29 02:00:40 Yes. This is one of several serialization parts of
339 // Owner is not allowed to be removed from the device. 338 // Owner is not allowed to be removed from the device.
340 return; 339 return;
341 } 340 }
342 RemoveNonOwnerUserInternal(user_email, delegate); 341 RemoveNonOwnerUserInternal(account_id, delegate);
343 } 342 }
344 343
345 void ChromeUserManagerImpl::SaveUserOAuthStatus( 344 void ChromeUserManagerImpl::SaveUserOAuthStatus(
346 const std::string& user_id, 345 const AccountId& account_id,
347 user_manager::User::OAuthTokenStatus oauth_token_status) { 346 user_manager::User::OAuthTokenStatus oauth_token_status) {
348 DCHECK_CURRENTLY_ON(BrowserThread::UI); 347 DCHECK_CURRENTLY_ON(BrowserThread::UI);
349 ChromeUserManager::SaveUserOAuthStatus(user_id, oauth_token_status); 348 ChromeUserManager::SaveUserOAuthStatus(account_id, oauth_token_status);
350 349
351 GetUserFlow(user_id)->HandleOAuthTokenStatusChange(oauth_token_status); 350 GetUserFlow(account_id)->HandleOAuthTokenStatusChange(oauth_token_status);
352 } 351 }
353 352
354 void ChromeUserManagerImpl::SaveUserDisplayName( 353 void ChromeUserManagerImpl::SaveUserDisplayName(
355 const std::string& user_id, 354 const AccountId& account_id,
356 const base::string16& display_name) { 355 const base::string16& display_name) {
357 DCHECK_CURRENTLY_ON(BrowserThread::UI); 356 DCHECK_CURRENTLY_ON(BrowserThread::UI);
358 ChromeUserManager::SaveUserDisplayName(user_id, display_name); 357 ChromeUserManager::SaveUserDisplayName(account_id, display_name);
359 358
360 // Do not update local state if data stored or cached outside the user's 359 // Do not update local state if data stored or cached outside the user's
361 // cryptohome is to be treated as ephemeral. 360 // cryptohome is to be treated as ephemeral.
362 if (!IsUserNonCryptohomeDataEphemeral(user_id)) 361 if (!IsUserNonCryptohomeDataEphemeral(account_id))
achuithb 2015/10/28 23:11:45 I think use {} here because of the line break?
Alexander Alekseev 2015/10/29 02:00:40 Done.
363 supervised_user_manager_->UpdateManagerName(user_id, display_name); 362 supervised_user_manager_->UpdateManagerName(account_id.GetUserEmail(),
363 display_name);
364 } 364 }
365 365
366 void ChromeUserManagerImpl::StopPolicyObserverForTesting() { 366 void ChromeUserManagerImpl::StopPolicyObserverForTesting() {
367 avatar_policy_observer_.reset(); 367 avatar_policy_observer_.reset();
368 wallpaper_policy_observer_.reset(); 368 wallpaper_policy_observer_.reset();
369 } 369 }
370 370
371 void ChromeUserManagerImpl::Observe( 371 void ChromeUserManagerImpl::Observe(
372 int type, 372 int type,
373 const content::NotificationSource& source, 373 const content::NotificationSource& source,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 break; 405 break;
406 } 406 }
407 case chrome::NOTIFICATION_PROFILE_CREATED: { 407 case chrome::NOTIFICATION_PROFILE_CREATED: {
408 Profile* profile = content::Source<Profile>(source).ptr(); 408 Profile* profile = content::Source<Profile>(source).ptr();
409 user_manager::User* user = 409 user_manager::User* user =
410 ProfileHelper::Get()->GetUserByProfile(profile); 410 ProfileHelper::Get()->GetUserByProfile(profile);
411 if (user != NULL) { 411 if (user != NULL) {
412 user->set_profile_is_created(); 412 user->set_profile_is_created();
413 413
414 if (user->HasGaiaAccount()) { 414 if (user->HasGaiaAccount()) {
415 UserImageManager* image_manager = GetUserImageManager(user->email()); 415 UserImageManager* image_manager =
416 GetUserImageManager(user->GetAccountId());
416 image_manager->UserProfileCreated(); 417 image_manager->UserProfileCreated();
achuithb 2015/10/28 23:11:45 Maybe just: GetUserImageManager(user->GetAccountId
Alexander Alekseev 2015/10/29 02:00:40 Done.
417 } 418 }
418 } 419 }
419 420
420 // If there is pending user switch, do it now. 421 // If there is pending user switch, do it now.
421 if (!GetPendingUserSwitchID().empty()) { 422 if (GetPendingUserSwitchID().is_valid()) {
422 // Call SwitchActiveUser async because otherwise it may cause 423 // Call SwitchActiveUser async because otherwise it may cause
423 // ProfileManager::GetProfile before the profile gets registered 424 // ProfileManager::GetProfile before the profile gets registered
424 // in ProfileManager. It happens in case of sync profile load when 425 // in ProfileManager. It happens in case of sync profile load when
425 // NOTIFICATION_PROFILE_CREATED is called synchronously. 426 // NOTIFICATION_PROFILE_CREATED is called synchronously.
426 base::MessageLoop::current()->PostTask( 427 base::MessageLoop::current()->PostTask(
427 FROM_HERE, 428 FROM_HERE,
428 base::Bind(&ChromeUserManagerImpl::SwitchActiveUser, 429 base::Bind(&ChromeUserManagerImpl::SwitchActiveUser,
429 weak_factory_.GetWeakPtr(), 430 weak_factory_.GetWeakPtr(),
430 GetPendingUserSwitchID())); 431 GetPendingUserSwitchID()));
431 SetPendingUserSwitchID(std::string()); 432 SetPendingUserSwitchId(EmptyAccountId());
432 } 433 }
433 break; 434 break;
434 } 435 }
435 default: 436 default:
436 NOTREACHED(); 437 NOTREACHED();
437 } 438 }
438 } 439 }
439 440
440 void ChromeUserManagerImpl::OnExternalDataSet(const std::string& policy, 441 void ChromeUserManagerImpl::OnExternalDataSet(const std::string& policy,
441 const std::string& user_id) { 442 const std::string& user_id) {
442 if (policy == policy::key::kUserAvatarImage) 443 if (policy == policy::key::kUserAvatarImage)
443 GetUserImageManager(user_id)->OnExternalDataSet(policy); 444 GetUserImageManager(AccountId::FromUserEmail(user_id))
445 ->OnExternalDataSet(policy);
444 else if (policy == policy::key::kWallpaperImage) 446 else if (policy == policy::key::kWallpaperImage)
445 WallpaperManager::Get()->OnPolicySet(policy, user_id); 447 WallpaperManager::Get()->OnPolicySet(policy, user_id);
446 else 448 else
447 NOTREACHED(); 449 NOTREACHED();
448 } 450 }
449 451
450 void ChromeUserManagerImpl::OnExternalDataCleared(const std::string& policy, 452 void ChromeUserManagerImpl::OnExternalDataCleared(const std::string& policy,
451 const std::string& user_id) { 453 const std::string& user_id) {
452 if (policy == policy::key::kUserAvatarImage) 454 if (policy == policy::key::kUserAvatarImage)
453 GetUserImageManager(user_id)->OnExternalDataCleared(policy); 455 GetUserImageManager(AccountId::FromUserEmail(user_id))
456 ->OnExternalDataCleared(policy);
454 else if (policy == policy::key::kWallpaperImage) 457 else if (policy == policy::key::kWallpaperImage)
455 WallpaperManager::Get()->OnPolicyCleared(policy, user_id); 458 WallpaperManager::Get()->OnPolicyCleared(policy, user_id);
456 else 459 else
457 NOTREACHED(); 460 NOTREACHED();
458 } 461 }
459 462
460 void ChromeUserManagerImpl::OnExternalDataFetched( 463 void ChromeUserManagerImpl::OnExternalDataFetched(
461 const std::string& policy, 464 const std::string& policy,
462 const std::string& user_id, 465 const std::string& user_id,
463 scoped_ptr<std::string> data) { 466 scoped_ptr<std::string> data) {
464 if (policy == policy::key::kUserAvatarImage) 467 if (policy == policy::key::kUserAvatarImage)
465 GetUserImageManager(user_id)->OnExternalDataFetched(policy, data.Pass()); 468 GetUserImageManager(AccountId::FromUserEmail(user_id))
469 ->OnExternalDataFetched(policy, data.Pass());
466 else if (policy == policy::key::kWallpaperImage) 470 else if (policy == policy::key::kWallpaperImage)
467 WallpaperManager::Get()->OnPolicyFetched(policy, user_id, data.Pass()); 471 WallpaperManager::Get()->OnPolicyFetched(policy, user_id, data.Pass());
468 else 472 else
469 NOTREACHED(); 473 NOTREACHED();
470 } 474 }
471 475
472 void ChromeUserManagerImpl::OnPolicyUpdated(const std::string& user_id) { 476 void ChromeUserManagerImpl::OnPolicyUpdated(const std::string& user_id) {
473 const user_manager::User* user = FindUser(user_id); 477 const user_manager::User* user = FindUser(AccountId::FromUserEmail(user_id));
474 if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT) 478 if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT)
475 return; 479 return;
476 UpdatePublicAccountDisplayName(user_id); 480 UpdatePublicAccountDisplayName(user_id);
477 } 481 }
478 482
479 void ChromeUserManagerImpl::OnDeviceLocalAccountsChanged() { 483 void ChromeUserManagerImpl::OnDeviceLocalAccountsChanged() {
480 // No action needed here, changes to the list of device-local accounts get 484 // No action needed here, changes to the list of device-local accounts get
481 // handled via the kAccountsPrefDeviceLocalAccounts device setting observer. 485 // handled via the kAccountsPrefDeviceLocalAccounts device setting observer.
482 } 486 }
483 487
484 bool ChromeUserManagerImpl::CanCurrentUserLock() const { 488 bool ChromeUserManagerImpl::CanCurrentUserLock() const {
485 return ChromeUserManager::CanCurrentUserLock() && 489 return ChromeUserManager::CanCurrentUserLock() &&
486 GetCurrentUserFlow()->CanLockScreen(); 490 GetCurrentUserFlow()->CanLockScreen();
487 } 491 }
488 492
489 bool ChromeUserManagerImpl::IsUserNonCryptohomeDataEphemeral( 493 bool ChromeUserManagerImpl::IsUserNonCryptohomeDataEphemeral(
490 const std::string& user_id) const { 494 const AccountId& account_id) const {
491 // Data belonging to the obsolete public accounts whose data has not been 495 // Data belonging to the obsolete public accounts whose data has not been
492 // removed yet is not ephemeral. 496 // removed yet is not ephemeral.
493 bool is_obsolete_public_account = IsPublicAccountMarkedForRemoval(user_id); 497 bool is_obsolete_public_account = IsPublicAccountMarkedForRemoval(account_id);
494 498
495 return !is_obsolete_public_account && 499 return !is_obsolete_public_account &&
496 ChromeUserManager::IsUserNonCryptohomeDataEphemeral(user_id); 500 ChromeUserManager::IsUserNonCryptohomeDataEphemeral(account_id);
497 } 501 }
498 502
499 bool ChromeUserManagerImpl::AreEphemeralUsersEnabled() const { 503 bool ChromeUserManagerImpl::AreEphemeralUsersEnabled() const {
500 policy::BrowserPolicyConnectorChromeOS* connector = 504 policy::BrowserPolicyConnectorChromeOS* connector =
501 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 505 g_browser_process->platform_part()->browser_policy_connector_chromeos();
502 return GetEphemeralUsersEnabled() && 506 return GetEphemeralUsersEnabled() &&
503 (connector->IsEnterpriseManaged() || !GetOwnerEmail().empty()); 507 (connector->IsEnterpriseManaged() || GetOwnerAccountId().is_valid());
504 } 508 }
505 509
506 void ChromeUserManagerImpl::OnUserRemoved(const std::string& user_id) { 510 void ChromeUserManagerImpl::OnUserRemoved(const AccountId& account_id) {
507 RemoveReportingUser(FullyCanonicalize(user_id)); 511 RemoveReportingUser(FullyCanonicalize(account_id.GetUserEmail()));
508 } 512 }
509 513
510 const std::string& ChromeUserManagerImpl::GetApplicationLocale() const { 514 const std::string& ChromeUserManagerImpl::GetApplicationLocale() const {
511 return g_browser_process->GetApplicationLocale(); 515 return g_browser_process->GetApplicationLocale();
512 } 516 }
513 517
514 PrefService* ChromeUserManagerImpl::GetLocalState() const { 518 PrefService* ChromeUserManagerImpl::GetLocalState() const {
515 return g_browser_process ? g_browser_process->local_state() : NULL; 519 return g_browser_process ? g_browser_process->local_state() : NULL;
516 } 520 }
517 521
518 void ChromeUserManagerImpl::HandleUserOAuthTokenStatusChange( 522 void ChromeUserManagerImpl::HandleUserOAuthTokenStatusChange(
519 const std::string& user_id, 523 const AccountId& account_id,
520 user_manager::User::OAuthTokenStatus status) const { 524 user_manager::User::OAuthTokenStatus status) const {
521 GetUserFlow(user_id)->HandleOAuthTokenStatusChange(status); 525 GetUserFlow(account_id)->HandleOAuthTokenStatusChange(status);
522 } 526 }
523 527
524 bool ChromeUserManagerImpl::IsEnterpriseManaged() const { 528 bool ChromeUserManagerImpl::IsEnterpriseManaged() const {
525 policy::BrowserPolicyConnectorChromeOS* connector = 529 policy::BrowserPolicyConnectorChromeOS* connector =
526 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 530 g_browser_process->platform_part()->browser_policy_connector_chromeos();
527 return connector->IsEnterpriseManaged(); 531 return connector->IsEnterpriseManaged();
528 } 532 }
529 533
530 void ChromeUserManagerImpl::LoadPublicAccounts( 534 void ChromeUserManagerImpl::LoadPublicAccounts(
531 std::set<std::string>* public_sessions_set) { 535 std::set<AccountId>* public_sessions_set) {
532 const base::ListValue* prefs_public_sessions = 536 const base::ListValue* prefs_public_sessions =
533 GetLocalState()->GetList(kPublicAccounts); 537 GetLocalState()->GetList(kPublicAccounts);
534 std::vector<std::string> public_sessions; 538 std::vector<AccountId> public_sessions;
535 ParseUserList(*prefs_public_sessions, 539 ParseUserList(*prefs_public_sessions, std::set<AccountId>(), &public_sessions,
536 std::set<std::string>(),
537 &public_sessions,
538 public_sessions_set); 540 public_sessions_set);
539 for (std::vector<std::string>::const_iterator it = public_sessions.begin(); 541 for (const AccountId& account_id : public_sessions) {
540 it != public_sessions.end(); 542 users_.push_back(user_manager::User::CreatePublicAccountUser(account_id));
541 ++it) { 543 UpdatePublicAccountDisplayName(account_id.GetUserEmail());
542 users_.push_back(user_manager::User::CreatePublicAccountUser(*it));
543 UpdatePublicAccountDisplayName(*it);
544 } 544 }
545 } 545 }
546 546
547 void ChromeUserManagerImpl::PerformPreUserListLoadingActions() { 547 void ChromeUserManagerImpl::PerformPreUserListLoadingActions() {
548 // Clean up user list first. All code down the path should be synchronous, 548 // Clean up user list first. All code down the path should be synchronous,
549 // so that local state after transaction rollback is in consistent state. 549 // so that local state after transaction rollback is in consistent state.
550 // This process also should not trigger EnsureUsersLoaded again. 550 // This process also should not trigger EnsureUsersLoaded again.
551 if (supervised_user_manager_->HasFailedUserCreationTransaction()) 551 if (supervised_user_manager_->HasFailedUserCreationTransaction())
552 supervised_user_manager_->RollbackUserCreationTransaction(); 552 supervised_user_manager_->RollbackUserCreationTransaction();
553 553
554 // Abandon all unfinished bootstraps. 554 // Abandon all unfinished bootstraps.
555 bootstrap_manager_->RemoveAllPendingBootstrap(); 555 bootstrap_manager_->RemoveAllPendingBootstrap();
556 } 556 }
557 557
558 void ChromeUserManagerImpl::PerformPostUserListLoadingActions() { 558 void ChromeUserManagerImpl::PerformPostUserListLoadingActions() {
559 for (user_manager::UserList::iterator ui = users_.begin(), ue = users_.end(); 559 for (user_manager::UserList::iterator ui = users_.begin(), ue = users_.end();
560 ui != ue; 560 ui != ue;
561 ++ui) { 561 ++ui) {
562 GetUserImageManager((*ui)->email())->LoadUserImage(); 562 GetUserImageManager((*ui)->GetAccountId())->LoadUserImage();
563 } 563 }
564 } 564 }
565 565
566 void ChromeUserManagerImpl::PerformPostUserLoggedInActions( 566 void ChromeUserManagerImpl::PerformPostUserLoggedInActions(
567 bool browser_restart) { 567 bool browser_restart) {
568 // Initialize the session length limiter and start it only if 568 // Initialize the session length limiter and start it only if
569 // session limit is defined by the policy. 569 // session limit is defined by the policy.
570 session_length_limiter_.reset( 570 session_length_limiter_.reset(
571 new SessionLengthLimiter(NULL, browser_restart)); 571 new SessionLengthLimiter(NULL, browser_restart));
572 } 572 }
573 573
574 bool ChromeUserManagerImpl::IsDemoApp(const std::string& user_id) const { 574 bool ChromeUserManagerImpl::IsDemoApp(const AccountId& account_id) const {
575 return DemoAppLauncher::IsDemoAppSession(user_id); 575 return DemoAppLauncher::IsDemoAppSession(account_id.GetUserEmail());
576 } 576 }
577 577
578 bool ChromeUserManagerImpl::IsKioskApp(const std::string& user_id) const { 578 bool ChromeUserManagerImpl::IsKioskApp(const AccountId& account_id) const {
579 policy::DeviceLocalAccount::Type device_local_account_type; 579 policy::DeviceLocalAccount::Type device_local_account_type;
580 return policy::IsDeviceLocalAccountUser(user_id, 580 return policy::IsDeviceLocalAccountUser(account_id.GetUserEmail(),
581 &device_local_account_type) && 581 &device_local_account_type) &&
582 device_local_account_type == 582 device_local_account_type ==
583 policy::DeviceLocalAccount::TYPE_KIOSK_APP; 583 policy::DeviceLocalAccount::TYPE_KIOSK_APP;
584 } 584 }
585 585
586 bool ChromeUserManagerImpl::IsPublicAccountMarkedForRemoval( 586 bool ChromeUserManagerImpl::IsPublicAccountMarkedForRemoval(
587 const std::string& user_id) const { 587 const AccountId& account_id) const {
588 return user_id == 588 return account_id == AccountId::FromUserEmail(GetLocalState()->GetString(
589 GetLocalState()->GetString(kPublicAccountPendingDataRemoval); 589 kPublicAccountPendingDataRemoval));
590 } 590 }
591 591
592 void ChromeUserManagerImpl::RetrieveTrustedDevicePolicies() { 592 void ChromeUserManagerImpl::RetrieveTrustedDevicePolicies() {
593 // Local state may not be initialized in unit_tests. 593 // Local state may not be initialized in unit_tests.
594 if (!GetLocalState()) 594 if (!GetLocalState())
595 return; 595 return;
596 596
597 SetEphemeralUsersEnabled(false); 597 SetEphemeralUsersEnabled(false);
598 SetOwnerEmail(std::string()); 598 SetOwnerId(EmptyAccountId());
599 599
600 // Schedule a callback if device policy has not yet been verified. 600 // Schedule a callback if device policy has not yet been verified.
601 if (CrosSettingsProvider::TRUSTED != 601 if (CrosSettingsProvider::TRUSTED !=
602 cros_settings_->PrepareTrustedValues( 602 cros_settings_->PrepareTrustedValues(
603 base::Bind(&ChromeUserManagerImpl::RetrieveTrustedDevicePolicies, 603 base::Bind(&ChromeUserManagerImpl::RetrieveTrustedDevicePolicies,
604 weak_factory_.GetWeakPtr()))) { 604 weak_factory_.GetWeakPtr()))) {
605 return; 605 return;
606 } 606 }
607 607
608 bool ephemeral_users_enabled = false; 608 bool ephemeral_users_enabled = false;
609 cros_settings_->GetBoolean(kAccountsPrefEphemeralUsersEnabled, 609 cros_settings_->GetBoolean(kAccountsPrefEphemeralUsersEnabled,
610 &ephemeral_users_enabled); 610 &ephemeral_users_enabled);
611 SetEphemeralUsersEnabled(ephemeral_users_enabled); 611 SetEphemeralUsersEnabled(ephemeral_users_enabled);
612 612
613 std::string owner_email; 613 std::string owner_email;
614 cros_settings_->GetString(kDeviceOwner, &owner_email); 614 cros_settings_->GetString(kDeviceOwner, &owner_email);
615 SetOwnerEmail(owner_email); 615 SetOwnerId(AccountId::FromUserEmail(owner_email));
616 616
617 EnsureUsersLoaded(); 617 EnsureUsersLoaded();
618 618
619 bool changed = UpdateAndCleanUpPublicAccounts( 619 bool changed = UpdateAndCleanUpPublicAccounts(
620 policy::GetDeviceLocalAccounts(cros_settings_)); 620 policy::GetDeviceLocalAccounts(cros_settings_));
621 621
622 // If ephemeral users are enabled and we are on the login screen, take this 622 // If ephemeral users are enabled and we are on the login screen, take this
623 // opportunity to clean up by removing all regular users except the owner. 623 // opportunity to clean up by removing all regular users except the owner.
624 if (GetEphemeralUsersEnabled() && !IsUserLoggedIn()) { 624 if (GetEphemeralUsersEnabled() && !IsUserLoggedIn()) {
625 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); 625 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers);
626 prefs_users_update->Clear(); 626 prefs_users_update->Clear();
627 for (user_manager::UserList::iterator it = users_.begin(); 627 for (user_manager::UserList::iterator it = users_.begin();
628 it != users_.end();) { 628 it != users_.end();) {
629 const std::string user_email = (*it)->email(); 629 const AccountId account_id = (*it)->GetAccountId();
630 if ((*it)->HasGaiaAccount() && user_email != GetOwnerEmail()) { 630 if ((*it)->HasGaiaAccount() && account_id != GetOwnerAccountId()) {
631 RemoveNonCryptohomeData(user_email); 631 RemoveNonCryptohomeData(account_id);
632 DeleteUser(*it); 632 DeleteUser(*it);
633 it = users_.erase(it); 633 it = users_.erase(it);
634 changed = true; 634 changed = true;
635 } else { 635 } else {
636 if ((*it)->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT) 636 if ((*it)->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT)
637 prefs_users_update->Append(new base::StringValue(user_email)); 637 prefs_users_update->Append(
638 new base::StringValue(account_id.GetUserEmail()));
638 ++it; 639 ++it;
639 } 640 }
640 } 641 }
641 } 642 }
642 643
643 if (changed) 644 if (changed)
644 NotifyUserListChanged(); 645 NotifyUserListChanged();
645 } 646 }
646 647
647 void ChromeUserManagerImpl::GuestUserLoggedIn() { 648 void ChromeUserManagerImpl::GuestUserLoggedIn() {
648 DCHECK_CURRENTLY_ON(BrowserThread::UI); 649 DCHECK_CURRENTLY_ON(BrowserThread::UI);
649 ChromeUserManager::GuestUserLoggedIn(); 650 ChromeUserManager::GuestUserLoggedIn();
650 651
651 // TODO(nkostylev): Add support for passing guest session cryptohome 652 // TODO(nkostylev): Add support for passing guest session cryptohome
652 // mount point. Legacy (--login-profile) value will be used for now. 653 // mount point. Legacy (--login-profile) value will be used for now.
653 // http://crosbug.com/230859 654 // http://crosbug.com/230859
654 active_user_->SetStubImage( 655 active_user_->SetStubImage(
655 user_manager::UserImage( 656 user_manager::UserImage(
656 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 657 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
657 IDR_PROFILE_PICTURE_LOADING)), 658 IDR_PROFILE_PICTURE_LOADING)),
658 user_manager::User::USER_IMAGE_INVALID, 659 user_manager::User::USER_IMAGE_INVALID,
659 false); 660 false);
660 661
661 // Initializes wallpaper after active_user_ is set. 662 // Initializes wallpaper after active_user_ is set.
662 WallpaperManager::Get()->SetUserWallpaperNow(chromeos::login::kGuestUserName); 663 WallpaperManager::Get()->SetUserWallpaperNow(chromeos::login::kGuestUserName);
663 } 664 }
664 665
665 void ChromeUserManagerImpl::RegularUserLoggedIn(const std::string& user_id) { 666 void ChromeUserManagerImpl::RegularUserLoggedIn(const AccountId& account_id) {
666 ChromeUserManager::RegularUserLoggedIn(user_id); 667 ChromeUserManager::RegularUserLoggedIn(account_id);
667 668
668 if (FakeOwnership()) { 669 if (FakeOwnership()) {
669 std::string owner_email = GetActiveUser()->email(); 670 const AccountId owner_id = GetActiveUser()->GetAccountId();
achuithb 2015/10/28 23:11:45 owner_account_id?
Alexander Alekseev 2015/10/29 02:00:40 Done.
670 VLOG(1) << "Set device owner to: " << owner_email; 671 VLOG(1) << "Set device owner to: " << owner_id.GetUserEmail();
671 CrosSettings::Get()->SetString(kDeviceOwner, owner_email); 672 CrosSettings::Get()->SetString(kDeviceOwner, owner_id.GetUserEmail());
672 SetOwnerEmail(owner_email); 673 SetOwnerId(owner_id);
673 } 674 }
674 675
675 if (IsCurrentUserNew()) 676 if (IsCurrentUserNew())
676 WallpaperManager::Get()->SetUserWallpaperNow(user_id); 677 WallpaperManager::Get()->SetUserWallpaperNow(account_id.GetUserEmail());
677 678
678 GetUserImageManager(user_id)->UserLoggedIn(IsCurrentUserNew(), false); 679 GetUserImageManager(account_id)->UserLoggedIn(IsCurrentUserNew(), false);
679 680
680 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); 681 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
681 682
682 // Make sure that new data is persisted to Local State. 683 // Make sure that new data is persisted to Local State.
683 GetLocalState()->CommitPendingWrite(); 684 GetLocalState()->CommitPendingWrite();
684 } 685 }
685 686
686 void ChromeUserManagerImpl::RegularUserLoggedInAsEphemeral( 687 void ChromeUserManagerImpl::RegularUserLoggedInAsEphemeral(
687 const std::string& user_id) { 688 const AccountId& account_id) {
688 DCHECK_CURRENTLY_ON(BrowserThread::UI); 689 DCHECK_CURRENTLY_ON(BrowserThread::UI);
689 ChromeUserManager::RegularUserLoggedInAsEphemeral(user_id); 690 ChromeUserManager::RegularUserLoggedInAsEphemeral(account_id);
690 691
691 GetUserImageManager(user_id)->UserLoggedIn(IsCurrentUserNew(), false); 692 GetUserImageManager(account_id)->UserLoggedIn(IsCurrentUserNew(), false);
692 WallpaperManager::Get()->SetUserWallpaperNow(user_id); 693 WallpaperManager::Get()->SetUserWallpaperNow(account_id.GetUserEmail());
693 } 694 }
694 695
695 void ChromeUserManagerImpl::SupervisedUserLoggedIn(const std::string& user_id) { 696 void ChromeUserManagerImpl::SupervisedUserLoggedIn(
697 const AccountId& account_id) {
696 // TODO(nkostylev): Refactor, share code with RegularUserLoggedIn(). 698 // TODO(nkostylev): Refactor, share code with RegularUserLoggedIn().
697 699
698 // Remove the user from the user list. 700 // Remove the user from the user list.
699 active_user_ = RemoveRegularOrSupervisedUserFromList(user_id); 701 active_user_ = RemoveRegularOrSupervisedUserFromList(account_id);
700 702
701 // If the user was not found on the user list, create a new user. 703 // If the user was not found on the user list, create a new user.
702 if (!GetActiveUser()) { 704 if (!GetActiveUser()) {
703 SetIsCurrentUserNew(true); 705 SetIsCurrentUserNew(true);
704 active_user_ = user_manager::User::CreateSupervisedUser(user_id); 706 active_user_ = user_manager::User::CreateSupervisedUser(account_id);
705 // Leaving OAuth token status at the default state = unknown. 707 // Leaving OAuth token status at the default state = unknown.
706 WallpaperManager::Get()->SetUserWallpaperNow(user_id); 708 WallpaperManager::Get()->SetUserWallpaperNow(account_id.GetUserEmail());
707 } else { 709 } else {
708 if (supervised_user_manager_->CheckForFirstRun(user_id)) { 710 if (supervised_user_manager_->CheckForFirstRun(account_id.GetUserEmail())) {
709 SetIsCurrentUserNew(true); 711 SetIsCurrentUserNew(true);
710 WallpaperManager::Get()->SetUserWallpaperNow(user_id); 712 WallpaperManager::Get()->SetUserWallpaperNow(account_id.GetUserEmail());
711 } else { 713 } else {
712 SetIsCurrentUserNew(false); 714 SetIsCurrentUserNew(false);
713 } 715 }
714 } 716 }
715 717
716 // Add the user to the front of the user list. 718 // Add the user to the front of the user list.
717 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); 719 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers);
718 prefs_users_update->Insert(0, new base::StringValue(user_id)); 720 prefs_users_update->Insert(0,
721 new base::StringValue(account_id.GetUserEmail()));
719 users_.insert(users_.begin(), active_user_); 722 users_.insert(users_.begin(), active_user_);
720 723
721 // Now that user is in the list, save display name. 724 // Now that user is in the list, save display name.
722 if (IsCurrentUserNew()) { 725 if (IsCurrentUserNew()) {
723 SaveUserDisplayName(GetActiveUser()->email(), 726 SaveUserDisplayName(GetActiveUser()->GetAccountId(),
724 GetActiveUser()->GetDisplayName()); 727 GetActiveUser()->GetDisplayName());
725 } 728 }
726 729
727 GetUserImageManager(user_id)->UserLoggedIn(IsCurrentUserNew(), true); 730 GetUserImageManager(account_id)->UserLoggedIn(IsCurrentUserNew(), true);
728 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); 731 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
729 732
730 // Make sure that new data is persisted to Local State. 733 // Make sure that new data is persisted to Local State.
731 GetLocalState()->CommitPendingWrite(); 734 GetLocalState()->CommitPendingWrite();
732 } 735 }
733 736
734 bool ChromeUserManagerImpl::HasPendingBootstrap( 737 bool ChromeUserManagerImpl::HasPendingBootstrap(
735 const std::string& user_id) const { 738 const AccountId& account_id) const {
736 return bootstrap_manager_->HasPendingBootstrap(user_id); 739 return bootstrap_manager_->HasPendingBootstrap(account_id.GetUserEmail());
737 } 740 }
738 741
739 void ChromeUserManagerImpl::PublicAccountUserLoggedIn( 742 void ChromeUserManagerImpl::PublicAccountUserLoggedIn(
740 user_manager::User* user) { 743 user_manager::User* user) {
741 SetIsCurrentUserNew(true); 744 SetIsCurrentUserNew(true);
742 active_user_ = user; 745 active_user_ = user;
743 746
744 // The UserImageManager chooses a random avatar picture when a user logs in 747 // The UserImageManager chooses a random avatar picture when a user logs in
745 // for the first time. Tell the UserImageManager that this user is not new to 748 // for the first time. Tell the UserImageManager that this user is not new to
746 // prevent the avatar from getting changed. 749 // prevent the avatar from getting changed.
747 GetUserImageManager(user->email())->UserLoggedIn(false, true); 750 GetUserImageManager(user->GetAccountId())->UserLoggedIn(false, true);
748 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); 751 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
749 } 752 }
750 753
751 void ChromeUserManagerImpl::KioskAppLoggedIn(const std::string& app_id) { 754 void ChromeUserManagerImpl::KioskAppLoggedIn(
755 const AccountId& kiosk_app_account_id) {
752 DCHECK_CURRENTLY_ON(BrowserThread::UI); 756 DCHECK_CURRENTLY_ON(BrowserThread::UI);
753 policy::DeviceLocalAccount::Type device_local_account_type; 757 policy::DeviceLocalAccount::Type device_local_account_type;
754 DCHECK(policy::IsDeviceLocalAccountUser(app_id, &device_local_account_type)); 758 DCHECK(policy::IsDeviceLocalAccountUser(kiosk_app_account_id.GetUserEmail(),
759 &device_local_account_type));
755 DCHECK_EQ(policy::DeviceLocalAccount::TYPE_KIOSK_APP, 760 DCHECK_EQ(policy::DeviceLocalAccount::TYPE_KIOSK_APP,
756 device_local_account_type); 761 device_local_account_type);
757 762
758 active_user_ = user_manager::User::CreateKioskAppUser(app_id); 763 active_user_ = user_manager::User::CreateKioskAppUser(kiosk_app_account_id);
759 active_user_->SetStubImage( 764 active_user_->SetStubImage(
760 user_manager::UserImage( 765 user_manager::UserImage(
761 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 766 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
762 IDR_PROFILE_PICTURE_LOADING)), 767 IDR_PROFILE_PICTURE_LOADING)),
763 user_manager::User::USER_IMAGE_INVALID, 768 user_manager::User::USER_IMAGE_INVALID,
764 false); 769 false);
765 770
766 WallpaperManager::Get()->SetUserWallpaperNow(app_id); 771 WallpaperManager::Get()->SetUserWallpaperNow(
772 kiosk_app_account_id.GetUserEmail());
767 773
768 // TODO(bartfab): Add KioskAppUsers to the users_ list and keep metadata like 774 // TODO(bartfab): Add KioskAppUsers to the users_ list and keep metadata like
769 // the kiosk_app_id in these objects, removing the need to re-parse the 775 // the kiosk_app_id in these objects, removing the need to re-parse the
770 // device-local account list here to extract the kiosk_app_id. 776 // device-local account list here to extract the kiosk_app_id.
771 const std::vector<policy::DeviceLocalAccount> device_local_accounts = 777 const std::vector<policy::DeviceLocalAccount> device_local_accounts =
772 policy::GetDeviceLocalAccounts(cros_settings_); 778 policy::GetDeviceLocalAccounts(cros_settings_);
773 const policy::DeviceLocalAccount* account = NULL; 779 const policy::DeviceLocalAccount* account = NULL;
774 for (std::vector<policy::DeviceLocalAccount>::const_iterator it = 780 for (std::vector<policy::DeviceLocalAccount>::const_iterator it =
775 device_local_accounts.begin(); 781 device_local_accounts.begin();
776 it != device_local_accounts.end(); 782 it != device_local_accounts.end();
777 ++it) { 783 ++it) {
778 if (it->user_id == app_id) { 784 if (it->user_id == kiosk_app_account_id.GetUserEmail()) {
779 account = &*it; 785 account = &*it;
780 break; 786 break;
781 } 787 }
782 } 788 }
783 std::string kiosk_app_id; 789 std::string kiosk_app_name;
784 if (account) { 790 if (account) {
785 kiosk_app_id = account->kiosk_app_id; 791 kiosk_app_name = account->kiosk_app_id;
786 } else { 792 } else {
787 LOG(ERROR) << "Logged into nonexistent kiosk-app account: " << app_id; 793 LOG(ERROR) << "Logged into nonexistent kiosk-app account: "
794 << kiosk_app_account_id.GetUserEmail();
788 NOTREACHED(); 795 NOTREACHED();
789 } 796 }
790 797
791 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 798 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
792 command_line->AppendSwitch(::switches::kForceAppMode); 799 command_line->AppendSwitch(::switches::kForceAppMode);
793 command_line->AppendSwitchASCII(::switches::kAppId, kiosk_app_id); 800 command_line->AppendSwitchASCII(::switches::kAppId, kiosk_app_name);
794 801
795 // Disable window animation since kiosk app runs in a single full screen 802 // Disable window animation since kiosk app runs in a single full screen
796 // window and window animation causes start-up janks. 803 // window and window animation causes start-up janks.
797 command_line->AppendSwitch(wm::switches::kWindowAnimationsDisabled); 804 command_line->AppendSwitch(wm::switches::kWindowAnimationsDisabled);
798 } 805 }
799 806
800 void ChromeUserManagerImpl::DemoAccountLoggedIn() { 807 void ChromeUserManagerImpl::DemoAccountLoggedIn() {
801 DCHECK_CURRENTLY_ON(BrowserThread::UI); 808 DCHECK_CURRENTLY_ON(BrowserThread::UI);
802 active_user_ = user_manager::User::CreateKioskAppUser( 809 active_user_ = user_manager::User::CreateKioskAppUser(login::DemoAccountId());
803 login::DemoAccountId().GetUserEmail());
804 active_user_->SetStubImage( 810 active_user_->SetStubImage(
805 user_manager::UserImage( 811 user_manager::UserImage(
806 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 812 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
807 IDR_PROFILE_PICTURE_LOADING)), 813 IDR_PROFILE_PICTURE_LOADING)),
808 user_manager::User::USER_IMAGE_INVALID, 814 user_manager::User::USER_IMAGE_INVALID,
809 false); 815 false);
810 WallpaperManager::Get()->SetUserWallpaperNow( 816 WallpaperManager::Get()->SetUserWallpaperNow(
811 login::DemoAccountId().GetUserEmail()); 817 login::DemoAccountId().GetUserEmail());
812 818
813 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 819 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
(...skipping 27 matching lines...) Expand all
841 847
842 void ChromeUserManagerImpl::UpdateOwnership() { 848 void ChromeUserManagerImpl::UpdateOwnership() {
843 bool is_owner = 849 bool is_owner =
844 FakeOwnership() || DeviceSettingsService::Get()->HasPrivateOwnerKey(); 850 FakeOwnership() || DeviceSettingsService::Get()->HasPrivateOwnerKey();
845 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner"); 851 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner");
846 852
847 SetCurrentUserIsOwner(is_owner); 853 SetCurrentUserIsOwner(is_owner);
848 } 854 }
849 855
850 void ChromeUserManagerImpl::RemoveNonCryptohomeData( 856 void ChromeUserManagerImpl::RemoveNonCryptohomeData(
851 const std::string& user_id) { 857 const AccountId& account_id) {
852 ChromeUserManager::RemoveNonCryptohomeData(user_id); 858 ChromeUserManager::RemoveNonCryptohomeData(account_id);
853 859
854 WallpaperManager::Get()->RemoveUserWallpaperInfo(user_id); 860 WallpaperManager::Get()->RemoveUserWallpaperInfo(account_id.GetUserEmail());
855 GetUserImageManager(user_id)->DeleteUserImage(); 861 GetUserImageManager(account_id)->DeleteUserImage();
856 862
857 supervised_user_manager_->RemoveNonCryptohomeData(user_id); 863 supervised_user_manager_->RemoveNonCryptohomeData(account_id.GetUserEmail());
858 864
859 multi_profile_user_controller_->RemoveCachedValues(user_id); 865 multi_profile_user_controller_->RemoveCachedValues(account_id.GetUserEmail());
860 866
861 EasyUnlockService::ResetLocalStateForUser(user_id); 867 EasyUnlockService::ResetLocalStateForUser(account_id.GetUserEmail());
862 } 868 }
863 869
864 void 870 void
865 ChromeUserManagerImpl::CleanUpPublicAccountNonCryptohomeDataPendingRemoval() { 871 ChromeUserManagerImpl::CleanUpPublicAccountNonCryptohomeDataPendingRemoval() {
866 PrefService* local_state = GetLocalState(); 872 PrefService* local_state = GetLocalState();
867 const std::string public_account_pending_data_removal = 873 const std::string public_account_pending_data_removal =
868 local_state->GetString(kPublicAccountPendingDataRemoval); 874 local_state->GetString(kPublicAccountPendingDataRemoval);
869 if (public_account_pending_data_removal.empty() || 875 if (public_account_pending_data_removal.empty() ||
870 (IsUserLoggedIn() && 876 (IsUserLoggedIn() &&
871 public_account_pending_data_removal == GetActiveUser()->email())) { 877 public_account_pending_data_removal == GetActiveUser()->email())) {
872 return; 878 return;
873 } 879 }
874 880
875 RemoveNonCryptohomeData(public_account_pending_data_removal); 881 RemoveNonCryptohomeData(
882 AccountId::FromUserEmail(public_account_pending_data_removal));
876 local_state->ClearPref(kPublicAccountPendingDataRemoval); 883 local_state->ClearPref(kPublicAccountPendingDataRemoval);
877 } 884 }
878 885
879 void ChromeUserManagerImpl::CleanUpPublicAccountNonCryptohomeData( 886 void ChromeUserManagerImpl::CleanUpPublicAccountNonCryptohomeData(
880 const std::vector<std::string>& old_public_accounts) { 887 const std::vector<std::string>& old_public_accounts) {
881 std::set<std::string> users; 888 std::set<std::string> users;
882 for (user_manager::UserList::const_iterator it = users_.begin(); 889 for (user_manager::UserList::const_iterator it = users_.begin();
883 it != users_.end(); 890 it != users_.end();
884 ++it) 891 ++it)
885 users.insert((*it)->email()); 892 users.insert((*it)->email());
886 893
887 // If the user is logged into a public account that has been removed from the 894 // If the user is logged into a public account that has been removed from the
888 // user list, mark the account's data as pending removal after logout. 895 // user list, mark the account's data as pending removal after logout.
889 if (IsLoggedInAsPublicAccount()) { 896 if (IsLoggedInAsPublicAccount()) {
890 const std::string active_user_id = GetActiveUser()->email(); 897 const std::string active_user_id = GetActiveUser()->email();
891 if (users.find(active_user_id) == users.end()) { 898 if (users.find(active_user_id) == users.end()) {
892 GetLocalState()->SetString(kPublicAccountPendingDataRemoval, 899 GetLocalState()->SetString(kPublicAccountPendingDataRemoval,
893 active_user_id); 900 active_user_id);
894 users.insert(active_user_id); 901 users.insert(active_user_id);
895 } 902 }
896 } 903 }
897 904
898 // Remove the data belonging to any other public accounts that are no longer 905 // Remove the data belonging to any other public accounts that are no longer
899 // found on the user list. 906 // found on the user list.
900 for (std::vector<std::string>::const_iterator it = 907 for (std::vector<std::string>::const_iterator it =
901 old_public_accounts.begin(); 908 old_public_accounts.begin();
902 it != old_public_accounts.end(); 909 it != old_public_accounts.end();
903 ++it) { 910 ++it) {
904 if (users.find(*it) == users.end()) 911 if (users.find(*it) == users.end())
905 RemoveNonCryptohomeData(*it); 912 RemoveNonCryptohomeData(AccountId::FromUserEmail(*it));
906 } 913 }
907 } 914 }
908 915
909 bool ChromeUserManagerImpl::UpdateAndCleanUpPublicAccounts( 916 bool ChromeUserManagerImpl::UpdateAndCleanUpPublicAccounts(
910 const std::vector<policy::DeviceLocalAccount>& device_local_accounts) { 917 const std::vector<policy::DeviceLocalAccount>& device_local_accounts) {
911 // Try to remove any public account data marked as pending removal. 918 // Try to remove any public account data marked as pending removal.
912 CleanUpPublicAccountNonCryptohomeDataPendingRemoval(); 919 CleanUpPublicAccountNonCryptohomeDataPendingRemoval();
913 920
914 // Get the current list of public accounts. 921 // Get the current list of public accounts.
915 std::vector<std::string> old_public_accounts; 922 std::vector<std::string> old_public_accounts;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 } 975 }
969 976
970 // Add the new public accounts to the front of the user list. 977 // Add the new public accounts to the front of the user list.
971 for (std::vector<std::string>::const_reverse_iterator it = 978 for (std::vector<std::string>::const_reverse_iterator it =
972 new_public_accounts.rbegin(); 979 new_public_accounts.rbegin();
973 it != new_public_accounts.rend(); 980 it != new_public_accounts.rend();
974 ++it) { 981 ++it) {
975 if (IsLoggedInAsPublicAccount() && *it == GetActiveUser()->email()) 982 if (IsLoggedInAsPublicAccount() && *it == GetActiveUser()->email())
976 users_.insert(users_.begin(), GetLoggedInUser()); 983 users_.insert(users_.begin(), GetLoggedInUser());
977 else 984 else
978 users_.insert(users_.begin(), 985 users_.insert(users_.begin(), user_manager::User::CreatePublicAccountUser(
979 user_manager::User::CreatePublicAccountUser(*it)); 986 AccountId::FromUserEmail(*it)));
980 UpdatePublicAccountDisplayName(*it); 987 UpdatePublicAccountDisplayName(*it);
981 } 988 }
982 989
983 for (user_manager::UserList::iterator 990 for (user_manager::UserList::iterator
984 ui = users_.begin(), 991 ui = users_.begin(),
985 ue = users_.begin() + new_public_accounts.size(); 992 ue = users_.begin() + new_public_accounts.size();
986 ui != ue; 993 ui != ue;
987 ++ui) { 994 ++ui) {
988 GetUserImageManager((*ui)->email())->LoadUserImage(); 995 GetUserImageManager((*ui)->GetAccountId())->LoadUserImage();
989 } 996 }
990 997
991 // Remove data belonging to public accounts that are no longer found on the 998 // Remove data belonging to public accounts that are no longer found on the
992 // user list. 999 // user list.
993 CleanUpPublicAccountNonCryptohomeData(old_public_accounts); 1000 CleanUpPublicAccountNonCryptohomeData(old_public_accounts);
994 1001
995 return true; 1002 return true;
996 } 1003 }
997 1004
998 void ChromeUserManagerImpl::UpdatePublicAccountDisplayName( 1005 void ChromeUserManagerImpl::UpdatePublicAccountDisplayName(
999 const std::string& user_id) { 1006 const std::string& user_id) {
1000 std::string display_name; 1007 std::string display_name;
1001 1008
1002 if (device_local_account_policy_service_) { 1009 if (device_local_account_policy_service_) {
1003 policy::DeviceLocalAccountPolicyBroker* broker = 1010 policy::DeviceLocalAccountPolicyBroker* broker =
1004 device_local_account_policy_service_->GetBrokerForUser(user_id); 1011 device_local_account_policy_service_->GetBrokerForUser(user_id);
1005 if (broker) 1012 if (broker)
1006 display_name = broker->GetDisplayName(); 1013 display_name = broker->GetDisplayName();
1007 } 1014 }
1008 1015
1009 // Set or clear the display name. 1016 // Set or clear the display name.
1010 SaveUserDisplayName(user_id, base::UTF8ToUTF16(display_name)); 1017 SaveUserDisplayName(AccountId::FromUserEmail(user_id),
1018 base::UTF8ToUTF16(display_name));
1011 } 1019 }
1012 1020
1013 UserFlow* ChromeUserManagerImpl::GetCurrentUserFlow() const { 1021 UserFlow* ChromeUserManagerImpl::GetCurrentUserFlow() const {
1014 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1022 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1015 if (!IsUserLoggedIn()) 1023 if (!IsUserLoggedIn())
1016 return GetDefaultUserFlow(); 1024 return GetDefaultUserFlow();
1017 return GetUserFlow(GetLoggedInUser()->email()); 1025 return GetUserFlow(GetLoggedInUser()->GetAccountId());
1018 } 1026 }
1019 1027
1020 UserFlow* ChromeUserManagerImpl::GetUserFlow(const std::string& user_id) const { 1028 UserFlow* ChromeUserManagerImpl::GetUserFlow(
1029 const AccountId& account_id) const {
1021 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1030 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1022 FlowMap::const_iterator it = specific_flows_.find(user_id); 1031 FlowMap::const_iterator it = specific_flows_.find(account_id);
1023 if (it != specific_flows_.end()) 1032 if (it != specific_flows_.end())
1024 return it->second; 1033 return it->second;
1025 return GetDefaultUserFlow(); 1034 return GetDefaultUserFlow();
1026 } 1035 }
1027 1036
1028 void ChromeUserManagerImpl::SetUserFlow(const std::string& user_id, 1037 void ChromeUserManagerImpl::SetUserFlow(const AccountId& account_id,
1029 UserFlow* flow) { 1038 UserFlow* flow) {
1030 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1039 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1031 ResetUserFlow(user_id); 1040 ResetUserFlow(account_id);
1032 specific_flows_[user_id] = flow; 1041 specific_flows_[account_id] = flow;
1033 } 1042 }
1034 1043
1035 void ChromeUserManagerImpl::ResetUserFlow(const std::string& user_id) { 1044 void ChromeUserManagerImpl::ResetUserFlow(const AccountId& account_id) {
1036 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1045 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1037 FlowMap::iterator it = specific_flows_.find(user_id); 1046 FlowMap::iterator it = specific_flows_.find(account_id);
1038 if (it != specific_flows_.end()) { 1047 if (it != specific_flows_.end()) {
1039 delete it->second; 1048 delete it->second;
1040 specific_flows_.erase(it); 1049 specific_flows_.erase(it);
1041 } 1050 }
1042 } 1051 }
1043 1052
1044 bool ChromeUserManagerImpl::AreSupervisedUsersAllowed() const { 1053 bool ChromeUserManagerImpl::AreSupervisedUsersAllowed() const {
1045 bool supervised_users_allowed = false; 1054 bool supervised_users_allowed = false;
1046 cros_settings_->GetBoolean(kAccountsPrefSupervisedUsersEnabled, 1055 cros_settings_->GetBoolean(kAccountsPrefSupervisedUsersEnabled,
1047 &supervised_users_allowed); 1056 &supervised_users_allowed);
(...skipping 15 matching lines...) Expand all
1063 } 1072 }
1064 1073
1065 void ChromeUserManagerImpl::NotifyUserAddedToSession( 1074 void ChromeUserManagerImpl::NotifyUserAddedToSession(
1066 const user_manager::User* added_user, 1075 const user_manager::User* added_user,
1067 bool user_switch_pending) { 1076 bool user_switch_pending) {
1068 // Special case for user session restoration after browser crash. 1077 // Special case for user session restoration after browser crash.
1069 // We don't switch to each user session that has been restored as once all 1078 // We don't switch to each user session that has been restored as once all
1070 // session will be restored we'll switch to the session that has been used 1079 // session will be restored we'll switch to the session that has been used
1071 // before the crash. 1080 // before the crash.
1072 if (user_switch_pending && 1081 if (user_switch_pending &&
1073 !UserSessionManager::GetInstance()->UserSessionsRestoreInProgress()) { 1082 !UserSessionManager::GetInstance()->UserSessionsRestoreInProgress()) {
achuithb 2015/10/28 23:11:45 can probably drop {}
Alexander Alekseev 2015/10/29 02:00:40 Here is a multiline condition. I don't think this
1074 SetPendingUserSwitchID(added_user->email()); 1083 SetPendingUserSwitchId(added_user->GetAccountId());
1075 } 1084 }
1076 1085
1077 UpdateNumberOfUsers(); 1086 UpdateNumberOfUsers();
1078 ChromeUserManager::NotifyUserAddedToSession(added_user, user_switch_pending); 1087 ChromeUserManager::NotifyUserAddedToSession(added_user, user_switch_pending);
1079 } 1088 }
1080 1089
1081 void ChromeUserManagerImpl::OnUserNotAllowed(const std::string& user_email) { 1090 void ChromeUserManagerImpl::OnUserNotAllowed(const std::string& user_email) {
1082 LOG(ERROR) << "Shutdown session because a user is not allowed to be in the " 1091 LOG(ERROR) << "Shutdown session because a user is not allowed to be in the "
1083 "current session"; 1092 "current session";
1084 chromeos::ShowMultiprofilesSessionAbortedDialog(user_email); 1093 chromeos::ShowMultiprofilesSessionAbortedDialog(user_email);
1085 } 1094 }
1086 1095
1087 void ChromeUserManagerImpl::RemovePendingBootstrapUser( 1096 void ChromeUserManagerImpl::RemovePendingBootstrapUser(
1088 const std::string& user_id) { 1097 const std::string& user_id) {
1089 DCHECK(HasPendingBootstrap(user_id)); 1098 const AccountId account_id(AccountId::FromUserEmail(user_id));
1090 RemoveNonOwnerUserInternal(user_id, NULL); 1099 DCHECK(HasPendingBootstrap(account_id));
1100 RemoveNonOwnerUserInternal(account_id, nullptr);
1091 } 1101 }
1092 1102
1093 void ChromeUserManagerImpl::UpdateNumberOfUsers() { 1103 void ChromeUserManagerImpl::UpdateNumberOfUsers() {
1094 size_t users = GetLoggedInUsers().size(); 1104 size_t users = GetLoggedInUsers().size();
1095 if (users) { 1105 if (users) {
1096 // Write the user number as UMA stat when a multi user session is possible. 1106 // Write the user number as UMA stat when a multi user session is possible.
1097 if ((users + GetUsersAllowedForMultiProfile().size()) > 1) 1107 if ((users + GetUsersAllowedForMultiProfile().size()) > 1)
1098 ash::MultiProfileUMA::RecordUserCount(users); 1108 ash::MultiProfileUMA::RecordUserCount(users);
1099 } 1109 }
1100 1110
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 g_browser_process->platform_part()->GetTimezoneResolver()->Start(); 1144 g_browser_process->platform_part()->GetTimezoneResolver()->Start();
1135 } else { 1145 } else {
1136 g_browser_process->platform_part()->GetTimezoneResolver()->Stop(); 1146 g_browser_process->platform_part()->GetTimezoneResolver()->Stop();
1137 } 1147 }
1138 } 1148 }
1139 1149
1140 void ChromeUserManagerImpl::SetUserAffiliation( 1150 void ChromeUserManagerImpl::SetUserAffiliation(
1141 const std::string& user_email, 1151 const std::string& user_email,
1142 const AffiliationIDSet& user_affiliation_ids) { 1152 const AffiliationIDSet& user_affiliation_ids) {
1143 std::string canonicalized_email = FullyCanonicalize(user_email); 1153 std::string canonicalized_email = FullyCanonicalize(user_email);
1144 user_manager::User* user = FindUserAndModify(canonicalized_email); 1154 user_manager::User* user =
1155 FindUserAndModify(AccountId::FromUserEmail(canonicalized_email));
1145 1156
1146 if (user) { 1157 if (user) {
1147 policy::BrowserPolicyConnectorChromeOS const* const connector = 1158 policy::BrowserPolicyConnectorChromeOS const* const connector =
1148 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 1159 g_browser_process->platform_part()->browser_policy_connector_chromeos();
1149 const bool is_affiliated = chromeos::IsUserAffiliated( 1160 const bool is_affiliated = chromeos::IsUserAffiliated(
1150 user_affiliation_ids, connector->GetDeviceAffiliationIDs(), 1161 user_affiliation_ids, connector->GetDeviceAffiliationIDs(),
1151 canonicalized_email, connector->GetEnterpriseDomain()); 1162 canonicalized_email, connector->GetEnterpriseDomain());
1152 user->set_affiliation(is_affiliated); 1163 user->set_affiliation(is_affiliated);
1153 1164
1154 if (user->GetType() == user_manager::USER_TYPE_REGULAR) { 1165 if (user->GetType() == user_manager::USER_TYPE_REGULAR) {
(...skipping 18 matching lines...) Expand all
1173 users_update->AppendIfNotPresent( 1184 users_update->AppendIfNotPresent(
1174 new base::StringValue(FullyCanonicalize(user_id))); 1185 new base::StringValue(FullyCanonicalize(user_id)));
1175 } 1186 }
1176 1187
1177 void ChromeUserManagerImpl::RemoveReportingUser(const std::string& user_id) { 1188 void ChromeUserManagerImpl::RemoveReportingUser(const std::string& user_id) {
1178 ListPrefUpdate users_update(GetLocalState(), kReportingUsers); 1189 ListPrefUpdate users_update(GetLocalState(), kReportingUsers);
1179 users_update->Remove(base::StringValue(FullyCanonicalize(user_id)), NULL); 1190 users_update->Remove(base::StringValue(FullyCanonicalize(user_id)), NULL);
1180 } 1191 }
1181 1192
1182 } // namespace chromeos 1193 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698