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; | |
Ivan Korotkov
2012/03/01 20:16:30
What's the point of making guest/demo user ephemer
use bartfab instead
2012/03/05 18:07:32
It is logically consistent. The guest user's recen
| |
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 base::Unretained(this), | 483 base::Unretained(this), |
474 image_path)); | 484 image_path)); |
475 } | 485 } |
476 } | 486 } |
477 | 487 |
478 bool UserManager::IsKnownUser(const std::string& email) const { | 488 bool UserManager::IsKnownUser(const std::string& email) const { |
479 return FindUser(email) != NULL; | 489 return FindUser(email) != NULL; |
480 } | 490 } |
481 | 491 |
482 const User* UserManager::FindUser(const std::string& email) const { | 492 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) | 493 if (logged_in_user_ && logged_in_user_->email() == email) |
485 return logged_in_user_; | 494 return logged_in_user_; |
486 const UserList& users = GetUsers(); | 495 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 } | 496 } |
493 | 497 |
494 bool UserManager::IsDisplayNameUnique(const std::string& display_name) const { | 498 bool UserManager::IsDisplayNameUnique(const std::string& display_name) const { |
495 return display_name_count_[display_name] < 2; | 499 return display_name_count_[display_name] < 2; |
496 } | 500 } |
497 | 501 |
498 void UserManager::SaveUserOAuthStatus( | 502 void UserManager::SaveUserOAuthStatus( |
499 const std::string& username, | 503 const std::string& username, |
500 User::OAuthTokenStatus oauth_token_status) { | 504 User::OAuthTokenStatus oauth_token_status) { |
501 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 505 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
502 PrefService* local_state = g_browser_process->local_state(); | 506 |
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"; | 507 DVLOG(1) << "Saving user OAuth token status in Local State"; |
507 User* user = const_cast<User*>(FindUser(username)); | 508 User* user = const_cast<User*>(FindUser(username)); |
508 if (user) | 509 if (user) |
509 user->set_oauth_token_status(oauth_token_status); | 510 user->set_oauth_token_status(oauth_token_status); |
511 | |
512 // Do not update local store if the user is ephemeral. | |
513 if (IsEphemeralUser(username)) | |
514 return; | |
515 | |
516 PrefService* local_state = g_browser_process->local_state(); | |
517 | |
518 DictionaryPrefUpdate oauth_status_update(local_state, kUserOAuthTokenStatus); | |
519 oauth_status_update->SetWithoutPathExpansion(username, | |
520 new base::FundamentalValue(static_cast<int>(oauth_token_status))); | |
510 } | 521 } |
511 | 522 |
512 User::OAuthTokenStatus UserManager::LoadUserOAuthStatus( | 523 User::OAuthTokenStatus UserManager::LoadUserOAuthStatus( |
513 const std::string& username) const { | 524 const std::string& username) const { |
514 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 525 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
515 | 526 |
516 if (CommandLine::ForCurrentProcess()->HasSwitch( | 527 if (CommandLine::ForCurrentProcess()->HasSwitch( |
517 switches::kSkipOAuthLogin)) { | 528 switches::kSkipOAuthLogin)) { |
518 // Use OAUTH_TOKEN_STATUS_VALID flag if kSkipOAuthLogin is present. | 529 // Use OAUTH_TOKEN_STATUS_VALID flag if kSkipOAuthLogin is present. |
519 return User::OAUTH_TOKEN_STATUS_VALID; | 530 return User::OAUTH_TOKEN_STATUS_VALID; |
(...skipping 16 matching lines...) Expand all Loading... | |
536 void UserManager::SaveUserDisplayEmail(const std::string& username, | 547 void UserManager::SaveUserDisplayEmail(const std::string& username, |
537 const std::string& display_email) { | 548 const std::string& display_email) { |
538 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 549 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
539 | 550 |
540 User* user = const_cast<User*>(FindUser(username)); | 551 User* user = const_cast<User*>(FindUser(username)); |
541 if (!user) | 552 if (!user) |
542 return; // Ignore if there is no such user. | 553 return; // Ignore if there is no such user. |
543 | 554 |
544 user->set_display_email(display_email); | 555 user->set_display_email(display_email); |
545 | 556 |
557 // Do not update local store if the user is ephemeral. | |
558 if (IsEphemeralUser(username)) | |
559 return; | |
560 | |
546 PrefService* local_state = g_browser_process->local_state(); | 561 PrefService* local_state = g_browser_process->local_state(); |
547 | 562 |
548 DictionaryPrefUpdate display_email_update(local_state, kUserDisplayEmail); | 563 DictionaryPrefUpdate display_email_update(local_state, kUserDisplayEmail); |
549 display_email_update->SetWithoutPathExpansion( | 564 display_email_update->SetWithoutPathExpansion( |
550 username, | 565 username, |
551 base::Value::CreateStringValue(display_email)); | 566 base::Value::CreateStringValue(display_email)); |
552 } | 567 } |
553 | 568 |
554 std::string UserManager::GetUserDisplayEmail( | 569 std::string UserManager::GetUserDisplayEmail( |
555 const std::string& username) const { | 570 const std::string& username) const { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
607 } | 622 } |
608 | 623 |
609 void UserManager::Observe(int type, | 624 void UserManager::Observe(int type, |
610 const content::NotificationSource& source, | 625 const content::NotificationSource& source, |
611 const content::NotificationDetails& details) { | 626 const content::NotificationDetails& details) { |
612 switch (type) { | 627 switch (type) { |
613 case chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED: | 628 case chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED: |
614 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 629 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
615 base::Bind(&UserManager::CheckOwnership, | 630 base::Bind(&UserManager::CheckOwnership, |
616 base::Unretained(this))); | 631 base::Unretained(this))); |
632 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
633 base::Bind(&UserManager::RetrieveTrustedDevicePolicies, | |
634 base::Unretained(this))); | |
617 break; | 635 break; |
618 case chrome::NOTIFICATION_PROFILE_ADDED: | 636 case chrome::NOTIFICATION_PROFILE_ADDED: |
619 if (user_is_logged_in() && !IsLoggedInAsGuest()) { | 637 if (user_is_logged_in() && !IsLoggedInAsGuest()) { |
620 Profile* profile = content::Source<Profile>(source).ptr(); | 638 Profile* profile = content::Source<Profile>(source).ptr(); |
621 if (!profile->IsOffTheRecord() && | 639 if (!profile->IsOffTheRecord() && |
622 profile == ProfileManager::GetDefaultProfile()) { | 640 profile == ProfileManager::GetDefaultProfile()) { |
623 DCHECK(NULL == observed_sync_service_); | 641 DCHECK(NULL == observed_sync_service_); |
624 observed_sync_service_ = | 642 observed_sync_service_ = |
625 ProfileSyncServiceFactory::GetForProfile(profile); | 643 ProfileSyncServiceFactory::GetForProfile(profile); |
626 if (observed_sync_service_) | 644 if (observed_sync_service_) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
681 | 699 |
682 // Protected constructor and destructor. | 700 // Protected constructor and destructor. |
683 UserManager::UserManager() | 701 UserManager::UserManager() |
684 : ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_(new UserImageLoader)), | 702 : ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_(new UserImageLoader)), |
685 demo_user_(kDemoUser, false), | 703 demo_user_(kDemoUser, false), |
686 guest_user_(kGuestUser, true), | 704 guest_user_(kGuestUser, true), |
687 stub_user_(kStubUser, false), | 705 stub_user_(kStubUser, false), |
688 logged_in_user_(NULL), | 706 logged_in_user_(NULL), |
689 current_user_is_owner_(false), | 707 current_user_is_owner_(false), |
690 current_user_is_new_(false), | 708 current_user_is_new_(false), |
709 current_user_is_ephemeral_(false), | |
691 user_is_logged_in_(false), | 710 user_is_logged_in_(false), |
692 observed_sync_service_(NULL), | 711 observed_sync_service_(NULL), |
693 last_image_set_async_(false), | 712 last_image_set_async_(false), |
694 downloaded_profile_image_data_url_(chrome::kAboutBlankURL) { | 713 downloaded_profile_image_data_url_(chrome::kAboutBlankURL) { |
695 // Use stub as the logged-in user for test paths without login. | 714 // Use stub as the logged-in user for test paths without login. |
696 if (!system::runtime_environment::IsRunningOnChromeOS()) | 715 if (!system::runtime_environment::IsRunningOnChromeOS()) |
697 StubUserLoggedIn(); | 716 StubUserLoggedIn(); |
698 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, | 717 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, |
699 content::NotificationService::AllSources()); | 718 content::NotificationService::AllSources()); |
700 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, | 719 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, |
701 content::NotificationService::AllSources()); | 720 content::NotificationService::AllSources()); |
721 RetrieveTrustedDevicePolicies(); | |
702 } | 722 } |
703 | 723 |
704 UserManager::~UserManager() { | 724 UserManager::~UserManager() { |
705 } | 725 } |
706 | 726 |
707 FilePath UserManager::GetImagePathForUser(const std::string& username) { | 727 FilePath UserManager::GetImagePathForUser(const std::string& username) { |
708 std::string filename = username + ".png"; | 728 std::string filename = username + ".png"; |
709 FilePath user_data_dir; | 729 FilePath user_data_dir; |
710 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 730 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
711 return user_data_dir.AppendASCII(filename); | 731 return user_data_dir.AppendASCII(filename); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
787 if (prefs_display_emails && | 807 if (prefs_display_emails && |
788 prefs_display_emails->GetStringWithoutPathExpansion( | 808 prefs_display_emails->GetStringWithoutPathExpansion( |
789 email, &display_email)) { | 809 email, &display_email)) { |
790 user->set_display_email(display_email); | 810 user->set_display_email(display_email); |
791 } | 811 } |
792 } | 812 } |
793 } | 813 } |
794 } | 814 } |
795 } | 815 } |
796 | 816 |
817 void UserManager::RetrieveTrustedDevicePolicies() { | |
818 ephemeral_users_enabled_.reset(); | |
819 owner_.reset(); | |
820 | |
821 CrosSettings* cros_settings = CrosSettings::Get(); | |
822 // Schedule a callback if device policy has not yet been verified. | |
823 if (!cros_settings->GetTrusted( | |
824 kAccountsPrefEphemeralUsersEnabled, | |
825 base::Bind(&UserManager::RetrieveTrustedDevicePolicies, | |
826 base::Unretained(this)))) { | |
827 return; | |
828 } | |
829 bool* ephemeral_users_enabled = new bool; | |
830 cros_settings->GetBoolean(kAccountsPrefEphemeralUsersEnabled, | |
831 ephemeral_users_enabled); | |
832 ephemeral_users_enabled_.reset(ephemeral_users_enabled); | |
833 | |
834 if (g_browser_process->browser_policy_connector()->IsEnterpriseManaged()) { | |
835 owner_.reset(new std::string); | |
836 } else { | |
837 std::string* owner = new std::string; | |
838 cros_settings->GetString(kDeviceOwner, owner); | |
839 owner_.reset(owner); | |
840 } | |
841 | |
842 if (*ephemeral_users_enabled_) | |
843 RemoveAllExceptOwnerFromList(); | |
Ivan Korotkov
2012/03/02 12:39:38
Discussed this with Nikita:
Please consider delayi
use bartfab instead
2012/03/05 18:07:32
I discussed this with the folks here at the office
| |
844 } | |
845 | |
846 bool UserManager::AreEphemeralUsersEnabled() const { | |
847 return ephemeral_users_enabled_.get() && | |
848 *ephemeral_users_enabled_ && | |
849 owner_.get(); | |
850 } | |
851 | |
852 bool UserManager::IsEphemeralUser(const std::string& email) const { | |
853 // The guest user always is ephemeral. | |
854 if (email == guest_user_.email()) | |
855 return true; | |
856 | |
857 // The currently logged-in user is ephemeral iff logged in as ephemeral. | |
858 if (logged_in_user_ && (email == logged_in_user_->email())) | |
859 return current_user_is_ephemeral_; | |
860 | |
861 // Any other user is ephemeral iff ephemeral users are enabled, the user is | |
862 // not the owner and is not in the persistent list. | |
863 return AreEphemeralUsersEnabled() && | |
864 (email != *owner_) && | |
865 !FindUserInList(email); | |
866 } | |
867 | |
868 const User* UserManager::FindUserInList(const std::string& email) const { | |
869 const UserList& users = GetUsers(); | |
870 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | |
871 if ((*it)->email() == email) | |
872 return *it; | |
873 } | |
874 return NULL; | |
875 } | |
876 | |
797 void UserManager::StubUserLoggedIn() { | 877 void UserManager::StubUserLoggedIn() { |
798 logged_in_user_ = &stub_user_; | 878 logged_in_user_ = &stub_user_; |
799 stub_user_.SetImage(GetDefaultImage(kStubDefaultImageIndex), | 879 stub_user_.SetImage(GetDefaultImage(kStubDefaultImageIndex), |
800 kStubDefaultImageIndex); | 880 kStubDefaultImageIndex); |
801 } | 881 } |
802 | 882 |
803 void UserManager::NotifyOnLogin() { | 883 void UserManager::NotifyOnLogin() { |
804 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 884 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
805 content::NotificationService::current()->Notify( | 885 content::NotificationService::current()->Notify( |
806 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 886 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
915 base::Unretained(this), | 995 base::Unretained(this), |
916 username, image_path.value(), image_index, true)); | 996 username, image_path.value(), image_index, true)); |
917 } | 997 } |
918 | 998 |
919 void UserManager::SaveImageToLocalState(const std::string& username, | 999 void UserManager::SaveImageToLocalState(const std::string& username, |
920 const std::string& image_path, | 1000 const std::string& image_path, |
921 int image_index, | 1001 int image_index, |
922 bool is_async) { | 1002 bool is_async) { |
923 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1003 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
924 | 1004 |
1005 // Ignore for ephemeral users. | |
1006 if (IsEphemeralUser(username)) | |
1007 return; | |
1008 | |
925 // TODO(ivankr): use unique filenames for user images each time | 1009 // 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 | 1010 // a new image is set so that only the last image update is saved |
927 // to Local State and notified. | 1011 // to Local State and notified. |
928 if (is_async && !last_image_set_async_) { | 1012 if (is_async && !last_image_set_async_) { |
929 DVLOG(1) << "Ignoring saved image because it has changed"; | 1013 DVLOG(1) << "Ignoring saved image because it has changed"; |
930 return; | 1014 return; |
931 } else if (!is_async) { | 1015 } else if (!is_async) { |
932 // Reset the async image save flag if called directly from the UI thread. | 1016 // Reset the async image save flag if called directly from the UI thread. |
933 last_image_set_async_ = false; | 1017 last_image_set_async_ = false; |
934 } | 1018 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1066 } | 1150 } |
1067 | 1151 |
1068 User* UserManager::CreateUser(const std::string& email) const { | 1152 User* UserManager::CreateUser(const std::string& email) const { |
1069 User* user = new User(email, email == kGuestUser); | 1153 User* user = new User(email, email == kGuestUser); |
1070 user->set_oauth_token_status(LoadUserOAuthStatus(email)); | 1154 user->set_oauth_token_status(LoadUserOAuthStatus(email)); |
1071 // Used to determine whether user's display name is unique. | 1155 // Used to determine whether user's display name is unique. |
1072 ++display_name_count_[user->GetDisplayName()]; | 1156 ++display_name_count_[user->GetDisplayName()]; |
1073 return user; | 1157 return user; |
1074 } | 1158 } |
1075 | 1159 |
1160 void UserManager::RemoveAllExceptOwnerFromList() { | |
1161 const std::string owner_email = *owner_; | |
1162 // If a user is currently logged in and the login occurred before ephemeral | |
1163 // users were enabled, this user should not be deleted yet either. | |
Ivan Korotkov
2012/03/02 12:39:38
Are we sure about that decision? As far as I under
Nikita (slow)
2012/03/02 12:51:42
And this only makes sense when we want "Enable eph
use bartfab instead
2012/03/05 18:07:32
Even with ephemeral users exposed as a consumer se
| |
1164 std::string logged_in_user_email; | |
1165 if (user_is_logged_in_ && !current_user_is_ephemeral_) | |
1166 logged_in_user_email = logged_in_user_->email(); | |
1167 | |
1168 PrefService* prefs = g_browser_process->local_state(); | |
1169 ListPrefUpdate prefs_users_update(prefs, kLoggedInUsers); | |
1170 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages); | |
1171 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); | |
1172 DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail); | |
1173 | |
1174 scoped_ptr<base::ListValue> users(prefs_users_update->DeepCopy()); | |
1175 prefs_users_update->Clear(); | |
1176 for (base::ListValue::const_iterator user = users->begin(); | |
1177 user != users->end(); ++user) { | |
1178 std::string user_email; | |
1179 (*user)->GetAsString(&user_email); | |
1180 if (user_email == owner_email || user_email == logged_in_user_email) { | |
1181 prefs_users_update->Append(Value::CreateStringValue(user_email)); | |
1182 continue; | |
1183 } | |
1184 std::string image_path_string; | |
1185 prefs_images_update->GetStringWithoutPathExpansion(user_email, | |
1186 &image_path_string); | |
1187 prefs_images_update->RemoveWithoutPathExpansion(user_email, NULL); | |
1188 prefs_oauth_update->RemoveWithoutPathExpansion(user_email, NULL); | |
1189 prefs_display_email_update->RemoveWithoutPathExpansion(user_email, NULL); | |
1190 | |
1191 int default_image_id = User::kInvalidImageIndex; | |
1192 if (!image_path_string.empty() && | |
1193 !IsDefaultImagePath(image_path_string, &default_image_id)) { | |
1194 FilePath image_path(image_path_string); | |
1195 BrowserThread::PostTask( | |
1196 BrowserThread::FILE, | |
1197 FROM_HERE, | |
1198 base::Bind(&UserManager::DeleteUserImage, | |
1199 base::Unretained(this), | |
1200 image_path)); | |
1201 } | |
1202 } | |
1203 | |
1204 if (!users_.empty()) { | |
1205 UserList users_update; | |
1206 for (UserList::iterator user = users_.begin(); user != users_.end(); | |
1207 ++user) { | |
1208 if ((*user)->email() == owner_email || *user == logged_in_user_) { | |
1209 users_update.push_back(*user); | |
1210 } else { | |
1211 --display_name_count_[(*user)->GetDisplayName()]; | |
1212 delete *user; | |
1213 } | |
1214 } | |
1215 users_ = users_update; | |
1216 // Trigger a redraw of the login window. | |
1217 content::NotificationService::current()->Notify( | |
1218 chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, | |
1219 content::Source<UserManager>(this), | |
1220 content::NotificationService::NoDetails()); | |
1221 } | |
1222 } | |
1223 | |
1076 } // namespace chromeos | 1224 } // namespace chromeos |
OLD | NEW |