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 "components/user_manager/user_manager_base.h" | 5 #include "components/user_manager/user_manager_base.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 const char kUserDisplayEmail[] = "UserDisplayEmail"; | 51 const char kUserDisplayEmail[] = "UserDisplayEmail"; |
52 | 52 |
53 // A dictionary that maps user IDs to OAuth token presence flag. | 53 // A dictionary that maps user IDs to OAuth token presence flag. |
54 const char kUserOAuthTokenStatus[] = "OAuthTokenStatus"; | 54 const char kUserOAuthTokenStatus[] = "OAuthTokenStatus"; |
55 | 55 |
56 // A dictionary that maps user IDs to a flag indicating whether online | 56 // A dictionary that maps user IDs to a flag indicating whether online |
57 // authentication against GAIA should be enforced during the next sign-in. | 57 // authentication against GAIA should be enforced during the next sign-in. |
58 const char kUserForceOnlineSignin[] = "UserForceOnlineSignin"; | 58 const char kUserForceOnlineSignin[] = "UserForceOnlineSignin"; |
59 | 59 |
60 // A string pref containing the ID of the last user who logged in if it was | 60 // A string pref containing the ID of the last user who logged in if it was |
61 // a regular user or an empty string if it was another type of user (guest, | 61 // a user with gaia account (regular) or an empty string if it was another type |
62 // kiosk, public account, etc.). | 62 // of user (guest, kiosk, public account, etc.). |
63 const char kLastLoggedInRegularUser[] = "LastLoggedInRegularUser"; | 63 const char kLastLoggedInGaiaUser[] = "LastLoggedInRegularUser"; |
64 | 64 |
65 // A string pref containing the ID of the last active user. | 65 // A string pref containing the ID of the last active user. |
66 // In case of browser crash, this pref will be used to set active user after | 66 // In case of browser crash, this pref will be used to set active user after |
67 // session restore. | 67 // session restore. |
68 const char kLastActiveUser[] = "LastActiveUser"; | 68 const char kLastActiveUser[] = "LastActiveUser"; |
69 | 69 |
70 // Upper bound for a histogram metric reporting the amount of time between | 70 // Upper bound for a histogram metric reporting the amount of time between |
71 // one regular user logging out and a different regular user logging in. | 71 // one regular user logging out and a different regular user logging in. |
72 const int kLogoutToLoginDelayMaxSec = 1800; | 72 const int kLogoutToLoginDelayMaxSec = 1800; |
73 | 73 |
(...skipping 12 matching lines...) Expand all Loading... | |
86 void ResolveLocale(const std::string& raw_locale, | 86 void ResolveLocale(const std::string& raw_locale, |
87 std::string* resolved_locale) { | 87 std::string* resolved_locale) { |
88 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale)); | 88 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale)); |
89 } | 89 } |
90 | 90 |
91 } // namespace | 91 } // namespace |
92 | 92 |
93 // static | 93 // static |
94 void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) { | 94 void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) { |
95 registry->RegisterListPref(kRegularUsers); | 95 registry->RegisterListPref(kRegularUsers); |
96 registry->RegisterStringPref(kLastLoggedInRegularUser, std::string()); | 96 registry->RegisterStringPref(kLastLoggedInGaiaUser, std::string()); |
97 registry->RegisterDictionaryPref(kUserDisplayName); | 97 registry->RegisterDictionaryPref(kUserDisplayName); |
98 registry->RegisterDictionaryPref(kUserGivenName); | 98 registry->RegisterDictionaryPref(kUserGivenName); |
99 registry->RegisterDictionaryPref(kUserDisplayEmail); | 99 registry->RegisterDictionaryPref(kUserDisplayEmail); |
100 registry->RegisterDictionaryPref(kUserOAuthTokenStatus); | 100 registry->RegisterDictionaryPref(kUserOAuthTokenStatus); |
101 registry->RegisterDictionaryPref(kUserForceOnlineSignin); | 101 registry->RegisterDictionaryPref(kUserForceOnlineSignin); |
102 registry->RegisterStringPref(kLastActiveUser, std::string()); | 102 registry->RegisterStringPref(kLastActiveUser, std::string()); |
103 } | 103 } |
104 | 104 |
105 UserManagerBase::UserManagerBase( | 105 UserManagerBase::UserManagerBase( |
106 scoped_refptr<base::TaskRunner> task_runner, | 106 scoped_refptr<base::TaskRunner> task_runner, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 active_user_->set_is_logged_in(true); | 211 active_user_->set_is_logged_in(true); |
212 active_user_->set_is_active(true); | 212 active_user_->set_is_active(true); |
213 active_user_->set_username_hash(username_hash); | 213 active_user_->set_username_hash(username_hash); |
214 | 214 |
215 // Place user who just signed in to the top of the logged in users. | 215 // Place user who just signed in to the top of the logged in users. |
216 logged_in_users_.insert(logged_in_users_.begin(), active_user_); | 216 logged_in_users_.insert(logged_in_users_.begin(), active_user_); |
217 SetLRUUser(active_user_); | 217 SetLRUUser(active_user_); |
218 | 218 |
219 if (!primary_user_) { | 219 if (!primary_user_) { |
220 primary_user_ = active_user_; | 220 primary_user_ = active_user_; |
221 if (primary_user_->GetType() == USER_TYPE_REGULAR) | 221 if (primary_user_->HasGaiaAccount()) |
222 SendRegularUserLoginMetrics(user_id); | 222 SendGaiaUserLoginMetrics(user_id); |
223 } | 223 } |
224 | 224 |
225 UMA_HISTOGRAM_ENUMERATION( | 225 UMA_HISTOGRAM_ENUMERATION( |
226 "UserManager.LoginUserType", active_user_->GetType(), NUM_USER_TYPES); | 226 "UserManager.LoginUserType", active_user_->GetType(), NUM_USER_TYPES); |
227 | 227 |
228 GetLocalState()->SetString( | 228 GetLocalState()->SetString( |
229 kLastLoggedInRegularUser, | 229 kLastLoggedInGaiaUser, active_user_->HasGaiaAccount() ? user_id : ""); |
230 (active_user_->GetType() == USER_TYPE_REGULAR) ? user_id : ""); | |
231 | 230 |
232 NotifyOnLogin(); | 231 NotifyOnLogin(); |
233 PerformPostUserLoggedInActions(browser_restart); | 232 PerformPostUserLoggedInActions(browser_restart); |
234 } | 233 } |
235 | 234 |
236 void UserManagerBase::SwitchActiveUser(const std::string& user_id) { | 235 void UserManagerBase::SwitchActiveUser(const std::string& user_id) { |
237 User* user = FindUserAndModify(user_id); | 236 User* user = FindUserAndModify(user_id); |
238 if (!user) { | 237 if (!user) { |
239 NOTREACHED() << "Switching to a non-existing user"; | 238 NOTREACHED() << "Switching to a non-existing user"; |
240 return; | 239 return; |
241 } | 240 } |
242 if (user == active_user_) { | 241 if (user == active_user_) { |
243 NOTREACHED() << "Switching to a user who is already active"; | 242 NOTREACHED() << "Switching to a user who is already active"; |
244 return; | 243 return; |
245 } | 244 } |
246 if (!user->is_logged_in()) { | 245 if (!user->is_logged_in()) { |
247 NOTREACHED() << "Switching to a user that is not logged in"; | 246 NOTREACHED() << "Switching to a user that is not logged in"; |
248 return; | 247 return; |
249 } | 248 } |
250 if (user->GetType() != USER_TYPE_REGULAR) { | 249 if (!user->HasGaiaAccount()) { |
251 NOTREACHED() << "Switching to a non-regular user"; | 250 NOTREACHED() << "Switching to a non-regular user"; |
Nikita (slow)
2014/11/14 09:34:52
nit: update comment?
merkulova
2014/11/14 10:09:49
Done.
| |
252 return; | 251 return; |
253 } | 252 } |
254 if (user->username_hash().empty()) { | 253 if (user->username_hash().empty()) { |
255 NOTREACHED() << "Switching to a user that doesn't have username_hash set"; | 254 NOTREACHED() << "Switching to a user that doesn't have username_hash set"; |
256 return; | 255 return; |
257 } | 256 } |
258 | 257 |
259 DCHECK(active_user_); | 258 DCHECK(active_user_); |
260 active_user_->set_is_active(false); | 259 active_user_->set_is_active(false); |
261 user->set_is_active(true); | 260 user->set_is_active(true); |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 bool UserManagerBase::CanCurrentUserLock() const { | 543 bool UserManagerBase::CanCurrentUserLock() const { |
545 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 544 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
546 return IsUserLoggedIn() && active_user_->can_lock(); | 545 return IsUserLoggedIn() && active_user_->can_lock(); |
547 } | 546 } |
548 | 547 |
549 bool UserManagerBase::IsUserLoggedIn() const { | 548 bool UserManagerBase::IsUserLoggedIn() const { |
550 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 549 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
551 return active_user_; | 550 return active_user_; |
552 } | 551 } |
553 | 552 |
554 bool UserManagerBase::IsLoggedInAsRegularUser() const { | 553 bool UserManagerBase::IsLoggedInAsUserWithGaiaAccount() const { |
555 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 554 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
556 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_REGULAR; | 555 return IsUserLoggedIn() && active_user_->HasGaiaAccount(); |
556 } | |
557 | |
558 bool UserManagerBase::IsLoggedInAsRegularSupervisedUser() const { | |
559 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | |
560 return IsUserLoggedIn() && active_user_->GetType() == | |
561 USER_TYPE_REGULAR_SUPERVISED; | |
557 } | 562 } |
558 | 563 |
559 bool UserManagerBase::IsLoggedInAsDemoUser() const { | 564 bool UserManagerBase::IsLoggedInAsDemoUser() const { |
560 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 565 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
561 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_RETAIL_MODE; | 566 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_RETAIL_MODE; |
562 } | 567 } |
563 | 568 |
564 bool UserManagerBase::IsLoggedInAsPublicAccount() const { | 569 bool UserManagerBase::IsLoggedInAsPublicAccount() const { |
565 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 570 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
566 return IsUserLoggedIn() && | 571 return IsUserLoggedIn() && |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 } | 609 } |
605 | 610 |
606 // Data belonging to the owner, anyone found on the user list and obsolete | 611 // Data belonging to the owner, anyone found on the user list and obsolete |
607 // public accounts whose data has not been removed yet is not ephemeral. | 612 // public accounts whose data has not been removed yet is not ephemeral. |
608 if (user_id == GetOwnerEmail() || UserExistsInList(user_id) || | 613 if (user_id == GetOwnerEmail() || UserExistsInList(user_id) || |
609 IsPublicAccountMarkedForRemoval(user_id)) { | 614 IsPublicAccountMarkedForRemoval(user_id)) { |
610 return false; | 615 return false; |
611 } | 616 } |
612 | 617 |
613 // Data belonging to the currently logged-in user is ephemeral when: | 618 // Data belonging to the currently logged-in user is ephemeral when: |
614 // a) The user logged into a regular account while the ephemeral users policy | 619 // a) The user logged into a regular gaia account while the ephemeral users |
615 // was enabled. | 620 // policy was enabled. |
616 // - or - | 621 // - or - |
617 // b) The user logged into any other account type. | 622 // b) The user logged into any other account type. |
618 if (IsUserLoggedIn() && (user_id == GetLoggedInUser()->email()) && | 623 if (IsUserLoggedIn() && (user_id == GetLoggedInUser()->email()) && |
619 (is_current_user_ephemeral_regular_user_ || !IsLoggedInAsRegularUser())) { | 624 (is_current_user_ephemeral_regular_user_ || |
625 !IsLoggedInAsUserWithGaiaAccount())) { | |
620 return true; | 626 return true; |
621 } | 627 } |
622 | 628 |
623 // Data belonging to any other user is ephemeral when: | 629 // Data belonging to any other user is ephemeral when: |
624 // a) Going through the regular login flow and the ephemeral users policy is | 630 // a) Going through the regular login flow and the ephemeral users policy is |
625 // enabled. | 631 // enabled. |
626 // - or - | 632 // - or - |
627 // b) The browser is restarting after a crash. | 633 // b) The browser is restarting after a crash. |
628 return AreEphemeralUsersEnabled() || | 634 return AreEphemeralUsersEnabled() || |
629 session_manager::SessionManager::HasBrowserRestarted(); | 635 session_manager::SessionManager::HasBrowserRestarted(); |
(...skipping 22 matching lines...) Expand all Loading... | |
652 } | 658 } |
653 | 659 |
654 void UserManagerBase::NotifyLocalStateChanged() { | 660 void UserManagerBase::NotifyLocalStateChanged() { |
655 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 661 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
656 FOR_EACH_OBSERVER( | 662 FOR_EACH_OBSERVER( |
657 UserManager::Observer, observer_list_, LocalStateChanged(this)); | 663 UserManager::Observer, observer_list_, LocalStateChanged(this)); |
658 } | 664 } |
659 | 665 |
660 bool UserManagerBase::CanUserBeRemoved(const User* user) const { | 666 bool UserManagerBase::CanUserBeRemoved(const User* user) const { |
661 // Only regular and supervised users are allowed to be manually removed. | 667 // Only regular and supervised users are allowed to be manually removed. |
662 if (!user || (user->GetType() != USER_TYPE_REGULAR && | 668 if (!user || !(user->HasGaiaAccount() || user->IsSupervised())) |
663 user->GetType() != USER_TYPE_SUPERVISED)) { | |
664 return false; | 669 return false; |
665 } | |
666 | 670 |
667 // Sanity check: we must not remove single user unless it's an enterprise | 671 // Sanity check: we must not remove single user unless it's an enterprise |
668 // device. This check may seem redundant at a first sight because | 672 // device. This check may seem redundant at a first sight because |
669 // this single user must be an owner and we perform special check later | 673 // this single user must be an owner and we perform special check later |
670 // in order not to remove an owner. However due to non-instant nature of | 674 // in order not to remove an owner. However due to non-instant nature of |
671 // ownership assignment this later check may sometimes fail. | 675 // ownership assignment this later check may sometimes fail. |
672 // See http://crosbug.com/12723 | 676 // See http://crosbug.com/12723 |
673 if (users_.size() < 2 && !IsEnterpriseManaged()) | 677 if (users_.size() < 2 && !IsEnterpriseManaged()) |
674 return false; | 678 return false; |
675 | 679 |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
915 const std::string& user_id) { | 919 const std::string& user_id) { |
916 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); | 920 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); |
917 prefs_users_update->Clear(); | 921 prefs_users_update->Clear(); |
918 User* user = NULL; | 922 User* user = NULL; |
919 for (UserList::iterator it = users_.begin(); it != users_.end();) { | 923 for (UserList::iterator it = users_.begin(); it != users_.end();) { |
920 const std::string user_email = (*it)->email(); | 924 const std::string user_email = (*it)->email(); |
921 if (user_email == user_id) { | 925 if (user_email == user_id) { |
922 user = *it; | 926 user = *it; |
923 it = users_.erase(it); | 927 it = users_.erase(it); |
924 } else { | 928 } else { |
925 if ((*it)->GetType() == USER_TYPE_REGULAR || | 929 if ((*it)->HasGaiaAccount() || (*it)->IsSupervised()) |
926 (*it)->GetType() == USER_TYPE_SUPERVISED) { | |
927 prefs_users_update->Append(new base::StringValue(user_email)); | 930 prefs_users_update->Append(new base::StringValue(user_email)); |
928 } | |
929 ++it; | 931 ++it; |
930 } | 932 } |
931 } | 933 } |
932 return user; | 934 return user; |
933 } | 935 } |
934 | 936 |
935 void UserManagerBase::NotifyActiveUserChanged(const User* active_user) { | 937 void UserManagerBase::NotifyActiveUserChanged(const User* active_user) { |
936 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 938 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
937 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, | 939 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, |
938 session_state_observer_list_, | 940 session_state_observer_list_, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1002 GetLocalState()->SetString(kLastActiveUser, user->email()); | 1004 GetLocalState()->SetString(kLastActiveUser, user->email()); |
1003 GetLocalState()->CommitPendingWrite(); | 1005 GetLocalState()->CommitPendingWrite(); |
1004 | 1006 |
1005 UserList::iterator it = | 1007 UserList::iterator it = |
1006 std::find(lru_logged_in_users_.begin(), lru_logged_in_users_.end(), user); | 1008 std::find(lru_logged_in_users_.begin(), lru_logged_in_users_.end(), user); |
1007 if (it != lru_logged_in_users_.end()) | 1009 if (it != lru_logged_in_users_.end()) |
1008 lru_logged_in_users_.erase(it); | 1010 lru_logged_in_users_.erase(it); |
1009 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user); | 1011 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user); |
1010 } | 1012 } |
1011 | 1013 |
1012 void UserManagerBase::SendRegularUserLoginMetrics(const std::string& user_id) { | 1014 void UserManagerBase::SendGaiaUserLoginMetrics(const std::string& user_id) { |
1013 // If this isn't the first time Chrome was run after the system booted, | 1015 // If this isn't the first time Chrome was run after the system booted, |
1014 // assume that Chrome was restarted because a previous session ended. | 1016 // assume that Chrome was restarted because a previous session ended. |
1015 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 1017 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
1016 chromeos::switches::kFirstExecAfterBoot)) { | 1018 chromeos::switches::kFirstExecAfterBoot)) { |
1017 const std::string last_email = | 1019 const std::string last_email = |
1018 GetLocalState()->GetString(kLastLoggedInRegularUser); | 1020 GetLocalState()->GetString(kLastLoggedInGaiaUser); |
1019 const base::TimeDelta time_to_login = | 1021 const base::TimeDelta time_to_login = |
1020 base::TimeTicks::Now() - manager_creation_time_; | 1022 base::TimeTicks::Now() - manager_creation_time_; |
1021 if (!last_email.empty() && user_id != last_email && | 1023 if (!last_email.empty() && user_id != last_email && |
1022 time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) { | 1024 time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) { |
1023 UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay", | 1025 UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay", |
1024 time_to_login.InSeconds(), | 1026 time_to_login.InSeconds(), |
1025 0, | 1027 0, |
1026 kLogoutToLoginDelayMaxSec, | 1028 kLogoutToLoginDelayMaxSec, |
1027 50); | 1029 50); |
1028 } | 1030 } |
(...skipping 30 matching lines...) Expand all Loading... | |
1059 } | 1061 } |
1060 | 1062 |
1061 void UserManagerBase::DeleteUser(User* user) { | 1063 void UserManagerBase::DeleteUser(User* user) { |
1062 const bool is_active_user = (user == active_user_); | 1064 const bool is_active_user = (user == active_user_); |
1063 delete user; | 1065 delete user; |
1064 if (is_active_user) | 1066 if (is_active_user) |
1065 active_user_ = NULL; | 1067 active_user_ = NULL; |
1066 } | 1068 } |
1067 | 1069 |
1068 } // namespace user_manager | 1070 } // namespace user_manager |
OLD | NEW |