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

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

Issue 10207030: Asynchronously load wallpapers when user pod is selected. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add user wallpaper for first time logged in user and ephemeral users Created 8 years, 7 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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 logged_in_user_ = CreateUser(email); 376 logged_in_user_ = CreateUser(email);
377 } else { 377 } else {
378 logged_in_user_ = *logged_in_user; 378 logged_in_user_ = *logged_in_user;
379 users_.erase(logged_in_user); 379 users_.erase(logged_in_user);
380 } 380 }
381 // This user must be in the front of the user list. 381 // This user must be in the front of the user list.
382 users_.insert(users_.begin(), logged_in_user_); 382 users_.insert(users_.begin(), logged_in_user_);
383 383
384 if (is_current_user_new_) { 384 if (is_current_user_new_) {
385 SetInitialUserImage(email); 385 SetInitialUserImage(email);
386 SetInitialUserWallpaper(email);
386 } else { 387 } else {
387 // Download profile image if it's user image and see if it has changed. 388 // Download profile image if it's user image and see if it has changed.
388 int image_index = logged_in_user_->image_index(); 389 int image_index = logged_in_user_->image_index();
389 if (image_index == User::kProfileImageIndex) { 390 if (image_index == User::kProfileImageIndex) {
390 InitDownloadedProfileImage(); 391 InitDownloadedProfileImage();
391 BrowserThread::PostDelayedTask( 392 BrowserThread::PostDelayedTask(
392 BrowserThread::UI, 393 BrowserThread::UI,
393 FROM_HERE, 394 FROM_HERE,
394 base::Bind(&UserManagerImpl::DownloadProfileImage, 395 base::Bind(&UserManagerImpl::DownloadProfileImage,
395 base::Unretained(this), 396 base::Unretained(this),
(...skipping 18 matching lines...) Expand all
414 } 415 }
415 416
416 NotifyOnLogin(); 417 NotifyOnLogin();
417 } 418 }
418 419
419 void UserManagerImpl::DemoUserLoggedIn() { 420 void UserManagerImpl::DemoUserLoggedIn() {
420 is_current_user_new_ = true; 421 is_current_user_new_ = true;
421 is_current_user_ephemeral_ = true; 422 is_current_user_ephemeral_ = true;
422 logged_in_user_ = new User(kDemoUser, false); 423 logged_in_user_ = new User(kDemoUser, false);
423 SetInitialUserImage(kDemoUser); 424 SetInitialUserImage(kDemoUser);
425 SetInitialUserWallpaper(kDemoUser);
424 NotifyOnLogin(); 426 NotifyOnLogin();
425 } 427 }
426 428
427 void UserManagerImpl::GuestUserLoggedIn() { 429 void UserManagerImpl::GuestUserLoggedIn() {
428 is_current_user_ephemeral_ = true; 430 is_current_user_ephemeral_ = true;
429 // Guest user always uses the same wallpaper. 431 // Guest user always uses the same wallpaper.
430 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex(); 432 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex();
431 logged_in_user_ = new User(kGuestUser, true); 433 logged_in_user_ = new User(kGuestUser, true);
434 SetInitialUserWallpaper(kGuestUser);
432 NotifyOnLogin(); 435 NotifyOnLogin();
433 } 436 }
434 437
435 void UserManagerImpl::EphemeralUserLoggedIn(const std::string& email) { 438 void UserManagerImpl::EphemeralUserLoggedIn(const std::string& email) {
436 is_current_user_new_ = true; 439 is_current_user_new_ = true;
437 is_current_user_ephemeral_ = true; 440 is_current_user_ephemeral_ = true;
438 logged_in_user_ = CreateUser(email); 441 logged_in_user_ = CreateUser(email);
439 SetInitialUserImage(email); 442 SetInitialUserImage(email);
443 SetInitialUserWallpaper(email);
440 NotifyOnLogin(); 444 NotifyOnLogin();
441 } 445 }
442 446
443 void UserManagerImpl::StubUserLoggedIn() { 447 void UserManagerImpl::StubUserLoggedIn() {
444 is_current_user_ephemeral_ = true; 448 is_current_user_ephemeral_ = true;
445 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex(); 449 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex();
446 logged_in_user_ = new User(kStubUser, false); 450 logged_in_user_ = new User(kStubUser, false);
447 logged_in_user_->SetImage(GetDefaultImage(kStubDefaultImageIndex), 451 logged_in_user_->SetImage(GetDefaultImage(kStubDefaultImageIndex),
448 kStubDefaultImageIndex); 452 kStubDefaultImageIndex);
453 SetInitialUserWallpaper(kStubUser);
454 }
455
456 void UserManagerImpl::UserSelected(const std::string& email) {
457 if (IsKnownUser(email)) {
458 ash::Shell::GetInstance()->desktop_background_controller()->
459 SetDefaultWallpaper(FindUserWallpaperIndex(email));
460 }
449 } 461 }
450 462
451 void UserManagerImpl::RemoveUser(const std::string& email, 463 void UserManagerImpl::RemoveUser(const std::string& email,
452 RemoveUserDelegate* delegate) { 464 RemoveUserDelegate* delegate) {
453 if (!IsKnownUser(email)) 465 if (!IsKnownUser(email))
454 return; 466 return;
455 467
456 // Sanity check: we must not remove single user. This check may seem 468 // Sanity check: we must not remove single user. This check may seem
457 // redundant at a first sight because this single user must be an owner and 469 // redundant at a first sight because this single user must be an owner and
458 // we perform special check later in order not to remove an owner. However 470 // we perform special check later in order not to remove an owner. However
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 887
876 const User* UserManagerImpl::FindUserInList(const std::string& email) const { 888 const User* UserManagerImpl::FindUserInList(const std::string& email) const {
877 const UserList& users = GetUsers(); 889 const UserList& users = GetUsers();
878 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { 890 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) {
879 if ((*it)->email() == email) 891 if ((*it)->email() == email)
880 return *it; 892 return *it;
881 } 893 }
882 return NULL; 894 return NULL;
883 } 895 }
884 896
897 int UserManagerImpl::FindUserWallpaperIndex(const std::string& email) {
898 PrefService* local_state = g_browser_process->local_state();
899 const DictionaryValue* user_wallpapers =
900 local_state->GetDictionary(UserManager::kUserWallpapers);
901 int index;
902 if (!user_wallpapers->GetIntegerWithoutPathExpansion(email, &index))
903 index = current_user_wallpaper_index_;
904 if (index < 0 || index >= ash::GetWallpaperCount()) {
905 index = ash::GetDefaultWallpaperIndex();
906 SaveUserWallpaperIndex(index);
907 }
908 return index;
909 }
910
885 void UserManagerImpl::NotifyOnLogin() { 911 void UserManagerImpl::NotifyOnLogin() {
886 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 912 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
887 content::NotificationService::current()->Notify( 913 content::NotificationService::current()->Notify(
888 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 914 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
889 content::Source<UserManagerImpl>(this), 915 content::Source<UserManagerImpl>(this),
890 content::Details<const User>(logged_in_user_)); 916 content::Details<const User>(logged_in_user_));
891 917
892 LoadKeyStore(); 918 LoadKeyStore();
893 919
894 // Schedules current user ownership check on file thread. 920 // Schedules current user ownership check on file thread.
(...skipping 28 matching lines...) Expand all
923 } 949 }
924 key_store_loaded_ = true; 950 key_store_loaded_ = true;
925 } 951 }
926 952
927 void UserManagerImpl::SetInitialUserImage(const std::string& username) { 953 void UserManagerImpl::SetInitialUserImage(const std::string& username) {
928 // Choose a random default image. 954 // Choose a random default image.
929 int image_id = base::RandInt(0, kDefaultImagesCount - 1); 955 int image_id = base::RandInt(0, kDefaultImagesCount - 1);
930 SaveUserDefaultImageIndex(username, image_id); 956 SaveUserDefaultImageIndex(username, image_id);
931 } 957 }
932 958
959 void UserManagerImpl::SetInitialUserWallpaper(const std::string& username) {
960 if (username == kGuestUser)
961 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex();
962 else
963 current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex();
Nikita (slow) 2012/05/02 09:22:23 Ideally we might start preloading some random wall
bshe 2012/05/03 01:02:00 I agree, ideally we should start loading wallpaper
964 SaveUserWallpaperIndex(current_user_wallpaper_index_);
965 ash::Shell::GetInstance()->desktop_background_controller()->
966 SetDefaultWallpaper(current_user_wallpaper_index_);
967 }
968
933 int UserManagerImpl::GetUserWallpaperIndex() { 969 int UserManagerImpl::GetUserWallpaperIndex() {
934 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 970 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
935 971
936 // If at login screen, use the default guest wallpaper. 972 // If at login screen, use the default guest wallpaper.
937 if (!IsUserLoggedIn()) 973 if (!IsUserLoggedIn())
938 return ash::GetGuestWallpaperIndex(); 974 return ash::GetGuestWallpaperIndex();
939 // If logged in as other ephemeral users (Demo/Stub/Normal user with 975 // If logged in as other ephemeral users (Demo/Stub/Normal user with
940 // ephemeral policy enabled/Guest), use the index in memory. 976 // ephemeral policy enabled/Guest), use the index in memory.
941 if (IsCurrentUserEphemeral()) 977 if (IsCurrentUserEphemeral())
942 return current_user_wallpaper_index_; 978 return current_user_wallpaper_index_;
943 979
944 const chromeos::User& user = GetLoggedInUser(); 980 const chromeos::User& user = GetLoggedInUser();
945 std::string username = user.email(); 981 std::string username = user.email();
946 DCHECK(!username.empty()); 982 DCHECK(!username.empty());
947 983 return FindUserWallpaperIndex(username);
948 PrefService* local_state = g_browser_process->local_state();
949 const DictionaryValue* user_wallpapers =
950 local_state->GetDictionary(UserManager::kUserWallpapers);
951 int index;
952 if (!user_wallpapers->GetIntegerWithoutPathExpansion(username, &index))
953 index = current_user_wallpaper_index_;
954
955 if (index < 0 || index >= ash::GetWallpaperCount()) {
956 index = ash::GetDefaultWallpaperIndex();
957 SaveUserWallpaperIndex(index);
958 }
959 return index;
960 } 984 }
961 985
962 void UserManagerImpl::SaveUserWallpaperIndex(int wallpaper_index) { 986 void UserManagerImpl::SaveUserWallpaperIndex(int wallpaper_index) {
963 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 987 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
964 988
965 current_user_wallpaper_index_ = wallpaper_index; 989 current_user_wallpaper_index_ = wallpaper_index;
966 // Ephemeral users can not save data to local state. We just cache the index 990 // Ephemeral users can not save data to local state. We just cache the index
967 // in memory for them. 991 // in memory for them.
968 if (IsCurrentUserEphemeral() || !IsUserLoggedIn()) { 992 if (IsCurrentUserEphemeral() || !IsUserLoggedIn()) {
969 return; 993 return;
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 BrowserThread::PostTask( 1290 BrowserThread::PostTask(
1267 BrowserThread::FILE, 1291 BrowserThread::FILE,
1268 FROM_HERE, 1292 FROM_HERE,
1269 base::Bind(&UserManagerImpl::DeleteUserImage, 1293 base::Bind(&UserManagerImpl::DeleteUserImage,
1270 base::Unretained(this), 1294 base::Unretained(this),
1271 image_path)); 1295 image_path));
1272 } 1296 }
1273 } 1297 }
1274 1298
1275 } // namespace chromeos 1299 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698