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