| 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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 if (is_current_user_ephemeral_) | 318 if (is_current_user_ephemeral_) |
| 319 delete logged_in_user_; | 319 delete logged_in_user_; |
| 320 } | 320 } |
| 321 | 321 |
| 322 const UserList& UserManagerImpl::GetUsers() const { | 322 const UserList& UserManagerImpl::GetUsers() const { |
| 323 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); | 323 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); |
| 324 return users_; | 324 return users_; |
| 325 } | 325 } |
| 326 | 326 |
| 327 void UserManagerImpl::UserLoggedIn(const std::string& email) { | 327 void UserManagerImpl::UserLoggedIn(const std::string& email) { |
| 328 // Get a random wallpaper each time a user logged in. |
| 329 current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex(); |
| 330 |
| 328 // Remove the stub user if it is still around. | 331 // Remove the stub user if it is still around. |
| 329 if (logged_in_user_) { | 332 if (logged_in_user_) { |
| 330 DCHECK(IsLoggedInAsStub()); | 333 DCHECK(IsLoggedInAsStub()); |
| 331 delete logged_in_user_; | 334 delete logged_in_user_; |
| 332 logged_in_user_ = NULL; | 335 logged_in_user_ = NULL; |
| 333 is_current_user_ephemeral_ = false; | 336 is_current_user_ephemeral_ = false; |
| 334 } | 337 } |
| 335 | 338 |
| 336 if (email == kGuestUser) { | 339 if (email == kGuestUser) { |
| 337 GuestUserLoggedIn(); | 340 GuestUserLoggedIn(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 void UserManagerImpl::DemoUserLoggedIn() { | 418 void UserManagerImpl::DemoUserLoggedIn() { |
| 416 is_current_user_new_ = true; | 419 is_current_user_new_ = true; |
| 417 is_current_user_ephemeral_ = true; | 420 is_current_user_ephemeral_ = true; |
| 418 logged_in_user_ = new User(kDemoUser, false); | 421 logged_in_user_ = new User(kDemoUser, false); |
| 419 SetInitialUserImage(kDemoUser); | 422 SetInitialUserImage(kDemoUser); |
| 420 NotifyOnLogin(); | 423 NotifyOnLogin(); |
| 421 } | 424 } |
| 422 | 425 |
| 423 void UserManagerImpl::GuestUserLoggedIn() { | 426 void UserManagerImpl::GuestUserLoggedIn() { |
| 424 is_current_user_ephemeral_ = true; | 427 is_current_user_ephemeral_ = true; |
| 428 // Guest user always uses the same wallpaper. |
| 429 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex(); |
| 425 logged_in_user_ = new User(kGuestUser, true); | 430 logged_in_user_ = new User(kGuestUser, true); |
| 426 NotifyOnLogin(); | 431 NotifyOnLogin(); |
| 427 } | 432 } |
| 428 | 433 |
| 429 void UserManagerImpl::EphemeralUserLoggedIn(const std::string& email) { | 434 void UserManagerImpl::EphemeralUserLoggedIn(const std::string& email) { |
| 430 is_current_user_new_ = true; | 435 is_current_user_new_ = true; |
| 431 is_current_user_ephemeral_ = true; | 436 is_current_user_ephemeral_ = true; |
| 432 logged_in_user_ = CreateUser(email); | 437 logged_in_user_ = CreateUser(email); |
| 433 SetInitialUserImage(email); | 438 SetInitialUserImage(email); |
| 434 NotifyOnLogin(); | 439 NotifyOnLogin(); |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 | 919 |
| 915 void UserManagerImpl::SetInitialUserImage(const std::string& username) { | 920 void UserManagerImpl::SetInitialUserImage(const std::string& username) { |
| 916 // Choose a random default image. | 921 // Choose a random default image. |
| 917 int image_id = base::RandInt(0, kDefaultImagesCount - 1); | 922 int image_id = base::RandInt(0, kDefaultImagesCount - 1); |
| 918 SaveUserDefaultImageIndex(username, image_id); | 923 SaveUserDefaultImageIndex(username, image_id); |
| 919 } | 924 } |
| 920 | 925 |
| 921 int UserManagerImpl::GetUserWallpaperIndex() { | 926 int UserManagerImpl::GetUserWallpaperIndex() { |
| 922 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 927 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 923 | 928 |
| 924 // If at login screen or logged in as a guest/incognito user, then use the | 929 // If at login screen, use the default guest wallpaper. |
| 925 // randomly generated wallpaper. | 930 if (!IsUserLoggedIn()) |
| 926 if (IsLoggedInAsGuest() || !IsUserLoggedIn()) | |
| 927 return ash::GetGuestWallpaperIndex(); | 931 return ash::GetGuestWallpaperIndex(); |
| 932 // If logged in as other ephemeral users (Demo/Stub/Normal user with |
| 933 // ephemeral policy enabled/Guest), use the index in memory. |
| 934 if (IsCurrentUserEphemeral()) |
| 935 return current_user_wallpaper_index_; |
| 928 | 936 |
| 929 const chromeos::User& user = GetLoggedInUser(); | 937 const chromeos::User& user = GetLoggedInUser(); |
| 930 std::string username = user.email(); | 938 std::string username = user.email(); |
| 931 DCHECK(!username.empty()); | 939 DCHECK(!username.empty()); |
| 932 | 940 |
| 933 PrefService* local_state = g_browser_process->local_state(); | 941 PrefService* local_state = g_browser_process->local_state(); |
| 934 const DictionaryValue* user_wallpapers = | 942 const DictionaryValue* user_wallpapers = |
| 935 local_state->GetDictionary(UserManager::kUserWallpapers); | 943 local_state->GetDictionary(UserManager::kUserWallpapers); |
| 936 int index = ash::GetDefaultWallpaperIndex(); | 944 int index; |
| 937 if (!user_wallpapers->GetIntegerWithoutPathExpansion(username, &index)) | 945 if (!user_wallpapers->GetIntegerWithoutPathExpansion(username, &index)) |
| 938 SaveUserWallpaperIndex(index); | 946 index = current_user_wallpaper_index_; |
| 939 | 947 |
| 940 DCHECK(index >=0 && index < ash::GetWallpaperCount()); | 948 DCHECK(index >=0 && index < ash::GetWallpaperCount()); |
| 941 return index; | 949 return index; |
| 942 } | 950 } |
| 943 | 951 |
| 944 void UserManagerImpl::SaveUserWallpaperIndex(int wallpaper_index) { | 952 void UserManagerImpl::SaveUserWallpaperIndex(int wallpaper_index) { |
| 945 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 953 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 946 // If at login screen or logged in as a guest/incognito user, then return. | 954 |
| 947 // Guest/incognito user can not change wallpaper according to chromium-os | 955 current_user_wallpaper_index_ = wallpaper_index; |
| 948 // issue 26900. | 956 // Ephemeral users can not save data to local state. We just cache the index |
| 949 if (IsLoggedInAsGuest() || !IsUserLoggedIn()) | 957 // in memory for them. |
| 958 if (IsCurrentUserEphemeral() || !IsUserLoggedIn()) { |
| 950 return; | 959 return; |
| 960 } |
| 951 | 961 |
| 952 const chromeos::User& user = GetLoggedInUser(); | 962 const chromeos::User& user = GetLoggedInUser(); |
| 953 std::string username = user.email(); | 963 std::string username = user.email(); |
| 954 DCHECK(!username.empty()); | 964 DCHECK(!username.empty()); |
| 955 | 965 |
| 956 PrefService* local_state = g_browser_process->local_state(); | 966 PrefService* local_state = g_browser_process->local_state(); |
| 957 DictionaryPrefUpdate wallpapers_update(local_state, | 967 DictionaryPrefUpdate wallpapers_update(local_state, |
| 958 UserManager::kUserWallpapers); | 968 UserManager::kUserWallpapers); |
| 959 wallpapers_update->SetWithoutPathExpansion(username, | 969 wallpapers_update->SetWithoutPathExpansion(username, |
| 960 new base::FundamentalValue(wallpaper_index)); | 970 new base::FundamentalValue(wallpaper_index)); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 BrowserThread::PostTask( | 1256 BrowserThread::PostTask( |
| 1247 BrowserThread::FILE, | 1257 BrowserThread::FILE, |
| 1248 FROM_HERE, | 1258 FROM_HERE, |
| 1249 base::Bind(&UserManagerImpl::DeleteUserImage, | 1259 base::Bind(&UserManagerImpl::DeleteUserImage, |
| 1250 base::Unretained(this), | 1260 base::Unretained(this), |
| 1251 image_path)); | 1261 image_path)); |
| 1252 } | 1262 } |
| 1253 } | 1263 } |
| 1254 | 1264 |
| 1255 } // namespace chromeos | 1265 } // namespace chromeos |
| OLD | NEW |