| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 const char kDeviceId[] = "device_id"; | 89 const char kDeviceId[] = "device_id"; |
| 90 | 90 |
| 91 // Key of the reason for re-auth. | 91 // Key of the reason for re-auth. |
| 92 const char kReauthReasonKey[] = "reauth_reason"; | 92 const char kReauthReasonKey[] = "reauth_reason"; |
| 93 | 93 |
| 94 // Upper bound for a histogram metric reporting the amount of time between | 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. | 95 // one regular user logging out and a different regular user logging in. |
| 96 const int kLogoutToLoginDelayMaxSec = 1800; | 96 const int kLogoutToLoginDelayMaxSec = 1800; |
| 97 | 97 |
| 98 // Callback that is called after user removal is complete. | 98 // Callback that is called after user removal is complete. |
| 99 void OnRemoveUserComplete(const std::string& user_email, | 99 void OnRemoveUserComplete(const UserID& user_id, |
| 100 bool success, | 100 bool success, |
| 101 cryptohome::MountError return_code) { | 101 cryptohome::MountError return_code) { |
| 102 // Log the error, but there's not much we can do. | 102 // Log the error, but there's not much we can do. |
| 103 if (!success) { | 103 if (!success) { |
| 104 LOG(ERROR) << "Removal of cryptohome for " << user_email | 104 LOG(ERROR) << "Removal of cryptohome for " << user_id.GetUserEmail() |
| 105 << " failed, return code: " << return_code; | 105 << " failed, return code: " << return_code; |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Runs on SequencedWorkerPool thread. Passes resolved locale to UI thread. | 109 // Runs on SequencedWorkerPool thread. Passes resolved locale to UI thread. |
| 110 void ResolveLocale(const std::string& raw_locale, | 110 void ResolveLocale(const std::string& raw_locale, |
| 111 std::string* resolved_locale) { | 111 std::string* resolved_locale) { |
| 112 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale)); | 112 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale)); |
| 113 } | 113 } |
| 114 | 114 |
| 115 // Checks if values in |dict| correspond with |user_id| identity. | 115 // Checks if values in |dict| correspond with |user_id| identity. |
| 116 bool UserMatches(const UserID& user_id, const base::DictionaryValue& dict) { | 116 bool UserMatches(const UserID& user_id, const base::DictionaryValue& dict) { |
| 117 std::string value; | 117 std::string value; |
| 118 | 118 |
| 119 bool has_email = dict.GetString(kCanonicalEmail, &value); | 119 bool has_email = dict.GetString(kCanonicalEmail, &value); |
| 120 if (has_email && user_id == value) | 120 if (has_email && user_id == UserID::FromUserEmail(value)) |
| 121 return true; | 121 return true; |
| 122 | 122 |
| 123 // TODO(antrim): update code once user id is really a struct. | 123 // TODO(antrim): update code once user id is really a struct. |
| 124 bool has_gaia_id = dict.GetString(kGAIAIdKey, &value); | 124 bool has_gaia_id = dict.GetString(kGAIAIdKey, &value); |
| 125 if (has_gaia_id && user_id == value) | 125 if (has_gaia_id && user_id.GetGaiaId() == value) |
| 126 return true; | 126 return true; |
| 127 | 127 |
| 128 return false; | 128 return false; |
| 129 } | 129 } |
| 130 | 130 |
| 131 // Fills relevant |dict| values based on |user_id|. | 131 // Fills relevant |dict| values based on |user_id|. |
| 132 void UpdateIdentity(const UserID& user_id, base::DictionaryValue& dict) { | 132 void UpdateIdentity(const UserID& user_id, base::DictionaryValue& dict) { |
| 133 dict.SetString(kCanonicalEmail, user_id); | 133 dict.SetString(kCanonicalEmail, user_id.GetUserEmail()); |
| 134 } | 134 } |
| 135 | 135 |
| 136 } // namespace | 136 } // namespace |
| 137 | 137 |
| 138 // static | 138 // static |
| 139 void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) { | 139 void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) { |
| 140 registry->RegisterListPref(kRegularUsers); | 140 registry->RegisterListPref(kRegularUsers); |
| 141 registry->RegisterListPref(kKnownUsers); | 141 registry->RegisterListPref(kKnownUsers); |
| 142 registry->RegisterStringPref(kLastLoggedInGaiaUser, std::string()); | 142 registry->RegisterStringPref(kLastLoggedInGaiaUser, std::string()); |
| 143 registry->RegisterDictionaryPref(kUserDisplayName); | 143 registry->RegisterDictionaryPref(kUserDisplayName); |
| 144 registry->RegisterDictionaryPref(kUserGivenName); | 144 registry->RegisterDictionaryPref(kUserGivenName); |
| 145 registry->RegisterDictionaryPref(kUserDisplayEmail); | 145 registry->RegisterDictionaryPref(kUserDisplayEmail); |
| 146 registry->RegisterDictionaryPref(kUserOAuthTokenStatus); | 146 registry->RegisterDictionaryPref(kUserOAuthTokenStatus); |
| 147 registry->RegisterDictionaryPref(kUserForceOnlineSignin); | 147 registry->RegisterDictionaryPref(kUserForceOnlineSignin); |
| 148 registry->RegisterDictionaryPref(kUserType); | 148 registry->RegisterDictionaryPref(kUserType); |
| 149 registry->RegisterStringPref(kLastActiveUser, std::string()); | 149 registry->RegisterStringPref(kLastActiveUser, std::string()); |
| 150 } | 150 } |
| 151 | 151 |
| 152 UserManagerBase::UserManagerBase( | 152 UserManagerBase::UserManagerBase( |
| 153 scoped_refptr<base::TaskRunner> task_runner, | 153 scoped_refptr<base::TaskRunner> task_runner, |
| 154 scoped_refptr<base::TaskRunner> blocking_task_runner) | 154 scoped_refptr<base::TaskRunner> blocking_task_runner) |
| 155 : active_user_(NULL), | 155 : active_user_(NULL), |
| 156 primary_user_(NULL), | 156 primary_user_(NULL), |
| 157 user_loading_stage_(STAGE_NOT_LOADED), | 157 user_loading_stage_(STAGE_NOT_LOADED), |
| 158 session_started_(false), | 158 session_started_(false), |
| 159 is_current_user_owner_(false), | 159 is_current_user_owner_(false), |
| 160 is_current_user_new_(false), | 160 is_current_user_new_(false), |
| 161 is_current_user_ephemeral_regular_user_(false), | 161 is_current_user_ephemeral_regular_user_(false), |
| 162 ephemeral_users_enabled_(false), | 162 ephemeral_users_enabled_(false), |
| 163 owner_id_(std::string(), std::string()), |
| 163 manager_creation_time_(base::TimeTicks::Now()), | 164 manager_creation_time_(base::TimeTicks::Now()), |
| 165 pending_user_switch_(std::string(), std::string()), |
| 166 last_session_active_user_(std::string(), std::string()), |
| 164 last_session_active_user_initialized_(false), | 167 last_session_active_user_initialized_(false), |
| 165 task_runner_(task_runner), | 168 task_runner_(task_runner), |
| 166 blocking_task_runner_(blocking_task_runner), | 169 blocking_task_runner_(blocking_task_runner), |
| 167 weak_factory_(this) { | 170 weak_factory_(this) { |
| 168 UpdateLoginState(); | 171 UpdateLoginState(); |
| 169 } | 172 } |
| 170 | 173 |
| 171 UserManagerBase::~UserManagerBase() { | 174 UserManagerBase::~UserManagerBase() { |
| 172 // Can't use STLDeleteElements because of the private destructor of User. | 175 // Can't use STLDeleteElements because of the private destructor of User. |
| 173 for (UserList::iterator it = users_.begin(); it != users_.end(); | 176 for (UserList::iterator it = users_.begin(); it != users_.end(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 191 } | 194 } |
| 192 | 195 |
| 193 const UserList& UserManagerBase::GetLoggedInUsers() const { | 196 const UserList& UserManagerBase::GetLoggedInUsers() const { |
| 194 return logged_in_users_; | 197 return logged_in_users_; |
| 195 } | 198 } |
| 196 | 199 |
| 197 const UserList& UserManagerBase::GetLRULoggedInUsers() const { | 200 const UserList& UserManagerBase::GetLRULoggedInUsers() const { |
| 198 return lru_logged_in_users_; | 201 return lru_logged_in_users_; |
| 199 } | 202 } |
| 200 | 203 |
| 201 const std::string& UserManagerBase::GetOwnerEmail() const { | 204 const UserID& UserManagerBase::GetOwnerID() const { |
| 202 return owner_email_; | 205 return owner_id_; |
| 203 } | 206 } |
| 204 | 207 |
| 205 void UserManagerBase::UserLoggedIn(const std::string& user_id, | 208 void UserManagerBase::UserLoggedIn(const UserID& user_id, |
| 206 const std::string& username_hash, | 209 const std::string& username_hash, |
| 207 bool browser_restart) { | 210 bool browser_restart) { |
| 208 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 211 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 209 | 212 |
| 210 if (!last_session_active_user_initialized_) { | 213 if (!last_session_active_user_initialized_) { |
| 211 last_session_active_user_ = GetLocalState()->GetString(kLastActiveUser); | 214 last_session_active_user_ = UserID::FromUserEmail(GetLocalState()->GetString
(kLastActiveUser)); |
| 212 last_session_active_user_initialized_ = true; | 215 last_session_active_user_initialized_ = true; |
| 213 } | 216 } |
| 214 | 217 |
| 215 User* user = FindUserInListAndModify(user_id); | 218 User* user = FindUserInListAndModify(user_id); |
| 216 if (active_user_ && user) { | 219 if (active_user_ && user) { |
| 217 user->set_is_logged_in(true); | 220 user->set_is_logged_in(true); |
| 218 user->set_username_hash(username_hash); | 221 user->set_username_hash(username_hash); |
| 219 logged_in_users_.push_back(user); | 222 logged_in_users_.push_back(user); |
| 220 lru_logged_in_users_.push_back(user); | 223 lru_logged_in_users_.push_back(user); |
| 221 | 224 |
| 222 // Reset the new user flag if the user already exists. | 225 // Reset the new user flag if the user already exists. |
| 223 SetIsCurrentUserNew(false); | 226 SetIsCurrentUserNew(false); |
| 224 NotifyUserAddedToSession(user, true /* user switch pending */); | 227 NotifyUserAddedToSession(user, true /* user switch pending */); |
| 225 | 228 |
| 226 return; | 229 return; |
| 227 } | 230 } |
| 228 | 231 |
| 229 if (user_id == chromeos::login::kGuestUserName) { | 232 if (user_id == chromeos::login::GetGuestUserID()) { |
| 230 GuestUserLoggedIn(); | 233 GuestUserLoggedIn(); |
| 231 } else if (IsKioskApp(user_id)) { | 234 } else if (IsKioskApp(user_id)) { |
| 232 KioskAppLoggedIn(user_id); | 235 KioskAppLoggedIn(user_id.GetUserEmail()); |
| 233 } else if (IsDemoApp(user_id)) { | 236 } else if (IsDemoApp(user_id)) { |
| 234 DemoAccountLoggedIn(); | 237 DemoAccountLoggedIn(); |
| 235 } else { | 238 } else { |
| 236 EnsureUsersLoaded(); | 239 EnsureUsersLoaded(); |
| 237 | 240 |
| 238 if (user && user->GetType() == USER_TYPE_PUBLIC_ACCOUNT) { | 241 if (user && user->GetType() == USER_TYPE_PUBLIC_ACCOUNT) { |
| 239 PublicAccountUserLoggedIn(user); | 242 PublicAccountUserLoggedIn(user); |
| 240 } else if ((user && user->GetType() == USER_TYPE_SUPERVISED) || | 243 } else if ((user && user->GetType() == USER_TYPE_SUPERVISED) || |
| 241 (!user && | 244 (!user && |
| 242 gaia::ExtractDomainName(user_id) == | 245 gaia::ExtractDomainName(user_id.GetUserEmail()) == |
| 243 chromeos::login::kSupervisedUserDomain)) { | 246 chromeos::login::kSupervisedUserDomain)) { |
| 244 SupervisedUserLoggedIn(user_id); | 247 SupervisedUserLoggedIn(user_id); |
| 245 } else if (browser_restart && IsPublicAccountMarkedForRemoval(user_id)) { | 248 } else if (browser_restart && IsPublicAccountMarkedForRemoval(user_id)) { |
| 246 PublicAccountUserLoggedIn(User::CreatePublicAccountUser(user_id)); | 249 PublicAccountUserLoggedIn(User::CreatePublicAccountUser(user_id)); |
| 247 } else if (user_id != GetOwnerEmail() && !user && | 250 } else if (user_id != owner_id_ && !user && |
| 248 (AreEphemeralUsersEnabled() || browser_restart)) { | 251 (AreEphemeralUsersEnabled() || browser_restart)) { |
| 249 RegularUserLoggedInAsEphemeral(user_id); | 252 RegularUserLoggedInAsEphemeral(user_id); |
| 250 } else { | 253 } else { |
| 251 RegularUserLoggedIn(user_id); | 254 RegularUserLoggedIn(user_id); |
| 252 } | 255 } |
| 253 } | 256 } |
| 254 | 257 |
| 255 DCHECK(active_user_); | 258 DCHECK(active_user_); |
| 256 active_user_->set_is_logged_in(true); | 259 active_user_->set_is_logged_in(true); |
| 257 active_user_->set_is_active(true); | 260 active_user_->set_is_active(true); |
| 258 active_user_->set_username_hash(username_hash); | 261 active_user_->set_username_hash(username_hash); |
| 259 | 262 |
| 260 // Place user who just signed in to the top of the logged in users. | 263 // 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_); | 264 logged_in_users_.insert(logged_in_users_.begin(), active_user_); |
| 262 SetLRUUser(active_user_); | 265 SetLRUUser(active_user_); |
| 263 | 266 |
| 264 if (!primary_user_) { | 267 if (!primary_user_) { |
| 265 primary_user_ = active_user_; | 268 primary_user_ = active_user_; |
| 266 if (primary_user_->HasGaiaAccount()) | 269 if (primary_user_->HasGaiaAccount()) |
| 267 SendGaiaUserLoginMetrics(user_id); | 270 SendGaiaUserLoginMetrics(user_id); |
| 268 } | 271 } |
| 269 | 272 |
| 270 UMA_HISTOGRAM_ENUMERATION( | 273 UMA_HISTOGRAM_ENUMERATION( |
| 271 "UserManager.LoginUserType", active_user_->GetType(), NUM_USER_TYPES); | 274 "UserManager.LoginUserType", active_user_->GetType(), NUM_USER_TYPES); |
| 272 | 275 |
| 273 GetLocalState()->SetString( | 276 GetLocalState()->SetString( |
| 274 kLastLoggedInGaiaUser, active_user_->HasGaiaAccount() ? user_id : ""); | 277 kLastLoggedInGaiaUser, active_user_->HasGaiaAccount() ? user_id.GetUserEma
il() : ""); |
| 275 | 278 |
| 276 NotifyOnLogin(); | 279 NotifyOnLogin(); |
| 277 PerformPostUserLoggedInActions(browser_restart); | 280 PerformPostUserLoggedInActions(browser_restart); |
| 278 } | 281 } |
| 279 | 282 |
| 280 void UserManagerBase::SwitchActiveUser(const std::string& user_id) { | 283 void UserManagerBase::SwitchActiveUser(const UserID& user_id) { |
| 281 User* user = FindUserAndModify(user_id); | 284 User* user = FindUserAndModify(user_id); |
| 282 if (!user) { | 285 if (!user) { |
| 283 NOTREACHED() << "Switching to a non-existing user"; | 286 NOTREACHED() << "Switching to a non-existing user"; |
| 284 return; | 287 return; |
| 285 } | 288 } |
| 286 if (user == active_user_) { | 289 if (user == active_user_) { |
| 287 NOTREACHED() << "Switching to a user who is already active"; | 290 NOTREACHED() << "Switching to a user who is already active"; |
| 288 return; | 291 return; |
| 289 } | 292 } |
| 290 if (!user->is_logged_in()) { | 293 if (!user->is_logged_in()) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 310 SetLRUUser(active_user_); | 313 SetLRUUser(active_user_); |
| 311 | 314 |
| 312 NotifyActiveUserHashChanged(active_user_->username_hash()); | 315 NotifyActiveUserHashChanged(active_user_->username_hash()); |
| 313 NotifyActiveUserChanged(active_user_); | 316 NotifyActiveUserChanged(active_user_); |
| 314 } | 317 } |
| 315 | 318 |
| 316 void UserManagerBase::SwitchToLastActiveUser() { | 319 void UserManagerBase::SwitchToLastActiveUser() { |
| 317 if (last_session_active_user_.empty()) | 320 if (last_session_active_user_.empty()) |
| 318 return; | 321 return; |
| 319 | 322 |
| 320 if (GetActiveUser()->email() != last_session_active_user_) | 323 if (GetActiveUser()->GetUserID() != last_session_active_user_) |
| 321 SwitchActiveUser(last_session_active_user_); | 324 SwitchActiveUser(last_session_active_user_); |
| 322 | 325 |
| 323 // Make sure that this function gets run only once. | 326 // Make sure that this function gets run only once. |
| 324 last_session_active_user_.clear(); | 327 last_session_active_user_.clear(); |
| 325 } | 328 } |
| 326 | 329 |
| 327 void UserManagerBase::SessionStarted() { | 330 void UserManagerBase::SessionStarted() { |
| 328 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 331 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 329 session_started_ = true; | 332 session_started_ = true; |
| 330 | 333 |
| 331 UpdateLoginState(); | 334 UpdateLoginState(); |
| 332 session_manager::SessionManager::Get()->SetSessionState( | 335 session_manager::SessionManager::Get()->SetSessionState( |
| 333 session_manager::SESSION_STATE_ACTIVE); | 336 session_manager::SESSION_STATE_ACTIVE); |
| 334 | 337 |
| 335 if (IsCurrentUserNew()) { | 338 if (IsCurrentUserNew()) { |
| 336 // Make sure that the new user's data is persisted to Local State. | 339 // Make sure that the new user's data is persisted to Local State. |
| 337 GetLocalState()->CommitPendingWrite(); | 340 GetLocalState()->CommitPendingWrite(); |
| 338 } | 341 } |
| 339 } | 342 } |
| 340 | 343 |
| 341 void UserManagerBase::RemoveUser(const std::string& user_id, | 344 void UserManagerBase::RemoveUser(const UserID& user_id, |
| 342 RemoveUserDelegate* delegate) { | 345 RemoveUserDelegate* delegate) { |
| 343 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 346 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 344 | 347 |
| 345 if (!CanUserBeRemoved(FindUser(user_id))) | 348 if (!CanUserBeRemoved(FindUser(user_id))) |
| 346 return; | 349 return; |
| 347 | 350 |
| 348 RemoveUserInternal(user_id, delegate); | 351 RemoveUserInternal(user_id, delegate); |
| 349 } | 352 } |
| 350 | 353 |
| 351 void UserManagerBase::RemoveUserInternal(const std::string& user_email, | 354 void UserManagerBase::RemoveUserInternal(const UserID& user_id, |
| 352 RemoveUserDelegate* delegate) { | 355 RemoveUserDelegate* delegate) { |
| 353 RemoveNonOwnerUserInternal(user_email, delegate); | 356 RemoveNonOwnerUserInternal(user_id, delegate); |
| 354 } | 357 } |
| 355 | 358 |
| 356 void UserManagerBase::RemoveNonOwnerUserInternal(const std::string& user_email, | 359 void UserManagerBase::RemoveNonOwnerUserInternal(const UserID& user_id, |
| 357 RemoveUserDelegate* delegate) { | 360 RemoveUserDelegate* delegate) { |
| 358 if (delegate) | 361 if (delegate) |
| 359 delegate->OnBeforeUserRemoved(user_email); | 362 delegate->OnBeforeUserRemoved(user_id); |
| 360 RemoveUserFromList(user_email); | 363 RemoveUserFromList(user_id); |
| 361 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( | 364 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( |
| 362 user_email, base::Bind(&OnRemoveUserComplete, user_email)); | 365 user_id, base::Bind(&OnRemoveUserComplete, user_id)); |
| 363 | 366 |
| 364 if (delegate) | 367 if (delegate) |
| 365 delegate->OnUserRemoved(user_email); | 368 delegate->OnUserRemoved(user_id); |
| 366 } | 369 } |
| 367 | 370 |
| 368 void UserManagerBase::RemoveUserFromList(const std::string& user_id) { | 371 void UserManagerBase::RemoveUserFromList(const UserID& user_id) { |
| 369 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 372 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 370 RemoveNonCryptohomeData(user_id); | 373 RemoveNonCryptohomeData(user_id); |
| 371 if (user_loading_stage_ == STAGE_LOADED) { | 374 if (user_loading_stage_ == STAGE_LOADED) { |
| 372 DeleteUser(RemoveRegularOrSupervisedUserFromList(user_id)); | 375 DeleteUser(RemoveRegularOrSupervisedUserFromList(user_id)); |
| 373 } else if (user_loading_stage_ == STAGE_LOADING) { | 376 } else if (user_loading_stage_ == STAGE_LOADING) { |
| 374 DCHECK(gaia::ExtractDomainName(user_id) == | 377 DCHECK(gaia::ExtractDomainName(user_id.GetUserEmail()) == |
| 375 chromeos::login::kSupervisedUserDomain || | 378 chromeos::login::kSupervisedUserDomain || |
| 376 HasPendingBootstrap(user_id)); | 379 HasPendingBootstrap(user_id)); |
| 377 // Special case, removing partially-constructed supervised user or | 380 // Special case, removing partially-constructed supervised user or |
| 378 // boostrapping user during user list loading. | 381 // boostrapping user during user list loading. |
| 379 ListPrefUpdate users_update(GetLocalState(), kRegularUsers); | 382 ListPrefUpdate users_update(GetLocalState(), kRegularUsers); |
| 380 users_update->Remove(base::StringValue(user_id), NULL); | 383 users_update->Remove(base::StringValue(user_id.GetUserEmail()), NULL); |
| 381 } else { | 384 } else { |
| 382 NOTREACHED() << "Users are not loaded yet."; | 385 NOTREACHED() << "Users are not loaded yet."; |
| 383 return; | 386 return; |
| 384 } | 387 } |
| 385 | 388 |
| 386 // Make sure that new data is persisted to Local State. | 389 // Make sure that new data is persisted to Local State. |
| 387 GetLocalState()->CommitPendingWrite(); | 390 GetLocalState()->CommitPendingWrite(); |
| 388 } | 391 } |
| 389 | 392 |
| 390 bool UserManagerBase::IsKnownUser(const std::string& user_id) const { | 393 bool UserManagerBase::IsKnownUser(const UserID& user_id) const { |
| 391 return FindUser(user_id) != NULL; | 394 return FindUser(user_id) != NULL; |
| 392 } | 395 } |
| 393 | 396 |
| 394 const User* UserManagerBase::FindUser(const std::string& user_id) const { | 397 const User* UserManagerBase::FindUser(const UserID& user_id) const { |
| 395 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 398 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 396 if (active_user_ && active_user_->email() == user_id) | 399 if (active_user_ && active_user_->GetUserID() == user_id) |
| 397 return active_user_; | 400 return active_user_; |
| 398 return FindUserInList(user_id); | 401 return FindUserInList(user_id); |
| 399 } | 402 } |
| 400 | 403 |
| 401 User* UserManagerBase::FindUserAndModify(const std::string& user_id) { | 404 User* UserManagerBase::FindUserAndModify(const UserID& user_id) { |
| 402 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 405 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 403 if (active_user_ && active_user_->email() == user_id) | 406 if (active_user_ && active_user_->GetUserID() == user_id) |
| 404 return active_user_; | 407 return active_user_; |
| 405 return FindUserInListAndModify(user_id); | 408 return FindUserInListAndModify(user_id); |
| 406 } | 409 } |
| 407 | 410 |
| 408 const User* UserManagerBase::GetLoggedInUser() const { | 411 const User* UserManagerBase::GetLoggedInUser() const { |
| 409 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 412 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 410 return active_user_; | 413 return active_user_; |
| 411 } | 414 } |
| 412 | 415 |
| 413 User* UserManagerBase::GetLoggedInUser() { | 416 User* UserManagerBase::GetLoggedInUser() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 424 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 427 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 425 return active_user_; | 428 return active_user_; |
| 426 } | 429 } |
| 427 | 430 |
| 428 const User* UserManagerBase::GetPrimaryUser() const { | 431 const User* UserManagerBase::GetPrimaryUser() const { |
| 429 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 432 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 430 return primary_user_; | 433 return primary_user_; |
| 431 } | 434 } |
| 432 | 435 |
| 433 void UserManagerBase::SaveUserOAuthStatus( | 436 void UserManagerBase::SaveUserOAuthStatus( |
| 434 const std::string& user_id, | 437 const UserID& user_id, |
| 435 User::OAuthTokenStatus oauth_token_status) { | 438 User::OAuthTokenStatus oauth_token_status) { |
| 436 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 439 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 437 | 440 |
| 438 DVLOG(1) << "Saving user OAuth token status in Local State"; | 441 DVLOG(1) << "Saving user OAuth token status in Local State"; |
| 439 User* user = FindUserAndModify(user_id); | 442 User* user = FindUserAndModify(user_id); |
| 440 if (user) | 443 if (user) |
| 441 user->set_oauth_token_status(oauth_token_status); | 444 user->set_oauth_token_status(oauth_token_status); |
| 442 | 445 |
| 443 // Do not update local state if data stored or cached outside the user's | 446 // Do not update local state if data stored or cached outside the user's |
| 444 // cryptohome is to be treated as ephemeral. | 447 // cryptohome is to be treated as ephemeral. |
| 445 if (IsUserNonCryptohomeDataEphemeral(user_id)) | 448 if (IsUserNonCryptohomeDataEphemeral(user_id)) |
| 446 return; | 449 return; |
| 447 | 450 |
| 448 DictionaryPrefUpdate oauth_status_update(GetLocalState(), | 451 DictionaryPrefUpdate oauth_status_update(GetLocalState(), |
| 449 kUserOAuthTokenStatus); | 452 kUserOAuthTokenStatus); |
| 450 oauth_status_update->SetWithoutPathExpansion( | 453 oauth_status_update->SetWithoutPathExpansion( |
| 451 user_id, | 454 user_id.GetUserEmail(), |
| 452 new base::FundamentalValue(static_cast<int>(oauth_token_status))); | 455 new base::FundamentalValue(static_cast<int>(oauth_token_status))); |
| 453 } | 456 } |
| 454 | 457 |
| 455 void UserManagerBase::SaveForceOnlineSignin(const std::string& user_id, | 458 void UserManagerBase::SaveForceOnlineSignin(const UserID& user_id, |
| 456 bool force_online_signin) { | 459 bool force_online_signin) { |
| 457 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 460 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 458 | 461 |
| 459 // Do not update local state if data stored or cached outside the user's | 462 // Do not update local state if data stored or cached outside the user's |
| 460 // cryptohome is to be treated as ephemeral. | 463 // cryptohome is to be treated as ephemeral. |
| 461 if (IsUserNonCryptohomeDataEphemeral(user_id)) | 464 if (IsUserNonCryptohomeDataEphemeral(user_id)) |
| 462 return; | 465 return; |
| 463 | 466 |
| 464 DictionaryPrefUpdate force_online_update(GetLocalState(), | 467 DictionaryPrefUpdate force_online_update(GetLocalState(), |
| 465 kUserForceOnlineSignin); | 468 kUserForceOnlineSignin); |
| 466 force_online_update->SetBooleanWithoutPathExpansion(user_id, | 469 force_online_update->SetBooleanWithoutPathExpansion(user_id.GetUserEmail(), |
| 467 force_online_signin); | 470 force_online_signin); |
| 468 } | 471 } |
| 469 | 472 |
| 470 void UserManagerBase::SaveUserDisplayName(const std::string& user_id, | 473 void UserManagerBase::SaveUserDisplayName(const UserID& user_id, |
| 471 const base::string16& display_name) { | 474 const base::string16& display_name) { |
| 472 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 475 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 473 | 476 |
| 474 if (User* user = FindUserAndModify(user_id)) { | 477 if (User* user = FindUserAndModify(user_id)) { |
| 475 user->set_display_name(display_name); | 478 user->set_display_name(display_name); |
| 476 | 479 |
| 477 // Do not update local state if data stored or cached outside the user's | 480 // Do not update local state if data stored or cached outside the user's |
| 478 // cryptohome is to be treated as ephemeral. | 481 // cryptohome is to be treated as ephemeral. |
| 479 if (!IsUserNonCryptohomeDataEphemeral(user_id)) { | 482 if (!IsUserNonCryptohomeDataEphemeral(user_id)) { |
| 480 DictionaryPrefUpdate display_name_update(GetLocalState(), | 483 DictionaryPrefUpdate display_name_update(GetLocalState(), |
| 481 kUserDisplayName); | 484 kUserDisplayName); |
| 482 display_name_update->SetWithoutPathExpansion( | 485 display_name_update->SetWithoutPathExpansion( |
| 483 user_id, new base::StringValue(display_name)); | 486 user_id.GetUserEmail(), new base::StringValue(display_name)); |
| 484 } | 487 } |
| 485 } | 488 } |
| 486 } | 489 } |
| 487 | 490 |
| 488 base::string16 UserManagerBase::GetUserDisplayName( | 491 base::string16 UserManagerBase::GetUserDisplayName( |
| 489 const std::string& user_id) const { | 492 const UserID& user_id) const { |
| 490 const User* user = FindUser(user_id); | 493 const User* user = FindUser(user_id); |
| 491 return user ? user->display_name() : base::string16(); | 494 return user ? user->display_name() : base::string16(); |
| 492 } | 495 } |
| 493 | 496 |
| 494 void UserManagerBase::SaveUserDisplayEmail(const std::string& user_id, | 497 void UserManagerBase::SaveUserDisplayEmail(const UserID& user_id, |
| 495 const std::string& display_email) { | 498 const std::string& display_email) { |
| 496 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 499 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 497 | 500 |
| 498 User* user = FindUserAndModify(user_id); | 501 User* user = FindUserAndModify(user_id); |
| 499 if (!user) { | 502 if (!user) { |
| 500 LOG(ERROR) << "User not found: " << user_id; | 503 LOG(ERROR) << "User not found: " << user_id.GetUserEmail(); |
| 501 return; // Ignore if there is no such user. | 504 return; // Ignore if there is no such user. |
| 502 } | 505 } |
| 503 | 506 |
| 504 user->set_display_email(display_email); | 507 user->set_display_email(display_email); |
| 505 | 508 |
| 506 // Do not update local state if data stored or cached outside the user's | 509 // Do not update local state if data stored or cached outside the user's |
| 507 // cryptohome is to be treated as ephemeral. | 510 // cryptohome is to be treated as ephemeral. |
| 508 if (IsUserNonCryptohomeDataEphemeral(user_id)) | 511 if (IsUserNonCryptohomeDataEphemeral(user_id)) |
| 509 return; | 512 return; |
| 510 | 513 |
| 511 DictionaryPrefUpdate display_email_update(GetLocalState(), kUserDisplayEmail); | 514 DictionaryPrefUpdate display_email_update(GetLocalState(), kUserDisplayEmail); |
| 512 display_email_update->SetWithoutPathExpansion( | 515 display_email_update->SetWithoutPathExpansion( |
| 513 user_id, new base::StringValue(display_email)); | 516 user_id.GetUserEmail(), new base::StringValue(display_email)); |
| 514 } | 517 } |
| 515 | 518 |
| 516 std::string UserManagerBase::GetUserDisplayEmail( | 519 std::string UserManagerBase::GetUserDisplayEmail( |
| 517 const std::string& user_id) const { | 520 const UserID& user_id) const { |
| 518 const User* user = FindUser(user_id); | 521 const User* user = FindUser(user_id); |
| 519 return user ? user->display_email() : user_id; | 522 return user ? user->display_email() : user_id.GetUserEmail(); |
| 520 } | 523 } |
| 521 | 524 |
| 522 void UserManagerBase::SaveUserType(const std::string& user_id, | 525 void UserManagerBase::SaveUserType(const UserID& user_id, |
| 523 const UserType& user_type) { | 526 const UserType& user_type) { |
| 524 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 527 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 525 | 528 |
| 526 User* user = FindUserAndModify(user_id); | 529 User* user = FindUserAndModify(user_id); |
| 527 if (!user) { | 530 if (!user) { |
| 528 LOG(ERROR) << "User not found: " << user_id; | 531 LOG(ERROR) << "User not found: " << user_id.GetUserEmail(); |
| 529 return; // Ignore if there is no such user. | 532 return; // Ignore if there is no such user. |
| 530 } | 533 } |
| 531 | 534 |
| 532 // Do not update local state if data stored or cached outside the user's | 535 // Do not update local state if data stored or cached outside the user's |
| 533 // cryptohome is to be treated as ephemeral. | 536 // cryptohome is to be treated as ephemeral. |
| 534 if (IsUserNonCryptohomeDataEphemeral(user_id)) | 537 if (IsUserNonCryptohomeDataEphemeral(user_id)) |
| 535 return; | 538 return; |
| 536 | 539 |
| 537 DictionaryPrefUpdate user_type_update(GetLocalState(), kUserType); | 540 DictionaryPrefUpdate user_type_update(GetLocalState(), kUserType); |
| 538 user_type_update->SetWithoutPathExpansion( | 541 user_type_update->SetWithoutPathExpansion( |
| 539 user_id, new base::FundamentalValue(static_cast<int>(user_type))); | 542 user_id.GetUserEmail(), new base::FundamentalValue(static_cast<int>(user_t
ype))); |
| 540 GetLocalState()->CommitPendingWrite(); | 543 GetLocalState()->CommitPendingWrite(); |
| 541 } | 544 } |
| 542 | 545 |
| 543 void UserManagerBase::UpdateUsingSAML(const std::string& user_id, | 546 void UserManagerBase::UpdateUsingSAML(const UserID& user_id, |
| 544 const bool using_saml) { | 547 const bool using_saml) { |
| 545 SetKnownUserBooleanPref(user_id, kUsingSAMLKey, using_saml); | 548 SetKnownUserBooleanPref(user_id, kUsingSAMLKey, using_saml); |
| 546 } | 549 } |
| 547 | 550 |
| 548 bool UserManagerBase::FindUsingSAML(const std::string& user_id) { | 551 bool UserManagerBase::FindUsingSAML(const UserID& user_id) { |
| 549 bool using_saml; | 552 bool using_saml; |
| 550 if (GetKnownUserBooleanPref(user_id, kUsingSAMLKey, &using_saml)) | 553 if (GetKnownUserBooleanPref(user_id, kUsingSAMLKey, &using_saml)) |
| 551 return using_saml; | 554 return using_saml; |
| 552 return false; | 555 return false; |
| 553 } | 556 } |
| 554 | 557 |
| 555 void UserManagerBase::UpdateReauthReason(const std::string& user_id, | 558 void UserManagerBase::UpdateReauthReason(const UserID& user_id, |
| 556 const int reauth_reason) { | 559 const int reauth_reason) { |
| 557 SetKnownUserIntegerPref(user_id, kReauthReasonKey, reauth_reason); | 560 SetKnownUserIntegerPref(user_id, kReauthReasonKey, reauth_reason); |
| 558 } | 561 } |
| 559 | 562 |
| 560 bool UserManagerBase::FindReauthReason(const std::string& user_id, | 563 bool UserManagerBase::FindReauthReason(const UserID& user_id, |
| 561 int* out_value) { | 564 int* out_value) { |
| 562 return GetKnownUserIntegerPref(user_id, kReauthReasonKey, out_value); | 565 return GetKnownUserIntegerPref(user_id, kReauthReasonKey, out_value); |
| 563 } | 566 } |
| 564 | 567 |
| 565 void UserManagerBase::UpdateUserAccountData( | 568 void UserManagerBase::UpdateUserAccountData( |
| 566 const std::string& user_id, | 569 const UserID& user_id, |
| 567 const UserAccountData& account_data) { | 570 const UserAccountData& account_data) { |
| 568 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 571 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 569 | 572 |
| 570 SaveUserDisplayName(user_id, account_data.display_name()); | 573 SaveUserDisplayName(user_id, account_data.display_name()); |
| 571 | 574 |
| 572 if (User* user = FindUserAndModify(user_id)) { | 575 if (User* user = FindUserAndModify(user_id)) { |
| 573 base::string16 given_name = account_data.given_name(); | 576 base::string16 given_name = account_data.given_name(); |
| 574 user->set_given_name(given_name); | 577 user->set_given_name(given_name); |
| 575 if (!IsUserNonCryptohomeDataEphemeral(user_id)) { | 578 if (!IsUserNonCryptohomeDataEphemeral(user_id)) { |
| 576 DictionaryPrefUpdate given_name_update(GetLocalState(), kUserGivenName); | 579 DictionaryPrefUpdate given_name_update(GetLocalState(), kUserGivenName); |
| 577 given_name_update->SetWithoutPathExpansion( | 580 given_name_update->SetWithoutPathExpansion( |
| 578 user_id, new base::StringValue(given_name)); | 581 user_id.GetUserEmail(), new base::StringValue(given_name)); |
| 579 } | 582 } |
| 580 } | 583 } |
| 581 | 584 |
| 582 UpdateUserAccountLocale(user_id, account_data.locale()); | 585 UpdateUserAccountLocale(user_id, account_data.locale()); |
| 583 } | 586 } |
| 584 | 587 |
| 585 // static | 588 // static |
| 586 void UserManagerBase::ParseUserList(const base::ListValue& users_list, | 589 void UserManagerBase::ParseUserList(const base::ListValue& users_list, |
| 587 const std::set<std::string>& existing_users, | 590 const std::set<std::string>& existing_users, |
| 588 std::vector<std::string>* users_vector, | 591 std::vector<std::string>* users_vector, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 } | 623 } |
| 621 | 624 |
| 622 bool UserManagerBase::IsCurrentUserNew() const { | 625 bool UserManagerBase::IsCurrentUserNew() const { |
| 623 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 626 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 624 return is_current_user_new_; | 627 return is_current_user_new_; |
| 625 } | 628 } |
| 626 | 629 |
| 627 bool UserManagerBase::IsCurrentUserNonCryptohomeDataEphemeral() const { | 630 bool UserManagerBase::IsCurrentUserNonCryptohomeDataEphemeral() const { |
| 628 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 631 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 629 return IsUserLoggedIn() && | 632 return IsUserLoggedIn() && |
| 630 IsUserNonCryptohomeDataEphemeral(GetLoggedInUser()->email()); | 633 IsUserNonCryptohomeDataEphemeral(GetLoggedInUser()->GetUserID()); |
| 631 } | 634 } |
| 632 | 635 |
| 633 bool UserManagerBase::CanCurrentUserLock() const { | 636 bool UserManagerBase::CanCurrentUserLock() const { |
| 634 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 637 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 635 return IsUserLoggedIn() && active_user_->can_lock(); | 638 return IsUserLoggedIn() && active_user_->can_lock(); |
| 636 } | 639 } |
| 637 | 640 |
| 638 bool UserManagerBase::IsUserLoggedIn() const { | 641 bool UserManagerBase::IsUserLoggedIn() const { |
| 639 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 642 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 640 return active_user_; | 643 return active_user_; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 667 } | 670 } |
| 668 | 671 |
| 669 bool UserManagerBase::IsLoggedInAsKioskApp() const { | 672 bool UserManagerBase::IsLoggedInAsKioskApp() const { |
| 670 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 673 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 671 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_KIOSK_APP; | 674 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_KIOSK_APP; |
| 672 } | 675 } |
| 673 | 676 |
| 674 bool UserManagerBase::IsLoggedInAsStub() const { | 677 bool UserManagerBase::IsLoggedInAsStub() const { |
| 675 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 678 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 676 return IsUserLoggedIn() && | 679 return IsUserLoggedIn() && |
| 677 active_user_->email() == chromeos::login::kStubUser; | 680 active_user_->GetUserID() == chromeos::login::GetStubUserID(); |
| 678 } | 681 } |
| 679 | 682 |
| 680 bool UserManagerBase::IsSessionStarted() const { | 683 bool UserManagerBase::IsSessionStarted() const { |
| 681 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 684 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 682 return session_started_; | 685 return session_started_; |
| 683 } | 686 } |
| 684 | 687 |
| 685 bool UserManagerBase::IsUserNonCryptohomeDataEphemeral( | 688 bool UserManagerBase::IsUserNonCryptohomeDataEphemeral( |
| 686 const std::string& user_id) const { | 689 const UserID& user_id) const { |
| 687 // Data belonging to the guest and stub users is always ephemeral. | 690 // Data belonging to the guest and stub users is always ephemeral. |
| 688 if (user_id == chromeos::login::kGuestUserName || | 691 if (user_id == chromeos::login::GetGuestUserID() || |
| 689 user_id == chromeos::login::kStubUser) { | 692 user_id == chromeos::login::GetStubUserID()) { |
| 690 return true; | 693 return true; |
| 691 } | 694 } |
| 692 | 695 |
| 693 // Data belonging to the owner, anyone found on the user list and obsolete | 696 // 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. | 697 // public accounts whose data has not been removed yet is not ephemeral. |
| 695 if (user_id == GetOwnerEmail() || UserExistsInList(user_id) || | 698 if (user_id == owner_id_ || UserExistsInList(user_id) || |
| 696 IsPublicAccountMarkedForRemoval(user_id)) { | 699 IsPublicAccountMarkedForRemoval(user_id)) { |
| 697 return false; | 700 return false; |
| 698 } | 701 } |
| 699 | 702 |
| 700 // Data belonging to the currently logged-in user is ephemeral when: | 703 // 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 | 704 // a) The user logged into a regular gaia account while the ephemeral users |
| 702 // policy was enabled. | 705 // policy was enabled. |
| 703 // - or - | 706 // - or - |
| 704 // b) The user logged into any other account type. | 707 // b) The user logged into any other account type. |
| 705 if (IsUserLoggedIn() && (user_id == GetLoggedInUser()->email()) && | 708 if (IsUserLoggedIn() && (user_id == GetLoggedInUser()->GetUserID()) && |
| 706 (is_current_user_ephemeral_regular_user_ || | 709 (is_current_user_ephemeral_regular_user_ || |
| 707 !IsLoggedInAsUserWithGaiaAccount())) { | 710 !IsLoggedInAsUserWithGaiaAccount())) { |
| 708 return true; | 711 return true; |
| 709 } | 712 } |
| 710 | 713 |
| 711 // Data belonging to any other user is ephemeral when: | 714 // Data belonging to any other user is ephemeral when: |
| 712 // a) Going through the regular login flow and the ephemeral users policy is | 715 // a) Going through the regular login flow and the ephemeral users policy is |
| 713 // enabled. | 716 // enabled. |
| 714 // - or - | 717 // - or - |
| 715 // b) The browser is restarting after a crash. | 718 // b) The browser is restarting after a crash. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 // in order not to remove an owner. However due to non-instant nature of | 759 // in order not to remove an owner. However due to non-instant nature of |
| 757 // ownership assignment this later check may sometimes fail. | 760 // ownership assignment this later check may sometimes fail. |
| 758 // See http://crosbug.com/12723 | 761 // See http://crosbug.com/12723 |
| 759 if (users_.size() < 2 && !IsEnterpriseManaged()) | 762 if (users_.size() < 2 && !IsEnterpriseManaged()) |
| 760 return false; | 763 return false; |
| 761 | 764 |
| 762 // Sanity check: do not allow any of the the logged in users to be removed. | 765 // 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(); | 766 for (UserList::const_iterator it = logged_in_users_.begin(); |
| 764 it != logged_in_users_.end(); | 767 it != logged_in_users_.end(); |
| 765 ++it) { | 768 ++it) { |
| 766 if ((*it)->email() == user->email()) | 769 if ((*it)->GetUserID() == user->GetUserID()) |
| 767 return false; | 770 return false; |
| 768 } | 771 } |
| 769 | 772 |
| 770 return true; | 773 return true; |
| 771 } | 774 } |
| 772 | 775 |
| 773 bool UserManagerBase::GetEphemeralUsersEnabled() const { | 776 bool UserManagerBase::GetEphemeralUsersEnabled() const { |
| 774 return ephemeral_users_enabled_; | 777 return ephemeral_users_enabled_; |
| 775 } | 778 } |
| 776 | 779 |
| 777 void UserManagerBase::SetEphemeralUsersEnabled(bool enabled) { | 780 void UserManagerBase::SetEphemeralUsersEnabled(bool enabled) { |
| 778 ephemeral_users_enabled_ = enabled; | 781 ephemeral_users_enabled_ = enabled; |
| 779 } | 782 } |
| 780 | 783 |
| 781 void UserManagerBase::SetIsCurrentUserNew(bool is_new) { | 784 void UserManagerBase::SetIsCurrentUserNew(bool is_new) { |
| 782 is_current_user_new_ = is_new; | 785 is_current_user_new_ = is_new; |
| 783 } | 786 } |
| 784 | 787 |
| 785 bool UserManagerBase::HasPendingBootstrap(const std::string& user_id) const { | 788 bool UserManagerBase::HasPendingBootstrap(const UserID& user_id) const { |
| 786 return false; | 789 return false; |
| 787 } | 790 } |
| 788 | 791 |
| 789 void UserManagerBase::SetOwnerEmail(std::string owner_user_id) { | 792 void UserManagerBase::SetOwnerID(const UserID& owner_user_id) { |
| 790 owner_email_ = owner_user_id; | 793 owner_id_ = owner_user_id; |
| 791 } | 794 } |
| 792 | 795 |
| 793 const std::string& UserManagerBase::GetPendingUserSwitchID() const { | 796 const user_manager::UserID& UserManagerBase::GetPendingUserSwitchID() const { |
| 794 return pending_user_switch_; | 797 return pending_user_switch_; |
| 795 } | 798 } |
| 796 | 799 |
| 797 void UserManagerBase::SetPendingUserSwitchID(std::string user_id) { | 800 void UserManagerBase::SetPendingUserSwitchID(const user_manager::UserID& user_id
) { |
| 798 pending_user_switch_ = user_id; | 801 pending_user_switch_ = user_id; |
| 799 } | 802 } |
| 800 | 803 |
| 801 void UserManagerBase::EnsureUsersLoaded() { | 804 void UserManagerBase::EnsureUsersLoaded() { |
| 802 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 805 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 803 if (!GetLocalState()) | 806 if (!GetLocalState()) |
| 804 return; | 807 return; |
| 805 | 808 |
| 806 if (user_loading_stage_ != STAGE_NOT_LOADED) | 809 if (user_loading_stage_ != STAGE_NOT_LOADED) |
| 807 return; | 810 return; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 830 std::vector<std::string> regular_users; | 833 std::vector<std::string> regular_users; |
| 831 std::set<std::string> regular_users_set; | 834 std::set<std::string> regular_users_set; |
| 832 ParseUserList(*prefs_regular_users, | 835 ParseUserList(*prefs_regular_users, |
| 833 public_sessions_set, | 836 public_sessions_set, |
| 834 ®ular_users, | 837 ®ular_users, |
| 835 ®ular_users_set); | 838 ®ular_users_set); |
| 836 for (std::vector<std::string>::const_iterator it = regular_users.begin(); | 839 for (std::vector<std::string>::const_iterator it = regular_users.begin(); |
| 837 it != regular_users.end(); | 840 it != regular_users.end(); |
| 838 ++it) { | 841 ++it) { |
| 839 User* user = NULL; | 842 User* user = NULL; |
| 843 const UserID user_id(UserID::FromUserEmail(*it)); |
| 840 const std::string domain = gaia::ExtractDomainName(*it); | 844 const std::string domain = gaia::ExtractDomainName(*it); |
| 841 if (domain == chromeos::login::kSupervisedUserDomain) { | 845 if (domain == chromeos::login::kSupervisedUserDomain) { |
| 842 user = User::CreateSupervisedUser(*it); | 846 user = User::CreateSupervisedUser(user_id); |
| 843 } else { | 847 } else { |
| 844 user = User::CreateRegularUser(*it); | 848 user = User::CreateRegularUser(user_id); |
| 845 int user_type; | 849 int user_type; |
| 846 if (prefs_user_types->GetIntegerWithoutPathExpansion(*it, &user_type) && | 850 if (prefs_user_types->GetIntegerWithoutPathExpansion(*it, &user_type) && |
| 847 user_type == USER_TYPE_CHILD) { | 851 user_type == USER_TYPE_CHILD) { |
| 848 ChangeUserChildStatus(user, true /* is child */); | 852 ChangeUserChildStatus(user, true /* is child */); |
| 849 } | 853 } |
| 850 } | 854 } |
| 851 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); | 855 user->set_oauth_token_status(LoadUserOAuthStatus(user_id)); |
| 852 user->set_force_online_signin(LoadForceOnlineSignin(*it)); | 856 user->set_force_online_signin(LoadForceOnlineSignin(user_id)); |
| 853 user->set_using_saml(FindUsingSAML(*it)); | 857 user->set_using_saml(FindUsingSAML(user_id)); |
| 854 users_.push_back(user); | 858 users_.push_back(user); |
| 855 | 859 |
| 856 base::string16 display_name; | 860 base::string16 display_name; |
| 857 if (prefs_display_names->GetStringWithoutPathExpansion(*it, | 861 if (prefs_display_names->GetStringWithoutPathExpansion(*it, |
| 858 &display_name)) { | 862 &display_name)) { |
| 859 user->set_display_name(display_name); | 863 user->set_display_name(display_name); |
| 860 } | 864 } |
| 861 | 865 |
| 862 base::string16 given_name; | 866 base::string16 given_name; |
| 863 if (prefs_given_names->GetStringWithoutPathExpansion(*it, &given_name)) { | 867 if (prefs_given_names->GetStringWithoutPathExpansion(*it, &given_name)) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 874 user_loading_stage_ = STAGE_LOADED; | 878 user_loading_stage_ = STAGE_LOADED; |
| 875 | 879 |
| 876 PerformPostUserListLoadingActions(); | 880 PerformPostUserListLoadingActions(); |
| 877 } | 881 } |
| 878 | 882 |
| 879 UserList& UserManagerBase::GetUsersAndModify() { | 883 UserList& UserManagerBase::GetUsersAndModify() { |
| 880 EnsureUsersLoaded(); | 884 EnsureUsersLoaded(); |
| 881 return users_; | 885 return users_; |
| 882 } | 886 } |
| 883 | 887 |
| 884 const User* UserManagerBase::FindUserInList(const std::string& user_id) const { | 888 const User* UserManagerBase::FindUserInList(const UserID& user_id) const { |
| 885 const UserList& users = GetUsers(); | 889 const UserList& users = GetUsers(); |
| 886 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | 890 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { |
| 887 if ((*it)->email() == user_id) | 891 if ((*it)->GetUserID() == user_id) |
| 888 return *it; | 892 return *it; |
| 889 } | 893 } |
| 890 return NULL; | 894 return NULL; |
| 891 } | 895 } |
| 892 | 896 |
| 893 bool UserManagerBase::UserExistsInList(const std::string& user_id) const { | 897 bool UserManagerBase::UserExistsInList(const UserID& user_id) const { |
| 894 const base::ListValue* user_list = GetLocalState()->GetList(kRegularUsers); | 898 const base::ListValue* user_list = GetLocalState()->GetList(kRegularUsers); |
| 895 for (size_t i = 0; i < user_list->GetSize(); ++i) { | 899 for (size_t i = 0; i < user_list->GetSize(); ++i) { |
| 896 std::string email; | 900 std::string email; |
| 897 if (user_list->GetString(i, &email) && (user_id == email)) | 901 if (user_list->GetString(i, &email) && (user_id == UserID::FromUserEmail(ema
il))) |
| 898 return true; | 902 return true; |
| 899 } | 903 } |
| 900 return false; | 904 return false; |
| 901 } | 905 } |
| 902 | 906 |
| 903 User* UserManagerBase::FindUserInListAndModify(const std::string& user_id) { | 907 User* UserManagerBase::FindUserInListAndModify(const UserID& user_id) { |
| 904 UserList& users = GetUsersAndModify(); | 908 UserList& users = GetUsersAndModify(); |
| 905 for (UserList::iterator it = users.begin(); it != users.end(); ++it) { | 909 for (UserList::iterator it = users.begin(); it != users.end(); ++it) { |
| 906 if ((*it)->email() == user_id) | 910 if ((*it)->GetUserID() == user_id) |
| 907 return *it; | 911 return *it; |
| 908 } | 912 } |
| 909 return NULL; | 913 return NULL; |
| 910 } | 914 } |
| 911 | 915 |
| 912 void UserManagerBase::GuestUserLoggedIn() { | 916 void UserManagerBase::GuestUserLoggedIn() { |
| 913 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 917 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 914 active_user_ = User::CreateGuestUser(); | 918 active_user_ = User::CreateGuestUser(); |
| 915 } | 919 } |
| 916 | 920 |
| 917 void UserManagerBase::AddUserRecord(User* user) { | 921 void UserManagerBase::AddUserRecord(User* user) { |
| 918 // Add the user to the front of the user list. | 922 // Add the user to the front of the user list. |
| 919 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); | 923 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); |
| 920 prefs_users_update->Insert(0, new base::StringValue(user->email())); | 924 prefs_users_update->Insert(0, new base::StringValue(user->GetUserID().GetUserE
mail())); |
| 921 users_.insert(users_.begin(), user); | 925 users_.insert(users_.begin(), user); |
| 922 } | 926 } |
| 923 | 927 |
| 924 void UserManagerBase::RegularUserLoggedIn(const std::string& user_id) { | 928 void UserManagerBase::RegularUserLoggedIn(const UserID& user_id) { |
| 925 // Remove the user from the user list. | 929 // Remove the user from the user list. |
| 926 active_user_ = RemoveRegularOrSupervisedUserFromList(user_id); | 930 active_user_ = RemoveRegularOrSupervisedUserFromList(user_id); |
| 927 | 931 |
| 928 // If the user was not found on the user list, create a new user. | 932 // If the user was not found on the user list, create a new user. |
| 929 SetIsCurrentUserNew(!active_user_); | 933 SetIsCurrentUserNew(!active_user_); |
| 930 if (IsCurrentUserNew()) { | 934 if (IsCurrentUserNew()) { |
| 931 active_user_ = User::CreateRegularUser(user_id); | 935 active_user_ = User::CreateRegularUser(user_id); |
| 932 active_user_->set_oauth_token_status(LoadUserOAuthStatus(user_id)); | 936 active_user_->set_oauth_token_status(LoadUserOAuthStatus(user_id)); |
| 933 SaveUserDisplayName(active_user_->email(), | 937 SaveUserDisplayName(active_user_->GetUserID(), |
| 934 base::UTF8ToUTF16(active_user_->GetAccountName(true))); | 938 base::UTF8ToUTF16(active_user_->GetAccountName(true))); |
| 935 } | 939 } |
| 936 | 940 |
| 937 AddUserRecord(active_user_); | 941 AddUserRecord(active_user_); |
| 938 | 942 |
| 939 // Make sure that new data is persisted to Local State. | 943 // Make sure that new data is persisted to Local State. |
| 940 GetLocalState()->CommitPendingWrite(); | 944 GetLocalState()->CommitPendingWrite(); |
| 941 } | 945 } |
| 942 | 946 |
| 943 void UserManagerBase::RegularUserLoggedInAsEphemeral( | 947 void UserManagerBase::RegularUserLoggedInAsEphemeral( |
| 944 const std::string& user_id) { | 948 const UserID& user_id) { |
| 945 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 949 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 946 SetIsCurrentUserNew(true); | 950 SetIsCurrentUserNew(true); |
| 947 is_current_user_ephemeral_regular_user_ = true; | 951 is_current_user_ephemeral_regular_user_ = true; |
| 948 active_user_ = User::CreateRegularUser(user_id); | 952 active_user_ = User::CreateRegularUser(user_id); |
| 949 } | 953 } |
| 950 | 954 |
| 951 void UserManagerBase::NotifyOnLogin() { | 955 void UserManagerBase::NotifyOnLogin() { |
| 952 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 956 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 953 | 957 |
| 954 NotifyActiveUserHashChanged(active_user_->username_hash()); | 958 NotifyActiveUserHashChanged(active_user_->username_hash()); |
| 955 NotifyActiveUserChanged(active_user_); | 959 NotifyActiveUserChanged(active_user_); |
| 956 UpdateLoginState(); | 960 UpdateLoginState(); |
| 957 } | 961 } |
| 958 | 962 |
| 959 User::OAuthTokenStatus UserManagerBase::LoadUserOAuthStatus( | 963 User::OAuthTokenStatus UserManagerBase::LoadUserOAuthStatus( |
| 960 const std::string& user_id) const { | 964 const UserID& user_id) const { |
| 961 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 965 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 962 | 966 |
| 963 const base::DictionaryValue* prefs_oauth_status = | 967 const base::DictionaryValue* prefs_oauth_status = |
| 964 GetLocalState()->GetDictionary(kUserOAuthTokenStatus); | 968 GetLocalState()->GetDictionary(kUserOAuthTokenStatus); |
| 965 int oauth_token_status = User::OAUTH_TOKEN_STATUS_UNKNOWN; | 969 int oauth_token_status = User::OAUTH_TOKEN_STATUS_UNKNOWN; |
| 966 if (prefs_oauth_status && | 970 if (prefs_oauth_status && |
| 967 prefs_oauth_status->GetIntegerWithoutPathExpansion(user_id, | 971 prefs_oauth_status->GetIntegerWithoutPathExpansion(user_id.GetUserEmail(), |
| 968 &oauth_token_status)) { | 972 &oauth_token_status)) { |
| 969 User::OAuthTokenStatus status = | 973 User::OAuthTokenStatus status = |
| 970 static_cast<User::OAuthTokenStatus>(oauth_token_status); | 974 static_cast<User::OAuthTokenStatus>(oauth_token_status); |
| 971 HandleUserOAuthTokenStatusChange(user_id, status); | 975 HandleUserOAuthTokenStatusChange(user_id, status); |
| 972 | 976 |
| 973 return status; | 977 return status; |
| 974 } | 978 } |
| 975 return User::OAUTH_TOKEN_STATUS_UNKNOWN; | 979 return User::OAUTH_TOKEN_STATUS_UNKNOWN; |
| 976 } | 980 } |
| 977 | 981 |
| 978 bool UserManagerBase::LoadForceOnlineSignin(const std::string& user_id) const { | 982 bool UserManagerBase::LoadForceOnlineSignin(const UserID& user_id) const { |
| 979 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 983 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 980 | 984 |
| 981 const base::DictionaryValue* prefs_force_online = | 985 const base::DictionaryValue* prefs_force_online = |
| 982 GetLocalState()->GetDictionary(kUserForceOnlineSignin); | 986 GetLocalState()->GetDictionary(kUserForceOnlineSignin); |
| 983 bool force_online_signin = false; | 987 bool force_online_signin = false; |
| 984 if (prefs_force_online) { | 988 if (prefs_force_online) { |
| 985 prefs_force_online->GetBooleanWithoutPathExpansion(user_id, | 989 prefs_force_online->GetBooleanWithoutPathExpansion(user_id.GetUserEmail(), |
| 986 &force_online_signin); | 990 &force_online_signin); |
| 987 } | 991 } |
| 988 return force_online_signin; | 992 return force_online_signin; |
| 989 } | 993 } |
| 990 | 994 |
| 991 void UserManagerBase::RemoveNonCryptohomeData(const std::string& user_id) { | 995 void UserManagerBase::RemoveNonCryptohomeData(const UserID& user_id) { |
| 992 PrefService* prefs = GetLocalState(); | 996 PrefService* prefs = GetLocalState(); |
| 993 DictionaryPrefUpdate prefs_display_name_update(prefs, kUserDisplayName); | 997 DictionaryPrefUpdate prefs_display_name_update(prefs, kUserDisplayName); |
| 994 prefs_display_name_update->RemoveWithoutPathExpansion(user_id, NULL); | 998 prefs_display_name_update->RemoveWithoutPathExpansion(user_id.GetUserEmail(),
NULL); |
| 995 | 999 |
| 996 DictionaryPrefUpdate prefs_given_name_update(prefs, kUserGivenName); | 1000 DictionaryPrefUpdate prefs_given_name_update(prefs, kUserGivenName); |
| 997 prefs_given_name_update->RemoveWithoutPathExpansion(user_id, NULL); | 1001 prefs_given_name_update->RemoveWithoutPathExpansion(user_id.GetUserEmail(), NU
LL); |
| 998 | 1002 |
| 999 DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail); | 1003 DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail); |
| 1000 prefs_display_email_update->RemoveWithoutPathExpansion(user_id, NULL); | 1004 prefs_display_email_update->RemoveWithoutPathExpansion(user_id.GetUserEmail(),
NULL); |
| 1001 | 1005 |
| 1002 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); | 1006 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); |
| 1003 prefs_oauth_update->RemoveWithoutPathExpansion(user_id, NULL); | 1007 prefs_oauth_update->RemoveWithoutPathExpansion(user_id.GetUserEmail(), NULL); |
| 1004 | 1008 |
| 1005 DictionaryPrefUpdate prefs_force_online_update(prefs, kUserForceOnlineSignin); | 1009 DictionaryPrefUpdate prefs_force_online_update(prefs, kUserForceOnlineSignin); |
| 1006 prefs_force_online_update->RemoveWithoutPathExpansion(user_id, NULL); | 1010 prefs_force_online_update->RemoveWithoutPathExpansion(user_id.GetUserEmail(),
NULL); |
| 1007 | 1011 |
| 1008 RemoveKnownUserPrefs(user_id); | 1012 RemoveKnownUserPrefs(user_id); |
| 1009 | 1013 |
| 1010 std::string last_active_user = GetLocalState()->GetString(kLastActiveUser); | 1014 const std::string last_active_user = GetLocalState()->GetString(kLastActiveUse
r); |
| 1011 if (user_id == last_active_user) | 1015 if (user_id == UserID::FromUserEmail(last_active_user)) |
| 1012 GetLocalState()->SetString(kLastActiveUser, std::string()); | 1016 GetLocalState()->SetString(kLastActiveUser, std::string()); |
| 1013 } | 1017 } |
| 1014 | 1018 |
| 1015 bool UserManagerBase::FindKnownUserPrefs( | 1019 bool UserManagerBase::FindKnownUserPrefs( |
| 1016 const UserID& user_id, | 1020 const UserID& user_id, |
| 1017 const base::DictionaryValue** out_value) { | 1021 const base::DictionaryValue** out_value) { |
| 1018 PrefService* local_state = GetLocalState(); | 1022 PrefService* local_state = GetLocalState(); |
| 1019 | 1023 |
| 1020 // Local State may not be initialized in tests. | 1024 // Local State may not be initialized in tests. |
| 1021 if (!local_state) | 1025 if (!local_state) |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1157 | 1161 |
| 1158 std::string UserManagerBase::GetKnownUserDeviceId(const UserID& user_id) { | 1162 std::string UserManagerBase::GetKnownUserDeviceId(const UserID& user_id) { |
| 1159 std::string device_id; | 1163 std::string device_id; |
| 1160 if (GetKnownUserStringPref(user_id, kDeviceId, &device_id)) { | 1164 if (GetKnownUserStringPref(user_id, kDeviceId, &device_id)) { |
| 1161 return device_id; | 1165 return device_id; |
| 1162 } | 1166 } |
| 1163 return std::string(); | 1167 return std::string(); |
| 1164 } | 1168 } |
| 1165 | 1169 |
| 1166 User* UserManagerBase::RemoveRegularOrSupervisedUserFromList( | 1170 User* UserManagerBase::RemoveRegularOrSupervisedUserFromList( |
| 1167 const std::string& user_id) { | 1171 const UserID& user_id) { |
| 1168 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); | 1172 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); |
| 1169 prefs_users_update->Clear(); | 1173 prefs_users_update->Clear(); |
| 1170 User* user = NULL; | 1174 User* user = NULL; |
| 1171 for (UserList::iterator it = users_.begin(); it != users_.end();) { | 1175 for (UserList::iterator it = users_.begin(); it != users_.end();) { |
| 1172 const std::string user_email = (*it)->email(); | 1176 if ((*it)->GetUserID() == user_id) { |
| 1173 if (user_email == user_id) { | |
| 1174 user = *it; | 1177 user = *it; |
| 1175 it = users_.erase(it); | 1178 it = users_.erase(it); |
| 1176 } else { | 1179 } else { |
| 1177 if ((*it)->HasGaiaAccount() || (*it)->IsSupervised()) | 1180 if ((*it)->HasGaiaAccount() || (*it)->IsSupervised()) |
| 1178 prefs_users_update->Append(new base::StringValue(user_email)); | 1181 prefs_users_update->Append(new base::StringValue((*it)->GetUserID().GetU
serEmail())); |
| 1179 ++it; | 1182 ++it; |
| 1180 } | 1183 } |
| 1181 } | 1184 } |
| 1182 return user; | 1185 return user; |
| 1183 } | 1186 } |
| 1184 | 1187 |
| 1185 void UserManagerBase::RemoveKnownUserPrefs(const UserID& user_id) { | 1188 void UserManagerBase::RemoveKnownUserPrefs(const UserID& user_id) { |
| 1186 ListPrefUpdate update(GetLocalState(), kKnownUsers); | 1189 ListPrefUpdate update(GetLocalState(), kKnownUsers); |
| 1187 for (size_t i = 0; i < update->GetSize(); ++i) { | 1190 for (size_t i = 0; i < update->GetSize(); ++i) { |
| 1188 base::DictionaryValue* element = nullptr; | 1191 base::DictionaryValue* element = nullptr; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1215 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, | 1218 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, |
| 1216 session_state_observer_list_, | 1219 session_state_observer_list_, |
| 1217 ActiveUserHashChanged(hash)); | 1220 ActiveUserHashChanged(hash)); |
| 1218 } | 1221 } |
| 1219 | 1222 |
| 1220 void UserManagerBase::ChangeUserChildStatus(User* user, bool is_child) { | 1223 void UserManagerBase::ChangeUserChildStatus(User* user, bool is_child) { |
| 1221 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 1224 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 1222 if (user->IsSupervised() == is_child) | 1225 if (user->IsSupervised() == is_child) |
| 1223 return; | 1226 return; |
| 1224 user->SetIsChild(is_child); | 1227 user->SetIsChild(is_child); |
| 1225 SaveUserType(user->email(), is_child ? user_manager::USER_TYPE_CHILD | 1228 SaveUserType(user->GetUserID(), is_child ? user_manager::USER_TYPE_CHILD |
| 1226 : user_manager::USER_TYPE_REGULAR); | 1229 : user_manager::USER_TYPE_REGULAR); |
| 1227 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, | 1230 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, |
| 1228 session_state_observer_list_, | 1231 session_state_observer_list_, |
| 1229 UserChangedChildStatus(user)); | 1232 UserChangedChildStatus(user)); |
| 1230 } | 1233 } |
| 1231 | 1234 |
| 1232 void UserManagerBase::UpdateLoginState() { | 1235 void UserManagerBase::UpdateLoginState() { |
| 1233 if (!chromeos::LoginState::IsInitialized()) | 1236 if (!chromeos::LoginState::IsInitialized()) |
| 1234 return; // LoginState may not be initialized in tests. | 1237 return; // LoginState may not be initialized in tests. |
| 1235 | 1238 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1256 if (primary_user_) { | 1259 if (primary_user_) { |
| 1257 chromeos::LoginState::Get()->SetLoggedInStateAndPrimaryUser( | 1260 chromeos::LoginState::Get()->SetLoggedInStateAndPrimaryUser( |
| 1258 logged_in_state, login_user_type, primary_user_->username_hash()); | 1261 logged_in_state, login_user_type, primary_user_->username_hash()); |
| 1259 } else { | 1262 } else { |
| 1260 chromeos::LoginState::Get()->SetLoggedInState(logged_in_state, | 1263 chromeos::LoginState::Get()->SetLoggedInState(logged_in_state, |
| 1261 login_user_type); | 1264 login_user_type); |
| 1262 } | 1265 } |
| 1263 } | 1266 } |
| 1264 | 1267 |
| 1265 void UserManagerBase::SetLRUUser(User* user) { | 1268 void UserManagerBase::SetLRUUser(User* user) { |
| 1266 GetLocalState()->SetString(kLastActiveUser, user->email()); | 1269 GetLocalState()->SetString(kLastActiveUser, user->GetUserID().GetUserEmail()); |
| 1267 GetLocalState()->CommitPendingWrite(); | 1270 GetLocalState()->CommitPendingWrite(); |
| 1268 | 1271 |
| 1269 UserList::iterator it = | 1272 UserList::iterator it = |
| 1270 std::find(lru_logged_in_users_.begin(), lru_logged_in_users_.end(), user); | 1273 std::find(lru_logged_in_users_.begin(), lru_logged_in_users_.end(), user); |
| 1271 if (it != lru_logged_in_users_.end()) | 1274 if (it != lru_logged_in_users_.end()) |
| 1272 lru_logged_in_users_.erase(it); | 1275 lru_logged_in_users_.erase(it); |
| 1273 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user); | 1276 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user); |
| 1274 } | 1277 } |
| 1275 | 1278 |
| 1276 void UserManagerBase::SendGaiaUserLoginMetrics(const std::string& user_id) { | 1279 void UserManagerBase::SendGaiaUserLoginMetrics(const UserID& user_id) { |
| 1277 // If this isn't the first time Chrome was run after the system booted, | 1280 // If this isn't the first time Chrome was run after the system booted, |
| 1278 // assume that Chrome was restarted because a previous session ended. | 1281 // assume that Chrome was restarted because a previous session ended. |
| 1279 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 1282 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1280 chromeos::switches::kFirstExecAfterBoot)) { | 1283 chromeos::switches::kFirstExecAfterBoot)) { |
| 1281 const std::string last_email = | 1284 const std::string last_email = |
| 1282 GetLocalState()->GetString(kLastLoggedInGaiaUser); | 1285 GetLocalState()->GetString(kLastLoggedInGaiaUser); |
| 1283 const base::TimeDelta time_to_login = | 1286 const base::TimeDelta time_to_login = |
| 1284 base::TimeTicks::Now() - manager_creation_time_; | 1287 base::TimeTicks::Now() - manager_creation_time_; |
| 1285 if (!last_email.empty() && user_id != last_email && | 1288 if (!last_email.empty() && user_id != UserID::FromUserEmail(last_email) && |
| 1286 time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) { | 1289 time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) { |
| 1287 UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay", | 1290 UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay", |
| 1288 time_to_login.InSeconds(), | 1291 time_to_login.InSeconds(), |
| 1289 0, | 1292 0, |
| 1290 kLogoutToLoginDelayMaxSec, | 1293 kLogoutToLoginDelayMaxSec, |
| 1291 50); | 1294 50); |
| 1292 } | 1295 } |
| 1293 } | 1296 } |
| 1294 } | 1297 } |
| 1295 | 1298 |
| 1296 void UserManagerBase::UpdateUserAccountLocale(const std::string& user_id, | 1299 void UserManagerBase::UpdateUserAccountLocale(const UserID& user_id, |
| 1297 const std::string& locale) { | 1300 const std::string& locale) { |
| 1298 scoped_ptr<std::string> resolved_locale(new std::string()); | 1301 scoped_ptr<std::string> resolved_locale(new std::string()); |
| 1299 if (!locale.empty() && locale != GetApplicationLocale()) { | 1302 if (!locale.empty() && locale != GetApplicationLocale()) { |
| 1300 // base::Pased will NULL out |resolved_locale|, so cache the underlying ptr. | 1303 // base::Pased will NULL out |resolved_locale|, so cache the underlying ptr. |
| 1301 std::string* raw_resolved_locale = resolved_locale.get(); | 1304 std::string* raw_resolved_locale = resolved_locale.get(); |
| 1302 blocking_task_runner_->PostTaskAndReply( | 1305 blocking_task_runner_->PostTaskAndReply( |
| 1303 FROM_HERE, | 1306 FROM_HERE, |
| 1304 base::Bind(ResolveLocale, | 1307 base::Bind(ResolveLocale, |
| 1305 locale, | 1308 locale, |
| 1306 base::Unretained(raw_resolved_locale)), | 1309 base::Unretained(raw_resolved_locale)), |
| 1307 base::Bind(&UserManagerBase::DoUpdateAccountLocale, | 1310 base::Bind(&UserManagerBase::DoUpdateAccountLocale, |
| 1308 weak_factory_.GetWeakPtr(), | 1311 weak_factory_.GetWeakPtr(), |
| 1309 user_id, | 1312 user_id, |
| 1310 base::Passed(&resolved_locale))); | 1313 base::Passed(&resolved_locale))); |
| 1311 } else { | 1314 } else { |
| 1312 resolved_locale.reset(new std::string(locale)); | 1315 resolved_locale.reset(new std::string(locale)); |
| 1313 DoUpdateAccountLocale(user_id, resolved_locale.Pass()); | 1316 DoUpdateAccountLocale(user_id, resolved_locale.Pass()); |
| 1314 } | 1317 } |
| 1315 } | 1318 } |
| 1316 | 1319 |
| 1317 void UserManagerBase::DoUpdateAccountLocale( | 1320 void UserManagerBase::DoUpdateAccountLocale( |
| 1318 const std::string& user_id, | 1321 const UserID& user_id, |
| 1319 scoped_ptr<std::string> resolved_locale) { | 1322 scoped_ptr<std::string> resolved_locale) { |
| 1320 User* user = FindUserAndModify(user_id); | 1323 User* user = FindUserAndModify(user_id); |
| 1321 if (user && resolved_locale) | 1324 if (user && resolved_locale) |
| 1322 user->SetAccountLocale(*resolved_locale); | 1325 user->SetAccountLocale(*resolved_locale); |
| 1323 } | 1326 } |
| 1324 | 1327 |
| 1325 void UserManagerBase::DeleteUser(User* user) { | 1328 void UserManagerBase::DeleteUser(User* user) { |
| 1326 const bool is_active_user = (user == active_user_); | 1329 const bool is_active_user = (user == active_user_); |
| 1327 delete user; | 1330 delete user; |
| 1328 if (is_active_user) | 1331 if (is_active_user) |
| 1329 active_user_ = NULL; | 1332 active_user_ = NULL; |
| 1330 } | 1333 } |
| 1331 | 1334 |
| 1332 } // namespace user_manager | 1335 } // namespace user_manager |
| OLD | NEW |