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