| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 << " failed, return code: " << return_code; | 108 << " failed, return code: " << return_code; |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 // Runs on SequencedWorkerPool thread. Passes resolved locale to UI thread. | 112 // Runs on SequencedWorkerPool thread. Passes resolved locale to UI thread. |
| 113 void ResolveLocale(const std::string& raw_locale, | 113 void ResolveLocale(const std::string& raw_locale, |
| 114 std::string* resolved_locale) { | 114 std::string* resolved_locale) { |
| 115 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale)); | 115 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale)); |
| 116 } | 116 } |
| 117 | 117 |
| 118 // Checks if values in |dict| correspond with |account_id| identity. | 118 // Checks if values in |dict| correspond with |user_id| identity. |
| 119 bool UserMatches(const AccountId& account_id, | 119 bool UserMatches(const UserID& user_id, const base::DictionaryValue& dict) { |
| 120 const base::DictionaryValue& dict) { | |
| 121 std::string value; | 120 std::string value; |
| 122 | 121 |
| 123 bool has_email = dict.GetString(kCanonicalEmail, &value); | 122 bool has_email = dict.GetString(kCanonicalEmail, &value); |
| 124 if (has_email && account_id.GetUserEmail() == value) | 123 if (has_email && user_id == value) |
| 125 return true; | 124 return true; |
| 126 | 125 |
| 127 // TODO(antrim): update code once user id is really a struct. | 126 // TODO(antrim): update code once user id is really a struct. |
| 128 bool has_gaia_id = dict.GetString(kGAIAIdKey, &value); | 127 bool has_gaia_id = dict.GetString(kGAIAIdKey, &value); |
| 129 if (has_gaia_id && account_id.GetUserEmail() == value) | 128 if (has_gaia_id && user_id == value) |
| 130 return true; | 129 return true; |
| 131 | 130 |
| 132 return false; | 131 return false; |
| 133 } | 132 } |
| 134 | 133 |
| 135 // Fills relevant |dict| values based on |account_id|. | 134 // Fills relevant |dict| values based on |user_id|. |
| 136 void UpdateIdentity(const AccountId& account_id, base::DictionaryValue& dict) { | 135 void UpdateIdentity(const UserID& user_id, base::DictionaryValue& dict) { |
| 137 dict.SetString(kCanonicalEmail, account_id.GetUserEmail()); | 136 dict.SetString(kCanonicalEmail, user_id); |
| 138 } | 137 } |
| 139 | 138 |
| 140 } // namespace | 139 } // namespace |
| 141 | 140 |
| 142 // static | 141 // static |
| 143 void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) { | 142 void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) { |
| 144 registry->RegisterListPref(kRegularUsers); | 143 registry->RegisterListPref(kRegularUsers); |
| 145 registry->RegisterListPref(kKnownUsers); | 144 registry->RegisterListPref(kKnownUsers); |
| 146 registry->RegisterStringPref(kLastLoggedInGaiaUser, std::string()); | 145 registry->RegisterStringPref(kLastLoggedInGaiaUser, std::string()); |
| 147 registry->RegisterDictionaryPref(kUserDisplayName); | 146 registry->RegisterDictionaryPref(kUserDisplayName); |
| 148 registry->RegisterDictionaryPref(kUserGivenName); | 147 registry->RegisterDictionaryPref(kUserGivenName); |
| 149 registry->RegisterDictionaryPref(kUserDisplayEmail); | 148 registry->RegisterDictionaryPref(kUserDisplayEmail); |
| 150 registry->RegisterDictionaryPref(kUserOAuthTokenStatus); | 149 registry->RegisterDictionaryPref(kUserOAuthTokenStatus); |
| 151 registry->RegisterDictionaryPref(kUserForceOnlineSignin); | 150 registry->RegisterDictionaryPref(kUserForceOnlineSignin); |
| 152 registry->RegisterDictionaryPref(kUserType); | 151 registry->RegisterDictionaryPref(kUserType); |
| 153 registry->RegisterStringPref(kLastActiveUser, std::string()); | 152 registry->RegisterStringPref(kLastActiveUser, std::string()); |
| 154 } | 153 } |
| 155 | 154 |
| 156 UserManagerBase::UserManagerBase( | 155 UserManagerBase::UserManagerBase( |
| 157 scoped_refptr<base::TaskRunner> task_runner, | 156 scoped_refptr<base::TaskRunner> task_runner, |
| 158 scoped_refptr<base::TaskRunner> blocking_task_runner) | 157 scoped_refptr<base::TaskRunner> blocking_task_runner) |
| 159 : task_runner_(task_runner), | 158 : active_user_(NULL), |
| 159 primary_user_(NULL), |
| 160 user_loading_stage_(STAGE_NOT_LOADED), |
| 161 session_started_(false), |
| 162 is_current_user_owner_(false), |
| 163 is_current_user_new_(false), |
| 164 is_current_user_ephemeral_regular_user_(false), |
| 165 ephemeral_users_enabled_(false), |
| 166 manager_creation_time_(base::TimeTicks::Now()), |
| 167 last_session_active_user_initialized_(false), |
| 168 task_runner_(task_runner), |
| 160 blocking_task_runner_(blocking_task_runner), | 169 blocking_task_runner_(blocking_task_runner), |
| 161 weak_factory_(this) { | 170 weak_factory_(this) { |
| 162 UpdateLoginState(); | 171 UpdateLoginState(); |
| 163 } | 172 } |
| 164 | 173 |
| 165 UserManagerBase::~UserManagerBase() { | 174 UserManagerBase::~UserManagerBase() { |
| 166 // Can't use STLDeleteElements because of the private destructor of User. | 175 // Can't use STLDeleteElements because of the private destructor of User. |
| 167 for (UserList::iterator it = users_.begin(); it != users_.end(); | 176 for (UserList::iterator it = users_.begin(); it != users_.end(); |
| 168 it = users_.erase(it)) { | 177 it = users_.erase(it)) { |
| 169 DeleteUser(*it); | 178 DeleteUser(*it); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 185 } | 194 } |
| 186 | 195 |
| 187 const UserList& UserManagerBase::GetLoggedInUsers() const { | 196 const UserList& UserManagerBase::GetLoggedInUsers() const { |
| 188 return logged_in_users_; | 197 return logged_in_users_; |
| 189 } | 198 } |
| 190 | 199 |
| 191 const UserList& UserManagerBase::GetLRULoggedInUsers() const { | 200 const UserList& UserManagerBase::GetLRULoggedInUsers() const { |
| 192 return lru_logged_in_users_; | 201 return lru_logged_in_users_; |
| 193 } | 202 } |
| 194 | 203 |
| 195 const AccountId& UserManagerBase::GetOwnerAccountId() const { | 204 const std::string& UserManagerBase::GetOwnerEmail() const { |
| 196 return owner_account_id_; | 205 return owner_email_; |
| 197 } | 206 } |
| 198 | 207 |
| 199 void UserManagerBase::UserLoggedIn(const AccountId& account_id, | 208 void UserManagerBase::UserLoggedIn(const std::string& user_id, |
| 200 const std::string& username_hash, | 209 const std::string& username_hash, |
| 201 bool browser_restart) { | 210 bool browser_restart) { |
| 202 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 211 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 203 | 212 |
| 204 if (!last_session_active_account_id_initialized_) { | 213 if (!last_session_active_user_initialized_) { |
| 205 last_session_active_account_id_ = | 214 last_session_active_user_ = GetLocalState()->GetString(kLastActiveUser); |
| 206 AccountId::FromUserEmail(GetLocalState()->GetString(kLastActiveUser)); | 215 last_session_active_user_initialized_ = true; |
| 207 last_session_active_account_id_initialized_ = true; | |
| 208 } | 216 } |
| 209 | 217 |
| 210 User* user = FindUserInListAndModify(account_id); | 218 User* user = FindUserInListAndModify(user_id); |
| 211 if (active_user_ && user) { | 219 if (active_user_ && user) { |
| 212 user->set_is_logged_in(true); | 220 user->set_is_logged_in(true); |
| 213 user->set_username_hash(username_hash); | 221 user->set_username_hash(username_hash); |
| 214 logged_in_users_.push_back(user); | 222 logged_in_users_.push_back(user); |
| 215 lru_logged_in_users_.push_back(user); | 223 lru_logged_in_users_.push_back(user); |
| 216 | 224 |
| 217 // Reset the new user flag if the user already exists. | 225 // Reset the new user flag if the user already exists. |
| 218 SetIsCurrentUserNew(false); | 226 SetIsCurrentUserNew(false); |
| 219 NotifyUserAddedToSession(user, true /* user switch pending */); | 227 NotifyUserAddedToSession(user, true /* user switch pending */); |
| 220 | 228 |
| 221 return; | 229 return; |
| 222 } | 230 } |
| 223 | 231 |
| 224 if (account_id == chromeos::login::GuestAccountId()) { | 232 if (user_id == chromeos::login::kGuestUserName) { |
| 225 GuestUserLoggedIn(); | 233 GuestUserLoggedIn(); |
| 226 } else if (IsKioskApp(account_id)) { | 234 } else if (IsKioskApp(user_id)) { |
| 227 KioskAppLoggedIn(account_id); | 235 KioskAppLoggedIn(user_id); |
| 228 } else if (IsDemoApp(account_id)) { | 236 } else if (IsDemoApp(user_id)) { |
| 229 DemoAccountLoggedIn(); | 237 DemoAccountLoggedIn(); |
| 230 } else { | 238 } else { |
| 231 EnsureUsersLoaded(); | 239 EnsureUsersLoaded(); |
| 232 | 240 |
| 233 if (user && user->GetType() == USER_TYPE_PUBLIC_ACCOUNT) { | 241 if (user && user->GetType() == USER_TYPE_PUBLIC_ACCOUNT) { |
| 234 PublicAccountUserLoggedIn(user); | 242 PublicAccountUserLoggedIn(user); |
| 235 } else if ((user && user->GetType() == USER_TYPE_SUPERVISED) || | 243 } else if ((user && user->GetType() == USER_TYPE_SUPERVISED) || |
| 236 (!user && | 244 (!user && |
| 237 gaia::ExtractDomainName(account_id.GetUserEmail()) == | 245 gaia::ExtractDomainName(user_id) == |
| 238 chromeos::login::kSupervisedUserDomain)) { | 246 chromeos::login::kSupervisedUserDomain)) { |
| 239 SupervisedUserLoggedIn(account_id); | 247 SupervisedUserLoggedIn(user_id); |
| 240 } else if (browser_restart && IsPublicAccountMarkedForRemoval(account_id)) { | 248 } else if (browser_restart && IsPublicAccountMarkedForRemoval(user_id)) { |
| 241 PublicAccountUserLoggedIn(User::CreatePublicAccountUser(account_id)); | 249 PublicAccountUserLoggedIn(User::CreatePublicAccountUser(user_id)); |
| 242 } else if (account_id != GetOwnerAccountId() && !user && | 250 } else if (user_id != GetOwnerEmail() && !user && |
| 243 (AreEphemeralUsersEnabled() || browser_restart)) { | 251 (AreEphemeralUsersEnabled() || browser_restart)) { |
| 244 RegularUserLoggedInAsEphemeral(account_id); | 252 RegularUserLoggedInAsEphemeral(user_id); |
| 245 } else { | 253 } else { |
| 246 RegularUserLoggedIn(account_id); | 254 RegularUserLoggedIn(user_id); |
| 247 } | 255 } |
| 248 } | 256 } |
| 249 | 257 |
| 250 DCHECK(active_user_); | 258 DCHECK(active_user_); |
| 251 active_user_->set_is_logged_in(true); | 259 active_user_->set_is_logged_in(true); |
| 252 active_user_->set_is_active(true); | 260 active_user_->set_is_active(true); |
| 253 active_user_->set_username_hash(username_hash); | 261 active_user_->set_username_hash(username_hash); |
| 254 | 262 |
| 255 // 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. |
| 256 logged_in_users_.insert(logged_in_users_.begin(), active_user_); | 264 logged_in_users_.insert(logged_in_users_.begin(), active_user_); |
| 257 SetLRUUser(active_user_); | 265 SetLRUUser(active_user_); |
| 258 | 266 |
| 259 if (!primary_user_) { | 267 if (!primary_user_) { |
| 260 primary_user_ = active_user_; | 268 primary_user_ = active_user_; |
| 261 if (primary_user_->HasGaiaAccount()) | 269 if (primary_user_->HasGaiaAccount()) |
| 262 SendGaiaUserLoginMetrics(account_id); | 270 SendGaiaUserLoginMetrics(user_id); |
| 263 } | 271 } |
| 264 | 272 |
| 265 UMA_HISTOGRAM_ENUMERATION( | 273 UMA_HISTOGRAM_ENUMERATION( |
| 266 "UserManager.LoginUserType", active_user_->GetType(), NUM_USER_TYPES); | 274 "UserManager.LoginUserType", active_user_->GetType(), NUM_USER_TYPES); |
| 267 | 275 |
| 268 GetLocalState()->SetString( | 276 GetLocalState()->SetString( |
| 269 kLastLoggedInGaiaUser, | 277 kLastLoggedInGaiaUser, active_user_->HasGaiaAccount() ? user_id : ""); |
| 270 active_user_->HasGaiaAccount() ? account_id.GetUserEmail() : ""); | |
| 271 | 278 |
| 272 NotifyOnLogin(); | 279 NotifyOnLogin(); |
| 273 PerformPostUserLoggedInActions(browser_restart); | 280 PerformPostUserLoggedInActions(browser_restart); |
| 274 } | 281 } |
| 275 | 282 |
| 276 void UserManagerBase::SwitchActiveUser(const AccountId& account_id) { | 283 void UserManagerBase::SwitchActiveUser(const std::string& user_id) { |
| 277 User* user = FindUserAndModify(account_id); | 284 User* user = FindUserAndModify(user_id); |
| 278 if (!user) { | 285 if (!user) { |
| 279 NOTREACHED() << "Switching to a non-existing user"; | 286 NOTREACHED() << "Switching to a non-existing user"; |
| 280 return; | 287 return; |
| 281 } | 288 } |
| 282 if (user == active_user_) { | 289 if (user == active_user_) { |
| 283 NOTREACHED() << "Switching to a user who is already active"; | 290 NOTREACHED() << "Switching to a user who is already active"; |
| 284 return; | 291 return; |
| 285 } | 292 } |
| 286 if (!user->is_logged_in()) { | 293 if (!user->is_logged_in()) { |
| 287 NOTREACHED() << "Switching to a user that is not logged in"; | 294 NOTREACHED() << "Switching to a user that is not logged in"; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 303 active_user_ = user; | 310 active_user_ = user; |
| 304 | 311 |
| 305 // Move the user to the front. | 312 // Move the user to the front. |
| 306 SetLRUUser(active_user_); | 313 SetLRUUser(active_user_); |
| 307 | 314 |
| 308 NotifyActiveUserHashChanged(active_user_->username_hash()); | 315 NotifyActiveUserHashChanged(active_user_->username_hash()); |
| 309 NotifyActiveUserChanged(active_user_); | 316 NotifyActiveUserChanged(active_user_); |
| 310 } | 317 } |
| 311 | 318 |
| 312 void UserManagerBase::SwitchToLastActiveUser() { | 319 void UserManagerBase::SwitchToLastActiveUser() { |
| 313 if (!last_session_active_account_id_.is_valid()) | 320 if (last_session_active_user_.empty()) |
| 314 return; | 321 return; |
| 315 | 322 |
| 316 if (AccountId::FromUserEmail(GetActiveUser()->email()) != | 323 if (GetActiveUser()->email() != last_session_active_user_) |
| 317 last_session_active_account_id_) | 324 SwitchActiveUser(last_session_active_user_); |
| 318 SwitchActiveUser(last_session_active_account_id_); | |
| 319 | 325 |
| 320 // Make sure that this function gets run only once. | 326 // Make sure that this function gets run only once. |
| 321 last_session_active_account_id_.clear(); | 327 last_session_active_user_.clear(); |
| 322 } | 328 } |
| 323 | 329 |
| 324 void UserManagerBase::SessionStarted() { | 330 void UserManagerBase::SessionStarted() { |
| 325 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 331 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 326 session_started_ = true; | 332 session_started_ = true; |
| 327 | 333 |
| 328 UpdateLoginState(); | 334 UpdateLoginState(); |
| 329 session_manager::SessionManager::Get()->SetSessionState( | 335 session_manager::SessionManager::Get()->SetSessionState( |
| 330 session_manager::SESSION_STATE_ACTIVE); | 336 session_manager::SESSION_STATE_ACTIVE); |
| 331 | 337 |
| 332 if (IsCurrentUserNew()) { | 338 if (IsCurrentUserNew()) { |
| 333 // 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. |
| 334 GetLocalState()->CommitPendingWrite(); | 340 GetLocalState()->CommitPendingWrite(); |
| 335 } | 341 } |
| 336 } | 342 } |
| 337 | 343 |
| 338 void UserManagerBase::RemoveUser(const AccountId& account_id, | 344 void UserManagerBase::RemoveUser(const std::string& user_id, |
| 339 RemoveUserDelegate* delegate) { | 345 RemoveUserDelegate* delegate) { |
| 340 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 346 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 341 | 347 |
| 342 if (!CanUserBeRemoved(FindUser(account_id))) | 348 if (!CanUserBeRemoved(FindUser(user_id))) |
| 343 return; | 349 return; |
| 344 | 350 |
| 345 RemoveUserInternal(account_id, delegate); | 351 RemoveUserInternal(user_id, delegate); |
| 346 } | 352 } |
| 347 | 353 |
| 348 void UserManagerBase::RemoveUserInternal(const AccountId& account_id, | 354 void UserManagerBase::RemoveUserInternal(const std::string& user_email, |
| 349 RemoveUserDelegate* delegate) { | 355 RemoveUserDelegate* delegate) { |
| 350 RemoveNonOwnerUserInternal(account_id, delegate); | 356 RemoveNonOwnerUserInternal(user_email, delegate); |
| 351 } | 357 } |
| 352 | 358 |
| 353 void UserManagerBase::RemoveNonOwnerUserInternal(const AccountId& account_id, | 359 void UserManagerBase::RemoveNonOwnerUserInternal(const std::string& user_email, |
| 354 RemoveUserDelegate* delegate) { | 360 RemoveUserDelegate* delegate) { |
| 355 if (delegate) | 361 if (delegate) |
| 356 delegate->OnBeforeUserRemoved(account_id.GetUserEmail()); | 362 delegate->OnBeforeUserRemoved(user_email); |
| 357 RemoveUserFromList(account_id); | 363 RemoveUserFromList(user_email); |
| 358 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( | 364 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( |
| 359 account_id.GetUserEmail(), | 365 user_email, base::Bind(&OnRemoveUserComplete, user_email)); |
| 360 base::Bind(&OnRemoveUserComplete, account_id.GetUserEmail())); | |
| 361 | 366 |
| 362 if (delegate) | 367 if (delegate) |
| 363 delegate->OnUserRemoved(account_id.GetUserEmail()); | 368 delegate->OnUserRemoved(user_email); |
| 364 } | 369 } |
| 365 | 370 |
| 366 void UserManagerBase::RemoveUserFromList(const AccountId& account_id) { | 371 void UserManagerBase::RemoveUserFromList(const std::string& user_id) { |
| 367 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 372 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 368 RemoveNonCryptohomeData(account_id); | 373 RemoveNonCryptohomeData(user_id); |
| 369 if (user_loading_stage_ == STAGE_LOADED) { | 374 if (user_loading_stage_ == STAGE_LOADED) { |
| 370 DeleteUser(RemoveRegularOrSupervisedUserFromList(account_id)); | 375 DeleteUser(RemoveRegularOrSupervisedUserFromList(user_id)); |
| 371 } else if (user_loading_stage_ == STAGE_LOADING) { | 376 } else if (user_loading_stage_ == STAGE_LOADING) { |
| 372 DCHECK(gaia::ExtractDomainName(account_id.GetUserEmail()) == | 377 DCHECK(gaia::ExtractDomainName(user_id) == |
| 373 chromeos::login::kSupervisedUserDomain || | 378 chromeos::login::kSupervisedUserDomain || |
| 374 HasPendingBootstrap(account_id)); | 379 HasPendingBootstrap(user_id)); |
| 375 // Special case, removing partially-constructed supervised user or | 380 // Special case, removing partially-constructed supervised user or |
| 376 // boostrapping user during user list loading. | 381 // boostrapping user during user list loading. |
| 377 ListPrefUpdate users_update(GetLocalState(), kRegularUsers); | 382 ListPrefUpdate users_update(GetLocalState(), kRegularUsers); |
| 378 users_update->Remove(base::StringValue(account_id.GetUserEmail()), nullptr); | 383 users_update->Remove(base::StringValue(user_id), NULL); |
| 379 OnUserRemoved(account_id); | 384 OnUserRemoved(user_id); |
| 380 } else { | 385 } else { |
| 381 NOTREACHED() << "Users are not loaded yet."; | 386 NOTREACHED() << "Users are not loaded yet."; |
| 382 return; | 387 return; |
| 383 } | 388 } |
| 384 | 389 |
| 385 // Make sure that new data is persisted to Local State. | 390 // Make sure that new data is persisted to Local State. |
| 386 GetLocalState()->CommitPendingWrite(); | 391 GetLocalState()->CommitPendingWrite(); |
| 387 } | 392 } |
| 388 | 393 |
| 389 bool UserManagerBase::IsKnownUser(const AccountId& account_id) const { | 394 bool UserManagerBase::IsKnownUser(const std::string& user_id) const { |
| 390 return FindUser(account_id) != nullptr; | 395 return FindUser(user_id) != NULL; |
| 391 } | 396 } |
| 392 | 397 |
| 393 const User* UserManagerBase::FindUser(const AccountId& account_id) const { | 398 const User* UserManagerBase::FindUser(const std::string& user_id) const { |
| 394 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 399 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 395 if (active_user_ && active_user_->GetAccountId() == account_id) | 400 if (active_user_ && active_user_->email() == user_id) |
| 396 return active_user_; | 401 return active_user_; |
| 397 return FindUserInList(account_id); | 402 return FindUserInList(user_id); |
| 398 } | 403 } |
| 399 | 404 |
| 400 User* UserManagerBase::FindUserAndModify(const AccountId& account_id) { | 405 User* UserManagerBase::FindUserAndModify(const std::string& user_id) { |
| 401 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 406 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 402 if (active_user_ && active_user_->GetAccountId() == account_id) | 407 if (active_user_ && active_user_->email() == user_id) |
| 403 return active_user_; | 408 return active_user_; |
| 404 return FindUserInListAndModify(account_id); | 409 return FindUserInListAndModify(user_id); |
| 405 } | 410 } |
| 406 | 411 |
| 407 const User* UserManagerBase::GetLoggedInUser() const { | 412 const User* UserManagerBase::GetLoggedInUser() const { |
| 408 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 413 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 409 return active_user_; | 414 return active_user_; |
| 410 } | 415 } |
| 411 | 416 |
| 412 User* UserManagerBase::GetLoggedInUser() { | 417 User* UserManagerBase::GetLoggedInUser() { |
| 413 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 418 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 414 return active_user_; | 419 return active_user_; |
| 415 } | 420 } |
| 416 | 421 |
| 417 const User* UserManagerBase::GetActiveUser() const { | 422 const User* UserManagerBase::GetActiveUser() const { |
| 418 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 423 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 419 return active_user_; | 424 return active_user_; |
| 420 } | 425 } |
| 421 | 426 |
| 422 User* UserManagerBase::GetActiveUser() { | 427 User* UserManagerBase::GetActiveUser() { |
| 423 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 428 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 424 return active_user_; | 429 return active_user_; |
| 425 } | 430 } |
| 426 | 431 |
| 427 const User* UserManagerBase::GetPrimaryUser() const { | 432 const User* UserManagerBase::GetPrimaryUser() const { |
| 428 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 433 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 429 return primary_user_; | 434 return primary_user_; |
| 430 } | 435 } |
| 431 | 436 |
| 432 void UserManagerBase::SaveUserOAuthStatus( | 437 void UserManagerBase::SaveUserOAuthStatus( |
| 433 const AccountId& account_id, | 438 const std::string& user_id, |
| 434 User::OAuthTokenStatus oauth_token_status) { | 439 User::OAuthTokenStatus oauth_token_status) { |
| 435 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 440 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 436 | 441 |
| 437 DVLOG(1) << "Saving user OAuth token status in Local State"; | 442 DVLOG(1) << "Saving user OAuth token status in Local State"; |
| 438 User* user = FindUserAndModify(account_id); | 443 User* user = FindUserAndModify(user_id); |
| 439 if (user) | 444 if (user) |
| 440 user->set_oauth_token_status(oauth_token_status); | 445 user->set_oauth_token_status(oauth_token_status); |
| 441 | 446 |
| 442 // Do not update local state if data stored or cached outside the user's | 447 // Do not update local state if data stored or cached outside the user's |
| 443 // cryptohome is to be treated as ephemeral. | 448 // cryptohome is to be treated as ephemeral. |
| 444 if (IsUserNonCryptohomeDataEphemeral(account_id)) | 449 if (IsUserNonCryptohomeDataEphemeral(user_id)) |
| 445 return; | 450 return; |
| 446 | 451 |
| 447 DictionaryPrefUpdate oauth_status_update(GetLocalState(), | 452 DictionaryPrefUpdate oauth_status_update(GetLocalState(), |
| 448 kUserOAuthTokenStatus); | 453 kUserOAuthTokenStatus); |
| 449 oauth_status_update->SetWithoutPathExpansion( | 454 oauth_status_update->SetWithoutPathExpansion( |
| 450 account_id.GetUserEmail(), | 455 user_id, |
| 451 new base::FundamentalValue(static_cast<int>(oauth_token_status))); | 456 new base::FundamentalValue(static_cast<int>(oauth_token_status))); |
| 452 } | 457 } |
| 453 | 458 |
| 454 void UserManagerBase::SaveForceOnlineSignin(const AccountId& account_id, | 459 void UserManagerBase::SaveForceOnlineSignin(const std::string& user_id, |
| 455 bool force_online_signin) { | 460 bool force_online_signin) { |
| 456 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 461 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 457 | 462 |
| 458 // Do not update local state if data stored or cached outside the user's | 463 // Do not update local state if data stored or cached outside the user's |
| 459 // cryptohome is to be treated as ephemeral. | 464 // cryptohome is to be treated as ephemeral. |
| 460 if (IsUserNonCryptohomeDataEphemeral(account_id)) | 465 if (IsUserNonCryptohomeDataEphemeral(user_id)) |
| 461 return; | 466 return; |
| 462 | 467 |
| 463 DictionaryPrefUpdate force_online_update(GetLocalState(), | 468 DictionaryPrefUpdate force_online_update(GetLocalState(), |
| 464 kUserForceOnlineSignin); | 469 kUserForceOnlineSignin); |
| 465 force_online_update->SetBooleanWithoutPathExpansion(account_id.GetUserEmail(), | 470 force_online_update->SetBooleanWithoutPathExpansion(user_id, |
| 466 force_online_signin); | 471 force_online_signin); |
| 467 } | 472 } |
| 468 | 473 |
| 469 void UserManagerBase::SaveUserDisplayName(const AccountId& account_id, | 474 void UserManagerBase::SaveUserDisplayName(const std::string& user_id, |
| 470 const base::string16& display_name) { | 475 const base::string16& display_name) { |
| 471 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 476 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 472 | 477 |
| 473 if (User* user = FindUserAndModify(account_id)) { | 478 if (User* user = FindUserAndModify(user_id)) { |
| 474 user->set_display_name(display_name); | 479 user->set_display_name(display_name); |
| 475 | 480 |
| 476 // Do not update local state if data stored or cached outside the user's | 481 // Do not update local state if data stored or cached outside the user's |
| 477 // cryptohome is to be treated as ephemeral. | 482 // cryptohome is to be treated as ephemeral. |
| 478 if (!IsUserNonCryptohomeDataEphemeral(account_id)) { | 483 if (!IsUserNonCryptohomeDataEphemeral(user_id)) { |
| 479 DictionaryPrefUpdate display_name_update(GetLocalState(), | 484 DictionaryPrefUpdate display_name_update(GetLocalState(), |
| 480 kUserDisplayName); | 485 kUserDisplayName); |
| 481 display_name_update->SetWithoutPathExpansion( | 486 display_name_update->SetWithoutPathExpansion( |
| 482 account_id.GetUserEmail(), new base::StringValue(display_name)); | 487 user_id, new base::StringValue(display_name)); |
| 483 } | 488 } |
| 484 } | 489 } |
| 485 } | 490 } |
| 486 | 491 |
| 487 base::string16 UserManagerBase::GetUserDisplayName( | 492 base::string16 UserManagerBase::GetUserDisplayName( |
| 488 const AccountId& account_id) const { | 493 const std::string& user_id) const { |
| 489 const User* user = FindUser(account_id); | 494 const User* user = FindUser(user_id); |
| 490 return user ? user->display_name() : base::string16(); | 495 return user ? user->display_name() : base::string16(); |
| 491 } | 496 } |
| 492 | 497 |
| 493 void UserManagerBase::SaveUserDisplayEmail(const AccountId& account_id, | 498 void UserManagerBase::SaveUserDisplayEmail(const std::string& user_id, |
| 494 const std::string& display_email) { | 499 const std::string& display_email) { |
| 495 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 500 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 496 | 501 |
| 497 User* user = FindUserAndModify(account_id); | 502 User* user = FindUserAndModify(user_id); |
| 498 if (!user) { | 503 if (!user) { |
| 499 LOG(ERROR) << "User not found: " << account_id.GetUserEmail(); | 504 LOG(ERROR) << "User not found: " << user_id; |
| 500 return; // Ignore if there is no such user. | 505 return; // Ignore if there is no such user. |
| 501 } | 506 } |
| 502 | 507 |
| 503 user->set_display_email(display_email); | 508 user->set_display_email(display_email); |
| 504 | 509 |
| 505 // Do not update local state if data stored or cached outside the user's | 510 // Do not update local state if data stored or cached outside the user's |
| 506 // cryptohome is to be treated as ephemeral. | 511 // cryptohome is to be treated as ephemeral. |
| 507 if (IsUserNonCryptohomeDataEphemeral(account_id)) | 512 if (IsUserNonCryptohomeDataEphemeral(user_id)) |
| 508 return; | 513 return; |
| 509 | 514 |
| 510 DictionaryPrefUpdate display_email_update(GetLocalState(), kUserDisplayEmail); | 515 DictionaryPrefUpdate display_email_update(GetLocalState(), kUserDisplayEmail); |
| 511 display_email_update->SetWithoutPathExpansion( | 516 display_email_update->SetWithoutPathExpansion( |
| 512 account_id.GetUserEmail(), new base::StringValue(display_email)); | 517 user_id, new base::StringValue(display_email)); |
| 513 } | 518 } |
| 514 | 519 |
| 515 std::string UserManagerBase::GetUserDisplayEmail( | 520 std::string UserManagerBase::GetUserDisplayEmail( |
| 516 const AccountId& account_id) const { | 521 const std::string& user_id) const { |
| 517 const User* user = FindUser(account_id); | 522 const User* user = FindUser(user_id); |
| 518 return user ? user->display_email() : account_id.GetUserEmail(); | 523 return user ? user->display_email() : user_id; |
| 519 } | 524 } |
| 520 | 525 |
| 521 void UserManagerBase::SaveUserType(const AccountId& account_id, | 526 void UserManagerBase::SaveUserType(const std::string& user_id, |
| 522 const UserType& user_type) { | 527 const UserType& user_type) { |
| 523 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 528 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 524 | 529 |
| 525 User* user = FindUserAndModify(account_id); | 530 User* user = FindUserAndModify(user_id); |
| 526 if (!user) { | 531 if (!user) { |
| 527 LOG(ERROR) << "User not found: " << account_id.GetUserEmail(); | 532 LOG(ERROR) << "User not found: " << user_id; |
| 528 return; // Ignore if there is no such user. | 533 return; // Ignore if there is no such user. |
| 529 } | 534 } |
| 530 | 535 |
| 531 // Do not update local state if data stored or cached outside the user's | 536 // Do not update local state if data stored or cached outside the user's |
| 532 // cryptohome is to be treated as ephemeral. | 537 // cryptohome is to be treated as ephemeral. |
| 533 if (IsUserNonCryptohomeDataEphemeral(account_id)) | 538 if (IsUserNonCryptohomeDataEphemeral(user_id)) |
| 534 return; | 539 return; |
| 535 | 540 |
| 536 DictionaryPrefUpdate user_type_update(GetLocalState(), kUserType); | 541 DictionaryPrefUpdate user_type_update(GetLocalState(), kUserType); |
| 537 user_type_update->SetWithoutPathExpansion( | 542 user_type_update->SetWithoutPathExpansion( |
| 538 account_id.GetUserEmail(), | 543 user_id, new base::FundamentalValue(static_cast<int>(user_type))); |
| 539 new base::FundamentalValue(static_cast<int>(user_type))); | |
| 540 GetLocalState()->CommitPendingWrite(); | 544 GetLocalState()->CommitPendingWrite(); |
| 541 } | 545 } |
| 542 | 546 |
| 543 void UserManagerBase::UpdateUsingSAML(const AccountId& account_id, | 547 void UserManagerBase::UpdateUsingSAML(const std::string& user_id, |
| 544 const bool using_saml) { | 548 const bool using_saml) { |
| 545 SetKnownUserBooleanPref(account_id, kUsingSAMLKey, using_saml); | 549 SetKnownUserBooleanPref(user_id, kUsingSAMLKey, using_saml); |
| 546 } | 550 } |
| 547 | 551 |
| 548 bool UserManagerBase::FindUsingSAML(const AccountId& account_id) { | 552 bool UserManagerBase::FindUsingSAML(const std::string& user_id) { |
| 549 bool using_saml; | 553 bool using_saml; |
| 550 if (GetKnownUserBooleanPref(account_id, kUsingSAMLKey, &using_saml)) | 554 if (GetKnownUserBooleanPref(user_id, kUsingSAMLKey, &using_saml)) |
| 551 return using_saml; | 555 return using_saml; |
| 552 return false; | 556 return false; |
| 553 } | 557 } |
| 554 | 558 |
| 555 void UserManagerBase::UpdateReauthReason(const AccountId& account_id, | 559 void UserManagerBase::UpdateReauthReason(const std::string& user_id, |
| 556 const int reauth_reason) { | 560 const int reauth_reason) { |
| 557 SetKnownUserIntegerPref(account_id, kReauthReasonKey, reauth_reason); | 561 SetKnownUserIntegerPref(user_id, kReauthReasonKey, reauth_reason); |
| 558 } | 562 } |
| 559 | 563 |
| 560 bool UserManagerBase::FindReauthReason(const AccountId& account_id, | 564 bool UserManagerBase::FindReauthReason(const std::string& user_id, |
| 561 int* out_value) { | 565 int* out_value) { |
| 562 return GetKnownUserIntegerPref(account_id, kReauthReasonKey, out_value); | 566 return GetKnownUserIntegerPref(user_id, kReauthReasonKey, out_value); |
| 563 } | 567 } |
| 564 | 568 |
| 565 void UserManagerBase::UpdateUserAccountData( | 569 void UserManagerBase::UpdateUserAccountData( |
| 566 const AccountId& account_id, | 570 const std::string& user_id, |
| 567 const UserAccountData& account_data) { | 571 const UserAccountData& account_data) { |
| 568 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 572 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 569 | 573 |
| 570 SaveUserDisplayName(account_id, account_data.display_name()); | 574 SaveUserDisplayName(user_id, account_data.display_name()); |
| 571 | 575 |
| 572 if (User* user = FindUserAndModify(account_id)) { | 576 if (User* user = FindUserAndModify(user_id)) { |
| 573 base::string16 given_name = account_data.given_name(); | 577 base::string16 given_name = account_data.given_name(); |
| 574 user->set_given_name(given_name); | 578 user->set_given_name(given_name); |
| 575 if (!IsUserNonCryptohomeDataEphemeral(account_id)) { | 579 if (!IsUserNonCryptohomeDataEphemeral(user_id)) { |
| 576 DictionaryPrefUpdate given_name_update(GetLocalState(), kUserGivenName); | 580 DictionaryPrefUpdate given_name_update(GetLocalState(), kUserGivenName); |
| 577 given_name_update->SetWithoutPathExpansion( | 581 given_name_update->SetWithoutPathExpansion( |
| 578 account_id.GetUserEmail(), new base::StringValue(given_name)); | 582 user_id, new base::StringValue(given_name)); |
| 579 } | 583 } |
| 580 } | 584 } |
| 581 | 585 |
| 582 UpdateUserAccountLocale(account_id, account_data.locale()); | 586 UpdateUserAccountLocale(user_id, account_data.locale()); |
| 583 } | 587 } |
| 584 | 588 |
| 585 // static | 589 // static |
| 586 void UserManagerBase::ParseUserList(const base::ListValue& users_list, | 590 void UserManagerBase::ParseUserList(const base::ListValue& users_list, |
| 587 const std::set<AccountId>& existing_users, | 591 const std::set<std::string>& existing_users, |
| 588 std::vector<AccountId>* users_vector, | 592 std::vector<std::string>* users_vector, |
| 589 std::set<AccountId>* users_set) { | 593 std::set<std::string>* users_set) { |
| 590 users_vector->clear(); | 594 users_vector->clear(); |
| 591 users_set->clear(); | 595 users_set->clear(); |
| 592 for (size_t i = 0; i < users_list.GetSize(); ++i) { | 596 for (size_t i = 0; i < users_list.GetSize(); ++i) { |
| 593 std::string email; | 597 std::string email; |
| 594 if (!users_list.GetString(i, &email) || email.empty()) { | 598 if (!users_list.GetString(i, &email) || email.empty()) { |
| 595 LOG(ERROR) << "Corrupt entry in user list at index " << i << "."; | 599 LOG(ERROR) << "Corrupt entry in user list at index " << i << "."; |
| 596 continue; | 600 continue; |
| 597 } | 601 } |
| 598 const AccountId account_id(AccountId::FromUserEmail(email)); | 602 if (existing_users.find(email) != existing_users.end() || |
| 599 if (existing_users.find(account_id) != existing_users.end() || | 603 !users_set->insert(email).second) { |
| 600 !users_set->insert(account_id).second) { | |
| 601 LOG(ERROR) << "Duplicate user: " << email; | 604 LOG(ERROR) << "Duplicate user: " << email; |
| 602 continue; | 605 continue; |
| 603 } | 606 } |
| 604 users_vector->push_back(account_id); | 607 users_vector->push_back(email); |
| 605 } | 608 } |
| 606 } | 609 } |
| 607 | 610 |
| 608 bool UserManagerBase::IsCurrentUserOwner() const { | 611 bool UserManagerBase::IsCurrentUserOwner() const { |
| 609 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 612 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 610 base::AutoLock lk(is_current_user_owner_lock_); | 613 base::AutoLock lk(is_current_user_owner_lock_); |
| 611 return is_current_user_owner_; | 614 return is_current_user_owner_; |
| 612 } | 615 } |
| 613 | 616 |
| 614 void UserManagerBase::SetCurrentUserIsOwner(bool is_current_user_owner) { | 617 void UserManagerBase::SetCurrentUserIsOwner(bool is_current_user_owner) { |
| 615 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 618 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 616 { | 619 { |
| 617 base::AutoLock lk(is_current_user_owner_lock_); | 620 base::AutoLock lk(is_current_user_owner_lock_); |
| 618 is_current_user_owner_ = is_current_user_owner; | 621 is_current_user_owner_ = is_current_user_owner; |
| 619 } | 622 } |
| 620 UpdateLoginState(); | 623 UpdateLoginState(); |
| 621 } | 624 } |
| 622 | 625 |
| 623 bool UserManagerBase::IsCurrentUserNew() const { | 626 bool UserManagerBase::IsCurrentUserNew() const { |
| 624 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 627 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 625 return is_current_user_new_; | 628 return is_current_user_new_; |
| 626 } | 629 } |
| 627 | 630 |
| 628 bool UserManagerBase::IsCurrentUserNonCryptohomeDataEphemeral() const { | 631 bool UserManagerBase::IsCurrentUserNonCryptohomeDataEphemeral() const { |
| 629 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 632 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 630 return IsUserLoggedIn() && | 633 return IsUserLoggedIn() && |
| 631 IsUserNonCryptohomeDataEphemeral(GetLoggedInUser()->GetAccountId()); | 634 IsUserNonCryptohomeDataEphemeral(GetLoggedInUser()->email()); |
| 632 } | 635 } |
| 633 | 636 |
| 634 bool UserManagerBase::CanCurrentUserLock() const { | 637 bool UserManagerBase::CanCurrentUserLock() const { |
| 635 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 638 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 636 return IsUserLoggedIn() && active_user_->can_lock(); | 639 return IsUserLoggedIn() && active_user_->can_lock(); |
| 637 } | 640 } |
| 638 | 641 |
| 639 bool UserManagerBase::IsUserLoggedIn() const { | 642 bool UserManagerBase::IsUserLoggedIn() const { |
| 640 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 643 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 641 return active_user_; | 644 return active_user_; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 return IsUserLoggedIn() && | 680 return IsUserLoggedIn() && |
| 678 active_user_->email() == chromeos::login::kStubUser; | 681 active_user_->email() == chromeos::login::kStubUser; |
| 679 } | 682 } |
| 680 | 683 |
| 681 bool UserManagerBase::IsSessionStarted() const { | 684 bool UserManagerBase::IsSessionStarted() const { |
| 682 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 685 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 683 return session_started_; | 686 return session_started_; |
| 684 } | 687 } |
| 685 | 688 |
| 686 bool UserManagerBase::IsUserNonCryptohomeDataEphemeral( | 689 bool UserManagerBase::IsUserNonCryptohomeDataEphemeral( |
| 687 const AccountId& account_id) const { | 690 const std::string& user_id) const { |
| 688 // Data belonging to the guest and stub users is always ephemeral. | 691 // Data belonging to the guest and stub users is always ephemeral. |
| 689 if (account_id == chromeos::login::GuestAccountId() || | 692 if (user_id == chromeos::login::kGuestUserName || |
| 690 account_id == chromeos::login::StubAccountId()) { | 693 user_id == chromeos::login::kStubUser) { |
| 691 return true; | 694 return true; |
| 692 } | 695 } |
| 693 | 696 |
| 694 // Data belonging to the owner, anyone found on the user list and obsolete | 697 // Data belonging to the owner, anyone found on the user list and obsolete |
| 695 // public accounts whose data has not been removed yet is not ephemeral. | 698 // public accounts whose data has not been removed yet is not ephemeral. |
| 696 if (account_id == GetOwnerAccountId() || UserExistsInList(account_id) || | 699 if (user_id == GetOwnerEmail() || UserExistsInList(user_id) || |
| 697 IsPublicAccountMarkedForRemoval(account_id)) { | 700 IsPublicAccountMarkedForRemoval(user_id)) { |
| 698 return false; | 701 return false; |
| 699 } | 702 } |
| 700 | 703 |
| 701 // Data belonging to the currently logged-in user is ephemeral when: | 704 // Data belonging to the currently logged-in user is ephemeral when: |
| 702 // a) The user logged into a regular gaia account while the ephemeral users | 705 // a) The user logged into a regular gaia account while the ephemeral users |
| 703 // policy was enabled. | 706 // policy was enabled. |
| 704 // - or - | 707 // - or - |
| 705 // b) The user logged into any other account type. | 708 // b) The user logged into any other account type. |
| 706 if (IsUserLoggedIn() && (account_id == GetLoggedInUser()->GetAccountId()) && | 709 if (IsUserLoggedIn() && (user_id == GetLoggedInUser()->email()) && |
| 707 (is_current_user_ephemeral_regular_user_ || | 710 (is_current_user_ephemeral_regular_user_ || |
| 708 !IsLoggedInAsUserWithGaiaAccount())) { | 711 !IsLoggedInAsUserWithGaiaAccount())) { |
| 709 return true; | 712 return true; |
| 710 } | 713 } |
| 711 | 714 |
| 712 // Data belonging to any other user is ephemeral when: | 715 // Data belonging to any other user is ephemeral when: |
| 713 // a) Going through the regular login flow and the ephemeral users policy is | 716 // a) Going through the regular login flow and the ephemeral users policy is |
| 714 // enabled. | 717 // enabled. |
| 715 // - or - | 718 // - or - |
| 716 // b) The browser is restarting after a crash. | 719 // b) The browser is restarting after a crash. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 } | 779 } |
| 777 | 780 |
| 778 void UserManagerBase::SetEphemeralUsersEnabled(bool enabled) { | 781 void UserManagerBase::SetEphemeralUsersEnabled(bool enabled) { |
| 779 ephemeral_users_enabled_ = enabled; | 782 ephemeral_users_enabled_ = enabled; |
| 780 } | 783 } |
| 781 | 784 |
| 782 void UserManagerBase::SetIsCurrentUserNew(bool is_new) { | 785 void UserManagerBase::SetIsCurrentUserNew(bool is_new) { |
| 783 is_current_user_new_ = is_new; | 786 is_current_user_new_ = is_new; |
| 784 } | 787 } |
| 785 | 788 |
| 786 bool UserManagerBase::HasPendingBootstrap(const AccountId& account_id) const { | 789 bool UserManagerBase::HasPendingBootstrap(const std::string& user_id) const { |
| 787 return false; | 790 return false; |
| 788 } | 791 } |
| 789 | 792 |
| 790 void UserManagerBase::SetOwnerId(const AccountId& owner_account_id) { | 793 void UserManagerBase::SetOwnerEmail(const std::string& owner_user_id) { |
| 791 owner_account_id_ = owner_account_id; | 794 owner_email_ = owner_user_id; |
| 792 } | 795 } |
| 793 | 796 |
| 794 const AccountId& UserManagerBase::GetPendingUserSwitchID() const { | 797 const std::string& UserManagerBase::GetPendingUserSwitchID() const { |
| 795 return pending_user_switch_; | 798 return pending_user_switch_; |
| 796 } | 799 } |
| 797 | 800 |
| 798 void UserManagerBase::SetPendingUserSwitchId(const AccountId& account_id) { | 801 void UserManagerBase::SetPendingUserSwitchID(const std::string& user_id) { |
| 799 pending_user_switch_ = account_id; | 802 pending_user_switch_ = user_id; |
| 800 } | 803 } |
| 801 | 804 |
| 802 void UserManagerBase::EnsureUsersLoaded() { | 805 void UserManagerBase::EnsureUsersLoaded() { |
| 803 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 806 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 804 if (!GetLocalState()) | 807 if (!GetLocalState()) |
| 805 return; | 808 return; |
| 806 | 809 |
| 807 if (user_loading_stage_ != STAGE_NOT_LOADED) | 810 if (user_loading_stage_ != STAGE_NOT_LOADED) |
| 808 return; | 811 return; |
| 809 user_loading_stage_ = STAGE_LOADING; | 812 user_loading_stage_ = STAGE_LOADING; |
| 810 | 813 |
| 811 PerformPreUserListLoadingActions(); | 814 PerformPreUserListLoadingActions(); |
| 812 | 815 |
| 813 PrefService* local_state = GetLocalState(); | 816 PrefService* local_state = GetLocalState(); |
| 814 const base::ListValue* prefs_regular_users = | 817 const base::ListValue* prefs_regular_users = |
| 815 local_state->GetList(kRegularUsers); | 818 local_state->GetList(kRegularUsers); |
| 816 | 819 |
| 817 const base::DictionaryValue* prefs_display_names = | 820 const base::DictionaryValue* prefs_display_names = |
| 818 local_state->GetDictionary(kUserDisplayName); | 821 local_state->GetDictionary(kUserDisplayName); |
| 819 const base::DictionaryValue* prefs_given_names = | 822 const base::DictionaryValue* prefs_given_names = |
| 820 local_state->GetDictionary(kUserGivenName); | 823 local_state->GetDictionary(kUserGivenName); |
| 821 const base::DictionaryValue* prefs_display_emails = | 824 const base::DictionaryValue* prefs_display_emails = |
| 822 local_state->GetDictionary(kUserDisplayEmail); | 825 local_state->GetDictionary(kUserDisplayEmail); |
| 823 const base::DictionaryValue* prefs_user_types = | 826 const base::DictionaryValue* prefs_user_types = |
| 824 local_state->GetDictionary(kUserType); | 827 local_state->GetDictionary(kUserType); |
| 825 | 828 |
| 826 // Load public sessions first. | 829 // Load public sessions first. |
| 827 std::set<AccountId> public_sessions_set; | 830 std::set<std::string> public_sessions_set; |
| 828 LoadPublicAccounts(&public_sessions_set); | 831 LoadPublicAccounts(&public_sessions_set); |
| 829 | 832 |
| 830 // Load regular users and supervised users. | 833 // Load regular users and supervised users. |
| 831 std::vector<AccountId> regular_users; | 834 std::vector<std::string> regular_users; |
| 832 std::set<AccountId> regular_users_set; | 835 std::set<std::string> regular_users_set; |
| 833 ParseUserList(*prefs_regular_users, | 836 ParseUserList(*prefs_regular_users, |
| 834 public_sessions_set, | 837 public_sessions_set, |
| 835 ®ular_users, | 838 ®ular_users, |
| 836 ®ular_users_set); | 839 ®ular_users_set); |
| 837 for (std::vector<AccountId>::const_iterator it = regular_users.begin(); | 840 for (std::vector<std::string>::const_iterator it = regular_users.begin(); |
| 838 it != regular_users.end(); ++it) { | 841 it != regular_users.end(); |
| 839 User* user = nullptr; | 842 ++it) { |
| 840 const std::string domain = gaia::ExtractDomainName(it->GetUserEmail()); | 843 User* user = NULL; |
| 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(*it); |
| 843 } else { | 847 } else { |
| 844 user = User::CreateRegularUser(*it); | 848 user = User::CreateRegularUser(*it); |
| 845 int user_type; | 849 int user_type; |
| 846 if (prefs_user_types->GetIntegerWithoutPathExpansion(it->GetUserEmail(), | 850 if (prefs_user_types->GetIntegerWithoutPathExpansion(*it, &user_type) && |
| 847 &user_type) && | |
| 848 user_type == USER_TYPE_CHILD) { | 851 user_type == USER_TYPE_CHILD) { |
| 849 ChangeUserChildStatus(user, true /* is child */); | 852 ChangeUserChildStatus(user, true /* is child */); |
| 850 } | 853 } |
| 851 } | 854 } |
| 852 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); | 855 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); |
| 853 user->set_force_online_signin(LoadForceOnlineSignin(*it)); | 856 user->set_force_online_signin(LoadForceOnlineSignin(*it)); |
| 854 user->set_using_saml(FindUsingSAML(*it)); | 857 user->set_using_saml(FindUsingSAML(*it)); |
| 855 users_.push_back(user); | 858 users_.push_back(user); |
| 856 | 859 |
| 857 base::string16 display_name; | 860 base::string16 display_name; |
| 858 if (prefs_display_names->GetStringWithoutPathExpansion(it->GetUserEmail(), | 861 if (prefs_display_names->GetStringWithoutPathExpansion(*it, |
| 859 &display_name)) { | 862 &display_name)) { |
| 860 user->set_display_name(display_name); | 863 user->set_display_name(display_name); |
| 861 } | 864 } |
| 862 | 865 |
| 863 base::string16 given_name; | 866 base::string16 given_name; |
| 864 if (prefs_given_names->GetStringWithoutPathExpansion(it->GetUserEmail(), | 867 if (prefs_given_names->GetStringWithoutPathExpansion(*it, &given_name)) { |
| 865 &given_name)) { | |
| 866 user->set_given_name(given_name); | 868 user->set_given_name(given_name); |
| 867 } | 869 } |
| 868 | 870 |
| 869 std::string display_email; | 871 std::string display_email; |
| 870 if (prefs_display_emails->GetStringWithoutPathExpansion(it->GetUserEmail(), | 872 if (prefs_display_emails->GetStringWithoutPathExpansion(*it, |
| 871 &display_email)) { | 873 &display_email)) { |
| 872 user->set_display_email(display_email); | 874 user->set_display_email(display_email); |
| 873 } | 875 } |
| 874 } | 876 } |
| 875 | 877 |
| 876 user_loading_stage_ = STAGE_LOADED; | 878 user_loading_stage_ = STAGE_LOADED; |
| 877 | 879 |
| 878 PerformPostUserListLoadingActions(); | 880 PerformPostUserListLoadingActions(); |
| 879 } | 881 } |
| 880 | 882 |
| 881 UserList& UserManagerBase::GetUsersAndModify() { | 883 UserList& UserManagerBase::GetUsersAndModify() { |
| 882 EnsureUsersLoaded(); | 884 EnsureUsersLoaded(); |
| 883 return users_; | 885 return users_; |
| 884 } | 886 } |
| 885 | 887 |
| 886 const User* UserManagerBase::FindUserInList(const AccountId& account_id) const { | 888 const User* UserManagerBase::FindUserInList(const std::string& user_id) const { |
| 887 const UserList& users = GetUsers(); | 889 const UserList& users = GetUsers(); |
| 888 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | 890 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { |
| 889 if ((*it)->GetAccountId() == account_id) | 891 if ((*it)->email() == user_id) |
| 890 return *it; | 892 return *it; |
| 891 } | 893 } |
| 892 return nullptr; | 894 return NULL; |
| 893 } | 895 } |
| 894 | 896 |
| 895 bool UserManagerBase::UserExistsInList(const AccountId& account_id) const { | 897 bool UserManagerBase::UserExistsInList(const std::string& user_id) const { |
| 896 const base::ListValue* user_list = GetLocalState()->GetList(kRegularUsers); | 898 const base::ListValue* user_list = GetLocalState()->GetList(kRegularUsers); |
| 897 for (size_t i = 0; i < user_list->GetSize(); ++i) { | 899 for (size_t i = 0; i < user_list->GetSize(); ++i) { |
| 898 std::string email; | 900 std::string email; |
| 899 if (user_list->GetString(i, &email) && (account_id.GetUserEmail() == email)) | 901 if (user_list->GetString(i, &email) && (user_id == email)) |
| 900 return true; | 902 return true; |
| 901 } | 903 } |
| 902 return false; | 904 return false; |
| 903 } | 905 } |
| 904 | 906 |
| 905 User* UserManagerBase::FindUserInListAndModify(const AccountId& account_id) { | 907 User* UserManagerBase::FindUserInListAndModify(const std::string& user_id) { |
| 906 UserList& users = GetUsersAndModify(); | 908 UserList& users = GetUsersAndModify(); |
| 907 for (UserList::iterator it = users.begin(); it != users.end(); ++it) { | 909 for (UserList::iterator it = users.begin(); it != users.end(); ++it) { |
| 908 if ((*it)->GetAccountId() == account_id) | 910 if ((*it)->email() == user_id) |
| 909 return *it; | 911 return *it; |
| 910 } | 912 } |
| 911 return nullptr; | 913 return NULL; |
| 912 } | 914 } |
| 913 | 915 |
| 914 void UserManagerBase::GuestUserLoggedIn() { | 916 void UserManagerBase::GuestUserLoggedIn() { |
| 915 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 917 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 916 active_user_ = User::CreateGuestUser(); | 918 active_user_ = User::CreateGuestUser(); |
| 917 } | 919 } |
| 918 | 920 |
| 919 void UserManagerBase::AddUserRecord(User* user) { | 921 void UserManagerBase::AddUserRecord(User* user) { |
| 920 // Add the user to the front of the user list. | 922 // Add the user to the front of the user list. |
| 921 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); | 923 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); |
| 922 prefs_users_update->Insert(0, new base::StringValue(user->email())); | 924 prefs_users_update->Insert(0, new base::StringValue(user->email())); |
| 923 users_.insert(users_.begin(), user); | 925 users_.insert(users_.begin(), user); |
| 924 } | 926 } |
| 925 | 927 |
| 926 void UserManagerBase::RegularUserLoggedIn(const AccountId& account_id) { | 928 void UserManagerBase::RegularUserLoggedIn(const std::string& user_id) { |
| 927 // Remove the user from the user list. | 929 // Remove the user from the user list. |
| 928 active_user_ = RemoveRegularOrSupervisedUserFromList(account_id); | 930 active_user_ = RemoveRegularOrSupervisedUserFromList(user_id); |
| 929 | 931 |
| 930 // 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. |
| 931 SetIsCurrentUserNew(!active_user_); | 933 SetIsCurrentUserNew(!active_user_); |
| 932 if (IsCurrentUserNew()) { | 934 if (IsCurrentUserNew()) { |
| 933 active_user_ = User::CreateRegularUser(account_id); | 935 active_user_ = User::CreateRegularUser(user_id); |
| 934 active_user_->set_oauth_token_status(LoadUserOAuthStatus(account_id)); | 936 active_user_->set_oauth_token_status(LoadUserOAuthStatus(user_id)); |
| 935 SaveUserDisplayName(active_user_->GetAccountId(), | 937 SaveUserDisplayName(active_user_->email(), |
| 936 base::UTF8ToUTF16(active_user_->GetAccountName(true))); | 938 base::UTF8ToUTF16(active_user_->GetAccountName(true))); |
| 937 } | 939 } |
| 938 | 940 |
| 939 AddUserRecord(active_user_); | 941 AddUserRecord(active_user_); |
| 940 | 942 |
| 941 // Make sure that new data is persisted to Local State. | 943 // Make sure that new data is persisted to Local State. |
| 942 GetLocalState()->CommitPendingWrite(); | 944 GetLocalState()->CommitPendingWrite(); |
| 943 } | 945 } |
| 944 | 946 |
| 945 void UserManagerBase::RegularUserLoggedInAsEphemeral( | 947 void UserManagerBase::RegularUserLoggedInAsEphemeral( |
| 946 const AccountId& account_id) { | 948 const std::string& user_id) { |
| 947 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 949 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 948 SetIsCurrentUserNew(true); | 950 SetIsCurrentUserNew(true); |
| 949 is_current_user_ephemeral_regular_user_ = true; | 951 is_current_user_ephemeral_regular_user_ = true; |
| 950 active_user_ = User::CreateRegularUser(account_id); | 952 active_user_ = User::CreateRegularUser(user_id); |
| 951 } | 953 } |
| 952 | 954 |
| 953 void UserManagerBase::NotifyOnLogin() { | 955 void UserManagerBase::NotifyOnLogin() { |
| 954 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 956 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 955 | 957 |
| 956 NotifyActiveUserHashChanged(active_user_->username_hash()); | 958 NotifyActiveUserHashChanged(active_user_->username_hash()); |
| 957 NotifyActiveUserChanged(active_user_); | 959 NotifyActiveUserChanged(active_user_); |
| 958 UpdateLoginState(); | 960 UpdateLoginState(); |
| 959 } | 961 } |
| 960 | 962 |
| 961 User::OAuthTokenStatus UserManagerBase::LoadUserOAuthStatus( | 963 User::OAuthTokenStatus UserManagerBase::LoadUserOAuthStatus( |
| 962 const AccountId& account_id) const { | 964 const std::string& user_id) const { |
| 963 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 965 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 964 | 966 |
| 965 const base::DictionaryValue* prefs_oauth_status = | 967 const base::DictionaryValue* prefs_oauth_status = |
| 966 GetLocalState()->GetDictionary(kUserOAuthTokenStatus); | 968 GetLocalState()->GetDictionary(kUserOAuthTokenStatus); |
| 967 int oauth_token_status = User::OAUTH_TOKEN_STATUS_UNKNOWN; | 969 int oauth_token_status = User::OAUTH_TOKEN_STATUS_UNKNOWN; |
| 968 if (prefs_oauth_status && | 970 if (prefs_oauth_status && |
| 969 prefs_oauth_status->GetIntegerWithoutPathExpansion( | 971 prefs_oauth_status->GetIntegerWithoutPathExpansion(user_id, |
| 970 account_id.GetUserEmail(), &oauth_token_status)) { | 972 &oauth_token_status)) { |
| 971 User::OAuthTokenStatus status = | 973 User::OAuthTokenStatus status = |
| 972 static_cast<User::OAuthTokenStatus>(oauth_token_status); | 974 static_cast<User::OAuthTokenStatus>(oauth_token_status); |
| 973 HandleUserOAuthTokenStatusChange(account_id, status); | 975 HandleUserOAuthTokenStatusChange(user_id, status); |
| 974 | 976 |
| 975 return status; | 977 return status; |
| 976 } | 978 } |
| 977 return User::OAUTH_TOKEN_STATUS_UNKNOWN; | 979 return User::OAUTH_TOKEN_STATUS_UNKNOWN; |
| 978 } | 980 } |
| 979 | 981 |
| 980 bool UserManagerBase::LoadForceOnlineSignin(const AccountId& account_id) const { | 982 bool UserManagerBase::LoadForceOnlineSignin(const std::string& user_id) const { |
| 981 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 983 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 982 | 984 |
| 983 const base::DictionaryValue* prefs_force_online = | 985 const base::DictionaryValue* prefs_force_online = |
| 984 GetLocalState()->GetDictionary(kUserForceOnlineSignin); | 986 GetLocalState()->GetDictionary(kUserForceOnlineSignin); |
| 985 bool force_online_signin = false; | 987 bool force_online_signin = false; |
| 986 if (prefs_force_online) { | 988 if (prefs_force_online) { |
| 987 prefs_force_online->GetBooleanWithoutPathExpansion( | 989 prefs_force_online->GetBooleanWithoutPathExpansion(user_id, |
| 988 account_id.GetUserEmail(), &force_online_signin); | 990 &force_online_signin); |
| 989 } | 991 } |
| 990 return force_online_signin; | 992 return force_online_signin; |
| 991 } | 993 } |
| 992 | 994 |
| 993 void UserManagerBase::RemoveNonCryptohomeData(const AccountId& account_id) { | 995 void UserManagerBase::RemoveNonCryptohomeData(const std::string& user_id) { |
| 994 PrefService* prefs = GetLocalState(); | 996 PrefService* prefs = GetLocalState(); |
| 995 DictionaryPrefUpdate prefs_display_name_update(prefs, kUserDisplayName); | 997 DictionaryPrefUpdate prefs_display_name_update(prefs, kUserDisplayName); |
| 996 prefs_display_name_update->RemoveWithoutPathExpansion( | 998 prefs_display_name_update->RemoveWithoutPathExpansion(user_id, NULL); |
| 997 account_id.GetUserEmail(), nullptr); | |
| 998 | 999 |
| 999 DictionaryPrefUpdate prefs_given_name_update(prefs, kUserGivenName); | 1000 DictionaryPrefUpdate prefs_given_name_update(prefs, kUserGivenName); |
| 1000 prefs_given_name_update->RemoveWithoutPathExpansion(account_id.GetUserEmail(), | 1001 prefs_given_name_update->RemoveWithoutPathExpansion(user_id, NULL); |
| 1001 nullptr); | |
| 1002 | 1002 |
| 1003 DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail); | 1003 DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail); |
| 1004 prefs_display_email_update->RemoveWithoutPathExpansion( | 1004 prefs_display_email_update->RemoveWithoutPathExpansion(user_id, NULL); |
| 1005 account_id.GetUserEmail(), nullptr); | |
| 1006 | 1005 |
| 1007 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); | 1006 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); |
| 1008 prefs_oauth_update->RemoveWithoutPathExpansion(account_id.GetUserEmail(), | 1007 prefs_oauth_update->RemoveWithoutPathExpansion(user_id, NULL); |
| 1009 nullptr); | |
| 1010 | 1008 |
| 1011 DictionaryPrefUpdate prefs_force_online_update(prefs, kUserForceOnlineSignin); | 1009 DictionaryPrefUpdate prefs_force_online_update(prefs, kUserForceOnlineSignin); |
| 1012 prefs_force_online_update->RemoveWithoutPathExpansion( | 1010 prefs_force_online_update->RemoveWithoutPathExpansion(user_id, NULL); |
| 1013 account_id.GetUserEmail(), nullptr); | |
| 1014 | 1011 |
| 1015 RemoveKnownUserPrefs(account_id); | 1012 RemoveKnownUserPrefs(user_id); |
| 1016 | 1013 |
| 1017 const AccountId last_active_user = | 1014 std::string last_active_user = GetLocalState()->GetString(kLastActiveUser); |
| 1018 AccountId::FromUserEmail(GetLocalState()->GetString(kLastActiveUser)); | 1015 if (user_id == last_active_user) |
| 1019 if (account_id == last_active_user) | |
| 1020 GetLocalState()->SetString(kLastActiveUser, std::string()); | 1016 GetLocalState()->SetString(kLastActiveUser, std::string()); |
| 1021 } | 1017 } |
| 1022 | 1018 |
| 1023 bool UserManagerBase::FindKnownUserPrefs( | 1019 bool UserManagerBase::FindKnownUserPrefs( |
| 1024 const AccountId& account_id, | 1020 const UserID& user_id, |
| 1025 const base::DictionaryValue** out_value) { | 1021 const base::DictionaryValue** out_value) { |
| 1026 PrefService* local_state = GetLocalState(); | 1022 PrefService* local_state = GetLocalState(); |
| 1027 | 1023 |
| 1028 // Local State may not be initialized in tests. | 1024 // Local State may not be initialized in tests. |
| 1029 if (!local_state) | 1025 if (!local_state) |
| 1030 return false; | 1026 return false; |
| 1031 if (IsUserNonCryptohomeDataEphemeral(account_id)) | 1027 if (IsUserNonCryptohomeDataEphemeral(user_id)) |
| 1032 return false; | 1028 return false; |
| 1033 | 1029 |
| 1034 const base::ListValue* known_users = local_state->GetList(kKnownUsers); | 1030 const base::ListValue* known_users = local_state->GetList(kKnownUsers); |
| 1035 for (size_t i = 0; i < known_users->GetSize(); ++i) { | 1031 for (size_t i = 0; i < known_users->GetSize(); ++i) { |
| 1036 const base::DictionaryValue* element = nullptr; | 1032 const base::DictionaryValue* element = nullptr; |
| 1037 if (known_users->GetDictionary(i, &element)) { | 1033 if (known_users->GetDictionary(i, &element)) { |
| 1038 if (UserMatches(account_id, *element)) { | 1034 if (UserMatches(user_id, *element)) { |
| 1039 known_users->GetDictionary(i, out_value); | 1035 known_users->GetDictionary(i, out_value); |
| 1040 return true; | 1036 return true; |
| 1041 } | 1037 } |
| 1042 } | 1038 } |
| 1043 } | 1039 } |
| 1044 return false; | 1040 return false; |
| 1045 } | 1041 } |
| 1046 | 1042 |
| 1047 void UserManagerBase::UpdateKnownUserPrefs(const AccountId& account_id, | 1043 void UserManagerBase::UpdateKnownUserPrefs(const UserID& user_id, |
| 1048 const base::DictionaryValue& values, | 1044 const base::DictionaryValue& values, |
| 1049 bool clear) { | 1045 bool clear) { |
| 1050 PrefService* local_state = GetLocalState(); | 1046 PrefService* local_state = GetLocalState(); |
| 1051 | 1047 |
| 1052 // Local State may not be initialized in tests. | 1048 // Local State may not be initialized in tests. |
| 1053 if (!local_state) | 1049 if (!local_state) |
| 1054 return; | 1050 return; |
| 1055 | 1051 |
| 1056 if (IsUserNonCryptohomeDataEphemeral(account_id)) | 1052 if (IsUserNonCryptohomeDataEphemeral(user_id)) |
| 1057 return; | 1053 return; |
| 1058 | 1054 |
| 1059 ListPrefUpdate update(local_state, kKnownUsers); | 1055 ListPrefUpdate update(local_state, kKnownUsers); |
| 1060 for (size_t i = 0; i < update->GetSize(); ++i) { | 1056 for (size_t i = 0; i < update->GetSize(); ++i) { |
| 1061 base::DictionaryValue* element = nullptr; | 1057 base::DictionaryValue* element = nullptr; |
| 1062 if (update->GetDictionary(i, &element)) { | 1058 if (update->GetDictionary(i, &element)) { |
| 1063 if (UserMatches(account_id, *element)) { | 1059 if (UserMatches(user_id, *element)) { |
| 1064 if (clear) | 1060 if (clear) |
| 1065 element->Clear(); | 1061 element->Clear(); |
| 1066 element->MergeDictionary(&values); | 1062 element->MergeDictionary(&values); |
| 1067 UpdateIdentity(account_id, *element); | 1063 UpdateIdentity(user_id, *element); |
| 1068 return; | 1064 return; |
| 1069 } | 1065 } |
| 1070 } | 1066 } |
| 1071 } | 1067 } |
| 1072 scoped_ptr<base::DictionaryValue> new_value(new base::DictionaryValue()); | 1068 scoped_ptr<base::DictionaryValue> new_value(new base::DictionaryValue()); |
| 1073 new_value->MergeDictionary(&values); | 1069 new_value->MergeDictionary(&values); |
| 1074 UpdateIdentity(account_id, *new_value); | 1070 UpdateIdentity(user_id, *new_value); |
| 1075 update->Append(new_value.release()); | 1071 update->Append(new_value.release()); |
| 1076 } | 1072 } |
| 1077 | 1073 |
| 1078 bool UserManagerBase::GetKnownUserStringPref(const AccountId& account_id, | 1074 bool UserManagerBase::GetKnownUserStringPref(const UserID& user_id, |
| 1079 const std::string& path, | 1075 const std::string& path, |
| 1080 std::string* out_value) { | 1076 std::string* out_value) { |
| 1081 const base::DictionaryValue* user_pref_dict = nullptr; | 1077 const base::DictionaryValue* user_pref_dict = nullptr; |
| 1082 if (!FindKnownUserPrefs(account_id, &user_pref_dict)) | 1078 if (!FindKnownUserPrefs(user_id, &user_pref_dict)) |
| 1083 return false; | 1079 return false; |
| 1084 | 1080 |
| 1085 return user_pref_dict->GetString(path, out_value); | 1081 return user_pref_dict->GetString(path, out_value); |
| 1086 } | 1082 } |
| 1087 | 1083 |
| 1088 void UserManagerBase::SetKnownUserStringPref(const AccountId& account_id, | 1084 void UserManagerBase::SetKnownUserStringPref(const UserID& user_id, |
| 1089 const std::string& path, | 1085 const std::string& path, |
| 1090 const std::string& in_value) { | 1086 const std::string& in_value) { |
| 1091 PrefService* local_state = GetLocalState(); | 1087 PrefService* local_state = GetLocalState(); |
| 1092 | 1088 |
| 1093 // Local State may not be initialized in tests. | 1089 // Local State may not be initialized in tests. |
| 1094 if (!local_state) | 1090 if (!local_state) |
| 1095 return; | 1091 return; |
| 1096 | 1092 |
| 1097 ListPrefUpdate update(local_state, kKnownUsers); | 1093 ListPrefUpdate update(local_state, kKnownUsers); |
| 1098 base::DictionaryValue dict; | 1094 base::DictionaryValue dict; |
| 1099 dict.SetString(path, in_value); | 1095 dict.SetString(path, in_value); |
| 1100 UpdateKnownUserPrefs(account_id, dict, false); | 1096 UpdateKnownUserPrefs(user_id, dict, false); |
| 1101 } | 1097 } |
| 1102 | 1098 |
| 1103 bool UserManagerBase::GetKnownUserBooleanPref(const AccountId& account_id, | 1099 bool UserManagerBase::GetKnownUserBooleanPref(const UserID& user_id, |
| 1104 const std::string& path, | 1100 const std::string& path, |
| 1105 bool* out_value) { | 1101 bool* out_value) { |
| 1106 const base::DictionaryValue* user_pref_dict = nullptr; | 1102 const base::DictionaryValue* user_pref_dict = nullptr; |
| 1107 if (!FindKnownUserPrefs(account_id, &user_pref_dict)) | 1103 if (!FindKnownUserPrefs(user_id, &user_pref_dict)) |
| 1108 return false; | 1104 return false; |
| 1109 | 1105 |
| 1110 return user_pref_dict->GetBoolean(path, out_value); | 1106 return user_pref_dict->GetBoolean(path, out_value); |
| 1111 } | 1107 } |
| 1112 | 1108 |
| 1113 void UserManagerBase::SetKnownUserBooleanPref(const AccountId& account_id, | 1109 void UserManagerBase::SetKnownUserBooleanPref(const UserID& user_id, |
| 1114 const std::string& path, | 1110 const std::string& path, |
| 1115 const bool in_value) { | 1111 const bool in_value) { |
| 1116 PrefService* local_state = GetLocalState(); | 1112 PrefService* local_state = GetLocalState(); |
| 1117 | 1113 |
| 1118 // Local State may not be initialized in tests. | 1114 // Local State may not be initialized in tests. |
| 1119 if (!local_state) | 1115 if (!local_state) |
| 1120 return; | 1116 return; |
| 1121 | 1117 |
| 1122 ListPrefUpdate update(local_state, kKnownUsers); | 1118 ListPrefUpdate update(local_state, kKnownUsers); |
| 1123 base::DictionaryValue dict; | 1119 base::DictionaryValue dict; |
| 1124 dict.SetBoolean(path, in_value); | 1120 dict.SetBoolean(path, in_value); |
| 1125 UpdateKnownUserPrefs(account_id, dict, false); | 1121 UpdateKnownUserPrefs(user_id, dict, false); |
| 1126 } | 1122 } |
| 1127 | 1123 |
| 1128 bool UserManagerBase::GetKnownUserIntegerPref(const AccountId& account_id, | 1124 bool UserManagerBase::GetKnownUserIntegerPref(const UserID& user_id, |
| 1129 const std::string& path, | 1125 const std::string& path, |
| 1130 int* out_value) { | 1126 int* out_value) { |
| 1131 const base::DictionaryValue* user_pref_dict = nullptr; | 1127 const base::DictionaryValue* user_pref_dict = nullptr; |
| 1132 if (!FindKnownUserPrefs(account_id, &user_pref_dict)) | 1128 if (!FindKnownUserPrefs(user_id, &user_pref_dict)) |
| 1133 return false; | 1129 return false; |
| 1134 return user_pref_dict->GetInteger(path, out_value); | 1130 return user_pref_dict->GetInteger(path, out_value); |
| 1135 } | 1131 } |
| 1136 | 1132 |
| 1137 void UserManagerBase::SetKnownUserIntegerPref(const AccountId& account_id, | 1133 void UserManagerBase::SetKnownUserIntegerPref(const UserID& user_id, |
| 1138 const std::string& path, | 1134 const std::string& path, |
| 1139 const int in_value) { | 1135 const int in_value) { |
| 1140 PrefService* local_state = GetLocalState(); | 1136 PrefService* local_state = GetLocalState(); |
| 1141 | 1137 |
| 1142 // Local State may not be initialized in tests. | 1138 // Local State may not be initialized in tests. |
| 1143 if (!local_state) | 1139 if (!local_state) |
| 1144 return; | 1140 return; |
| 1145 | 1141 |
| 1146 ListPrefUpdate update(local_state, kKnownUsers); | 1142 ListPrefUpdate update(local_state, kKnownUsers); |
| 1147 base::DictionaryValue dict; | 1143 base::DictionaryValue dict; |
| 1148 dict.SetInteger(path, in_value); | 1144 dict.SetInteger(path, in_value); |
| 1149 UpdateKnownUserPrefs(account_id, dict, false); | 1145 UpdateKnownUserPrefs(user_id, dict, false); |
| 1150 } | 1146 } |
| 1151 | 1147 |
| 1152 bool UserManagerBase::GetKnownUserAccountId( | 1148 bool UserManagerBase::GetKnownUserCanonicalEmail(const UserID& user_id, |
| 1153 const AccountId& authenticated_account_id, | 1149 std::string* out_email) { |
| 1154 AccountId* out_account_id) { | 1150 return GetKnownUserStringPref(user_id, kCanonicalEmail, out_email); |
| 1155 DCHECK(!authenticated_account_id.GetGaiaId().empty()); | |
| 1156 std::string canonical_email; | |
| 1157 if (!GetKnownUserStringPref( | |
| 1158 AccountId::FromGaiaId(authenticated_account_id.GetGaiaId()), | |
| 1159 kCanonicalEmail, &canonical_email)) | |
| 1160 return false; | |
| 1161 | |
| 1162 *out_account_id = authenticated_account_id; | |
| 1163 out_account_id->SetUserEmail(canonical_email); | |
| 1164 return true; | |
| 1165 } | 1151 } |
| 1166 | 1152 |
| 1167 void UserManagerBase::UpdateGaiaID(const AccountId& account_id, | 1153 void UserManagerBase::UpdateGaiaID(const UserID& user_id, |
| 1168 const std::string& gaia_id) { | 1154 const std::string& gaia_id) { |
| 1169 SetKnownUserStringPref(account_id, kGAIAIdKey, gaia_id); | 1155 SetKnownUserStringPref(user_id, kGAIAIdKey, gaia_id); |
| 1170 } | 1156 } |
| 1171 | 1157 |
| 1172 bool UserManagerBase::FindGaiaID(const AccountId& account_id, | 1158 bool UserManagerBase::FindGaiaID(const UserID& user_id, |
| 1173 std::string* out_value) { | 1159 std::string* out_value) { |
| 1174 return GetKnownUserStringPref(account_id, kGAIAIdKey, out_value); | 1160 return GetKnownUserStringPref(user_id, kGAIAIdKey, out_value); |
| 1175 } | 1161 } |
| 1176 | 1162 |
| 1177 void UserManagerBase::SetKnownUserDeviceId(const AccountId& account_id, | 1163 void UserManagerBase::SetKnownUserDeviceId(const UserID& user_id, |
| 1178 const std::string& device_id) { | 1164 const std::string& device_id) { |
| 1179 const std::string known_device_id = GetKnownUserDeviceId(account_id); | 1165 const std::string known_device_id = GetKnownUserDeviceId(user_id); |
| 1180 if (!known_device_id.empty() && device_id != known_device_id) { | 1166 if (!known_device_id.empty() && device_id != known_device_id) { |
| 1181 NOTREACHED() << "Trying to change device ID for known user."; | 1167 NOTREACHED() << "Trying to change device ID for known user."; |
| 1182 } | 1168 } |
| 1183 SetKnownUserStringPref(account_id, kDeviceId, device_id); | 1169 SetKnownUserStringPref(user_id, kDeviceId, device_id); |
| 1184 } | 1170 } |
| 1185 | 1171 |
| 1186 std::string UserManagerBase::GetKnownUserDeviceId(const AccountId& account_id) { | 1172 std::string UserManagerBase::GetKnownUserDeviceId(const UserID& user_id) { |
| 1187 std::string device_id; | 1173 std::string device_id; |
| 1188 if (GetKnownUserStringPref(account_id, kDeviceId, &device_id)) { | 1174 if (GetKnownUserStringPref(user_id, kDeviceId, &device_id)) { |
| 1189 return device_id; | 1175 return device_id; |
| 1190 } | 1176 } |
| 1191 return std::string(); | 1177 return std::string(); |
| 1192 } | 1178 } |
| 1193 | 1179 |
| 1194 void UserManagerBase::SetKnownUserGAPSCookie(const AccountId& account_id, | 1180 void UserManagerBase::SetKnownUserGAPSCookie(const UserID& user_id, |
| 1195 const std::string& gaps_cookie) { | 1181 const std::string& gaps_cookie) { |
| 1196 SetKnownUserStringPref(account_id, kGAPSCookie, gaps_cookie); | 1182 SetKnownUserStringPref(user_id, kGAPSCookie, gaps_cookie); |
| 1197 } | 1183 } |
| 1198 | 1184 |
| 1199 std::string UserManagerBase::GetKnownUserGAPSCookie( | 1185 std::string UserManagerBase::GetKnownUserGAPSCookie(const UserID& user_id) { |
| 1200 const AccountId& account_id) { | |
| 1201 std::string gaps_cookie; | 1186 std::string gaps_cookie; |
| 1202 if (GetKnownUserStringPref(account_id, kGAPSCookie, &gaps_cookie)) { | 1187 if (GetKnownUserStringPref(user_id, kGAPSCookie, &gaps_cookie)) { |
| 1203 return gaps_cookie; | 1188 return gaps_cookie; |
| 1204 } | 1189 } |
| 1205 return std::string(); | 1190 return std::string(); |
| 1206 } | 1191 } |
| 1207 | 1192 |
| 1208 User* UserManagerBase::RemoveRegularOrSupervisedUserFromList( | 1193 User* UserManagerBase::RemoveRegularOrSupervisedUserFromList( |
| 1209 const AccountId& account_id) { | 1194 const std::string& user_id) { |
| 1210 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); | 1195 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); |
| 1211 prefs_users_update->Clear(); | 1196 prefs_users_update->Clear(); |
| 1212 User* user = nullptr; | 1197 User* user = NULL; |
| 1213 for (UserList::iterator it = users_.begin(); it != users_.end();) { | 1198 for (UserList::iterator it = users_.begin(); it != users_.end();) { |
| 1214 if ((*it)->GetAccountId() == account_id) { | 1199 const std::string user_email = (*it)->email(); |
| 1200 if (user_email == user_id) { |
| 1215 user = *it; | 1201 user = *it; |
| 1216 it = users_.erase(it); | 1202 it = users_.erase(it); |
| 1217 } else { | 1203 } else { |
| 1218 if ((*it)->HasGaiaAccount() || (*it)->IsSupervised()) { | 1204 if ((*it)->HasGaiaAccount() || (*it)->IsSupervised()) |
| 1219 const std::string user_email = (*it)->email(); | |
| 1220 prefs_users_update->Append(new base::StringValue(user_email)); | 1205 prefs_users_update->Append(new base::StringValue(user_email)); |
| 1221 } | |
| 1222 ++it; | 1206 ++it; |
| 1223 } | 1207 } |
| 1224 } | 1208 } |
| 1225 OnUserRemoved(account_id); | 1209 OnUserRemoved(user_id); |
| 1226 return user; | 1210 return user; |
| 1227 } | 1211 } |
| 1228 | 1212 |
| 1229 void UserManagerBase::RemoveKnownUserPrefs(const AccountId& account_id) { | 1213 void UserManagerBase::RemoveKnownUserPrefs(const UserID& user_id) { |
| 1230 ListPrefUpdate update(GetLocalState(), kKnownUsers); | 1214 ListPrefUpdate update(GetLocalState(), kKnownUsers); |
| 1231 for (size_t i = 0; i < update->GetSize(); ++i) { | 1215 for (size_t i = 0; i < update->GetSize(); ++i) { |
| 1232 base::DictionaryValue* element = nullptr; | 1216 base::DictionaryValue* element = nullptr; |
| 1233 if (update->GetDictionary(i, &element)) { | 1217 if (update->GetDictionary(i, &element)) { |
| 1234 if (UserMatches(account_id, *element)) { | 1218 if (UserMatches(user_id, *element)) { |
| 1235 update->Remove(i, nullptr); | 1219 update->Remove(i, nullptr); |
| 1236 break; | 1220 break; |
| 1237 } | 1221 } |
| 1238 } | 1222 } |
| 1239 } | 1223 } |
| 1240 } | 1224 } |
| 1241 | 1225 |
| 1242 void UserManagerBase::NotifyActiveUserChanged(const User* active_user) { | 1226 void UserManagerBase::NotifyActiveUserChanged(const User* active_user) { |
| 1243 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 1227 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 1244 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, | 1228 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1259 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, | 1243 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, |
| 1260 session_state_observer_list_, | 1244 session_state_observer_list_, |
| 1261 ActiveUserHashChanged(hash)); | 1245 ActiveUserHashChanged(hash)); |
| 1262 } | 1246 } |
| 1263 | 1247 |
| 1264 void UserManagerBase::ChangeUserChildStatus(User* user, bool is_child) { | 1248 void UserManagerBase::ChangeUserChildStatus(User* user, bool is_child) { |
| 1265 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 1249 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 1266 if (user->IsSupervised() == is_child) | 1250 if (user->IsSupervised() == is_child) |
| 1267 return; | 1251 return; |
| 1268 user->SetIsChild(is_child); | 1252 user->SetIsChild(is_child); |
| 1269 SaveUserType(user->GetAccountId(), is_child | 1253 SaveUserType(user->email(), is_child ? user_manager::USER_TYPE_CHILD |
| 1270 ? user_manager::USER_TYPE_CHILD | 1254 : user_manager::USER_TYPE_REGULAR); |
| 1271 : user_manager::USER_TYPE_REGULAR); | |
| 1272 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, | 1255 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, |
| 1273 session_state_observer_list_, | 1256 session_state_observer_list_, |
| 1274 UserChangedChildStatus(user)); | 1257 UserChangedChildStatus(user)); |
| 1275 } | 1258 } |
| 1276 | 1259 |
| 1277 void UserManagerBase::UpdateLoginState() { | 1260 void UserManagerBase::UpdateLoginState() { |
| 1278 if (!chromeos::LoginState::IsInitialized()) | 1261 if (!chromeos::LoginState::IsInitialized()) |
| 1279 return; // LoginState may not be initialized in tests. | 1262 return; // LoginState may not be initialized in tests. |
| 1280 | 1263 |
| 1281 chromeos::LoginState::LoggedInState logged_in_state; | 1264 chromeos::LoginState::LoggedInState logged_in_state; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1311 GetLocalState()->SetString(kLastActiveUser, user->email()); | 1294 GetLocalState()->SetString(kLastActiveUser, user->email()); |
| 1312 GetLocalState()->CommitPendingWrite(); | 1295 GetLocalState()->CommitPendingWrite(); |
| 1313 | 1296 |
| 1314 UserList::iterator it = | 1297 UserList::iterator it = |
| 1315 std::find(lru_logged_in_users_.begin(), lru_logged_in_users_.end(), user); | 1298 std::find(lru_logged_in_users_.begin(), lru_logged_in_users_.end(), user); |
| 1316 if (it != lru_logged_in_users_.end()) | 1299 if (it != lru_logged_in_users_.end()) |
| 1317 lru_logged_in_users_.erase(it); | 1300 lru_logged_in_users_.erase(it); |
| 1318 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user); | 1301 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user); |
| 1319 } | 1302 } |
| 1320 | 1303 |
| 1321 void UserManagerBase::SendGaiaUserLoginMetrics(const AccountId& account_id) { | 1304 void UserManagerBase::SendGaiaUserLoginMetrics(const std::string& user_id) { |
| 1322 // If this isn't the first time Chrome was run after the system booted, | 1305 // If this isn't the first time Chrome was run after the system booted, |
| 1323 // assume that Chrome was restarted because a previous session ended. | 1306 // assume that Chrome was restarted because a previous session ended. |
| 1324 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 1307 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1325 chromeos::switches::kFirstExecAfterBoot)) { | 1308 chromeos::switches::kFirstExecAfterBoot)) { |
| 1326 const std::string last_email = | 1309 const std::string last_email = |
| 1327 GetLocalState()->GetString(kLastLoggedInGaiaUser); | 1310 GetLocalState()->GetString(kLastLoggedInGaiaUser); |
| 1328 const base::TimeDelta time_to_login = | 1311 const base::TimeDelta time_to_login = |
| 1329 base::TimeTicks::Now() - manager_creation_time_; | 1312 base::TimeTicks::Now() - manager_creation_time_; |
| 1330 if (!last_email.empty() && | 1313 if (!last_email.empty() && user_id != last_email && |
| 1331 account_id != AccountId::FromUserEmail(last_email) && | |
| 1332 time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) { | 1314 time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) { |
| 1333 UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay", | 1315 UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay", |
| 1334 time_to_login.InSeconds(), | 1316 time_to_login.InSeconds(), |
| 1335 0, | 1317 0, |
| 1336 kLogoutToLoginDelayMaxSec, | 1318 kLogoutToLoginDelayMaxSec, |
| 1337 50); | 1319 50); |
| 1338 } | 1320 } |
| 1339 } | 1321 } |
| 1340 } | 1322 } |
| 1341 | 1323 |
| 1342 void UserManagerBase::UpdateUserAccountLocale(const AccountId& account_id, | 1324 void UserManagerBase::UpdateUserAccountLocale(const std::string& user_id, |
| 1343 const std::string& locale) { | 1325 const std::string& locale) { |
| 1344 scoped_ptr<std::string> resolved_locale(new std::string()); | 1326 scoped_ptr<std::string> resolved_locale(new std::string()); |
| 1345 if (!locale.empty() && locale != GetApplicationLocale()) { | 1327 if (!locale.empty() && locale != GetApplicationLocale()) { |
| 1346 // base::Pased will nullptr out |resolved_locale|, so cache the underlying | 1328 // base::Pased will NULL out |resolved_locale|, so cache the underlying ptr. |
| 1347 // ptr. | |
| 1348 std::string* raw_resolved_locale = resolved_locale.get(); | 1329 std::string* raw_resolved_locale = resolved_locale.get(); |
| 1349 blocking_task_runner_->PostTaskAndReply( | 1330 blocking_task_runner_->PostTaskAndReply( |
| 1350 FROM_HERE, base::Bind(ResolveLocale, locale, | 1331 FROM_HERE, |
| 1351 base::Unretained(raw_resolved_locale)), | 1332 base::Bind(ResolveLocale, |
| 1333 locale, |
| 1334 base::Unretained(raw_resolved_locale)), |
| 1352 base::Bind(&UserManagerBase::DoUpdateAccountLocale, | 1335 base::Bind(&UserManagerBase::DoUpdateAccountLocale, |
| 1353 weak_factory_.GetWeakPtr(), account_id, | 1336 weak_factory_.GetWeakPtr(), |
| 1337 user_id, |
| 1354 base::Passed(&resolved_locale))); | 1338 base::Passed(&resolved_locale))); |
| 1355 } else { | 1339 } else { |
| 1356 resolved_locale.reset(new std::string(locale)); | 1340 resolved_locale.reset(new std::string(locale)); |
| 1357 DoUpdateAccountLocale(account_id, resolved_locale.Pass()); | 1341 DoUpdateAccountLocale(user_id, resolved_locale.Pass()); |
| 1358 } | 1342 } |
| 1359 } | 1343 } |
| 1360 | 1344 |
| 1361 void UserManagerBase::DoUpdateAccountLocale( | 1345 void UserManagerBase::DoUpdateAccountLocale( |
| 1362 const AccountId& account_id, | 1346 const std::string& user_id, |
| 1363 scoped_ptr<std::string> resolved_locale) { | 1347 scoped_ptr<std::string> resolved_locale) { |
| 1364 User* user = FindUserAndModify(account_id); | 1348 User* user = FindUserAndModify(user_id); |
| 1365 if (user && resolved_locale) | 1349 if (user && resolved_locale) |
| 1366 user->SetAccountLocale(*resolved_locale); | 1350 user->SetAccountLocale(*resolved_locale); |
| 1367 } | 1351 } |
| 1368 | 1352 |
| 1369 void UserManagerBase::DeleteUser(User* user) { | 1353 void UserManagerBase::DeleteUser(User* user) { |
| 1370 const bool is_active_user = (user == active_user_); | 1354 const bool is_active_user = (user == active_user_); |
| 1371 delete user; | 1355 delete user; |
| 1372 if (is_active_user) | 1356 if (is_active_user) |
| 1373 active_user_ = nullptr; | 1357 active_user_ = NULL; |
| 1374 } | 1358 } |
| 1375 | 1359 |
| 1376 } // namespace user_manager | 1360 } // namespace user_manager |
| OLD | NEW |