Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: components/user_manager/user_manager_base.cc

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

Powered by Google App Engine
This is Rietveld 408576698