Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/user_manager.h" | 5 #include "chrome/browser/chromeos/login/user_manager.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 #include "chrome/browser/chromeos/cryptohome/async_method_caller.h" | 29 #include "chrome/browser/chromeos/cryptohome/async_method_caller.h" |
| 30 #include "chrome/browser/chromeos/dbus/cryptohome_client.h" | 30 #include "chrome/browser/chromeos/dbus/cryptohome_client.h" |
| 31 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 31 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
| 32 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 32 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| 33 #include "chrome/browser/chromeos/login/default_user_images.h" | 33 #include "chrome/browser/chromeos/login/default_user_images.h" |
| 34 #include "chrome/browser/chromeos/login/helper.h" | 34 #include "chrome/browser/chromeos/login/helper.h" |
| 35 #include "chrome/browser/chromeos/login/login_display.h" | 35 #include "chrome/browser/chromeos/login/login_display.h" |
| 36 #include "chrome/browser/chromeos/login/ownership_service.h" | 36 #include "chrome/browser/chromeos/login/ownership_service.h" |
| 37 #include "chrome/browser/chromeos/login/remove_user_delegate.h" | 37 #include "chrome/browser/chromeos/login/remove_user_delegate.h" |
| 38 #include "chrome/browser/chromeos/system/runtime_environment.h" | 38 #include "chrome/browser/chromeos/system/runtime_environment.h" |
| 39 #include "chrome/browser/policy/browser_policy_connector.h" | |
| 39 #include "chrome/browser/prefs/pref_service.h" | 40 #include "chrome/browser/prefs/pref_service.h" |
| 40 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 41 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 41 #include "chrome/browser/profiles/profile_downloader.h" | 42 #include "chrome/browser/profiles/profile_downloader.h" |
| 42 #include "chrome/browser/profiles/profile_manager.h" | 43 #include "chrome/browser/profiles/profile_manager.h" |
| 43 #include "chrome/browser/sync/profile_sync_service.h" | 44 #include "chrome/browser/sync/profile_sync_service.h" |
| 44 #include "chrome/browser/sync/profile_sync_service_factory.h" | 45 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 45 #include "chrome/browser/ui/webui/web_ui_util.h" | 46 #include "chrome/browser/ui/webui/web_ui_util.h" |
| 46 #include "chrome/common/chrome_notification_types.h" | 47 #include "chrome/common/chrome_notification_types.h" |
| 47 #include "chrome/common/chrome_paths.h" | 48 #include "chrome/common/chrome_paths.h" |
| 48 #include "chrome/common/chrome_switches.h" | 49 #include "chrome/common/chrome_switches.h" |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 const_cast<UserManager*>(this)->EnsureUsersLoaded(); | 316 const_cast<UserManager*>(this)->EnsureUsersLoaded(); |
| 316 return users_; | 317 return users_; |
| 317 } | 318 } |
| 318 | 319 |
| 319 void UserManager::UserLoggedIn(const std::string& email) { | 320 void UserManager::UserLoggedIn(const std::string& email) { |
| 320 DCHECK(!user_is_logged_in_); | 321 DCHECK(!user_is_logged_in_); |
| 321 | 322 |
| 322 user_is_logged_in_ = true; | 323 user_is_logged_in_ = true; |
| 323 | 324 |
| 324 if (email == kGuestUser) { | 325 if (email == kGuestUser) { |
| 326 current_user_is_ephemeral_ = true; | |
| 325 GuestUserLoggedIn(); | 327 GuestUserLoggedIn(); |
| 326 return; | 328 return; |
| 327 } | 329 } |
| 328 | 330 |
| 329 if (email == kDemoUser) { | 331 if (email == kDemoUser) { |
| 332 current_user_is_ephemeral_ = true; | |
| 330 DemoUserLoggedIn(); | 333 DemoUserLoggedIn(); |
| 331 return; | 334 return; |
| 332 } | 335 } |
| 333 | 336 |
| 337 if (IsEphemeralUser(email)) { | |
| 338 current_user_is_ephemeral_ = true; | |
| 339 logged_in_user_ = CreateUser(email); | |
| 340 NotifyOnLogin(); | |
| 341 return; | |
| 342 } | |
| 343 | |
| 334 EnsureUsersLoaded(); | 344 EnsureUsersLoaded(); |
| 335 | 345 |
| 336 // Clear the prefs view of the users. | 346 // Clear the prefs view of the users. |
| 337 PrefService* prefs = g_browser_process->local_state(); | 347 PrefService* prefs = g_browser_process->local_state(); |
| 338 ListPrefUpdate prefs_users_update(prefs, kLoggedInUsers); | 348 ListPrefUpdate prefs_users_update(prefs, kLoggedInUsers); |
| 339 prefs_users_update->Clear(); | 349 prefs_users_update->Clear(); |
| 340 | 350 |
| 341 // Make sure this user is first. | 351 // Make sure this user is first. |
| 342 prefs_users_update->Append(Value::CreateStringValue(email)); | 352 prefs_users_update->Append(Value::CreateStringValue(email)); |
| 343 UserList::iterator logged_in_user = users_.end(); | 353 UserList::iterator logged_in_user = users_.end(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 | 430 |
| 421 // Sanity check: do not allow the logged-in user to remove himself. | 431 // Sanity check: do not allow the logged-in user to remove himself. |
| 422 if (logged_in_user_ && logged_in_user_->email() == email) | 432 if (logged_in_user_ && logged_in_user_->email() == email) |
| 423 return; | 433 return; |
| 424 | 434 |
| 425 RemoveUserInternal(email, delegate); | 435 RemoveUserInternal(email, delegate); |
| 426 } | 436 } |
| 427 | 437 |
| 428 void UserManager::RemoveUserFromList(const std::string& email) { | 438 void UserManager::RemoveUserFromList(const std::string& email) { |
| 429 EnsureUsersLoaded(); | 439 EnsureUsersLoaded(); |
| 430 | 440 RemoveUserFromListInternal(email); |
| 431 // Clear the prefs view of the users. | |
| 432 PrefService* prefs = g_browser_process->local_state(); | |
| 433 ListPrefUpdate prefs_users_update(prefs, kLoggedInUsers); | |
| 434 prefs_users_update->Clear(); | |
| 435 | |
| 436 UserList::iterator user_to_remove = users_.end(); | |
| 437 for (UserList::iterator it = users_.begin(); it != users_.end(); ++it) { | |
| 438 std::string user_email = (*it)->email(); | |
| 439 // Skip user that we would like to delete. | |
| 440 if (email != user_email) | |
| 441 prefs_users_update->Append(Value::CreateStringValue(user_email)); | |
| 442 else | |
| 443 user_to_remove = it; | |
| 444 } | |
| 445 | |
| 446 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages); | |
| 447 std::string image_path_string; | |
| 448 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string); | |
| 449 prefs_images_update->RemoveWithoutPathExpansion(email, NULL); | |
| 450 | |
| 451 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); | |
| 452 int oauth_status; | |
| 453 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); | |
| 454 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); | |
| 455 | |
| 456 DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail); | |
| 457 prefs_display_email_update->RemoveWithoutPathExpansion(email, NULL); | |
| 458 | |
| 459 if (user_to_remove != users_.end()) { | |
| 460 --display_name_count_[(*user_to_remove)->GetDisplayName()]; | |
| 461 delete *user_to_remove; | |
| 462 users_.erase(user_to_remove); | |
| 463 } | |
| 464 | |
| 465 int default_image_id = User::kInvalidImageIndex; | |
| 466 if (!image_path_string.empty() && | |
| 467 !IsDefaultImagePath(image_path_string, &default_image_id)) { | |
| 468 FilePath image_path(image_path_string); | |
| 469 BrowserThread::PostTask( | |
| 470 BrowserThread::FILE, | |
| 471 FROM_HERE, | |
| 472 base::Bind(&UserManager::DeleteUserImage, | |
| 473 base::Unretained(this), | |
| 474 image_path)); | |
| 475 } | |
| 476 } | 441 } |
| 477 | 442 |
| 478 bool UserManager::IsKnownUser(const std::string& email) const { | 443 bool UserManager::IsKnownUser(const std::string& email) const { |
| 479 return FindUser(email) != NULL; | 444 return FindUser(email) != NULL; |
| 480 } | 445 } |
| 481 | 446 |
| 482 const User* UserManager::FindUser(const std::string& email) const { | 447 const User* UserManager::FindUser(const std::string& email) const { |
| 483 // Speed up search by checking the logged-in user first. | |
| 484 if (logged_in_user_ && logged_in_user_->email() == email) | 448 if (logged_in_user_ && logged_in_user_->email() == email) |
| 485 return logged_in_user_; | 449 return logged_in_user_; |
| 486 const UserList& users = GetUsers(); | 450 return FindUserInList(email); |
| 487 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | |
| 488 if ((*it)->email() == email) | |
| 489 return *it; | |
| 490 } | |
| 491 return NULL; | |
| 492 } | 451 } |
| 493 | 452 |
| 494 bool UserManager::IsDisplayNameUnique(const std::string& display_name) const { | 453 bool UserManager::IsDisplayNameUnique(const std::string& display_name) const { |
| 495 return display_name_count_[display_name] < 2; | 454 return display_name_count_[display_name] < 2; |
| 496 } | 455 } |
| 497 | 456 |
| 498 void UserManager::SaveUserOAuthStatus( | 457 void UserManager::SaveUserOAuthStatus( |
| 499 const std::string& username, | 458 const std::string& username, |
| 500 User::OAuthTokenStatus oauth_token_status) { | 459 User::OAuthTokenStatus oauth_token_status) { |
| 501 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 502 PrefService* local_state = g_browser_process->local_state(); | 461 |
| 503 DictionaryPrefUpdate oauth_status_update(local_state, kUserOAuthTokenStatus); | |
| 504 oauth_status_update->SetWithoutPathExpansion(username, | |
| 505 new base::FundamentalValue(static_cast<int>(oauth_token_status))); | |
| 506 DVLOG(1) << "Saving user OAuth token status in Local State"; | 462 DVLOG(1) << "Saving user OAuth token status in Local State"; |
| 507 User* user = const_cast<User*>(FindUser(username)); | 463 User* user = const_cast<User*>(FindUser(username)); |
| 508 if (user) | 464 if (user) |
| 509 user->set_oauth_token_status(oauth_token_status); | 465 user->set_oauth_token_status(oauth_token_status); |
| 466 | |
| 467 // Do not update local store if the user is ephemeral. | |
| 468 if (IsEphemeralUser(username)) | |
| 469 return; | |
| 470 | |
| 471 PrefService* local_state = g_browser_process->local_state(); | |
| 472 | |
| 473 DictionaryPrefUpdate oauth_status_update(local_state, kUserOAuthTokenStatus); | |
| 474 oauth_status_update->SetWithoutPathExpansion(username, | |
| 475 new base::FundamentalValue(static_cast<int>(oauth_token_status))); | |
| 510 } | 476 } |
| 511 | 477 |
| 512 User::OAuthTokenStatus UserManager::LoadUserOAuthStatus( | 478 User::OAuthTokenStatus UserManager::LoadUserOAuthStatus( |
| 513 const std::string& username) const { | 479 const std::string& username) const { |
| 514 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 480 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 515 | 481 |
| 516 if (CommandLine::ForCurrentProcess()->HasSwitch( | 482 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 517 switches::kSkipOAuthLogin)) { | 483 switches::kSkipOAuthLogin)) { |
| 518 // Use OAUTH_TOKEN_STATUS_VALID flag if kSkipOAuthLogin is present. | 484 // Use OAUTH_TOKEN_STATUS_VALID flag if kSkipOAuthLogin is present. |
| 519 return User::OAUTH_TOKEN_STATUS_VALID; | 485 return User::OAUTH_TOKEN_STATUS_VALID; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 536 void UserManager::SaveUserDisplayEmail(const std::string& username, | 502 void UserManager::SaveUserDisplayEmail(const std::string& username, |
| 537 const std::string& display_email) { | 503 const std::string& display_email) { |
| 538 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 539 | 505 |
| 540 User* user = const_cast<User*>(FindUser(username)); | 506 User* user = const_cast<User*>(FindUser(username)); |
| 541 if (!user) | 507 if (!user) |
| 542 return; // Ignore if there is no such user. | 508 return; // Ignore if there is no such user. |
| 543 | 509 |
| 544 user->set_display_email(display_email); | 510 user->set_display_email(display_email); |
| 545 | 511 |
| 512 // Do not update local store if the user is ephemeral. | |
| 513 if (IsEphemeralUser(username)) | |
| 514 return; | |
| 515 | |
| 546 PrefService* local_state = g_browser_process->local_state(); | 516 PrefService* local_state = g_browser_process->local_state(); |
| 547 | 517 |
| 548 DictionaryPrefUpdate display_email_update(local_state, kUserDisplayEmail); | 518 DictionaryPrefUpdate display_email_update(local_state, kUserDisplayEmail); |
| 549 display_email_update->SetWithoutPathExpansion( | 519 display_email_update->SetWithoutPathExpansion( |
| 550 username, | 520 username, |
| 551 base::Value::CreateStringValue(display_email)); | 521 base::Value::CreateStringValue(display_email)); |
| 552 } | 522 } |
| 553 | 523 |
| 554 std::string UserManager::GetUserDisplayEmail( | 524 std::string UserManager::GetUserDisplayEmail( |
| 555 const std::string& username) const { | 525 const std::string& username) const { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 } | 577 } |
| 608 | 578 |
| 609 void UserManager::Observe(int type, | 579 void UserManager::Observe(int type, |
| 610 const content::NotificationSource& source, | 580 const content::NotificationSource& source, |
| 611 const content::NotificationDetails& details) { | 581 const content::NotificationDetails& details) { |
| 612 switch (type) { | 582 switch (type) { |
| 613 case chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED: | 583 case chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED: |
| 614 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 584 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 615 base::Bind(&UserManager::CheckOwnership, | 585 base::Bind(&UserManager::CheckOwnership, |
| 616 base::Unretained(this))); | 586 base::Unretained(this))); |
| 587 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 588 base::Bind(&UserManager::RetrieveTrustedDevicePolicies, | |
| 589 base::Unretained(this))); | |
| 617 break; | 590 break; |
| 618 case chrome::NOTIFICATION_PROFILE_ADDED: | 591 case chrome::NOTIFICATION_PROFILE_ADDED: |
| 619 if (user_is_logged_in() && !IsLoggedInAsGuest()) { | 592 if (user_is_logged_in() && !IsLoggedInAsGuest()) { |
| 620 Profile* profile = content::Source<Profile>(source).ptr(); | 593 Profile* profile = content::Source<Profile>(source).ptr(); |
| 621 if (!profile->IsOffTheRecord() && | 594 if (!profile->IsOffTheRecord() && |
| 622 profile == ProfileManager::GetDefaultProfile()) { | 595 profile == ProfileManager::GetDefaultProfile()) { |
| 623 DCHECK(NULL == observed_sync_service_); | 596 DCHECK(NULL == observed_sync_service_); |
| 624 observed_sync_service_ = | 597 observed_sync_service_ = |
| 625 ProfileSyncServiceFactory::GetForProfile(profile); | 598 ProfileSyncServiceFactory::GetForProfile(profile); |
| 626 if (observed_sync_service_) | 599 if (observed_sync_service_) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 681 | 654 |
| 682 // Protected constructor and destructor. | 655 // Protected constructor and destructor. |
| 683 UserManager::UserManager() | 656 UserManager::UserManager() |
| 684 : ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_(new UserImageLoader)), | 657 : ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_(new UserImageLoader)), |
| 685 demo_user_(kDemoUser, false), | 658 demo_user_(kDemoUser, false), |
| 686 guest_user_(kGuestUser, true), | 659 guest_user_(kGuestUser, true), |
| 687 stub_user_(kStubUser, false), | 660 stub_user_(kStubUser, false), |
| 688 logged_in_user_(NULL), | 661 logged_in_user_(NULL), |
| 689 current_user_is_owner_(false), | 662 current_user_is_owner_(false), |
| 690 current_user_is_new_(false), | 663 current_user_is_new_(false), |
| 664 current_user_is_ephemeral_(false), | |
| 691 user_is_logged_in_(false), | 665 user_is_logged_in_(false), |
| 666 ephemeral_users_enabled_(false), | |
| 692 observed_sync_service_(NULL), | 667 observed_sync_service_(NULL), |
| 693 last_image_set_async_(false), | 668 last_image_set_async_(false), |
| 694 downloaded_profile_image_data_url_(chrome::kAboutBlankURL) { | 669 downloaded_profile_image_data_url_(chrome::kAboutBlankURL) { |
| 695 // Use stub as the logged-in user for test paths without login. | 670 // Use stub as the logged-in user for test paths without login. |
| 696 if (!system::runtime_environment::IsRunningOnChromeOS()) | 671 if (!system::runtime_environment::IsRunningOnChromeOS()) |
| 697 StubUserLoggedIn(); | 672 StubUserLoggedIn(); |
| 698 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, | 673 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, |
| 699 content::NotificationService::AllSources()); | 674 content::NotificationService::AllSources()); |
| 700 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, | 675 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, |
| 701 content::NotificationService::AllSources()); | 676 content::NotificationService::AllSources()); |
| 677 RetrieveTrustedDevicePolicies(); | |
| 702 } | 678 } |
| 703 | 679 |
| 704 UserManager::~UserManager() { | 680 UserManager::~UserManager() { |
| 705 } | 681 } |
| 706 | 682 |
| 707 FilePath UserManager::GetImagePathForUser(const std::string& username) { | 683 FilePath UserManager::GetImagePathForUser(const std::string& username) { |
| 708 std::string filename = username + ".png"; | 684 std::string filename = username + ".png"; |
| 709 FilePath user_data_dir; | 685 FilePath user_data_dir; |
| 710 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 686 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 711 return user_data_dir.AppendASCII(filename); | 687 return user_data_dir.AppendASCII(filename); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 787 if (prefs_display_emails && | 763 if (prefs_display_emails && |
| 788 prefs_display_emails->GetStringWithoutPathExpansion( | 764 prefs_display_emails->GetStringWithoutPathExpansion( |
| 789 email, &display_email)) { | 765 email, &display_email)) { |
| 790 user->set_display_email(display_email); | 766 user->set_display_email(display_email); |
| 791 } | 767 } |
| 792 } | 768 } |
| 793 } | 769 } |
| 794 } | 770 } |
| 795 } | 771 } |
| 796 | 772 |
| 773 void UserManager::RetrieveTrustedDevicePolicies() { | |
| 774 ephemeral_users_enabled_ = false; | |
| 775 owner_email_ = ""; | |
| 776 | |
| 777 CrosSettings* cros_settings = CrosSettings::Get(); | |
| 778 // Schedule a callback if device policy has not yet been verified. | |
| 779 if (!cros_settings->GetTrusted( | |
| 780 kAccountsPrefEphemeralUsersEnabled, | |
| 781 base::Bind(&UserManager::RetrieveTrustedDevicePolicies, | |
| 782 base::Unretained(this)))) { | |
| 783 return; | |
| 784 } | |
| 785 | |
| 786 cros_settings->GetBoolean(kAccountsPrefEphemeralUsersEnabled, | |
| 787 &ephemeral_users_enabled_); | |
| 788 if (g_browser_process->browser_policy_connector()->IsEnterpriseManaged()) | |
| 789 owner_email_ = ""; | |
|
Nikita (slow)
2012/03/07 10:03:04
You could always call
cros_settings->GetString(kD
use bartfab instead
2012/03/07 11:10:08
Done.
| |
| 790 else | |
| 791 cros_settings->GetString(kDeviceOwner, &owner_email_); | |
| 792 | |
| 793 // If ephemeral users are enabled, remove all users except the owner. | |
| 794 if (ephemeral_users_enabled_) { | |
| 795 scoped_ptr<base::ListValue> users( | |
| 796 g_browser_process->local_state()->GetList(kLoggedInUsers)->DeepCopy()); | |
| 797 | |
| 798 bool changed = false; | |
| 799 for (base::ListValue::const_iterator user = users->begin(); | |
| 800 user != users->end(); ++user) { | |
| 801 std::string user_email; | |
| 802 (*user)->GetAsString(&user_email); | |
| 803 if (user_email != owner_email_) { | |
| 804 RemoveUserFromListInternal(user_email); | |
| 805 changed = true; | |
| 806 } | |
| 807 } | |
| 808 | |
| 809 if (changed) { | |
| 810 // Trigger a redraw of the login window. | |
| 811 content::NotificationService::current()->Notify( | |
| 812 chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, | |
| 813 content::Source<UserManager>(this), | |
| 814 content::NotificationService::NoDetails()); | |
| 815 } | |
| 816 } | |
| 817 } | |
| 818 | |
| 819 bool UserManager::AreEphemeralUsersEnabled() const { | |
| 820 return ephemeral_users_enabled_ && | |
| 821 (g_browser_process->browser_policy_connector()->IsEnterpriseManaged() || | |
| 822 !owner_email_.empty()); | |
| 823 } | |
| 824 | |
| 825 bool UserManager::IsEphemeralUser(const std::string& email) const { | |
| 826 // The guest user always is ephemeral. | |
| 827 if (email == guest_user_.email()) | |
| 828 return true; | |
| 829 | |
| 830 // The currently logged-in user is ephemeral iff logged in as ephemeral. | |
| 831 if (logged_in_user_ && (email == logged_in_user_->email())) | |
| 832 return current_user_is_ephemeral_; | |
| 833 | |
| 834 // Any other user is ephemeral iff ephemeral users are enabled, the user is | |
| 835 // not the owner and is not in the persistent list. | |
| 836 return AreEphemeralUsersEnabled() && | |
| 837 (email != owner_email_) && | |
| 838 !FindUserInList(email); | |
| 839 } | |
| 840 | |
| 841 const User* UserManager::FindUserInList(const std::string& email) const { | |
| 842 const UserList& users = GetUsers(); | |
| 843 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | |
| 844 if ((*it)->email() == email) | |
| 845 return *it; | |
| 846 } | |
| 847 return NULL; | |
| 848 } | |
| 849 | |
| 797 void UserManager::StubUserLoggedIn() { | 850 void UserManager::StubUserLoggedIn() { |
| 798 logged_in_user_ = &stub_user_; | 851 logged_in_user_ = &stub_user_; |
| 799 stub_user_.SetImage(GetDefaultImage(kStubDefaultImageIndex), | 852 stub_user_.SetImage(GetDefaultImage(kStubDefaultImageIndex), |
| 800 kStubDefaultImageIndex); | 853 kStubDefaultImageIndex); |
| 801 } | 854 } |
| 802 | 855 |
| 803 void UserManager::NotifyOnLogin() { | 856 void UserManager::NotifyOnLogin() { |
| 804 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 857 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 805 content::NotificationService::current()->Notify( | 858 content::NotificationService::current()->Notify( |
| 806 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 859 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 826 // Note: this calls crypto::EnsureTPMTokenReady() | 879 // Note: this calls crypto::EnsureTPMTokenReady() |
| 827 cert_library->RequestCertificates(); | 880 cert_library->RequestCertificates(); |
| 828 } | 881 } |
| 829 | 882 |
| 830 // Schedules current user ownership check on file thread. | 883 // Schedules current user ownership check on file thread. |
| 831 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 884 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 832 base::Bind(&UserManager::CheckOwnership, | 885 base::Bind(&UserManager::CheckOwnership, |
| 833 base::Unretained(this))); | 886 base::Unretained(this))); |
| 834 } | 887 } |
| 835 | 888 |
| 889 void UserManager::LogoutForTest() { | |
| 890 if (logged_in_user_ && current_user_is_ephemeral_) | |
| 891 delete logged_in_user_; | |
| 892 logged_in_user_ = NULL; | |
| 893 current_user_is_owner_ = false; | |
| 894 current_user_is_new_ = false; | |
| 895 current_user_is_ephemeral_ = false; | |
| 896 user_is_logged_in_ = false; | |
| 897 } | |
| 898 | |
| 836 void UserManager::SetInitialUserImage(const std::string& username) { | 899 void UserManager::SetInitialUserImage(const std::string& username) { |
| 837 // Choose a random default image. | 900 // Choose a random default image. |
| 838 int image_id = base::RandInt(0, kDefaultImagesCount - 1); | 901 int image_id = base::RandInt(0, kDefaultImagesCount - 1); |
| 839 SaveUserDefaultImageIndex(username, image_id); | 902 SaveUserDefaultImageIndex(username, image_id); |
| 840 } | 903 } |
| 841 | 904 |
| 842 void UserManager::SetUserImage(const std::string& username, | 905 void UserManager::SetUserImage(const std::string& username, |
| 843 int image_index, | 906 int image_index, |
| 844 const SkBitmap& image) { | 907 const SkBitmap& image) { |
| 845 User* user = const_cast<User*>(FindUser(username)); | 908 User* user = const_cast<User*>(FindUser(username)); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 869 } | 932 } |
| 870 } | 933 } |
| 871 | 934 |
| 872 void UserManager::SaveUserImageInternal(const std::string& username, | 935 void UserManager::SaveUserImageInternal(const std::string& username, |
| 873 int image_index, | 936 int image_index, |
| 874 const SkBitmap& image) { | 937 const SkBitmap& image) { |
| 875 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 938 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 876 | 939 |
| 877 SetUserImage(username, image_index, image); | 940 SetUserImage(username, image_index, image); |
| 878 | 941 |
| 942 // Ignore for ephemeral users. | |
| 943 if (IsEphemeralUser(username)) | |
| 944 return; | |
| 945 | |
| 879 FilePath image_path = GetImagePathForUser(username); | 946 FilePath image_path = GetImagePathForUser(username); |
| 880 DVLOG(1) << "Saving user image to " << image_path.value(); | 947 DVLOG(1) << "Saving user image to " << image_path.value(); |
| 881 | 948 |
| 882 last_image_set_async_ = true; | 949 last_image_set_async_ = true; |
| 883 | 950 |
| 884 BrowserThread::PostTask( | 951 BrowserThread::PostTask( |
| 885 BrowserThread::FILE, | 952 BrowserThread::FILE, |
| 886 FROM_HERE, | 953 FROM_HERE, |
| 887 base::Bind(&UserManager::SaveImageToFile, | 954 base::Bind(&UserManager::SaveImageToFile, |
| 888 base::Unretained(this), | 955 base::Unretained(this), |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 915 base::Unretained(this), | 982 base::Unretained(this), |
| 916 username, image_path.value(), image_index, true)); | 983 username, image_path.value(), image_index, true)); |
| 917 } | 984 } |
| 918 | 985 |
| 919 void UserManager::SaveImageToLocalState(const std::string& username, | 986 void UserManager::SaveImageToLocalState(const std::string& username, |
| 920 const std::string& image_path, | 987 const std::string& image_path, |
| 921 int image_index, | 988 int image_index, |
| 922 bool is_async) { | 989 bool is_async) { |
| 923 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 990 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 924 | 991 |
| 992 // Ignore for ephemeral users. | |
| 993 if (IsEphemeralUser(username)) | |
| 994 return; | |
| 995 | |
| 925 // TODO(ivankr): use unique filenames for user images each time | 996 // TODO(ivankr): use unique filenames for user images each time |
| 926 // a new image is set so that only the last image update is saved | 997 // a new image is set so that only the last image update is saved |
| 927 // to Local State and notified. | 998 // to Local State and notified. |
| 928 if (is_async && !last_image_set_async_) { | 999 if (is_async && !last_image_set_async_) { |
| 929 DVLOG(1) << "Ignoring saved image because it has changed"; | 1000 DVLOG(1) << "Ignoring saved image because it has changed"; |
| 930 return; | 1001 return; |
| 931 } else if (!is_async) { | 1002 } else if (!is_async) { |
| 932 // Reset the async image save flag if called directly from the UI thread. | 1003 // Reset the async image save flag if called directly from the UI thread. |
| 933 last_image_set_async_ = false; | 1004 last_image_set_async_ = false; |
| 934 } | 1005 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1066 } | 1137 } |
| 1067 | 1138 |
| 1068 User* UserManager::CreateUser(const std::string& email) const { | 1139 User* UserManager::CreateUser(const std::string& email) const { |
| 1069 User* user = new User(email, email == kGuestUser); | 1140 User* user = new User(email, email == kGuestUser); |
| 1070 user->set_oauth_token_status(LoadUserOAuthStatus(email)); | 1141 user->set_oauth_token_status(LoadUserOAuthStatus(email)); |
| 1071 // Used to determine whether user's display name is unique. | 1142 // Used to determine whether user's display name is unique. |
| 1072 ++display_name_count_[user->GetDisplayName()]; | 1143 ++display_name_count_[user->GetDisplayName()]; |
| 1073 return user; | 1144 return user; |
| 1074 } | 1145 } |
| 1075 | 1146 |
| 1147 void UserManager::RemoveUserFromListInternal(const std::string& email) { | |
| 1148 // Clear the prefs view of the users. | |
| 1149 PrefService* prefs = g_browser_process->local_state(); | |
| 1150 ListPrefUpdate prefs_users_update(prefs, kLoggedInUsers); | |
| 1151 prefs_users_update->Clear(); | |
| 1152 | |
| 1153 UserList::iterator user_to_remove = users_.end(); | |
| 1154 for (UserList::iterator it = users_.begin(); it != users_.end(); ++it) { | |
| 1155 std::string user_email = (*it)->email(); | |
| 1156 // Skip user that we would like to delete. | |
| 1157 if (email != user_email) | |
| 1158 prefs_users_update->Append(Value::CreateStringValue(user_email)); | |
| 1159 else | |
| 1160 user_to_remove = it; | |
| 1161 } | |
| 1162 | |
| 1163 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages); | |
| 1164 std::string image_path_string; | |
| 1165 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string); | |
| 1166 prefs_images_update->RemoveWithoutPathExpansion(email, NULL); | |
| 1167 | |
| 1168 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); | |
| 1169 int oauth_status; | |
| 1170 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); | |
| 1171 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); | |
| 1172 | |
| 1173 DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail); | |
| 1174 prefs_display_email_update->RemoveWithoutPathExpansion(email, NULL); | |
| 1175 | |
| 1176 if (user_to_remove != users_.end()) { | |
| 1177 --display_name_count_[(*user_to_remove)->GetDisplayName()]; | |
| 1178 delete *user_to_remove; | |
| 1179 users_.erase(user_to_remove); | |
| 1180 } | |
| 1181 | |
| 1182 int default_image_id = User::kInvalidImageIndex; | |
| 1183 if (!image_path_string.empty() && | |
| 1184 !IsDefaultImagePath(image_path_string, &default_image_id)) { | |
| 1185 FilePath image_path(image_path_string); | |
| 1186 BrowserThread::PostTask( | |
| 1187 BrowserThread::FILE, | |
| 1188 FROM_HERE, | |
| 1189 base::Bind(&UserManager::DeleteUserImage, | |
| 1190 base::Unretained(this), | |
| 1191 image_path)); | |
| 1192 } | |
| 1193 } | |
| 1194 | |
| 1076 } // namespace chromeos | 1195 } // namespace chromeos |
| OLD | NEW |