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
3 // found in the LICENSE file.
5 #include "components/user_manager/user_manager_base.h"
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/command_line.h"
13 #include "base/compiler_specific.h"
14 #include "base/format_macros.h"
15 #include "base/location.h"
16 #include "base/logging.h"
17 #include "base/macros.h"
18 #include "base/metrics/histogram.h"
19 #include "base/prefs/pref_registry_simple.h"
20 #include "base/prefs/pref_service.h"
21 #include "base/prefs/scoped_user_pref_update.h"
22 #include "base/strings/string_util.h"
23 #include "base/strings/stringprintf.h"
24 #include "base/strings/utf_string_conversions.h"
25 #include "base/task_runner.h"
26 #include "base/values.h"
27 #include "chromeos/chromeos_switches.h"
28 #include "chromeos/cryptohome/async_method_caller.h"
29 #include "chromeos/login/login_state.h"
30 #include "chromeos/login/user_names.h"
31 #include "components/session_manager/core/session_manager.h"
32 #include "components/user_manager/remove_user_delegate.h"
33 #include "components/user_manager/user_type.h"
34 #include "google_apis/gaia/gaia_auth_util.h"
35 #include "ui/base/l10n/l10n_util.h"
37 namespace user_manager
{
40 // A vector pref of the the regular users known on this device, arranged in LRU
42 const char kRegularUsers
[] = "LoggedInUsers";
44 // A dictionary that maps user IDs to the displayed name.
45 const char kUserDisplayName
[] = "UserDisplayName";
47 // A dictionary that maps user IDs to the user's given name.
48 const char kUserGivenName
[] = "UserGivenName";
50 // A dictionary that maps user IDs to the displayed (non-canonical) emails.
51 const char kUserDisplayEmail
[] = "UserDisplayEmail";
53 // A dictionary that maps user IDs to OAuth token presence flag.
54 const char kUserOAuthTokenStatus
[] = "OAuthTokenStatus";
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.
58 const char kUserForceOnlineSignin
[] = "UserForceOnlineSignin";
60 // A dictionary that maps user ID to the user type.
61 const char kUserType
[] = "UserType";
63 // A string pref containing the ID of the last user who logged in if it was
64 // a user with gaia account (regular) or an empty string if it was another type
65 // of user (guest, kiosk, public account, etc.).
66 const char kLastLoggedInGaiaUser
[] = "LastLoggedInRegularUser";
68 // A string pref containing the ID of the last active user.
69 // In case of browser crash, this pref will be used to set active user after
71 const char kLastActiveUser
[] = "LastActiveUser";
73 // A vector pref of preferences of known users. All new preferences should be
74 // placed in this list.
75 const char kKnownUsers
[] = "KnownUsers";
77 // Known user preferences keys (stored in Local State).
79 // Key of canonical e-mail value.
80 const char kCanonicalEmail
[] = "email";
82 // Key of obfuscated GAIA id value.
83 const char kGAIAIdKey
[] = "gaia_id";
85 // Key of whether this user ID refers to a SAML user.
86 const char kUsingSAMLKey
[] = "using_saml";
89 const char kDeviceId
[] = "device_id";
91 // Key of the reason for re-auth.
92 const char kReauthReasonKey
[] = "reauth_reason";
94 // Upper bound for a histogram metric reporting the amount of time between
95 // one regular user logging out and a different regular user logging in.
96 const int kLogoutToLoginDelayMaxSec
= 1800;
98 // Callback that is called after user removal is complete.
99 void OnRemoveUserComplete(const std::string
& user_email
,
101 cryptohome::MountError return_code
) {
102 // Log the error, but there's not much we can do.
104 LOG(ERROR
) << "Removal of cryptohome for " << user_email
105 << " failed, return code: " << return_code
;
109 // Runs on SequencedWorkerPool thread. Passes resolved locale to UI thread.
110 void ResolveLocale(const std::string
& raw_locale
,
111 std::string
* resolved_locale
) {
112 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale
, resolved_locale
));
115 // Checks if values in |dict| correspond with |user_id| identity.
116 bool UserMatches(const UserID
& user_id
, const base::DictionaryValue
& dict
) {
119 bool has_email
= dict
.GetString(kCanonicalEmail
, &value
);
120 if (has_email
&& user_id
== value
)
123 // TODO(antrim): update code once user id is really a struct.
124 bool has_gaia_id
= dict
.GetString(kGAIAIdKey
, &value
);
125 if (has_gaia_id
&& user_id
== value
)
131 // Fills relevant |dict| values based on |user_id|.
132 void UpdateIdentity(const UserID
& user_id
, base::DictionaryValue
& dict
) {
133 dict
.SetString(kCanonicalEmail
, user_id
);
139 void UserManagerBase::RegisterPrefs(PrefRegistrySimple
* registry
) {
140 registry
->RegisterListPref(kRegularUsers
);
141 registry
->RegisterListPref(kKnownUsers
);
142 registry
->RegisterStringPref(kLastLoggedInGaiaUser
, std::string());
143 registry
->RegisterDictionaryPref(kUserDisplayName
);
144 registry
->RegisterDictionaryPref(kUserGivenName
);
145 registry
->RegisterDictionaryPref(kUserDisplayEmail
);
146 registry
->RegisterDictionaryPref(kUserOAuthTokenStatus
);
147 registry
->RegisterDictionaryPref(kUserForceOnlineSignin
);
148 registry
->RegisterDictionaryPref(kUserType
);
149 registry
->RegisterStringPref(kLastActiveUser
, std::string());
152 UserManagerBase::UserManagerBase(
153 scoped_refptr
<base::TaskRunner
> task_runner
,
154 scoped_refptr
<base::TaskRunner
> blocking_task_runner
)
155 : active_user_(NULL
),
157 user_loading_stage_(STAGE_NOT_LOADED
),
158 session_started_(false),
159 is_current_user_owner_(false),
160 is_current_user_new_(false),
161 is_current_user_ephemeral_regular_user_(false),
162 ephemeral_users_enabled_(false),
163 manager_creation_time_(base::TimeTicks::Now()),
164 last_session_active_user_initialized_(false),
165 task_runner_(task_runner
),
166 blocking_task_runner_(blocking_task_runner
),
167 weak_factory_(this) {
171 UserManagerBase::~UserManagerBase() {
172 // Can't use STLDeleteElements because of the private destructor of User.
173 for (UserList::iterator it
= users_
.begin(); it
!= users_
.end();
174 it
= users_
.erase(it
)) {
177 // These are pointers to the same User instances that were in users_ list.
178 logged_in_users_
.clear();
179 lru_logged_in_users_
.clear();
181 DeleteUser(active_user_
);
184 void UserManagerBase::Shutdown() {
185 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
188 const UserList
& UserManagerBase::GetUsers() const {
189 const_cast<UserManagerBase
*>(this)->EnsureUsersLoaded();
193 const UserList
& UserManagerBase::GetLoggedInUsers() const {
194 return logged_in_users_
;
197 const UserList
& UserManagerBase::GetLRULoggedInUsers() const {
198 return lru_logged_in_users_
;
201 const std::string
& UserManagerBase::GetOwnerEmail() const {
205 void UserManagerBase::UserLoggedIn(const std::string
& user_id
,
206 const std::string
& username_hash
,
207 bool browser_restart
) {
208 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
210 if (!last_session_active_user_initialized_
) {
211 last_session_active_user_
= GetLocalState()->GetString(kLastActiveUser
);
212 last_session_active_user_initialized_
= true;
215 User
* user
= FindUserInListAndModify(user_id
);
216 if (active_user_
&& user
) {
217 user
->set_is_logged_in(true);
218 user
->set_username_hash(username_hash
);
219 logged_in_users_
.push_back(user
);
220 lru_logged_in_users_
.push_back(user
);
222 // Reset the new user flag if the user already exists.
223 SetIsCurrentUserNew(false);
224 NotifyUserAddedToSession(user
, true /* user switch pending */);
229 if (user_id
== chromeos::login::kGuestUserName
) {
231 } else if (IsKioskApp(user_id
)) {
232 KioskAppLoggedIn(user_id
);
233 } else if (IsDemoApp(user_id
)) {
234 DemoAccountLoggedIn();
238 if (user
&& user
->GetType() == USER_TYPE_PUBLIC_ACCOUNT
) {
239 PublicAccountUserLoggedIn(user
);
240 } else if ((user
&& user
->GetType() == USER_TYPE_SUPERVISED
) ||
242 gaia::ExtractDomainName(user_id
) ==
243 chromeos::login::kSupervisedUserDomain
)) {
244 SupervisedUserLoggedIn(user_id
);
245 } else if (browser_restart
&& IsPublicAccountMarkedForRemoval(user_id
)) {
246 PublicAccountUserLoggedIn(User::CreatePublicAccountUser(user_id
));
247 } else if (user_id
!= GetOwnerEmail() && !user
&&
248 (AreEphemeralUsersEnabled() || browser_restart
)) {
249 RegularUserLoggedInAsEphemeral(user_id
);
251 RegularUserLoggedIn(user_id
);
255 DCHECK(active_user_
);
256 active_user_
->set_is_logged_in(true);
257 active_user_
->set_is_active(true);
258 active_user_
->set_username_hash(username_hash
);
260 // Place user who just signed in to the top of the logged in users.
261 logged_in_users_
.insert(logged_in_users_
.begin(), active_user_
);
262 SetLRUUser(active_user_
);
264 if (!primary_user_
) {
265 primary_user_
= active_user_
;
266 if (primary_user_
->HasGaiaAccount())
267 SendGaiaUserLoginMetrics(user_id
);
270 UMA_HISTOGRAM_ENUMERATION(
271 "UserManager.LoginUserType", active_user_
->GetType(), NUM_USER_TYPES
);
273 GetLocalState()->SetString(
274 kLastLoggedInGaiaUser
, active_user_
->HasGaiaAccount() ? user_id
: "");
277 PerformPostUserLoggedInActions(browser_restart
);
280 void UserManagerBase::SwitchActiveUser(const std::string
& user_id
) {
281 User
* user
= FindUserAndModify(user_id
);
283 NOTREACHED() << "Switching to a non-existing user";
286 if (user
== active_user_
) {
287 NOTREACHED() << "Switching to a user who is already active";
290 if (!user
->is_logged_in()) {
291 NOTREACHED() << "Switching to a user that is not logged in";
294 if (!user
->HasGaiaAccount()) {
296 "Switching to a user without gaia account (non-regular one)";
299 if (user
->username_hash().empty()) {
300 NOTREACHED() << "Switching to a user that doesn't have username_hash set";
304 DCHECK(active_user_
);
305 active_user_
->set_is_active(false);
306 user
->set_is_active(true);
309 // Move the user to the front.
310 SetLRUUser(active_user_
);
312 NotifyActiveUserHashChanged(active_user_
->username_hash());
313 NotifyActiveUserChanged(active_user_
);
316 void UserManagerBase::SwitchToLastActiveUser() {
317 if (last_session_active_user_
.empty())
320 if (GetActiveUser()->email() != last_session_active_user_
)
321 SwitchActiveUser(last_session_active_user_
);
323 // Make sure that this function gets run only once.
324 last_session_active_user_
.clear();
327 void UserManagerBase::SessionStarted() {
328 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
329 session_started_
= true;
332 session_manager::SessionManager::Get()->SetSessionState(
333 session_manager::SESSION_STATE_ACTIVE
);
335 if (IsCurrentUserNew()) {
336 // Make sure that the new user's data is persisted to Local State.
337 GetLocalState()->CommitPendingWrite();
341 void UserManagerBase::RemoveUser(const std::string
& user_id
,
342 RemoveUserDelegate
* delegate
) {
343 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
345 if (!CanUserBeRemoved(FindUser(user_id
)))
348 RemoveUserInternal(user_id
, delegate
);
351 void UserManagerBase::RemoveUserInternal(const std::string
& user_email
,
352 RemoveUserDelegate
* delegate
) {
353 RemoveNonOwnerUserInternal(user_email
, delegate
);
356 void UserManagerBase::RemoveNonOwnerUserInternal(const std::string
& user_email
,
357 RemoveUserDelegate
* delegate
) {
359 delegate
->OnBeforeUserRemoved(user_email
);
360 RemoveUserFromList(user_email
);
361 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove(
362 user_email
, base::Bind(&OnRemoveUserComplete
, user_email
));
365 delegate
->OnUserRemoved(user_email
);
368 void UserManagerBase::RemoveUserFromList(const std::string
& user_id
) {
369 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
370 RemoveNonCryptohomeData(user_id
);
371 if (user_loading_stage_
== STAGE_LOADED
) {
372 DeleteUser(RemoveRegularOrSupervisedUserFromList(user_id
));
373 } else if (user_loading_stage_
== STAGE_LOADING
) {
374 DCHECK(gaia::ExtractDomainName(user_id
) ==
375 chromeos::login::kSupervisedUserDomain
||
376 HasPendingBootstrap(user_id
));
377 // Special case, removing partially-constructed supervised user or
378 // boostrapping user during user list loading.
379 ListPrefUpdate
users_update(GetLocalState(), kRegularUsers
);
380 users_update
->Remove(base::StringValue(user_id
), NULL
);
382 NOTREACHED() << "Users are not loaded yet.";
386 // Make sure that new data is persisted to Local State.
387 GetLocalState()->CommitPendingWrite();
390 bool UserManagerBase::IsKnownUser(const std::string
& user_id
) const {
391 return FindUser(user_id
) != NULL
;
394 const User
* UserManagerBase::FindUser(const std::string
& user_id
) const {
395 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
396 if (active_user_
&& active_user_
->email() == user_id
)
398 return FindUserInList(user_id
);
401 User
* UserManagerBase::FindUserAndModify(const std::string
& user_id
) {
402 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
403 if (active_user_
&& active_user_
->email() == user_id
)
405 return FindUserInListAndModify(user_id
);
408 const User
* UserManagerBase::GetLoggedInUser() const {
409 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
413 User
* UserManagerBase::GetLoggedInUser() {
414 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
418 const User
* UserManagerBase::GetActiveUser() const {
419 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
423 User
* UserManagerBase::GetActiveUser() {
424 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
428 const User
* UserManagerBase::GetPrimaryUser() const {
429 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
430 return primary_user_
;
433 void UserManagerBase::SaveUserOAuthStatus(
434 const std::string
& user_id
,
435 User::OAuthTokenStatus oauth_token_status
) {
436 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
438 DVLOG(1) << "Saving user OAuth token status in Local State";
439 User
* user
= FindUserAndModify(user_id
);
441 user
->set_oauth_token_status(oauth_token_status
);
443 // Do not update local state if data stored or cached outside the user's
444 // cryptohome is to be treated as ephemeral.
445 if (IsUserNonCryptohomeDataEphemeral(user_id
))
448 DictionaryPrefUpdate
oauth_status_update(GetLocalState(),
449 kUserOAuthTokenStatus
);
450 oauth_status_update
->SetWithoutPathExpansion(
452 new base::FundamentalValue(static_cast<int>(oauth_token_status
)));
455 void UserManagerBase::SaveForceOnlineSignin(const std::string
& user_id
,
456 bool force_online_signin
) {
457 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
459 // Do not update local state if data stored or cached outside the user's
460 // cryptohome is to be treated as ephemeral.
461 if (IsUserNonCryptohomeDataEphemeral(user_id
))
464 DictionaryPrefUpdate
force_online_update(GetLocalState(),
465 kUserForceOnlineSignin
);
466 force_online_update
->SetBooleanWithoutPathExpansion(user_id
,
467 force_online_signin
);
470 void UserManagerBase::SaveUserDisplayName(const std::string
& user_id
,
471 const base::string16
& display_name
) {
472 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
474 if (User
* user
= FindUserAndModify(user_id
)) {
475 user
->set_display_name(display_name
);
477 // Do not update local state if data stored or cached outside the user's
478 // cryptohome is to be treated as ephemeral.
479 if (!IsUserNonCryptohomeDataEphemeral(user_id
)) {
480 DictionaryPrefUpdate
display_name_update(GetLocalState(),
482 display_name_update
->SetWithoutPathExpansion(
483 user_id
, new base::StringValue(display_name
));
488 base::string16
UserManagerBase::GetUserDisplayName(
489 const std::string
& user_id
) const {
490 const User
* user
= FindUser(user_id
);
491 return user
? user
->display_name() : base::string16();
494 void UserManagerBase::SaveUserDisplayEmail(const std::string
& user_id
,
495 const std::string
& display_email
) {
496 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
498 User
* user
= FindUserAndModify(user_id
);
500 LOG(ERROR
) << "User not found: " << user_id
;
501 return; // Ignore if there is no such user.
504 user
->set_display_email(display_email
);
506 // Do not update local state if data stored or cached outside the user's
507 // cryptohome is to be treated as ephemeral.
508 if (IsUserNonCryptohomeDataEphemeral(user_id
))
511 DictionaryPrefUpdate
display_email_update(GetLocalState(), kUserDisplayEmail
);
512 display_email_update
->SetWithoutPathExpansion(
513 user_id
, new base::StringValue(display_email
));
516 std::string
UserManagerBase::GetUserDisplayEmail(
517 const std::string
& user_id
) const {
518 const User
* user
= FindUser(user_id
);
519 return user
? user
->display_email() : user_id
;
522 void UserManagerBase::SaveUserType(const std::string
& user_id
,
523 const UserType
& user_type
) {
524 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
526 User
* user
= FindUserAndModify(user_id
);
528 LOG(ERROR
) << "User not found: " << user_id
;
529 return; // Ignore if there is no such user.
532 // Do not update local state if data stored or cached outside the user's
533 // cryptohome is to be treated as ephemeral.
534 if (IsUserNonCryptohomeDataEphemeral(user_id
))
537 DictionaryPrefUpdate
user_type_update(GetLocalState(), kUserType
);
538 user_type_update
->SetWithoutPathExpansion(
539 user_id
, new base::FundamentalValue(static_cast<int>(user_type
)));
540 GetLocalState()->CommitPendingWrite();
543 void UserManagerBase::UpdateUsingSAML(const std::string
& user_id
,
544 const bool using_saml
) {
545 SetKnownUserBooleanPref(user_id
, kUsingSAMLKey
, using_saml
);
548 bool UserManagerBase::FindUsingSAML(const std::string
& user_id
) {
550 if (GetKnownUserBooleanPref(user_id
, kUsingSAMLKey
, &using_saml
))
555 void UserManagerBase::UpdateReauthReason(const std::string
& user_id
,
556 const int reauth_reason
) {
557 SetKnownUserIntegerPref(user_id
, kReauthReasonKey
, reauth_reason
);
560 bool UserManagerBase::FindReauthReason(const std::string
& user_id
,
562 return GetKnownUserIntegerPref(user_id
, kReauthReasonKey
, out_value
);
565 void UserManagerBase::UpdateUserAccountData(
566 const std::string
& user_id
,
567 const UserAccountData
& account_data
) {
568 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
570 SaveUserDisplayName(user_id
, account_data
.display_name());
572 if (User
* user
= FindUserAndModify(user_id
)) {
573 base::string16 given_name
= account_data
.given_name();
574 user
->set_given_name(given_name
);
575 if (!IsUserNonCryptohomeDataEphemeral(user_id
)) {
576 DictionaryPrefUpdate
given_name_update(GetLocalState(), kUserGivenName
);
577 given_name_update
->SetWithoutPathExpansion(
578 user_id
, new base::StringValue(given_name
));
582 UpdateUserAccountLocale(user_id
, account_data
.locale());
586 void UserManagerBase::ParseUserList(const base::ListValue
& users_list
,
587 const std::set
<std::string
>& existing_users
,
588 std::vector
<std::string
>* users_vector
,
589 std::set
<std::string
>* users_set
) {
590 users_vector
->clear();
592 for (size_t i
= 0; i
< users_list
.GetSize(); ++i
) {
594 if (!users_list
.GetString(i
, &email
) || email
.empty()) {
595 LOG(ERROR
) << "Corrupt entry in user list at index " << i
<< ".";
598 if (existing_users
.find(email
) != existing_users
.end() ||
599 !users_set
->insert(email
).second
) {
600 LOG(ERROR
) << "Duplicate user: " << email
;
603 users_vector
->push_back(email
);
607 bool UserManagerBase::IsCurrentUserOwner() const {
608 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
609 base::AutoLock
lk(is_current_user_owner_lock_
);
610 return is_current_user_owner_
;
613 void UserManagerBase::SetCurrentUserIsOwner(bool is_current_user_owner
) {
614 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
616 base::AutoLock
lk(is_current_user_owner_lock_
);
617 is_current_user_owner_
= is_current_user_owner
;
622 bool UserManagerBase::IsCurrentUserNew() const {
623 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
624 return is_current_user_new_
;
627 bool UserManagerBase::IsCurrentUserNonCryptohomeDataEphemeral() const {
628 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
629 return IsUserLoggedIn() &&
630 IsUserNonCryptohomeDataEphemeral(GetLoggedInUser()->email());
633 bool UserManagerBase::CanCurrentUserLock() const {
634 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
635 return IsUserLoggedIn() && active_user_
->can_lock();
638 bool UserManagerBase::IsUserLoggedIn() const {
639 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
643 bool UserManagerBase::IsLoggedInAsUserWithGaiaAccount() const {
644 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
645 return IsUserLoggedIn() && active_user_
->HasGaiaAccount();
648 bool UserManagerBase::IsLoggedInAsChildUser() const {
649 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
650 return IsUserLoggedIn() && active_user_
->GetType() == USER_TYPE_CHILD
;
653 bool UserManagerBase::IsLoggedInAsPublicAccount() const {
654 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
655 return IsUserLoggedIn() &&
656 active_user_
->GetType() == USER_TYPE_PUBLIC_ACCOUNT
;
659 bool UserManagerBase::IsLoggedInAsGuest() const {
660 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
661 return IsUserLoggedIn() && active_user_
->GetType() == USER_TYPE_GUEST
;
664 bool UserManagerBase::IsLoggedInAsSupervisedUser() const {
665 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
666 return IsUserLoggedIn() && active_user_
->GetType() == USER_TYPE_SUPERVISED
;
669 bool UserManagerBase::IsLoggedInAsKioskApp() const {
670 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
671 return IsUserLoggedIn() && active_user_
->GetType() == USER_TYPE_KIOSK_APP
;
674 bool UserManagerBase::IsLoggedInAsStub() const {
675 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
676 return IsUserLoggedIn() &&
677 active_user_
->email() == chromeos::login::kStubUser
;
680 bool UserManagerBase::IsSessionStarted() const {
681 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
682 return session_started_
;
685 bool UserManagerBase::IsUserNonCryptohomeDataEphemeral(
686 const std::string
& user_id
) const {
687 // Data belonging to the guest and stub users is always ephemeral.
688 if (user_id
== chromeos::login::kGuestUserName
||
689 user_id
== chromeos::login::kStubUser
) {
693 // Data belonging to the owner, anyone found on the user list and obsolete
694 // public accounts whose data has not been removed yet is not ephemeral.
695 if (user_id
== GetOwnerEmail() || UserExistsInList(user_id
) ||
696 IsPublicAccountMarkedForRemoval(user_id
)) {
700 // Data belonging to the currently logged-in user is ephemeral when:
701 // a) The user logged into a regular gaia account while the ephemeral users
702 // policy was enabled.
704 // b) The user logged into any other account type.
705 if (IsUserLoggedIn() && (user_id
== GetLoggedInUser()->email()) &&
706 (is_current_user_ephemeral_regular_user_
||
707 !IsLoggedInAsUserWithGaiaAccount())) {
711 // Data belonging to any other user is ephemeral when:
712 // a) Going through the regular login flow and the ephemeral users policy is
715 // b) The browser is restarting after a crash.
716 return AreEphemeralUsersEnabled() ||
717 session_manager::SessionManager::HasBrowserRestarted();
720 void UserManagerBase::AddObserver(UserManager::Observer
* obs
) {
721 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
722 observer_list_
.AddObserver(obs
);
725 void UserManagerBase::RemoveObserver(UserManager::Observer
* obs
) {
726 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
727 observer_list_
.RemoveObserver(obs
);
730 void UserManagerBase::AddSessionStateObserver(
731 UserManager::UserSessionStateObserver
* obs
) {
732 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
733 session_state_observer_list_
.AddObserver(obs
);
736 void UserManagerBase::RemoveSessionStateObserver(
737 UserManager::UserSessionStateObserver
* obs
) {
738 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
739 session_state_observer_list_
.RemoveObserver(obs
);
742 void UserManagerBase::NotifyLocalStateChanged() {
743 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
745 UserManager::Observer
, observer_list_
, LocalStateChanged(this));
748 bool UserManagerBase::CanUserBeRemoved(const User
* user
) const {
749 // Only regular and supervised users are allowed to be manually removed.
750 if (!user
|| !(user
->HasGaiaAccount() || user
->IsSupervised()))
753 // Sanity check: we must not remove single user unless it's an enterprise
754 // device. This check may seem redundant at a first sight because
755 // this single user must be an owner and we perform special check later
756 // in order not to remove an owner. However due to non-instant nature of
757 // ownership assignment this later check may sometimes fail.
758 // See http://crosbug.com/12723
759 if (users_
.size() < 2 && !IsEnterpriseManaged())
762 // Sanity check: do not allow any of the the logged in users to be removed.
763 for (UserList::const_iterator it
= logged_in_users_
.begin();
764 it
!= logged_in_users_
.end();
766 if ((*it
)->email() == user
->email())
773 bool UserManagerBase::GetEphemeralUsersEnabled() const {
774 return ephemeral_users_enabled_
;
777 void UserManagerBase::SetEphemeralUsersEnabled(bool enabled
) {
778 ephemeral_users_enabled_
= enabled
;
781 void UserManagerBase::SetIsCurrentUserNew(bool is_new
) {
782 is_current_user_new_
= is_new
;
785 bool UserManagerBase::HasPendingBootstrap(const std::string
& user_id
) const {
789 void UserManagerBase::SetOwnerEmail(std::string owner_user_id
) {
790 owner_email_
= owner_user_id
;
793 const std::string
& UserManagerBase::GetPendingUserSwitchID() const {
794 return pending_user_switch_
;
797 void UserManagerBase::SetPendingUserSwitchID(std::string user_id
) {
798 pending_user_switch_
= user_id
;
801 void UserManagerBase::EnsureUsersLoaded() {
802 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
803 if (!GetLocalState())
806 if (user_loading_stage_
!= STAGE_NOT_LOADED
)
808 user_loading_stage_
= STAGE_LOADING
;
810 PerformPreUserListLoadingActions();
812 PrefService
* local_state
= GetLocalState();
813 const base::ListValue
* prefs_regular_users
=
814 local_state
->GetList(kRegularUsers
);
816 const base::DictionaryValue
* prefs_display_names
=
817 local_state
->GetDictionary(kUserDisplayName
);
818 const base::DictionaryValue
* prefs_given_names
=
819 local_state
->GetDictionary(kUserGivenName
);
820 const base::DictionaryValue
* prefs_display_emails
=
821 local_state
->GetDictionary(kUserDisplayEmail
);
822 const base::DictionaryValue
* prefs_user_types
=
823 local_state
->GetDictionary(kUserType
);
825 // Load public sessions first.
826 std::set
<std::string
> public_sessions_set
;
827 LoadPublicAccounts(&public_sessions_set
);
829 // Load regular users and supervised users.
830 std::vector
<std::string
> regular_users
;
831 std::set
<std::string
> regular_users_set
;
832 ParseUserList(*prefs_regular_users
,
836 for (std::vector
<std::string
>::const_iterator it
= regular_users
.begin();
837 it
!= regular_users
.end();
840 const std::string domain
= gaia::ExtractDomainName(*it
);
841 if (domain
== chromeos::login::kSupervisedUserDomain
) {
842 user
= User::CreateSupervisedUser(*it
);
844 user
= User::CreateRegularUser(*it
);
846 if (prefs_user_types
->GetIntegerWithoutPathExpansion(*it
, &user_type
) &&
847 user_type
== USER_TYPE_CHILD
) {
848 ChangeUserChildStatus(user
, true /* is child */);
851 user
->set_oauth_token_status(LoadUserOAuthStatus(*it
));
852 user
->set_force_online_signin(LoadForceOnlineSignin(*it
));
853 user
->set_using_saml(FindUsingSAML(*it
));
854 users_
.push_back(user
);
856 base::string16 display_name
;
857 if (prefs_display_names
->GetStringWithoutPathExpansion(*it
,
859 user
->set_display_name(display_name
);
862 base::string16 given_name
;
863 if (prefs_given_names
->GetStringWithoutPathExpansion(*it
, &given_name
)) {
864 user
->set_given_name(given_name
);
867 std::string display_email
;
868 if (prefs_display_emails
->GetStringWithoutPathExpansion(*it
,
870 user
->set_display_email(display_email
);
874 user_loading_stage_
= STAGE_LOADED
;
876 PerformPostUserListLoadingActions();
879 UserList
& UserManagerBase::GetUsersAndModify() {
884 const User
* UserManagerBase::FindUserInList(const std::string
& user_id
) const {
885 const UserList
& users
= GetUsers();
886 for (UserList::const_iterator it
= users
.begin(); it
!= users
.end(); ++it
) {
887 if ((*it
)->email() == user_id
)
893 bool UserManagerBase::UserExistsInList(const std::string
& user_id
) const {
894 const base::ListValue
* user_list
= GetLocalState()->GetList(kRegularUsers
);
895 for (size_t i
= 0; i
< user_list
->GetSize(); ++i
) {
897 if (user_list
->GetString(i
, &email
) && (user_id
== email
))
903 User
* UserManagerBase::FindUserInListAndModify(const std::string
& user_id
) {
904 UserList
& users
= GetUsersAndModify();
905 for (UserList::iterator it
= users
.begin(); it
!= users
.end(); ++it
) {
906 if ((*it
)->email() == user_id
)
912 void UserManagerBase::GuestUserLoggedIn() {
913 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
914 active_user_
= User::CreateGuestUser();
917 void UserManagerBase::AddUserRecord(User
* user
) {
918 // Add the user to the front of the user list.
919 ListPrefUpdate
prefs_users_update(GetLocalState(), kRegularUsers
);
920 prefs_users_update
->Insert(0, new base::StringValue(user
->email()));
921 users_
.insert(users_
.begin(), user
);
924 void UserManagerBase::RegularUserLoggedIn(const std::string
& user_id
) {
925 // Remove the user from the user list.
926 active_user_
= RemoveRegularOrSupervisedUserFromList(user_id
);
928 // If the user was not found on the user list, create a new user.
929 SetIsCurrentUserNew(!active_user_
);
930 if (IsCurrentUserNew()) {
931 active_user_
= User::CreateRegularUser(user_id
);
932 active_user_
->set_oauth_token_status(LoadUserOAuthStatus(user_id
));
933 SaveUserDisplayName(active_user_
->email(),
934 base::UTF8ToUTF16(active_user_
->GetAccountName(true)));
937 AddUserRecord(active_user_
);
939 // Make sure that new data is persisted to Local State.
940 GetLocalState()->CommitPendingWrite();
943 void UserManagerBase::RegularUserLoggedInAsEphemeral(
944 const std::string
& user_id
) {
945 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
946 SetIsCurrentUserNew(true);
947 is_current_user_ephemeral_regular_user_
= true;
948 active_user_
= User::CreateRegularUser(user_id
);
951 void UserManagerBase::NotifyOnLogin() {
952 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
954 NotifyActiveUserHashChanged(active_user_
->username_hash());
955 NotifyActiveUserChanged(active_user_
);
959 User::OAuthTokenStatus
UserManagerBase::LoadUserOAuthStatus(
960 const std::string
& user_id
) const {
961 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
963 const base::DictionaryValue
* prefs_oauth_status
=
964 GetLocalState()->GetDictionary(kUserOAuthTokenStatus
);
965 int oauth_token_status
= User::OAUTH_TOKEN_STATUS_UNKNOWN
;
966 if (prefs_oauth_status
&&
967 prefs_oauth_status
->GetIntegerWithoutPathExpansion(user_id
,
968 &oauth_token_status
)) {
969 User::OAuthTokenStatus status
=
970 static_cast<User::OAuthTokenStatus
>(oauth_token_status
);
971 HandleUserOAuthTokenStatusChange(user_id
, status
);
975 return User::OAUTH_TOKEN_STATUS_UNKNOWN
;
978 bool UserManagerBase::LoadForceOnlineSignin(const std::string
& user_id
) const {
979 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
981 const base::DictionaryValue
* prefs_force_online
=
982 GetLocalState()->GetDictionary(kUserForceOnlineSignin
);
983 bool force_online_signin
= false;
984 if (prefs_force_online
) {
985 prefs_force_online
->GetBooleanWithoutPathExpansion(user_id
,
986 &force_online_signin
);
988 return force_online_signin
;
991 void UserManagerBase::RemoveNonCryptohomeData(const std::string
& user_id
) {
992 PrefService
* prefs
= GetLocalState();
993 DictionaryPrefUpdate
prefs_display_name_update(prefs
, kUserDisplayName
);
994 prefs_display_name_update
->RemoveWithoutPathExpansion(user_id
, NULL
);
996 DictionaryPrefUpdate
prefs_given_name_update(prefs
, kUserGivenName
);
997 prefs_given_name_update
->RemoveWithoutPathExpansion(user_id
, NULL
);
999 DictionaryPrefUpdate
prefs_display_email_update(prefs
, kUserDisplayEmail
);
1000 prefs_display_email_update
->RemoveWithoutPathExpansion(user_id
, NULL
);
1002 DictionaryPrefUpdate
prefs_oauth_update(prefs
, kUserOAuthTokenStatus
);
1003 prefs_oauth_update
->RemoveWithoutPathExpansion(user_id
, NULL
);
1005 DictionaryPrefUpdate
prefs_force_online_update(prefs
, kUserForceOnlineSignin
);
1006 prefs_force_online_update
->RemoveWithoutPathExpansion(user_id
, NULL
);
1008 RemoveKnownUserPrefs(user_id
);
1010 std::string last_active_user
= GetLocalState()->GetString(kLastActiveUser
);
1011 if (user_id
== last_active_user
)
1012 GetLocalState()->SetString(kLastActiveUser
, std::string());
1015 bool UserManagerBase::FindKnownUserPrefs(
1016 const UserID
& user_id
,
1017 const base::DictionaryValue
** out_value
) {
1018 PrefService
* local_state
= GetLocalState();
1020 // Local State may not be initialized in tests.
1023 if (IsUserNonCryptohomeDataEphemeral(user_id
))
1026 const base::ListValue
* known_users
= local_state
->GetList(kKnownUsers
);
1027 for (size_t i
= 0; i
< known_users
->GetSize(); ++i
) {
1028 const base::DictionaryValue
* element
= nullptr;
1029 if (known_users
->GetDictionary(i
, &element
)) {
1030 if (UserMatches(user_id
, *element
)) {
1031 known_users
->GetDictionary(i
, out_value
);
1039 void UserManagerBase::UpdateKnownUserPrefs(const UserID
& user_id
,
1040 const base::DictionaryValue
& values
,
1042 PrefService
* local_state
= GetLocalState();
1044 // Local State may not be initialized in tests.
1048 if (IsUserNonCryptohomeDataEphemeral(user_id
))
1051 ListPrefUpdate
update(local_state
, kKnownUsers
);
1052 for (size_t i
= 0; i
< update
->GetSize(); ++i
) {
1053 base::DictionaryValue
* element
= nullptr;
1054 if (update
->GetDictionary(i
, &element
)) {
1055 if (UserMatches(user_id
, *element
)) {
1058 element
->MergeDictionary(&values
);
1059 UpdateIdentity(user_id
, *element
);
1064 scoped_ptr
<base::DictionaryValue
> new_value(new base::DictionaryValue());
1065 new_value
->MergeDictionary(&values
);
1066 UpdateIdentity(user_id
, *new_value
);
1067 update
->Append(new_value
.release());
1070 bool UserManagerBase::GetKnownUserStringPref(const UserID
& user_id
,
1071 const std::string
& path
,
1072 std::string
* out_value
) {
1073 const base::DictionaryValue
* user_pref_dict
= nullptr;
1074 if (!FindKnownUserPrefs(user_id
, &user_pref_dict
))
1077 return user_pref_dict
->GetString(path
, out_value
);
1080 void UserManagerBase::SetKnownUserStringPref(const UserID
& user_id
,
1081 const std::string
& path
,
1082 const std::string
& in_value
) {
1083 PrefService
* local_state
= GetLocalState();
1085 // Local State may not be initialized in tests.
1089 ListPrefUpdate
update(local_state
, kKnownUsers
);
1090 base::DictionaryValue dict
;
1091 dict
.SetString(path
, in_value
);
1092 UpdateKnownUserPrefs(user_id
, dict
, false);
1095 bool UserManagerBase::GetKnownUserBooleanPref(const UserID
& user_id
,
1096 const std::string
& path
,
1098 const base::DictionaryValue
* user_pref_dict
= nullptr;
1099 if (!FindKnownUserPrefs(user_id
, &user_pref_dict
))
1102 return user_pref_dict
->GetBoolean(path
, out_value
);
1105 void UserManagerBase::SetKnownUserBooleanPref(const UserID
& user_id
,
1106 const std::string
& path
,
1107 const bool in_value
) {
1108 PrefService
* local_state
= GetLocalState();
1110 // Local State may not be initialized in tests.
1114 ListPrefUpdate
update(local_state
, kKnownUsers
);
1115 base::DictionaryValue dict
;
1116 dict
.SetBoolean(path
, in_value
);
1117 UpdateKnownUserPrefs(user_id
, dict
, false);
1120 bool UserManagerBase::GetKnownUserIntegerPref(const UserID
& user_id
,
1121 const std::string
& path
,
1123 const base::DictionaryValue
* user_pref_dict
= nullptr;
1124 if (!FindKnownUserPrefs(user_id
, &user_pref_dict
))
1126 return user_pref_dict
->GetInteger(path
, out_value
);
1129 void UserManagerBase::SetKnownUserIntegerPref(const UserID
& user_id
,
1130 const std::string
& path
,
1131 const int in_value
) {
1132 PrefService
* local_state
= GetLocalState();
1134 // Local State may not be initialized in tests.
1138 ListPrefUpdate
update(local_state
, kKnownUsers
);
1139 base::DictionaryValue dict
;
1140 dict
.SetInteger(path
, in_value
);
1141 UpdateKnownUserPrefs(user_id
, dict
, false);
1144 void UserManagerBase::UpdateGaiaID(const UserID
& user_id
,
1145 const std::string
& gaia_id
) {
1146 SetKnownUserStringPref(user_id
, kGAIAIdKey
, gaia_id
);
1149 bool UserManagerBase::FindGaiaID(const UserID
& user_id
,
1150 std::string
* out_value
) {
1151 return GetKnownUserStringPref(user_id
, kGAIAIdKey
, out_value
);
1154 void UserManagerBase::SetKnownUserDeviceId(const UserID
& user_id
,
1155 const std::string
& device_id
) {
1156 const std::string known_device_id
= GetKnownUserDeviceId(user_id
);
1157 if (!known_device_id
.empty() && device_id
!= known_device_id
) {
1158 NOTREACHED() << "Trying to change device ID for known user.";
1160 SetKnownUserStringPref(user_id
, kDeviceId
, device_id
);
1163 std::string
UserManagerBase::GetKnownUserDeviceId(const UserID
& user_id
) {
1164 std::string device_id
;
1165 if (GetKnownUserStringPref(user_id
, kDeviceId
, &device_id
)) {
1168 return std::string();
1171 User
* UserManagerBase::RemoveRegularOrSupervisedUserFromList(
1172 const std::string
& user_id
) {
1173 ListPrefUpdate
prefs_users_update(GetLocalState(), kRegularUsers
);
1174 prefs_users_update
->Clear();
1176 for (UserList::iterator it
= users_
.begin(); it
!= users_
.end();) {
1177 const std::string user_email
= (*it
)->email();
1178 if (user_email
== user_id
) {
1180 it
= users_
.erase(it
);
1182 if ((*it
)->HasGaiaAccount() || (*it
)->IsSupervised())
1183 prefs_users_update
->Append(new base::StringValue(user_email
));
1190 void UserManagerBase::RemoveKnownUserPrefs(const UserID
& user_id
) {
1191 ListPrefUpdate
update(GetLocalState(), kKnownUsers
);
1192 for (size_t i
= 0; i
< update
->GetSize(); ++i
) {
1193 base::DictionaryValue
* element
= nullptr;
1194 if (update
->GetDictionary(i
, &element
)) {
1195 if (UserMatches(user_id
, *element
)) {
1196 update
->Remove(i
, nullptr);
1203 void UserManagerBase::NotifyActiveUserChanged(const User
* active_user
) {
1204 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
1205 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver
,
1206 session_state_observer_list_
,
1207 ActiveUserChanged(active_user
));
1210 void UserManagerBase::NotifyUserAddedToSession(const User
* added_user
,
1211 bool user_switch_pending
) {
1212 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
1213 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver
,
1214 session_state_observer_list_
,
1215 UserAddedToSession(added_user
));
1218 void UserManagerBase::NotifyActiveUserHashChanged(const std::string
& hash
) {
1219 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
1220 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver
,
1221 session_state_observer_list_
,
1222 ActiveUserHashChanged(hash
));
1225 void UserManagerBase::ChangeUserChildStatus(User
* user
, bool is_child
) {
1226 DCHECK(task_runner_
->RunsTasksOnCurrentThread());
1227 if (user
->IsSupervised() == is_child
)
1229 user
->SetIsChild(is_child
);
1230 SaveUserType(user
->email(), is_child
? user_manager::USER_TYPE_CHILD
1231 : user_manager::USER_TYPE_REGULAR
);
1232 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver
,
1233 session_state_observer_list_
,
1234 UserChangedChildStatus(user
));
1237 void UserManagerBase::UpdateLoginState() {
1238 if (!chromeos::LoginState::IsInitialized())
1239 return; // LoginState may not be initialized in tests.
1241 chromeos::LoginState::LoggedInState logged_in_state
;
1242 logged_in_state
= active_user_
? chromeos::LoginState::LOGGED_IN_ACTIVE
1243 : chromeos::LoginState::LOGGED_IN_NONE
;
1245 chromeos::LoginState::LoggedInUserType login_user_type
;
1246 if (logged_in_state
== chromeos::LoginState::LOGGED_IN_NONE
)
1247 login_user_type
= chromeos::LoginState::LOGGED_IN_USER_NONE
;
1248 else if (is_current_user_owner_
)
1249 login_user_type
= chromeos::LoginState::LOGGED_IN_USER_OWNER
;
1250 else if (active_user_
->GetType() == USER_TYPE_GUEST
)
1251 login_user_type
= chromeos::LoginState::LOGGED_IN_USER_GUEST
;
1252 else if (active_user_
->GetType() == USER_TYPE_PUBLIC_ACCOUNT
)
1253 login_user_type
= chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT
;
1254 else if (active_user_
->GetType() == USER_TYPE_SUPERVISED
)
1255 login_user_type
= chromeos::LoginState::LOGGED_IN_USER_SUPERVISED
;
1256 else if (active_user_
->GetType() == USER_TYPE_KIOSK_APP
)
1257 login_user_type
= chromeos::LoginState::LOGGED_IN_USER_KIOSK_APP
;
1259 login_user_type
= chromeos::LoginState::LOGGED_IN_USER_REGULAR
;
1261 if (primary_user_
) {
1262 chromeos::LoginState::Get()->SetLoggedInStateAndPrimaryUser(
1263 logged_in_state
, login_user_type
, primary_user_
->username_hash());
1265 chromeos::LoginState::Get()->SetLoggedInState(logged_in_state
,
1270 void UserManagerBase::SetLRUUser(User
* user
) {
1271 GetLocalState()->SetString(kLastActiveUser
, user
->email());
1272 GetLocalState()->CommitPendingWrite();
1274 UserList::iterator it
=
1275 std::find(lru_logged_in_users_
.begin(), lru_logged_in_users_
.end(), user
);
1276 if (it
!= lru_logged_in_users_
.end())
1277 lru_logged_in_users_
.erase(it
);
1278 lru_logged_in_users_
.insert(lru_logged_in_users_
.begin(), user
);
1281 void UserManagerBase::SendGaiaUserLoginMetrics(const std::string
& user_id
) {
1282 // If this isn't the first time Chrome was run after the system booted,
1283 // assume that Chrome was restarted because a previous session ended.
1284 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
1285 chromeos::switches::kFirstExecAfterBoot
)) {
1286 const std::string last_email
=
1287 GetLocalState()->GetString(kLastLoggedInGaiaUser
);
1288 const base::TimeDelta time_to_login
=
1289 base::TimeTicks::Now() - manager_creation_time_
;
1290 if (!last_email
.empty() && user_id
!= last_email
&&
1291 time_to_login
.InSeconds() <= kLogoutToLoginDelayMaxSec
) {
1292 UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay",
1293 time_to_login
.InSeconds(),
1295 kLogoutToLoginDelayMaxSec
,
1301 void UserManagerBase::UpdateUserAccountLocale(const std::string
& user_id
,
1302 const std::string
& locale
) {
1303 scoped_ptr
<std::string
> resolved_locale(new std::string());
1304 if (!locale
.empty() && locale
!= GetApplicationLocale()) {
1305 // base::Pased will NULL out |resolved_locale|, so cache the underlying ptr.
1306 std::string
* raw_resolved_locale
= resolved_locale
.get();
1307 blocking_task_runner_
->PostTaskAndReply(
1309 base::Bind(ResolveLocale
,
1311 base::Unretained(raw_resolved_locale
)),
1312 base::Bind(&UserManagerBase::DoUpdateAccountLocale
,
1313 weak_factory_
.GetWeakPtr(),
1315 base::Passed(&resolved_locale
)));
1317 resolved_locale
.reset(new std::string(locale
));
1318 DoUpdateAccountLocale(user_id
, resolved_locale
.Pass());
1322 void UserManagerBase::DoUpdateAccountLocale(
1323 const std::string
& user_id
,
1324 scoped_ptr
<std::string
> resolved_locale
) {
1325 User
* user
= FindUserAndModify(user_id
);
1326 if (user
&& resolved_locale
)
1327 user
->SetAccountLocale(*resolved_locale
);
1330 void UserManagerBase::DeleteUser(User
* user
) {
1331 const bool is_active_user
= (user
== active_user_
);
1334 active_user_
= NULL
;
1337 } // namespace user_manager