| 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 "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/desktop_background/desktop_background_controller.h" | 10 #include "ash/desktop_background/desktop_background_controller.h" |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 logged_in_user_ = CreateUser(email); | 377 logged_in_user_ = CreateUser(email); |
| 378 } else { | 378 } else { |
| 379 logged_in_user_ = *logged_in_user; | 379 logged_in_user_ = *logged_in_user; |
| 380 users_.erase(logged_in_user); | 380 users_.erase(logged_in_user); |
| 381 } | 381 } |
| 382 // This user must be in the front of the user list. | 382 // This user must be in the front of the user list. |
| 383 users_.insert(users_.begin(), logged_in_user_); | 383 users_.insert(users_.begin(), logged_in_user_); |
| 384 | 384 |
| 385 if (is_current_user_new_) { | 385 if (is_current_user_new_) { |
| 386 SetInitialUserImage(email); | 386 SetInitialUserImage(email); |
| 387 SetInitialUserWallpaper(email); |
| 387 } else { | 388 } else { |
| 388 // Download profile image if it's user image and see if it has changed. | 389 // Download profile image if it's user image and see if it has changed. |
| 389 int image_index = logged_in_user_->image_index(); | 390 int image_index = logged_in_user_->image_index(); |
| 390 if (image_index == User::kProfileImageIndex) { | 391 if (image_index == User::kProfileImageIndex) { |
| 391 InitDownloadedProfileImage(); | 392 InitDownloadedProfileImage(); |
| 392 BrowserThread::PostDelayedTask( | 393 BrowserThread::PostDelayedTask( |
| 393 BrowserThread::UI, | 394 BrowserThread::UI, |
| 394 FROM_HERE, | 395 FROM_HERE, |
| 395 base::Bind(&UserManagerImpl::DownloadProfileImage, | 396 base::Bind(&UserManagerImpl::DownloadProfileImage, |
| 396 base::Unretained(this), | 397 base::Unretained(this), |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 } | 443 } |
| 443 | 444 |
| 444 void UserManagerImpl::StubUserLoggedIn() { | 445 void UserManagerImpl::StubUserLoggedIn() { |
| 445 is_current_user_ephemeral_ = true; | 446 is_current_user_ephemeral_ = true; |
| 446 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex(); | 447 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex(); |
| 447 logged_in_user_ = new User(kStubUser, false); | 448 logged_in_user_ = new User(kStubUser, false); |
| 448 logged_in_user_->SetImage(GetDefaultImage(kStubDefaultImageIndex), | 449 logged_in_user_->SetImage(GetDefaultImage(kStubDefaultImageIndex), |
| 449 kStubDefaultImageIndex); | 450 kStubDefaultImageIndex); |
| 450 } | 451 } |
| 451 | 452 |
| 453 void UserManagerImpl::UserSelected(const std::string& email) { |
| 454 if (IsKnownUser(email)) { |
| 455 ash::Shell::GetInstance()->desktop_background_controller()-> |
| 456 SetDefaultWallpaper(FindUserWallpaperIndex(email)); |
| 457 } |
| 458 } |
| 459 |
| 452 void UserManagerImpl::SessionStarted() { | 460 void UserManagerImpl::SessionStarted() { |
| 453 session_started_ = true; | 461 session_started_ = true; |
| 454 content::NotificationService::current()->Notify( | 462 content::NotificationService::current()->Notify( |
| 455 chrome::NOTIFICATION_SESSION_STARTED, | 463 chrome::NOTIFICATION_SESSION_STARTED, |
| 456 content::NotificationService::AllSources(), | 464 content::NotificationService::AllSources(), |
| 457 content::NotificationService::NoDetails()); | 465 content::NotificationService::NoDetails()); |
| 458 } | 466 } |
| 459 | 467 |
| 460 void UserManagerImpl::RemoveUser(const std::string& email, | 468 void UserManagerImpl::RemoveUser(const std::string& email, |
| 461 RemoveUserDelegate* delegate) { | 469 RemoveUserDelegate* delegate) { |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 | 896 |
| 889 const User* UserManagerImpl::FindUserInList(const std::string& email) const { | 897 const User* UserManagerImpl::FindUserInList(const std::string& email) const { |
| 890 const UserList& users = GetUsers(); | 898 const UserList& users = GetUsers(); |
| 891 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | 899 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { |
| 892 if ((*it)->email() == email) | 900 if ((*it)->email() == email) |
| 893 return *it; | 901 return *it; |
| 894 } | 902 } |
| 895 return NULL; | 903 return NULL; |
| 896 } | 904 } |
| 897 | 905 |
| 906 int UserManagerImpl::FindUserWallpaperIndex(const std::string& email) { |
| 907 PrefService* local_state = g_browser_process->local_state(); |
| 908 const DictionaryValue* user_wallpapers = |
| 909 local_state->GetDictionary(UserManager::kUserWallpapers); |
| 910 int index; |
| 911 if (!user_wallpapers->GetIntegerWithoutPathExpansion(email, &index)) |
| 912 index = current_user_wallpaper_index_; |
| 913 if (index < 0 || index >= ash::GetWallpaperCount()) { |
| 914 index = ash::GetDefaultWallpaperIndex(); |
| 915 SaveUserWallpaperIndex(index); |
| 916 } |
| 917 return index; |
| 918 } |
| 919 |
| 898 void UserManagerImpl::NotifyOnLogin() { | 920 void UserManagerImpl::NotifyOnLogin() { |
| 899 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 921 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 900 content::NotificationService::current()->Notify( | 922 content::NotificationService::current()->Notify( |
| 901 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 923 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 902 content::Source<UserManagerImpl>(this), | 924 content::Source<UserManagerImpl>(this), |
| 903 content::Details<const User>(logged_in_user_)); | 925 content::Details<const User>(logged_in_user_)); |
| 904 | 926 |
| 905 LoadKeyStore(); | 927 LoadKeyStore(); |
| 906 | 928 |
| 907 // Schedules current user ownership check on file thread. | 929 // Schedules current user ownership check on file thread. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 936 } | 958 } |
| 937 key_store_loaded_ = true; | 959 key_store_loaded_ = true; |
| 938 } | 960 } |
| 939 | 961 |
| 940 void UserManagerImpl::SetInitialUserImage(const std::string& username) { | 962 void UserManagerImpl::SetInitialUserImage(const std::string& username) { |
| 941 // Choose a random default image. | 963 // Choose a random default image. |
| 942 int image_id = base::RandInt(0, kDefaultImagesCount - 1); | 964 int image_id = base::RandInt(0, kDefaultImagesCount - 1); |
| 943 SaveUserDefaultImageIndex(username, image_id); | 965 SaveUserDefaultImageIndex(username, image_id); |
| 944 } | 966 } |
| 945 | 967 |
| 968 void UserManagerImpl::SetInitialUserWallpaper(const std::string& username) { |
| 969 // TODO(bshe): Ideally, wallpaper should start to load as soon as user click |
| 970 // "Add user". |
| 971 if (username == kGuestUser) |
| 972 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex(); |
| 973 else |
| 974 current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex(); |
| 975 SaveUserWallpaperIndex(current_user_wallpaper_index_); |
| 976 } |
| 977 |
| 946 int UserManagerImpl::GetUserWallpaperIndex() { | 978 int UserManagerImpl::GetUserWallpaperIndex() { |
| 947 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 979 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 948 | 980 |
| 949 // If at login screen, use an invalid index to prevent any wallpaper | 981 // If at login screen, use an invalid index to prevent any wallpaper |
| 950 // operation. | 982 // operation. |
| 951 if (!IsUserLoggedIn()) | 983 if (!IsUserLoggedIn() || IsLoggedInAsStub()) |
| 952 return ash::GetInvalidWallpaperIndex(); | 984 return ash::GetInvalidWallpaperIndex(); |
| 953 // If logged in as other ephemeral users (Demo/Stub/Normal user with | 985 // If logged in as other ephemeral users (Demo/Stub/Normal user with |
| 954 // ephemeral policy enabled/Guest), use the index in memory. | 986 // ephemeral policy enabled/Guest), use the index in memory. |
| 955 if (IsCurrentUserEphemeral()) | 987 if (IsCurrentUserEphemeral()) |
| 956 return current_user_wallpaper_index_; | 988 return current_user_wallpaper_index_; |
| 957 | 989 |
| 958 const chromeos::User& user = GetLoggedInUser(); | 990 const chromeos::User& user = GetLoggedInUser(); |
| 959 std::string username = user.email(); | 991 std::string username = user.email(); |
| 960 DCHECK(!username.empty()); | 992 DCHECK(!username.empty()); |
| 961 | 993 return FindUserWallpaperIndex(username); |
| 962 PrefService* local_state = g_browser_process->local_state(); | |
| 963 const DictionaryValue* user_wallpapers = | |
| 964 local_state->GetDictionary(UserManager::kUserWallpapers); | |
| 965 int index; | |
| 966 if (!user_wallpapers->GetIntegerWithoutPathExpansion(username, &index)) | |
| 967 index = current_user_wallpaper_index_; | |
| 968 | |
| 969 if (index < 0 || index >= ash::GetWallpaperCount()) { | |
| 970 index = ash::GetDefaultWallpaperIndex(); | |
| 971 SaveUserWallpaperIndex(index); | |
| 972 } | |
| 973 return index; | |
| 974 } | 994 } |
| 975 | 995 |
| 976 void UserManagerImpl::SaveUserWallpaperIndex(int wallpaper_index) { | 996 void UserManagerImpl::SaveUserWallpaperIndex(int wallpaper_index) { |
| 977 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 997 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 978 | 998 |
| 979 current_user_wallpaper_index_ = wallpaper_index; | 999 current_user_wallpaper_index_ = wallpaper_index; |
| 980 // Ephemeral users can not save data to local state. We just cache the index | 1000 // Ephemeral users can not save data to local state. We just cache the index |
| 981 // in memory for them. | 1001 // in memory for them. |
| 982 if (IsCurrentUserEphemeral() || !IsUserLoggedIn()) { | 1002 if (IsCurrentUserEphemeral() || !IsUserLoggedIn()) { |
| 983 return; | 1003 return; |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1280 BrowserThread::PostTask( | 1300 BrowserThread::PostTask( |
| 1281 BrowserThread::FILE, | 1301 BrowserThread::FILE, |
| 1282 FROM_HERE, | 1302 FROM_HERE, |
| 1283 base::Bind(&UserManagerImpl::DeleteUserImage, | 1303 base::Bind(&UserManagerImpl::DeleteUserImage, |
| 1284 base::Unretained(this), | 1304 base::Unretained(this), |
| 1285 image_path)); | 1305 image_path)); |
| 1286 } | 1306 } |
| 1287 } | 1307 } |
| 1288 | 1308 |
| 1289 } // namespace chromeos | 1309 } // namespace chromeos |
| OLD | NEW |