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