| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/login/user_manager_impl.h" | 5 #include "chrome/browser/chromeos/login/user_manager_impl.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); | 314 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); |
| 315 return users_; | 315 return users_; |
| 316 } | 316 } |
| 317 | 317 |
| 318 void UserManagerImpl::UserLoggedIn(const std::string& email) { | 318 void UserManagerImpl::UserLoggedIn(const std::string& email) { |
| 319 DCHECK(!is_user_logged_in_); | 319 DCHECK(!is_user_logged_in_); |
| 320 | 320 |
| 321 is_user_logged_in_ = true; | 321 is_user_logged_in_ = true; |
| 322 | 322 |
| 323 if (email == kGuestUser) { | 323 if (email == kGuestUser) { |
| 324 is_current_user_ephemeral_ = true; | |
| 325 GuestUserLoggedIn(); | 324 GuestUserLoggedIn(); |
| 326 return; | 325 return; |
| 327 } | 326 } |
| 328 | 327 |
| 329 if (email == kDemoUser) { | 328 if (email == kDemoUser) { |
| 330 is_current_user_ephemeral_ = true; | |
| 331 DemoUserLoggedIn(); | 329 DemoUserLoggedIn(); |
| 332 return; | 330 return; |
| 333 } | 331 } |
| 334 | 332 |
| 335 if (IsEphemeralUser(email)) { | 333 if (IsEphemeralUser(email)) { |
| 334 EphemeralUserLoggedIn(email); |
| 335 return; |
| 336 } |
| 337 |
| 338 EnsureUsersLoaded(); |
| 339 |
| 340 // Clear the prefs view of the users. |
| 341 PrefService* prefs = g_browser_process->local_state(); |
| 342 ListPrefUpdate prefs_users_update(prefs, UserManager::kLoggedInUsers); |
| 343 prefs_users_update->Clear(); |
| 344 |
| 345 // Make sure this user is first. |
| 346 prefs_users_update->Append(Value::CreateStringValue(email)); |
| 347 UserList::iterator logged_in_user = users_.end(); |
| 348 for (UserList::iterator it = users_.begin(); it != users_.end(); ++it) { |
| 349 std::string user_email = (*it)->email(); |
| 350 // Skip the most recent user. |
| 351 if (email != user_email) |
| 352 prefs_users_update->Append(Value::CreateStringValue(user_email)); |
| 353 else |
| 354 logged_in_user = it; |
| 355 } |
| 356 |
| 357 if (logged_in_user == users_.end()) { |
| 336 is_current_user_new_ = true; | 358 is_current_user_new_ = true; |
| 337 is_current_user_ephemeral_ = true; | |
| 338 logged_in_user_ = CreateUser(email); | 359 logged_in_user_ = CreateUser(email); |
| 339 SetInitialUserImage(email); | |
| 340 } else { | 360 } else { |
| 341 EnsureUsersLoaded(); | 361 logged_in_user_ = *logged_in_user; |
| 342 | 362 users_.erase(logged_in_user); |
| 343 // Clear the prefs view of the users. | |
| 344 PrefService* prefs = g_browser_process->local_state(); | |
| 345 ListPrefUpdate prefs_users_update(prefs, UserManager::kLoggedInUsers); | |
| 346 prefs_users_update->Clear(); | |
| 347 | |
| 348 // Make sure this user is first. | |
| 349 prefs_users_update->Append(Value::CreateStringValue(email)); | |
| 350 UserList::iterator logged_in_user = users_.end(); | |
| 351 for (UserList::iterator it = users_.begin(); it != users_.end(); ++it) { | |
| 352 std::string user_email = (*it)->email(); | |
| 353 // Skip the most recent user. | |
| 354 if (email != user_email) | |
| 355 prefs_users_update->Append(Value::CreateStringValue(user_email)); | |
| 356 else | |
| 357 logged_in_user = it; | |
| 358 } | |
| 359 | |
| 360 if (logged_in_user == users_.end()) { | |
| 361 is_current_user_new_ = true; | |
| 362 logged_in_user_ = CreateUser(email); | |
| 363 } else { | |
| 364 logged_in_user_ = *logged_in_user; | |
| 365 users_.erase(logged_in_user); | |
| 366 } | |
| 367 // This user must be in the front of the user list. | |
| 368 users_.insert(users_.begin(), logged_in_user_); | |
| 369 } | 363 } |
| 364 // This user must be in the front of the user list. |
| 365 users_.insert(users_.begin(), logged_in_user_); |
| 370 | 366 |
| 371 NotifyOnLogin(); | 367 NotifyOnLogin(); |
| 372 | 368 |
| 373 if (is_current_user_new_) { | 369 if (is_current_user_new_) { |
| 374 SetInitialUserImage(email); | 370 SetInitialUserImage(email); |
| 375 } else { | 371 } else { |
| 376 // Download profile image if it's user image and see if it has changed. | 372 // Download profile image if it's user image and see if it has changed. |
| 377 int image_index = logged_in_user_->image_index(); | 373 int image_index = logged_in_user_->image_index(); |
| 378 if (image_index == User::kProfileImageIndex) { | 374 if (image_index == User::kProfileImageIndex) { |
| 379 InitDownloadedProfileImage(); | 375 InitDownloadedProfileImage(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 397 histogram_index = kHistogramImageFromProfile; | 393 histogram_index = kHistogramImageFromProfile; |
| 398 break; | 394 break; |
| 399 } | 395 } |
| 400 UMA_HISTOGRAM_ENUMERATION("UserImage.LoggedIn", | 396 UMA_HISTOGRAM_ENUMERATION("UserImage.LoggedIn", |
| 401 histogram_index, | 397 histogram_index, |
| 402 kHistogramImagesCount); | 398 kHistogramImagesCount); |
| 403 } | 399 } |
| 404 } | 400 } |
| 405 | 401 |
| 406 void UserManagerImpl::DemoUserLoggedIn() { | 402 void UserManagerImpl::DemoUserLoggedIn() { |
| 403 is_current_user_new_ = true; |
| 404 is_current_user_ephemeral_ = true; |
| 407 logged_in_user_ = &demo_user_; | 405 logged_in_user_ = &demo_user_; |
| 406 SetInitialUserImage(kDemoUser); |
| 408 NotifyOnLogin(); | 407 NotifyOnLogin(); |
| 409 } | 408 } |
| 410 | 409 |
| 411 void UserManagerImpl::GuestUserLoggedIn() { | 410 void UserManagerImpl::GuestUserLoggedIn() { |
| 411 is_current_user_ephemeral_ = true; |
| 412 logged_in_user_ = &guest_user_; | 412 logged_in_user_ = &guest_user_; |
| 413 NotifyOnLogin(); | 413 NotifyOnLogin(); |
| 414 } | 414 } |
| 415 | 415 |
| 416 void UserManagerImpl::EphemeralUserLoggedIn(const std::string& email) { |
| 417 is_current_user_new_ = true; |
| 418 is_current_user_ephemeral_ = true; |
| 419 logged_in_user_ = CreateUser(email); |
| 420 SetInitialUserImage(email); |
| 421 NotifyOnLogin(); |
| 422 } |
| 423 |
| 416 void UserManagerImpl::RemoveUser(const std::string& email, | 424 void UserManagerImpl::RemoveUser(const std::string& email, |
| 417 RemoveUserDelegate* delegate) { | 425 RemoveUserDelegate* delegate) { |
| 418 if (!IsKnownUser(email)) | 426 if (!IsKnownUser(email)) |
| 419 return; | 427 return; |
| 420 | 428 |
| 421 // Sanity check: we must not remove single user. This check may seem | 429 // Sanity check: we must not remove single user. This check may seem |
| 422 // redundant at a first sight because this single user must be an owner and | 430 // redundant at a first sight because this single user must be an owner and |
| 423 // we perform special check later in order not to remove an owner. However | 431 // we perform special check later in order not to remove an owner. However |
| 424 // due to non-instant nature of ownership assignment this later check may | 432 // due to non-instant nature of ownership assignment this later check may |
| 425 // sometimes fail. See http://crosbug.com/12723 | 433 // sometimes fail. See http://crosbug.com/12723 |
| (...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 BrowserThread::PostTask( | 1179 BrowserThread::PostTask( |
| 1172 BrowserThread::FILE, | 1180 BrowserThread::FILE, |
| 1173 FROM_HERE, | 1181 FROM_HERE, |
| 1174 base::Bind(&UserManagerImpl::DeleteUserImage, | 1182 base::Bind(&UserManagerImpl::DeleteUserImage, |
| 1175 base::Unretained(this), | 1183 base::Unretained(this), |
| 1176 image_path)); | 1184 image_path)); |
| 1177 } | 1185 } |
| 1178 } | 1186 } |
| 1179 | 1187 |
| 1180 } // namespace chromeos | 1188 } // namespace chromeos |
| OLD | NEW |