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

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

Issue 9839098: Fix wallpaper change to a random one when user first click "set wallpaper". (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix linux_chromeos crash Created 8 years, 9 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) 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 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 base::Bind(&UserManagerImpl::CheckOwnership, 900 base::Bind(&UserManagerImpl::CheckOwnership,
901 base::Unretained(this))); 901 base::Unretained(this)));
902 } 902 }
903 903
904 void UserManagerImpl::SetInitialUserImage(const std::string& username) { 904 void UserManagerImpl::SetInitialUserImage(const std::string& username) {
905 // Choose a random default image. 905 // Choose a random default image.
906 int image_id = base::RandInt(0, kDefaultImagesCount - 1); 906 int image_id = base::RandInt(0, kDefaultImagesCount - 1);
907 SaveUserDefaultImageIndex(username, image_id); 907 SaveUserDefaultImageIndex(username, image_id);
908 } 908 }
909 909
910 int UserManagerImpl::GetUserWallpaper(const std::string& username) { 910 int UserManagerImpl::GetUserWallpaperIndex() {
911 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 911 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
912 912
913 // If at login screen or logged in as a guest/incognito user, then use the
914 // randomly generated wallpaper.
915 if (IsLoggedInAsGuest() || !IsUserLoggedIn())
Nikita (slow) 2012/03/25 21:24:08 + IsCurrentUserEphemeral() In fact you should rem
916 return ash::GetGuestWallpaperIndex();
917
918 const chromeos::User& user = GetLoggedInUser();
919 std::string username = user.email();
920 DCHECK(!username.empty());
921
913 PrefService* local_state = g_browser_process->local_state(); 922 PrefService* local_state = g_browser_process->local_state();
914 const DictionaryValue* user_wallpapers = 923 const DictionaryValue* user_wallpapers =
915 local_state->GetDictionary(UserManager::kUserWallpapers); 924 local_state->GetDictionary(UserManager::kUserWallpapers);
916 int index = ash::GetDefaultWallpaperIndex(); 925 int index = ash::GetDefaultWallpaperIndex();
917 user_wallpapers->GetIntegerWithoutPathExpansion(username, 926 if (!user_wallpapers->GetIntegerWithoutPathExpansion(username, &index))
918 &index); 927 SaveUserWallpaperIndex(index);
928
929 DCHECK(index >=0 && index < ash::GetWallpaperCount());
919 return index; 930 return index;
920 } 931 }
921 932
922 void UserManagerImpl::SaveWallpaperDefaultIndex(const std::string& username, 933 void UserManagerImpl::SaveUserWallpaperIndex(int wallpaper_index) {
923 int wallpaper_index) {
924 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 934 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
935 // If at login screen or logged in as a guest/incognito user, then return.
936 // Guest/incognito user can not change wallpaper according to chromium-os
937 // issue 26900.
938 if (IsLoggedInAsGuest() || !IsUserLoggedIn())
Nikita (slow) 2012/03/25 21:24:08 Change IsLoggedInAsGuest() to IsCurrentUserEphemer
939 return;
940
941 const chromeos::User& user = GetLoggedInUser();
942 std::string username = user.email();
943 DCHECK(!username.empty());
925 944
926 PrefService* local_state = g_browser_process->local_state(); 945 PrefService* local_state = g_browser_process->local_state();
927 DictionaryPrefUpdate wallpapers_update(local_state, 946 DictionaryPrefUpdate wallpapers_update(local_state,
928 UserManager::kUserWallpapers); 947 UserManager::kUserWallpapers);
929 wallpapers_update->SetWithoutPathExpansion(username, 948 wallpapers_update->SetWithoutPathExpansion(username,
930 new base::FundamentalValue(wallpaper_index)); 949 new base::FundamentalValue(wallpaper_index));
931 ash::Shell::GetInstance()->desktop_background_controller()->
932 OnDesktopBackgroundChanged();
933 } 950 }
934 951
935 void UserManagerImpl::SetUserImage(const std::string& username, 952 void UserManagerImpl::SetUserImage(const std::string& username,
936 int image_index, 953 int image_index,
937 const SkBitmap& image) { 954 const SkBitmap& image) {
938 User* user = const_cast<User*>(FindUser(username)); 955 User* user = const_cast<User*>(FindUser(username));
939 // User may have been removed by now. 956 // User may have been removed by now.
940 if (user) { 957 if (user) {
941 // For existing users, a valid image index should have been set upon loading 958 // For existing users, a valid image index should have been set upon loading
942 // them from Local State. 959 // them from Local State.
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 BrowserThread::PostTask( 1235 BrowserThread::PostTask(
1219 BrowserThread::FILE, 1236 BrowserThread::FILE,
1220 FROM_HERE, 1237 FROM_HERE,
1221 base::Bind(&UserManagerImpl::DeleteUserImage, 1238 base::Bind(&UserManagerImpl::DeleteUserImage,
1222 base::Unretained(this), 1239 base::Unretained(this),
1223 image_path)); 1240 image_path));
1224 } 1241 }
1225 } 1242 }
1226 1243
1227 } // namespace chromeos 1244 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698