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

Side by Side Diff: chrome/browser/chromeos/login/user_manager_impl.cc

Issue 14069017: Move *UserLoggedIn methods from UserManager to UserManagerImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nit addressed. Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <cstddef> 7 #include <cstddef>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 active_user_ = user; 332 active_user_ = user;
333 333
334 // TODO(nkostylev): Notify session_manager on active user change. 334 // TODO(nkostylev): Notify session_manager on active user change.
335 // http://crbug.com/230857 335 // http://crbug.com/230857
336 content::NotificationService::current()->Notify( 336 content::NotificationService::current()->Notify(
337 chrome::NOTIFICATION_ACTIVE_USER_CHANGED, 337 chrome::NOTIFICATION_ACTIVE_USER_CHANGED,
338 content::Source<UserManager>(this), 338 content::Source<UserManager>(this),
339 content::Details<const User>(active_user_)); 339 content::Details<const User>(active_user_));
340 } 340 }
341 341
342 void UserManagerImpl::RetailModeUserLoggedIn() {
343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
344 is_current_user_new_ = true;
345 active_user_ = User::CreateRetailModeUser();
346 user_image_manager_->UserLoggedIn(kRetailModeUserEMail,
347 is_current_user_new_,
348 true);
349 WallpaperManager::Get()->SetInitialUserWallpaper(kRetailModeUserEMail, false);
350 }
351
352 void UserManagerImpl::GuestUserLoggedIn() {
353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
354 WallpaperManager::Get()->SetInitialUserWallpaper(kGuestUserEMail, false);
355 active_user_ = User::CreateGuestUser();
356 // TODO(nkostylev): Add support for passing guest session cryptohome
357 // mount point. Legacy (--login-profile) value will be used for now.
358 // http://crosbug.com/230859
359 active_user_->SetStubImage(User::kInvalidImageIndex, false);
360 }
361
362 void UserManagerImpl::KioskAppLoggedIn(const std::string& username) {
363 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
364 DCHECK_EQ(gaia::ExtractDomainName(username), kKioskAppUserDomain);
365
366 WallpaperManager::Get()->SetInitialUserWallpaper(username, false);
367 active_user_ = User::CreateKioskAppUser(username);
368 active_user_->SetStubImage(User::kInvalidImageIndex, false);
369
370 CommandLine* command_line = CommandLine::ForCurrentProcess();
371 command_line->AppendSwitch(::switches::kForceAppMode);
372 command_line->AppendSwitchASCII(::switches::kAppId,
373 active_user_->GetAccountName(false));
374 }
375
376 void UserManagerImpl::LocallyManagedUserLoggedIn(
377 const std::string& username) {
378 // TODO(nkostylev): Refactor, share code with RegularUserLoggedIn().
379
380 // Remove the user from the user list.
381 active_user_ = RemoveRegularOrLocallyManagedUserFromList(username);
382 // If the user was not found on the user list, create a new user.
383 if (!active_user_) {
384 is_current_user_new_ = true;
385 active_user_ = User::CreateLocallyManagedUser(username);
386 // Leaving OAuth token status at the default state = unknown.
387 WallpaperManager::Get()->SetInitialUserWallpaper(username, true);
388 } else {
389 ListPrefUpdate prefs_new_users_update(g_browser_process->local_state(),
390 kLocallyManagedUsersFirstRun);
391 if (prefs_new_users_update->Remove(base::StringValue(username), NULL)) {
392 is_current_user_new_ = true;
393 WallpaperManager::Get()->SetInitialUserWallpaper(username, true);
394 }
395 }
396
397 // Add the user to the front of the user list.
398 ListPrefUpdate prefs_users_update(g_browser_process->local_state(),
399 kRegularUsers);
400 prefs_users_update->Insert(0, new base::StringValue(username));
401 users_.insert(users_.begin(), active_user_);
402
403 // Now that user is in the list, save display name.
404 if (is_current_user_new_) {
405 SaveUserDisplayName(active_user_->email(),
406 active_user_->GetDisplayName());
407 }
408
409 user_image_manager_->UserLoggedIn(username, is_current_user_new_, true);
410 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
411
412 // Make sure that new data is persisted to Local State.
413 g_browser_process->local_state()->CommitPendingWrite();
414 }
415
416 void UserManagerImpl::PublicAccountUserLoggedIn(User* user) {
417 is_current_user_new_ = true;
418 active_user_ = user;
419 // The UserImageManager chooses a random avatar picture when a user logs in
420 // for the first time. Tell the UserImageManager that this user is not new to
421 // prevent the avatar from getting changed.
422 user_image_manager_->UserLoggedIn(user->email(), false, true);
423 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
424 }
425
426 void UserManagerImpl::RegularUserLoggedIn(const std::string& email,
427 bool browser_restart) {
428 // Remove the user from the user list.
429 active_user_ = RemoveRegularOrLocallyManagedUserFromList(email);
430
431 // If the user was not found on the user list, create a new user.
432 if (!active_user_) {
433 is_current_user_new_ = true;
434 active_user_ = User::CreateRegularUser(email);
435 active_user_->set_oauth_token_status(LoadUserOAuthStatus(email));
436 SaveUserDisplayName(active_user_->email(),
437 UTF8ToUTF16(active_user_->GetAccountName(true)));
438 WallpaperManager::Get()->SetInitialUserWallpaper(email, true);
439 }
440
441 // Add the user to the front of the user list.
442 ListPrefUpdate prefs_users_update(g_browser_process->local_state(),
443 kRegularUsers);
444 prefs_users_update->Insert(0, new base::StringValue(email));
445 users_.insert(users_.begin(), active_user_);
446
447 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false);
448
449 if (!browser_restart) {
450 // For GAIA login flow, logged in user wallpaper may not be loaded.
451 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
452 }
453
454 // Make sure that new data is persisted to Local State.
455 g_browser_process->local_state()->CommitPendingWrite();
456 }
457
458 void UserManagerImpl::RegularUserLoggedInAsEphemeral(const std::string& email) {
459 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
460 is_current_user_new_ = true;
461 is_current_user_ephemeral_regular_user_ = true;
462 active_user_ = User::CreateRegularUser(email);
463 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false);
464 WallpaperManager::Get()->SetInitialUserWallpaper(email, false);
465 }
466
467 void UserManagerImpl::SessionStarted() { 342 void UserManagerImpl::SessionStarted() {
468 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
469 session_started_ = true; 344 session_started_ = true;
470 content::NotificationService::current()->Notify( 345 content::NotificationService::current()->Notify(
471 chrome::NOTIFICATION_SESSION_STARTED, 346 chrome::NOTIFICATION_SESSION_STARTED,
472 content::Source<UserManager>(this), 347 content::Source<UserManager>(this),
473 content::Details<const User>(active_user_)); 348 content::Details<const User>(active_user_));
474 if (is_current_user_new_) { 349 if (is_current_user_new_) {
475 // Make sure that the new user's data is persisted to Local State. 350 // Make sure that the new user's data is persisted to Local State.
476 g_browser_process->local_state()->CommitPendingWrite(); 351 g_browser_process->local_state()->CommitPendingWrite();
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 946
1072 User* UserManagerImpl::FindUserInListAndModify(const std::string& email) { 947 User* UserManagerImpl::FindUserInListAndModify(const std::string& email) {
1073 UserList& users = GetUsersAndModify(); 948 UserList& users = GetUsersAndModify();
1074 for (UserList::iterator it = users.begin(); it != users.end(); ++it) { 949 for (UserList::iterator it = users.begin(); it != users.end(); ++it) {
1075 if ((*it)->email() == email) 950 if ((*it)->email() == email)
1076 return *it; 951 return *it;
1077 } 952 }
1078 return NULL; 953 return NULL;
1079 } 954 }
1080 955
956 void UserManagerImpl::GuestUserLoggedIn() {
957 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
958 WallpaperManager::Get()->SetInitialUserWallpaper(kGuestUserEMail, false);
959 active_user_ = User::CreateGuestUser();
960 // TODO(nkostylev): Add support for passing guest session cryptohome
961 // mount point. Legacy (--login-profile) value will be used for now.
962 // http://crosbug.com/230859
963 active_user_->SetStubImage(User::kInvalidImageIndex, false);
964 }
965
966 void UserManagerImpl::RegularUserLoggedIn(const std::string& email,
967 bool browser_restart) {
968 // Remove the user from the user list.
969 active_user_ = RemoveRegularOrLocallyManagedUserFromList(email);
970
971 // If the user was not found on the user list, create a new user.
972 if (!active_user_) {
973 is_current_user_new_ = true;
974 active_user_ = User::CreateRegularUser(email);
975 active_user_->set_oauth_token_status(LoadUserOAuthStatus(email));
976 SaveUserDisplayName(active_user_->email(),
977 UTF8ToUTF16(active_user_->GetAccountName(true)));
978 WallpaperManager::Get()->SetInitialUserWallpaper(email, true);
979 }
980
981 // Add the user to the front of the user list.
982 ListPrefUpdate prefs_users_update(g_browser_process->local_state(),
983 kRegularUsers);
984 prefs_users_update->Insert(0, new base::StringValue(email));
985 users_.insert(users_.begin(), active_user_);
986
987 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false);
988
989 if (!browser_restart) {
990 // For GAIA login flow, logged in user wallpaper may not be loaded.
991 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
992 }
993
994 // Make sure that new data is persisted to Local State.
995 g_browser_process->local_state()->CommitPendingWrite();
996 }
997
998 void UserManagerImpl::RegularUserLoggedInAsEphemeral(const std::string& email) {
999 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1000 is_current_user_new_ = true;
1001 is_current_user_ephemeral_regular_user_ = true;
1002 active_user_ = User::CreateRegularUser(email);
1003 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false);
1004 WallpaperManager::Get()->SetInitialUserWallpaper(email, false);
1005 }
1006
1007 void UserManagerImpl::LocallyManagedUserLoggedIn(
1008 const std::string& username) {
1009 // TODO(nkostylev): Refactor, share code with RegularUserLoggedIn().
1010
1011 // Remove the user from the user list.
1012 active_user_ = RemoveRegularOrLocallyManagedUserFromList(username);
1013 // If the user was not found on the user list, create a new user.
1014 if (!active_user_) {
1015 is_current_user_new_ = true;
1016 active_user_ = User::CreateLocallyManagedUser(username);
1017 // Leaving OAuth token status at the default state = unknown.
1018 WallpaperManager::Get()->SetInitialUserWallpaper(username, true);
1019 } else {
1020 ListPrefUpdate prefs_new_users_update(g_browser_process->local_state(),
1021 kLocallyManagedUsersFirstRun);
1022 if (prefs_new_users_update->Remove(base::StringValue(username), NULL)) {
1023 is_current_user_new_ = true;
1024 WallpaperManager::Get()->SetInitialUserWallpaper(username, true);
1025 }
1026 }
1027
1028 // Add the user to the front of the user list.
1029 ListPrefUpdate prefs_users_update(g_browser_process->local_state(),
1030 kRegularUsers);
1031 prefs_users_update->Insert(0, new base::StringValue(username));
1032 users_.insert(users_.begin(), active_user_);
1033
1034 // Now that user is in the list, save display name.
1035 if (is_current_user_new_) {
1036 SaveUserDisplayName(active_user_->email(),
1037 active_user_->GetDisplayName());
1038 }
1039
1040 user_image_manager_->UserLoggedIn(username, is_current_user_new_, true);
1041 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
1042
1043 // Make sure that new data is persisted to Local State.
1044 g_browser_process->local_state()->CommitPendingWrite();
1045 }
1046
1047 void UserManagerImpl::PublicAccountUserLoggedIn(User* user) {
1048 is_current_user_new_ = true;
1049 active_user_ = user;
1050 // The UserImageManager chooses a random avatar picture when a user logs in
1051 // for the first time. Tell the UserImageManager that this user is not new to
1052 // prevent the avatar from getting changed.
1053 user_image_manager_->UserLoggedIn(user->email(), false, true);
1054 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
1055 }
1056
1057 void UserManagerImpl::KioskAppLoggedIn(const std::string& username) {
1058 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1059 DCHECK_EQ(gaia::ExtractDomainName(username), kKioskAppUserDomain);
1060
1061 WallpaperManager::Get()->SetInitialUserWallpaper(username, false);
1062 active_user_ = User::CreateKioskAppUser(username);
1063 active_user_->SetStubImage(User::kInvalidImageIndex, false);
1064
1065 CommandLine* command_line = CommandLine::ForCurrentProcess();
1066 command_line->AppendSwitch(::switches::kForceAppMode);
1067 command_line->AppendSwitchASCII(::switches::kAppId,
1068 active_user_->GetAccountName(false));
1069 }
1070
1071 void UserManagerImpl::RetailModeUserLoggedIn() {
1072 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1073 is_current_user_new_ = true;
1074 active_user_ = User::CreateRetailModeUser();
1075 user_image_manager_->UserLoggedIn(kRetailModeUserEMail,
1076 is_current_user_new_,
1077 true);
1078 WallpaperManager::Get()->SetInitialUserWallpaper(kRetailModeUserEMail, false);
1079 }
1080
1081 void UserManagerImpl::NotifyOnLogin() { 1081 void UserManagerImpl::NotifyOnLogin() {
1082 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1082 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1083 content::NotificationService::current()->Notify( 1083 content::NotificationService::current()->Notify(
1084 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 1084 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
1085 content::Source<UserManager>(this), 1085 content::Source<UserManager>(this),
1086 content::Details<const User>(active_user_)); 1086 content::Details<const User>(active_user_));
1087 1087
1088 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore(); 1088 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore();
1089 1089
1090 // Indicate to DeviceSettingsService that the owner key may have become 1090 // Indicate to DeviceSettingsService that the owner key may have become
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 content::NotificationService::NoDetails()); 1387 content::NotificationService::NoDetails());
1388 } 1388 }
1389 1389
1390 void UserManagerImpl::NotifyMergeSessionStateChanged() { 1390 void UserManagerImpl::NotifyMergeSessionStateChanged() {
1391 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1391 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1392 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_, 1392 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_,
1393 MergeSessionStateChanged(merge_session_state_)); 1393 MergeSessionStateChanged(merge_session_state_));
1394 } 1394 }
1395 1395
1396 } // namespace chromeos 1396 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/user_manager_impl.h ('k') | chrome/browser/chromeos/login/wizard_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698