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

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: Rebased. Created 5 years, 2 months 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& user_id) {
achuithb 2015/10/23 00:08:50 account_id here and below
Alexander Alekseev 2015/10/23 09:11:22 Done.
210 UserImageManagerMap::iterator ui = user_image_managers_.find(user_id); 210 UserImageManagerMap::iterator ui = user_image_managers_.find(user_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 new UserImageManagerImpl(user_id.GetUserEmail(), this));
214 user_image_managers_[user_id] = mgr; 215 user_image_managers_[user_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 {
(...skipping 85 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& user_id,
achuithb 2015/10/23 00:08:51 account_id?
Alexander Alekseev 2015/10/23 09:11:22 Done.
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(), user_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 (user_id == AccountId::FromUserEmail(owner)) {
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(user_id, delegate);
343 } 342 }
344 343
345 void ChromeUserManagerImpl::SaveUserOAuthStatus( 344 void ChromeUserManagerImpl::SaveUserOAuthStatus(
346 const std::string& user_id, 345 const AccountId& user_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(user_id, oauth_token_status);
350 349
351 GetUserFlow(user_id)->HandleOAuthTokenStatusChange(oauth_token_status); 350 GetUserFlow(user_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& user_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(user_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(user_id))
363 supervised_user_manager_->UpdateManagerName(user_id, display_name); 362 supervised_user_manager_->UpdateManagerName(user_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->GetUserID());
416 image_manager->UserProfileCreated(); 417 image_manager->UserProfileCreated();
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().empty()) {
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& user_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(user_id);
494 498
495 return !is_obsolete_public_account && 499 return !is_obsolete_public_account &&
496 ChromeUserManager::IsUserNonCryptohomeDataEphemeral(user_id); 500 ChromeUserManager::IsUserNonCryptohomeDataEphemeral(user_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() || !GetOwnerId().empty());
504 } 508 }
505 509
506 void ChromeUserManagerImpl::OnUserRemoved(const std::string& user_id) { 510 void ChromeUserManagerImpl::OnUserRemoved(const AccountId& user_id) {
507 RemoveReportingUser(FullyCanonicalize(user_id)); 511 RemoveReportingUser(FullyCanonicalize(user_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& user_id,
520 user_manager::User::OAuthTokenStatus status) const { 524 user_manager::User::OAuthTokenStatus status) const {
521 GetUserFlow(user_id)->HandleOAuthTokenStatusChange(status); 525 GetUserFlow(user_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 (std::vector<AccountId>::const_iterator it = public_sessions.begin();
achuithb 2015/10/23 00:08:51 for (const auto& account_id : public_sessions) {
Alexander Alekseev 2015/10/23 09:11:22 Done.
540 it != public_sessions.end(); 542 it != public_sessions.end(); ++it) {
541 ++it) {
542 users_.push_back(user_manager::User::CreatePublicAccountUser(*it)); 543 users_.push_back(user_manager::User::CreatePublicAccountUser(*it));
543 UpdatePublicAccountDisplayName(*it); 544 UpdatePublicAccountDisplayName(it->GetUserEmail());
544 } 545 }
545 } 546 }
546 547
547 void ChromeUserManagerImpl::PerformPreUserListLoadingActions() { 548 void ChromeUserManagerImpl::PerformPreUserListLoadingActions() {
548 // Clean up user list first. All code down the path should be synchronous, 549 // 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. 550 // so that local state after transaction rollback is in consistent state.
550 // This process also should not trigger EnsureUsersLoaded again. 551 // This process also should not trigger EnsureUsersLoaded again.
551 if (supervised_user_manager_->HasFailedUserCreationTransaction()) 552 if (supervised_user_manager_->HasFailedUserCreationTransaction())
552 supervised_user_manager_->RollbackUserCreationTransaction(); 553 supervised_user_manager_->RollbackUserCreationTransaction();
553 554
554 // Abandon all unfinished bootstraps. 555 // Abandon all unfinished bootstraps.
555 bootstrap_manager_->RemoveAllPendingBootstrap(); 556 bootstrap_manager_->RemoveAllPendingBootstrap();
556 } 557 }
557 558
558 void ChromeUserManagerImpl::PerformPostUserListLoadingActions() { 559 void ChromeUserManagerImpl::PerformPostUserListLoadingActions() {
559 for (user_manager::UserList::iterator ui = users_.begin(), ue = users_.end(); 560 for (user_manager::UserList::iterator ui = users_.begin(), ue = users_.end();
560 ui != ue; 561 ui != ue;
561 ++ui) { 562 ++ui) {
562 GetUserImageManager((*ui)->email())->LoadUserImage(); 563 GetUserImageManager((*ui)->GetUserID())->LoadUserImage();
563 } 564 }
564 } 565 }
565 566
566 void ChromeUserManagerImpl::PerformPostUserLoggedInActions( 567 void ChromeUserManagerImpl::PerformPostUserLoggedInActions(
567 bool browser_restart) { 568 bool browser_restart) {
568 // Initialize the session length limiter and start it only if 569 // Initialize the session length limiter and start it only if
569 // session limit is defined by the policy. 570 // session limit is defined by the policy.
570 session_length_limiter_.reset( 571 session_length_limiter_.reset(
571 new SessionLengthLimiter(NULL, browser_restart)); 572 new SessionLengthLimiter(NULL, browser_restart));
572 } 573 }
573 574
574 bool ChromeUserManagerImpl::IsDemoApp(const std::string& user_id) const { 575 bool ChromeUserManagerImpl::IsDemoApp(const AccountId& user_id) const {
575 return DemoAppLauncher::IsDemoAppSession(user_id); 576 return DemoAppLauncher::IsDemoAppSession(user_id.GetUserEmail());
576 } 577 }
577 578
578 bool ChromeUserManagerImpl::IsKioskApp(const std::string& user_id) const { 579 bool ChromeUserManagerImpl::IsKioskApp(const AccountId& user_id) const {
579 policy::DeviceLocalAccount::Type device_local_account_type; 580 policy::DeviceLocalAccount::Type device_local_account_type;
580 return policy::IsDeviceLocalAccountUser(user_id, 581 return policy::IsDeviceLocalAccountUser(user_id.GetUserEmail(),
581 &device_local_account_type) && 582 &device_local_account_type) &&
582 device_local_account_type == 583 device_local_account_type ==
583 policy::DeviceLocalAccount::TYPE_KIOSK_APP; 584 policy::DeviceLocalAccount::TYPE_KIOSK_APP;
584 } 585 }
585 586
586 bool ChromeUserManagerImpl::IsPublicAccountMarkedForRemoval( 587 bool ChromeUserManagerImpl::IsPublicAccountMarkedForRemoval(
587 const std::string& user_id) const { 588 const AccountId& user_id) const {
588 return user_id == 589 return user_id == AccountId::FromUserEmail(GetLocalState()->GetString(
589 GetLocalState()->GetString(kPublicAccountPendingDataRemoval); 590 kPublicAccountPendingDataRemoval));
590 } 591 }
591 592
592 void ChromeUserManagerImpl::RetrieveTrustedDevicePolicies() { 593 void ChromeUserManagerImpl::RetrieveTrustedDevicePolicies() {
593 // Local state may not be initialized in unit_tests. 594 // Local state may not be initialized in unit_tests.
594 if (!GetLocalState()) 595 if (!GetLocalState())
595 return; 596 return;
596 597
597 SetEphemeralUsersEnabled(false); 598 SetEphemeralUsersEnabled(false);
598 SetOwnerEmail(std::string()); 599 SetOwnerId(EmptyAccountId());
599 600
600 // Schedule a callback if device policy has not yet been verified. 601 // Schedule a callback if device policy has not yet been verified.
601 if (CrosSettingsProvider::TRUSTED != 602 if (CrosSettingsProvider::TRUSTED !=
602 cros_settings_->PrepareTrustedValues( 603 cros_settings_->PrepareTrustedValues(
603 base::Bind(&ChromeUserManagerImpl::RetrieveTrustedDevicePolicies, 604 base::Bind(&ChromeUserManagerImpl::RetrieveTrustedDevicePolicies,
604 weak_factory_.GetWeakPtr()))) { 605 weak_factory_.GetWeakPtr()))) {
605 return; 606 return;
606 } 607 }
607 608
608 bool ephemeral_users_enabled = false; 609 bool ephemeral_users_enabled = false;
609 cros_settings_->GetBoolean(kAccountsPrefEphemeralUsersEnabled, 610 cros_settings_->GetBoolean(kAccountsPrefEphemeralUsersEnabled,
610 &ephemeral_users_enabled); 611 &ephemeral_users_enabled);
611 SetEphemeralUsersEnabled(ephemeral_users_enabled); 612 SetEphemeralUsersEnabled(ephemeral_users_enabled);
612 613
613 std::string owner_email; 614 std::string owner_email;
614 cros_settings_->GetString(kDeviceOwner, &owner_email); 615 cros_settings_->GetString(kDeviceOwner, &owner_email);
615 SetOwnerEmail(owner_email); 616 SetOwnerId(AccountId::FromUserEmail(owner_email));
616 617
617 EnsureUsersLoaded(); 618 EnsureUsersLoaded();
618 619
619 bool changed = UpdateAndCleanUpPublicAccounts( 620 bool changed = UpdateAndCleanUpPublicAccounts(
620 policy::GetDeviceLocalAccounts(cros_settings_)); 621 policy::GetDeviceLocalAccounts(cros_settings_));
621 622
622 // If ephemeral users are enabled and we are on the login screen, take this 623 // 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. 624 // opportunity to clean up by removing all regular users except the owner.
624 if (GetEphemeralUsersEnabled() && !IsUserLoggedIn()) { 625 if (GetEphemeralUsersEnabled() && !IsUserLoggedIn()) {
625 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); 626 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers);
626 prefs_users_update->Clear(); 627 prefs_users_update->Clear();
627 for (user_manager::UserList::iterator it = users_.begin(); 628 for (user_manager::UserList::iterator it = users_.begin();
628 it != users_.end();) { 629 it != users_.end();) {
629 const std::string user_email = (*it)->email(); 630 const AccountId user_id = (*it)->GetUserID();
630 if ((*it)->HasGaiaAccount() && user_email != GetOwnerEmail()) { 631 if ((*it)->HasGaiaAccount() && user_id != GetOwnerId()) {
631 RemoveNonCryptohomeData(user_email); 632 RemoveNonCryptohomeData(user_id);
632 DeleteUser(*it); 633 DeleteUser(*it);
633 it = users_.erase(it); 634 it = users_.erase(it);
634 changed = true; 635 changed = true;
635 } else { 636 } else {
636 if ((*it)->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT) 637 if ((*it)->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT)
637 prefs_users_update->Append(new base::StringValue(user_email)); 638 prefs_users_update->Append(
639 new base::StringValue(user_id.GetUserEmail()));
638 ++it; 640 ++it;
639 } 641 }
640 } 642 }
641 } 643 }
642 644
643 if (changed) 645 if (changed)
644 NotifyUserListChanged(); 646 NotifyUserListChanged();
645 } 647 }
646 648
647 void ChromeUserManagerImpl::GuestUserLoggedIn() { 649 void ChromeUserManagerImpl::GuestUserLoggedIn() {
648 DCHECK_CURRENTLY_ON(BrowserThread::UI); 650 DCHECK_CURRENTLY_ON(BrowserThread::UI);
649 ChromeUserManager::GuestUserLoggedIn(); 651 ChromeUserManager::GuestUserLoggedIn();
650 652
651 // TODO(nkostylev): Add support for passing guest session cryptohome 653 // TODO(nkostylev): Add support for passing guest session cryptohome
652 // mount point. Legacy (--login-profile) value will be used for now. 654 // mount point. Legacy (--login-profile) value will be used for now.
653 // http://crosbug.com/230859 655 // http://crosbug.com/230859
654 active_user_->SetStubImage( 656 active_user_->SetStubImage(
655 user_manager::UserImage( 657 user_manager::UserImage(
656 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 658 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
657 IDR_PROFILE_PICTURE_LOADING)), 659 IDR_PROFILE_PICTURE_LOADING)),
658 user_manager::User::USER_IMAGE_INVALID, 660 user_manager::User::USER_IMAGE_INVALID,
659 false); 661 false);
660 662
661 // Initializes wallpaper after active_user_ is set. 663 // Initializes wallpaper after active_user_ is set.
662 WallpaperManager::Get()->SetUserWallpaperNow(chromeos::login::kGuestUserName); 664 WallpaperManager::Get()->SetUserWallpaperNow(chromeos::login::kGuestUserName);
663 } 665 }
664 666
665 void ChromeUserManagerImpl::RegularUserLoggedIn(const std::string& user_id) { 667 void ChromeUserManagerImpl::RegularUserLoggedIn(const AccountId& user_id) {
666 ChromeUserManager::RegularUserLoggedIn(user_id); 668 ChromeUserManager::RegularUserLoggedIn(user_id);
667 669
668 if (FakeOwnership()) { 670 if (FakeOwnership()) {
669 std::string owner_email = GetActiveUser()->email(); 671 const AccountId owner_id = GetActiveUser()->GetUserID();
670 VLOG(1) << "Set device owner to: " << owner_email; 672 VLOG(1) << "Set device owner to: " << owner_id.GetUserEmail();
671 CrosSettings::Get()->SetString(kDeviceOwner, owner_email); 673 CrosSettings::Get()->SetString(kDeviceOwner, owner_id.GetUserEmail());
672 SetOwnerEmail(owner_email); 674 SetOwnerId(owner_id);
673 } 675 }
674 676
675 if (IsCurrentUserNew()) 677 if (IsCurrentUserNew())
676 WallpaperManager::Get()->SetUserWallpaperNow(user_id); 678 WallpaperManager::Get()->SetUserWallpaperNow(user_id.GetUserEmail());
677 679
678 GetUserImageManager(user_id)->UserLoggedIn(IsCurrentUserNew(), false); 680 GetUserImageManager(user_id)->UserLoggedIn(IsCurrentUserNew(), false);
679 681
680 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); 682 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
681 683
682 // Make sure that new data is persisted to Local State. 684 // Make sure that new data is persisted to Local State.
683 GetLocalState()->CommitPendingWrite(); 685 GetLocalState()->CommitPendingWrite();
684 } 686 }
685 687
686 void ChromeUserManagerImpl::RegularUserLoggedInAsEphemeral( 688 void ChromeUserManagerImpl::RegularUserLoggedInAsEphemeral(
687 const std::string& user_id) { 689 const AccountId& user_id) {
688 DCHECK_CURRENTLY_ON(BrowserThread::UI); 690 DCHECK_CURRENTLY_ON(BrowserThread::UI);
689 ChromeUserManager::RegularUserLoggedInAsEphemeral(user_id); 691 ChromeUserManager::RegularUserLoggedInAsEphemeral(user_id);
690 692
691 GetUserImageManager(user_id)->UserLoggedIn(IsCurrentUserNew(), false); 693 GetUserImageManager(user_id)->UserLoggedIn(IsCurrentUserNew(), false);
692 WallpaperManager::Get()->SetUserWallpaperNow(user_id); 694 WallpaperManager::Get()->SetUserWallpaperNow(user_id.GetUserEmail());
693 } 695 }
694 696
695 void ChromeUserManagerImpl::SupervisedUserLoggedIn(const std::string& user_id) { 697 void ChromeUserManagerImpl::SupervisedUserLoggedIn(const AccountId& user_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(user_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(user_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(user_id.GetUserEmail());
707 } else { 709 } else {
708 if (supervised_user_manager_->CheckForFirstRun(user_id)) { 710 if (supervised_user_manager_->CheckForFirstRun(user_id.GetUserEmail())) {
709 SetIsCurrentUserNew(true); 711 SetIsCurrentUserNew(true);
710 WallpaperManager::Get()->SetUserWallpaperNow(user_id); 712 WallpaperManager::Get()->SetUserWallpaperNow(user_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, new base::StringValue(user_id.GetUserEmail()));
719 users_.insert(users_.begin(), active_user_); 721 users_.insert(users_.begin(), active_user_);
720 722
721 // Now that user is in the list, save display name. 723 // Now that user is in the list, save display name.
722 if (IsCurrentUserNew()) { 724 if (IsCurrentUserNew()) {
723 SaveUserDisplayName(GetActiveUser()->email(), 725 SaveUserDisplayName(GetActiveUser()->GetUserID(),
724 GetActiveUser()->GetDisplayName()); 726 GetActiveUser()->GetDisplayName());
725 } 727 }
726 728
727 GetUserImageManager(user_id)->UserLoggedIn(IsCurrentUserNew(), true); 729 GetUserImageManager(user_id)->UserLoggedIn(IsCurrentUserNew(), true);
728 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); 730 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
729 731
730 // Make sure that new data is persisted to Local State. 732 // Make sure that new data is persisted to Local State.
731 GetLocalState()->CommitPendingWrite(); 733 GetLocalState()->CommitPendingWrite();
732 } 734 }
733 735
734 bool ChromeUserManagerImpl::HasPendingBootstrap( 736 bool ChromeUserManagerImpl::HasPendingBootstrap(
735 const std::string& user_id) const { 737 const AccountId& user_id) const {
736 return bootstrap_manager_->HasPendingBootstrap(user_id); 738 return bootstrap_manager_->HasPendingBootstrap(user_id.GetUserEmail());
737 } 739 }
738 740
739 void ChromeUserManagerImpl::PublicAccountUserLoggedIn( 741 void ChromeUserManagerImpl::PublicAccountUserLoggedIn(
740 user_manager::User* user) { 742 user_manager::User* user) {
741 SetIsCurrentUserNew(true); 743 SetIsCurrentUserNew(true);
742 active_user_ = user; 744 active_user_ = user;
743 745
744 // The UserImageManager chooses a random avatar picture when a user logs in 746 // 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 747 // for the first time. Tell the UserImageManager that this user is not new to
746 // prevent the avatar from getting changed. 748 // prevent the avatar from getting changed.
747 GetUserImageManager(user->email())->UserLoggedIn(false, true); 749 GetUserImageManager(user->GetUserID())->UserLoggedIn(false, true);
748 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); 750 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
749 } 751 }
750 752
751 void ChromeUserManagerImpl::KioskAppLoggedIn(const std::string& app_id) { 753 void ChromeUserManagerImpl::KioskAppLoggedIn(const AccountId& app_id) {
752 DCHECK_CURRENTLY_ON(BrowserThread::UI); 754 DCHECK_CURRENTLY_ON(BrowserThread::UI);
753 policy::DeviceLocalAccount::Type device_local_account_type; 755 policy::DeviceLocalAccount::Type device_local_account_type;
754 DCHECK(policy::IsDeviceLocalAccountUser(app_id, &device_local_account_type)); 756 DCHECK(policy::IsDeviceLocalAccountUser(app_id.GetUserEmail(),
757 &device_local_account_type));
755 DCHECK_EQ(policy::DeviceLocalAccount::TYPE_KIOSK_APP, 758 DCHECK_EQ(policy::DeviceLocalAccount::TYPE_KIOSK_APP,
756 device_local_account_type); 759 device_local_account_type);
757 760
758 active_user_ = user_manager::User::CreateKioskAppUser(app_id); 761 active_user_ = user_manager::User::CreateKioskAppUser(app_id);
759 active_user_->SetStubImage( 762 active_user_->SetStubImage(
760 user_manager::UserImage( 763 user_manager::UserImage(
761 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 764 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
762 IDR_PROFILE_PICTURE_LOADING)), 765 IDR_PROFILE_PICTURE_LOADING)),
763 user_manager::User::USER_IMAGE_INVALID, 766 user_manager::User::USER_IMAGE_INVALID,
764 false); 767 false);
765 768
766 WallpaperManager::Get()->SetUserWallpaperNow(app_id); 769 WallpaperManager::Get()->SetUserWallpaperNow(app_id.GetUserEmail());
767 770
768 // TODO(bartfab): Add KioskAppUsers to the users_ list and keep metadata like 771 // 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 772 // 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. 773 // device-local account list here to extract the kiosk_app_id.
771 const std::vector<policy::DeviceLocalAccount> device_local_accounts = 774 const std::vector<policy::DeviceLocalAccount> device_local_accounts =
772 policy::GetDeviceLocalAccounts(cros_settings_); 775 policy::GetDeviceLocalAccounts(cros_settings_);
773 const policy::DeviceLocalAccount* account = NULL; 776 const policy::DeviceLocalAccount* account = NULL;
774 for (std::vector<policy::DeviceLocalAccount>::const_iterator it = 777 for (std::vector<policy::DeviceLocalAccount>::const_iterator it =
775 device_local_accounts.begin(); 778 device_local_accounts.begin();
776 it != device_local_accounts.end(); 779 it != device_local_accounts.end();
777 ++it) { 780 ++it) {
778 if (it->user_id == app_id) { 781 if (it->user_id == app_id.GetUserEmail()) {
779 account = &*it; 782 account = &*it;
780 break; 783 break;
781 } 784 }
782 } 785 }
783 std::string kiosk_app_id; 786 std::string kiosk_app_id;
784 if (account) { 787 if (account) {
785 kiosk_app_id = account->kiosk_app_id; 788 kiosk_app_id = account->kiosk_app_id;
786 } else { 789 } else {
787 LOG(ERROR) << "Logged into nonexistent kiosk-app account: " << app_id; 790 LOG(ERROR) << "Logged into nonexistent kiosk-app account: "
791 << app_id.GetUserEmail();
788 NOTREACHED(); 792 NOTREACHED();
789 } 793 }
790 794
791 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 795 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
792 command_line->AppendSwitch(::switches::kForceAppMode); 796 command_line->AppendSwitch(::switches::kForceAppMode);
793 command_line->AppendSwitchASCII(::switches::kAppId, kiosk_app_id); 797 command_line->AppendSwitchASCII(::switches::kAppId, kiosk_app_id);
794 798
795 // Disable window animation since kiosk app runs in a single full screen 799 // Disable window animation since kiosk app runs in a single full screen
796 // window and window animation causes start-up janks. 800 // window and window animation causes start-up janks.
797 command_line->AppendSwitch(wm::switches::kWindowAnimationsDisabled); 801 command_line->AppendSwitch(wm::switches::kWindowAnimationsDisabled);
798 } 802 }
799 803
800 void ChromeUserManagerImpl::DemoAccountLoggedIn() { 804 void ChromeUserManagerImpl::DemoAccountLoggedIn() {
801 DCHECK_CURRENTLY_ON(BrowserThread::UI); 805 DCHECK_CURRENTLY_ON(BrowserThread::UI);
802 active_user_ = user_manager::User::CreateKioskAppUser( 806 active_user_ = user_manager::User::CreateKioskAppUser(login::DemoAccountId());
803 login::DemoAccountId().GetUserEmail());
804 active_user_->SetStubImage( 807 active_user_->SetStubImage(
805 user_manager::UserImage( 808 user_manager::UserImage(
806 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 809 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
807 IDR_PROFILE_PICTURE_LOADING)), 810 IDR_PROFILE_PICTURE_LOADING)),
808 user_manager::User::USER_IMAGE_INVALID, 811 user_manager::User::USER_IMAGE_INVALID,
809 false); 812 false);
810 WallpaperManager::Get()->SetUserWallpaperNow( 813 WallpaperManager::Get()->SetUserWallpaperNow(
811 login::DemoAccountId().GetUserEmail()); 814 login::DemoAccountId().GetUserEmail());
812 815
813 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 816 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
(...skipping 26 matching lines...) Expand all
840 } 843 }
841 844
842 void ChromeUserManagerImpl::UpdateOwnership() { 845 void ChromeUserManagerImpl::UpdateOwnership() {
843 bool is_owner = 846 bool is_owner =
844 FakeOwnership() || DeviceSettingsService::Get()->HasPrivateOwnerKey(); 847 FakeOwnership() || DeviceSettingsService::Get()->HasPrivateOwnerKey();
845 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner"); 848 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner");
846 849
847 SetCurrentUserIsOwner(is_owner); 850 SetCurrentUserIsOwner(is_owner);
848 } 851 }
849 852
850 void ChromeUserManagerImpl::RemoveNonCryptohomeData( 853 void ChromeUserManagerImpl::RemoveNonCryptohomeData(const AccountId& user_id) {
851 const std::string& user_id) {
852 ChromeUserManager::RemoveNonCryptohomeData(user_id); 854 ChromeUserManager::RemoveNonCryptohomeData(user_id);
853 855
854 WallpaperManager::Get()->RemoveUserWallpaperInfo(user_id); 856 WallpaperManager::Get()->RemoveUserWallpaperInfo(user_id.GetUserEmail());
855 GetUserImageManager(user_id)->DeleteUserImage(); 857 GetUserImageManager(user_id)->DeleteUserImage();
856 858
857 supervised_user_manager_->RemoveNonCryptohomeData(user_id); 859 supervised_user_manager_->RemoveNonCryptohomeData(user_id.GetUserEmail());
858 860
859 multi_profile_user_controller_->RemoveCachedValues(user_id); 861 multi_profile_user_controller_->RemoveCachedValues(user_id.GetUserEmail());
860 862
861 EasyUnlockService::ResetLocalStateForUser(user_id); 863 EasyUnlockService::ResetLocalStateForUser(user_id.GetUserEmail());
862 } 864 }
863 865
864 void 866 void
865 ChromeUserManagerImpl::CleanUpPublicAccountNonCryptohomeDataPendingRemoval() { 867 ChromeUserManagerImpl::CleanUpPublicAccountNonCryptohomeDataPendingRemoval() {
866 PrefService* local_state = GetLocalState(); 868 PrefService* local_state = GetLocalState();
867 const std::string public_account_pending_data_removal = 869 const std::string public_account_pending_data_removal =
868 local_state->GetString(kPublicAccountPendingDataRemoval); 870 local_state->GetString(kPublicAccountPendingDataRemoval);
869 if (public_account_pending_data_removal.empty() || 871 if (public_account_pending_data_removal.empty() ||
870 (IsUserLoggedIn() && 872 (IsUserLoggedIn() &&
871 public_account_pending_data_removal == GetActiveUser()->email())) { 873 public_account_pending_data_removal == GetActiveUser()->email())) {
872 return; 874 return;
873 } 875 }
874 876
875 RemoveNonCryptohomeData(public_account_pending_data_removal); 877 RemoveNonCryptohomeData(
878 AccountId::FromUserEmail(public_account_pending_data_removal));
876 local_state->ClearPref(kPublicAccountPendingDataRemoval); 879 local_state->ClearPref(kPublicAccountPendingDataRemoval);
877 } 880 }
878 881
879 void ChromeUserManagerImpl::CleanUpPublicAccountNonCryptohomeData( 882 void ChromeUserManagerImpl::CleanUpPublicAccountNonCryptohomeData(
880 const std::vector<std::string>& old_public_accounts) { 883 const std::vector<std::string>& old_public_accounts) {
881 std::set<std::string> users; 884 std::set<std::string> users;
882 for (user_manager::UserList::const_iterator it = users_.begin(); 885 for (user_manager::UserList::const_iterator it = users_.begin();
883 it != users_.end(); 886 it != users_.end();
884 ++it) 887 ++it)
885 users.insert((*it)->email()); 888 users.insert((*it)->email());
886 889
887 // If the user is logged into a public account that has been removed from the 890 // 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. 891 // user list, mark the account's data as pending removal after logout.
889 if (IsLoggedInAsPublicAccount()) { 892 if (IsLoggedInAsPublicAccount()) {
890 const std::string active_user_id = GetActiveUser()->email(); 893 const std::string active_user_id = GetActiveUser()->email();
891 if (users.find(active_user_id) == users.end()) { 894 if (users.find(active_user_id) == users.end()) {
892 GetLocalState()->SetString(kPublicAccountPendingDataRemoval, 895 GetLocalState()->SetString(kPublicAccountPendingDataRemoval,
893 active_user_id); 896 active_user_id);
894 users.insert(active_user_id); 897 users.insert(active_user_id);
895 } 898 }
896 } 899 }
897 900
898 // Remove the data belonging to any other public accounts that are no longer 901 // Remove the data belonging to any other public accounts that are no longer
899 // found on the user list. 902 // found on the user list.
900 for (std::vector<std::string>::const_iterator it = 903 for (std::vector<std::string>::const_iterator it =
901 old_public_accounts.begin(); 904 old_public_accounts.begin();
902 it != old_public_accounts.end(); 905 it != old_public_accounts.end();
903 ++it) { 906 ++it) {
904 if (users.find(*it) == users.end()) 907 if (users.find(*it) == users.end())
905 RemoveNonCryptohomeData(*it); 908 RemoveNonCryptohomeData(AccountId::FromUserEmail(*it));
906 } 909 }
907 } 910 }
908 911
909 bool ChromeUserManagerImpl::UpdateAndCleanUpPublicAccounts( 912 bool ChromeUserManagerImpl::UpdateAndCleanUpPublicAccounts(
910 const std::vector<policy::DeviceLocalAccount>& device_local_accounts) { 913 const std::vector<policy::DeviceLocalAccount>& device_local_accounts) {
911 // Try to remove any public account data marked as pending removal. 914 // Try to remove any public account data marked as pending removal.
912 CleanUpPublicAccountNonCryptohomeDataPendingRemoval(); 915 CleanUpPublicAccountNonCryptohomeDataPendingRemoval();
913 916
914 // Get the current list of public accounts. 917 // Get the current list of public accounts.
915 std::vector<std::string> old_public_accounts; 918 std::vector<std::string> old_public_accounts;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 } 971 }
969 972
970 // Add the new public accounts to the front of the user list. 973 // Add the new public accounts to the front of the user list.
971 for (std::vector<std::string>::const_reverse_iterator it = 974 for (std::vector<std::string>::const_reverse_iterator it =
972 new_public_accounts.rbegin(); 975 new_public_accounts.rbegin();
973 it != new_public_accounts.rend(); 976 it != new_public_accounts.rend();
974 ++it) { 977 ++it) {
975 if (IsLoggedInAsPublicAccount() && *it == GetActiveUser()->email()) 978 if (IsLoggedInAsPublicAccount() && *it == GetActiveUser()->email())
976 users_.insert(users_.begin(), GetLoggedInUser()); 979 users_.insert(users_.begin(), GetLoggedInUser());
977 else 980 else
978 users_.insert(users_.begin(), 981 users_.insert(users_.begin(), user_manager::User::CreatePublicAccountUser(
979 user_manager::User::CreatePublicAccountUser(*it)); 982 AccountId::FromUserEmail(*it)));
980 UpdatePublicAccountDisplayName(*it); 983 UpdatePublicAccountDisplayName(*it);
981 } 984 }
982 985
983 for (user_manager::UserList::iterator 986 for (user_manager::UserList::iterator
984 ui = users_.begin(), 987 ui = users_.begin(),
985 ue = users_.begin() + new_public_accounts.size(); 988 ue = users_.begin() + new_public_accounts.size();
986 ui != ue; 989 ui != ue;
987 ++ui) { 990 ++ui) {
988 GetUserImageManager((*ui)->email())->LoadUserImage(); 991 GetUserImageManager((*ui)->GetUserID())->LoadUserImage();
989 } 992 }
990 993
991 // Remove data belonging to public accounts that are no longer found on the 994 // Remove data belonging to public accounts that are no longer found on the
992 // user list. 995 // user list.
993 CleanUpPublicAccountNonCryptohomeData(old_public_accounts); 996 CleanUpPublicAccountNonCryptohomeData(old_public_accounts);
994 997
995 return true; 998 return true;
996 } 999 }
997 1000
998 void ChromeUserManagerImpl::UpdatePublicAccountDisplayName( 1001 void ChromeUserManagerImpl::UpdatePublicAccountDisplayName(
999 const std::string& user_id) { 1002 const std::string& user_id) {
1000 std::string display_name; 1003 std::string display_name;
1001 1004
1002 if (device_local_account_policy_service_) { 1005 if (device_local_account_policy_service_) {
1003 policy::DeviceLocalAccountPolicyBroker* broker = 1006 policy::DeviceLocalAccountPolicyBroker* broker =
1004 device_local_account_policy_service_->GetBrokerForUser(user_id); 1007 device_local_account_policy_service_->GetBrokerForUser(user_id);
1005 if (broker) 1008 if (broker)
1006 display_name = broker->GetDisplayName(); 1009 display_name = broker->GetDisplayName();
1007 } 1010 }
1008 1011
1009 // Set or clear the display name. 1012 // Set or clear the display name.
1010 SaveUserDisplayName(user_id, base::UTF8ToUTF16(display_name)); 1013 SaveUserDisplayName(AccountId::FromUserEmail(user_id),
1014 base::UTF8ToUTF16(display_name));
1011 } 1015 }
1012 1016
1013 UserFlow* ChromeUserManagerImpl::GetCurrentUserFlow() const { 1017 UserFlow* ChromeUserManagerImpl::GetCurrentUserFlow() const {
1014 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1018 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1015 if (!IsUserLoggedIn()) 1019 if (!IsUserLoggedIn())
1016 return GetDefaultUserFlow(); 1020 return GetDefaultUserFlow();
1017 return GetUserFlow(GetLoggedInUser()->email()); 1021 return GetUserFlow(GetLoggedInUser()->GetUserID());
1018 } 1022 }
1019 1023
1020 UserFlow* ChromeUserManagerImpl::GetUserFlow(const std::string& user_id) const { 1024 UserFlow* ChromeUserManagerImpl::GetUserFlow(const AccountId& user_id) const {
1021 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1025 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1022 FlowMap::const_iterator it = specific_flows_.find(user_id); 1026 FlowMap::const_iterator it = specific_flows_.find(user_id);
1023 if (it != specific_flows_.end()) 1027 if (it != specific_flows_.end())
1024 return it->second; 1028 return it->second;
1025 return GetDefaultUserFlow(); 1029 return GetDefaultUserFlow();
1026 } 1030 }
1027 1031
1028 void ChromeUserManagerImpl::SetUserFlow(const std::string& user_id, 1032 void ChromeUserManagerImpl::SetUserFlow(const AccountId& user_id,
1029 UserFlow* flow) { 1033 UserFlow* flow) {
1030 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1034 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1031 ResetUserFlow(user_id); 1035 ResetUserFlow(user_id);
1032 specific_flows_[user_id] = flow; 1036 specific_flows_[user_id] = flow;
1033 } 1037 }
1034 1038
1035 void ChromeUserManagerImpl::ResetUserFlow(const std::string& user_id) { 1039 void ChromeUserManagerImpl::ResetUserFlow(const AccountId& user_id) {
1036 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1040 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1037 FlowMap::iterator it = specific_flows_.find(user_id); 1041 FlowMap::iterator it = specific_flows_.find(user_id);
1038 if (it != specific_flows_.end()) { 1042 if (it != specific_flows_.end()) {
1039 delete it->second; 1043 delete it->second;
1040 specific_flows_.erase(it); 1044 specific_flows_.erase(it);
1041 } 1045 }
1042 } 1046 }
1043 1047
1044 bool ChromeUserManagerImpl::AreSupervisedUsersAllowed() const { 1048 bool ChromeUserManagerImpl::AreSupervisedUsersAllowed() const {
1045 bool supervised_users_allowed = false; 1049 bool supervised_users_allowed = false;
(...skipping 18 matching lines...) Expand all
1064 1068
1065 void ChromeUserManagerImpl::NotifyUserAddedToSession( 1069 void ChromeUserManagerImpl::NotifyUserAddedToSession(
1066 const user_manager::User* added_user, 1070 const user_manager::User* added_user,
1067 bool user_switch_pending) { 1071 bool user_switch_pending) {
1068 // Special case for user session restoration after browser crash. 1072 // 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 1073 // 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 1074 // session will be restored we'll switch to the session that has been used
1071 // before the crash. 1075 // before the crash.
1072 if (user_switch_pending && 1076 if (user_switch_pending &&
1073 !UserSessionManager::GetInstance()->UserSessionsRestoreInProgress()) { 1077 !UserSessionManager::GetInstance()->UserSessionsRestoreInProgress()) {
1074 SetPendingUserSwitchID(added_user->email()); 1078 SetPendingUserSwitchId(added_user->GetUserID());
1075 } 1079 }
1076 1080
1077 UpdateNumberOfUsers(); 1081 UpdateNumberOfUsers();
1078 ChromeUserManager::NotifyUserAddedToSession(added_user, user_switch_pending); 1082 ChromeUserManager::NotifyUserAddedToSession(added_user, user_switch_pending);
1079 } 1083 }
1080 1084
1081 void ChromeUserManagerImpl::OnUserNotAllowed(const std::string& user_email) { 1085 void ChromeUserManagerImpl::OnUserNotAllowed(const std::string& user_email) {
1082 LOG(ERROR) << "Shutdown session because a user is not allowed to be in the " 1086 LOG(ERROR) << "Shutdown session because a user is not allowed to be in the "
1083 "current session"; 1087 "current session";
1084 chromeos::ShowMultiprofilesSessionAbortedDialog(user_email); 1088 chromeos::ShowMultiprofilesSessionAbortedDialog(user_email);
1085 } 1089 }
1086 1090
1087 void ChromeUserManagerImpl::RemovePendingBootstrapUser( 1091 void ChromeUserManagerImpl::RemovePendingBootstrapUser(
1088 const std::string& user_id) { 1092 const std::string& user_id) {
1089 DCHECK(HasPendingBootstrap(user_id)); 1093 const AccountId account_id(AccountId::FromUserEmail(user_id));
1090 RemoveNonOwnerUserInternal(user_id, NULL); 1094 DCHECK(HasPendingBootstrap(account_id));
1095 RemoveNonOwnerUserInternal(account_id, NULL);
achuithb 2015/10/23 00:08:51 nullptr
Alexander Alekseev 2015/10/23 09:11:22 Done.
1091 } 1096 }
1092 1097
1093 void ChromeUserManagerImpl::UpdateNumberOfUsers() { 1098 void ChromeUserManagerImpl::UpdateNumberOfUsers() {
1094 size_t users = GetLoggedInUsers().size(); 1099 size_t users = GetLoggedInUsers().size();
1095 if (users) { 1100 if (users) {
1096 // Write the user number as UMA stat when a multi user session is possible. 1101 // Write the user number as UMA stat when a multi user session is possible.
1097 if ((users + GetUsersAllowedForMultiProfile().size()) > 1) 1102 if ((users + GetUsersAllowedForMultiProfile().size()) > 1)
1098 ash::MultiProfileUMA::RecordUserCount(users); 1103 ash::MultiProfileUMA::RecordUserCount(users);
1099 } 1104 }
1100 1105
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 g_browser_process->platform_part()->GetTimezoneResolver()->Start(); 1139 g_browser_process->platform_part()->GetTimezoneResolver()->Start();
1135 } else { 1140 } else {
1136 g_browser_process->platform_part()->GetTimezoneResolver()->Stop(); 1141 g_browser_process->platform_part()->GetTimezoneResolver()->Stop();
1137 } 1142 }
1138 } 1143 }
1139 1144
1140 void ChromeUserManagerImpl::SetUserAffiliation( 1145 void ChromeUserManagerImpl::SetUserAffiliation(
1141 const std::string& user_email, 1146 const std::string& user_email,
1142 const AffiliationIDSet& user_affiliation_ids) { 1147 const AffiliationIDSet& user_affiliation_ids) {
1143 std::string canonicalized_email = FullyCanonicalize(user_email); 1148 std::string canonicalized_email = FullyCanonicalize(user_email);
1144 user_manager::User* user = FindUserAndModify(canonicalized_email); 1149 user_manager::User* user =
1150 FindUserAndModify(AccountId::FromUserEmail(canonicalized_email));
1145 1151
1146 if (user) { 1152 if (user) {
1147 policy::BrowserPolicyConnectorChromeOS const* const connector = 1153 policy::BrowserPolicyConnectorChromeOS const* const connector =
1148 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 1154 g_browser_process->platform_part()->browser_policy_connector_chromeos();
1149 const bool is_affiliated = chromeos::IsUserAffiliated( 1155 const bool is_affiliated = chromeos::IsUserAffiliated(
1150 user_affiliation_ids, connector->GetDeviceAffiliationIDs(), 1156 user_affiliation_ids, connector->GetDeviceAffiliationIDs(),
1151 canonicalized_email, connector->GetEnterpriseDomain()); 1157 canonicalized_email, connector->GetEnterpriseDomain());
1152 user->set_affiliation(is_affiliated); 1158 user->set_affiliation(is_affiliated);
1153 1159
1154 if (user->GetType() == user_manager::USER_TYPE_REGULAR) { 1160 if (user->GetType() == user_manager::USER_TYPE_REGULAR) {
(...skipping 18 matching lines...) Expand all
1173 users_update->AppendIfNotPresent( 1179 users_update->AppendIfNotPresent(
1174 new base::StringValue(FullyCanonicalize(user_id))); 1180 new base::StringValue(FullyCanonicalize(user_id)));
1175 } 1181 }
1176 1182
1177 void ChromeUserManagerImpl::RemoveReportingUser(const std::string& user_id) { 1183 void ChromeUserManagerImpl::RemoveReportingUser(const std::string& user_id) {
1178 ListPrefUpdate users_update(GetLocalState(), kReportingUsers); 1184 ListPrefUpdate users_update(GetLocalState(), kReportingUsers);
1179 users_update->Remove(base::StringValue(FullyCanonicalize(user_id)), NULL); 1185 users_update->Remove(base::StringValue(FullyCanonicalize(user_id)), NULL);
1180 } 1186 }
1181 1187
1182 } // namespace chromeos 1188 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698