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

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

Powered by Google App Engine
This is Rietveld 408576698