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

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

Issue 10454044: Added support for animated/nonanimated user image. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Deleted useless inclusions. Created 8 years, 6 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
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 17 matching lines...) Expand all
28 #include "chrome/browser/chromeos/cros/cert_library.h" 28 #include "chrome/browser/chromeos/cros/cert_library.h"
29 #include "chrome/browser/chromeos/cros/cros_library.h" 29 #include "chrome/browser/chromeos/cros/cros_library.h"
30 #include "chrome/browser/chromeos/cros_settings.h" 30 #include "chrome/browser/chromeos/cros_settings.h"
31 #include "chrome/browser/chromeos/cryptohome/async_method_caller.h" 31 #include "chrome/browser/chromeos/cryptohome/async_method_caller.h"
32 #include "chrome/browser/chromeos/input_method/input_method_manager.h" 32 #include "chrome/browser/chromeos/input_method/input_method_manager.h"
33 #include "chrome/browser/chromeos/login/default_user_images.h" 33 #include "chrome/browser/chromeos/login/default_user_images.h"
34 #include "chrome/browser/chromeos/login/helper.h" 34 #include "chrome/browser/chromeos/login/helper.h"
35 #include "chrome/browser/chromeos/login/login_display.h" 35 #include "chrome/browser/chromeos/login/login_display.h"
36 #include "chrome/browser/chromeos/login/ownership_service.h" 36 #include "chrome/browser/chromeos/login/ownership_service.h"
37 #include "chrome/browser/chromeos/login/remove_user_delegate.h" 37 #include "chrome/browser/chromeos/login/remove_user_delegate.h"
38 #include "chrome/browser/chromeos/login/user_image.h"
38 #include "chrome/browser/policy/browser_policy_connector.h" 39 #include "chrome/browser/policy/browser_policy_connector.h"
39 #include "chrome/browser/prefs/pref_service.h" 40 #include "chrome/browser/prefs/pref_service.h"
40 #include "chrome/browser/prefs/scoped_user_pref_update.h" 41 #include "chrome/browser/prefs/scoped_user_pref_update.h"
41 #include "chrome/browser/profiles/profile_downloader.h" 42 #include "chrome/browser/profiles/profile_downloader.h"
42 #include "chrome/browser/profiles/profile_manager.h" 43 #include "chrome/browser/profiles/profile_manager.h"
43 #include "chrome/browser/sync/profile_sync_service.h" 44 #include "chrome/browser/sync/profile_sync_service.h"
44 #include "chrome/browser/sync/profile_sync_service_factory.h" 45 #include "chrome/browser/sync/profile_sync_service_factory.h"
45 #include "chrome/browser/ui/webui/web_ui_util.h" 46 #include "chrome/browser/ui/webui/web_ui_util.h"
46 #include "chrome/common/chrome_notification_types.h" 47 #include "chrome/common/chrome_notification_types.h"
47 #include "chrome/common/chrome_paths.h" 48 #include "chrome/common/chrome_paths.h"
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 is_current_user_ephemeral_ = true; 348 is_current_user_ephemeral_ = true;
348 logged_in_user_ = CreateUser(email); 349 logged_in_user_ = CreateUser(email);
349 SetInitialUserImage(email); 350 SetInitialUserImage(email);
350 SetInitialUserWallpaper(email); 351 SetInitialUserWallpaper(email);
351 NotifyOnLogin(); 352 NotifyOnLogin();
352 } 353 }
353 354
354 void UserManagerImpl::StubUserLoggedIn() { 355 void UserManagerImpl::StubUserLoggedIn() {
355 is_current_user_ephemeral_ = true; 356 is_current_user_ephemeral_ = true;
356 logged_in_user_ = new User(kStubUser, false); 357 logged_in_user_ = new User(kStubUser, false);
357 logged_in_user_->SetImage(GetDefaultImage(kStubDefaultImageIndex), 358 logged_in_user_->SetImage(UserImage(GetDefaultImage(kStubDefaultImageIndex)),
358 kStubDefaultImageIndex); 359 kStubDefaultImageIndex);
359 } 360 }
360 361
361 void UserManagerImpl::UserSelected(const std::string& email) { 362 void UserManagerImpl::UserSelected(const std::string& email) {
362 if (IsKnownUser(email)) { 363 if (IsKnownUser(email)) {
363 User::WallpaperType type; 364 User::WallpaperType type;
364 int index; 365 int index;
365 GetUserWallpaperProperties(email, &type, &index); 366 GetUserWallpaperProperties(email, &type, &index);
366 if (type == User::RANDOM) { 367 if (type == User::RANDOM) {
367 // Generate a new random wallpaper index if the selected user chose 368 // Generate a new random wallpaper index if the selected user chose
368 // RANDOM wallpaper. 369 // RANDOM wallpaper.
369 index = ash::GetRandomWallpaperIndex(); 370 index = ash::GetRandomWallpaperIndex();
370 SaveUserWallpaperProperties(email, User::RANDOM, index); 371 SaveUserWallpaperProperties(email, User::RANDOM, index);
371 } else if (type == User::CUSTOMIZED) { 372 } else if (type == User::CUSTOMIZED) {
372 std::string wallpaper_path = 373 std::string wallpaper_path =
373 GetWallpaperPathForUser(email, false).value(); 374 GetWallpaperPathForUser(email, false).value();
374 // In customized mode, we use index pref to save the user selected 375 // In customized mode, we use index pref to save the user selected
375 // wallpaper layout. See function SaveWallpaperToLocalState(). 376 // wallpaper layout. See function SaveWallpaperToLocalState().
376 ash::WallpaperLayout layout = static_cast<ash::WallpaperLayout>(index); 377 ash::WallpaperLayout layout = static_cast<ash::WallpaperLayout>(index);
377 // Load user image asynchronously. 378 // Load user image asynchronously.
378 image_loader_->Start( 379 image_loader_->Start(
379 wallpaper_path, 0, 380 wallpaper_path, 0, false,
380 base::Bind(&UserManagerImpl::OnCustomWallpaperLoaded, 381 base::Bind(&UserManagerImpl::OnCustomWallpaperLoaded,
381 base::Unretained(this), email, layout)); 382 base::Unretained(this), email, layout));
382 return; 383 return;
383 } 384 }
384 ash::Shell::GetInstance()->desktop_background_controller()-> 385 ash::Shell::GetInstance()->desktop_background_controller()->
385 SetDefaultWallpaper(index); 386 SetDefaultWallpaper(index);
386 } 387 }
387 } 388 }
388 389
389 void UserManagerImpl::SessionStarted() { 390 void UserManagerImpl::SessionStarted() {
390 session_started_ = true; 391 session_started_ = true;
391 content::NotificationService::current()->Notify( 392 content::NotificationService::current()->Notify(
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 514
514 std::string UserManagerImpl::GetUserDisplayEmail( 515 std::string UserManagerImpl::GetUserDisplayEmail(
515 const std::string& username) const { 516 const std::string& username) const {
516 const User* user = FindUser(username); 517 const User* user = FindUser(username);
517 return user ? user->display_email() : username; 518 return user ? user->display_email() : username;
518 } 519 }
519 520
520 void UserManagerImpl::SaveUserDefaultImageIndex(const std::string& username, 521 void UserManagerImpl::SaveUserDefaultImageIndex(const std::string& username,
521 int image_index) { 522 int image_index) {
522 DCHECK(image_index >= 0 && image_index < kDefaultImagesCount); 523 DCHECK(image_index >= 0 && image_index < kDefaultImagesCount);
523 SetUserImage(username, image_index, GetDefaultImage(image_index)); 524 SetUserImage(username, image_index, UserImage(GetDefaultImage(image_index)));
524 SaveImageToLocalState(username, "", image_index, false); 525 SaveImageToLocalState(username, "", image_index, false);
525 } 526 }
526 527
527 void UserManagerImpl::SaveUserImage(const std::string& username, 528 void UserManagerImpl::SaveUserImage(const std::string& username,
528 const SkBitmap& image) { 529 const UserImage& user_image) {
529 SaveUserImageInternal(username, User::kExternalImageIndex, image); 530 SaveUserImageInternal(username, User::kExternalImageIndex, user_image);
530 } 531 }
531 532
532 void UserManagerImpl::SetLoggedInUserCustomWallpaperLayout( 533 void UserManagerImpl::SetLoggedInUserCustomWallpaperLayout(
533 ash::WallpaperLayout layout) { 534 ash::WallpaperLayout layout) {
534 // TODO(bshe): We current disabled the customized wallpaper feature for 535 // TODO(bshe): We current disabled the customized wallpaper feature for
535 // Ephemeral user. As we dont want to keep a copy of customized wallpaper in 536 // Ephemeral user. As we dont want to keep a copy of customized wallpaper in
536 // memory. Need a smarter way to solve this. 537 // memory. Need a smarter way to solve this.
537 if (IsCurrentUserEphemeral()) 538 if (IsCurrentUserEphemeral())
538 return; 539 return;
539 const chromeos::User& user = GetLoggedInUser(); 540 const chromeos::User& user = GetLoggedInUser();
540 std::string username = user.email(); 541 std::string username = user.email();
541 DCHECK(!username.empty()); 542 DCHECK(!username.empty());
542 543
543 std::string file_path = GetWallpaperPathForUser(username, false).value(); 544 std::string file_path = GetWallpaperPathForUser(username, false).value();
544 SaveWallpaperToLocalState(username, file_path, layout, User::CUSTOMIZED); 545 SaveWallpaperToLocalState(username, file_path, layout, User::CUSTOMIZED);
545 // Load wallpaper from file. 546 // Load wallpaper from file.
546 UserSelected(username); 547 UserSelected(username);
547 } 548 }
548 549
549 void UserManagerImpl::SaveUserImageFromFile(const std::string& username, 550 void UserManagerImpl::SaveUserImageFromFile(const std::string& username,
550 const FilePath& path) { 551 const FilePath& path) {
551 image_loader_->Start( 552 image_loader_->Start(
552 path.value(), login::kUserImageSize, 553 path.value(), login::kUserImageSize, true,
553 base::Bind(&UserManagerImpl::SaveUserImage, 554 base::Bind(&UserManagerImpl::SaveUserImage,
554 base::Unretained(this), username)); 555 base::Unretained(this), username));
555 } 556 }
556 557
557 void UserManagerImpl::SaveUserWallpaperFromFile(const std::string& username, 558 void UserManagerImpl::SaveUserWallpaperFromFile(const std::string& username,
558 const FilePath& path, 559 const FilePath& path,
559 ash::WallpaperLayout layout, 560 ash::WallpaperLayout layout,
560 WallpaperDelegate* delegate) { 561 WallpaperDelegate* delegate) {
561 // For wallpapers, save the image without resizing. 562 // For wallpapers, save the image without resizing.
562 image_loader_->Start( 563 image_loader_->Start(
563 path.value(), 0 /* Original size */, 564 path.value(), 0 /* Original size */, false,
564 base::Bind(&UserManagerImpl::SaveUserWallpaperInternal, 565 base::Bind(&UserManagerImpl::SaveUserWallpaperInternal,
565 base::Unretained(this), username, layout, User::CUSTOMIZED, 566 base::Unretained(this), username, layout, User::CUSTOMIZED,
566 delegate)); 567 delegate));
567 } 568 }
568 569
569 void UserManagerImpl::SaveUserImageFromProfileImage( 570 void UserManagerImpl::SaveUserImageFromProfileImage(
570 const std::string& username) { 571 const std::string& username) {
571 if (!downloaded_profile_image_.empty()) { 572 if (!downloaded_profile_image_.empty()) {
572 // Profile image has already been downloaded, so save it to file right now. 573 // Profile image has already been downloaded, so save it to file right now.
573 SaveUserImageInternal(username, User::kProfileImageIndex, 574 SaveUserImageInternal(username, User::kProfileImageIndex,
574 downloaded_profile_image_); 575 UserImage(downloaded_profile_image_));
575 } else { 576 } else {
576 // No profile image - use the stub image (gray avatar). 577 // No profile image - use the stub image (gray avatar).
577 SetUserImage(username, User::kProfileImageIndex, SkBitmap()); 578 SetUserImage(username, User::kProfileImageIndex, UserImage(SkBitmap()));
578 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); 579 SaveImageToLocalState(username, "", User::kProfileImageIndex, false);
579 } 580 }
580 } 581 }
581 582
582 void UserManagerImpl::DownloadProfileImage(const std::string& reason) { 583 void UserManagerImpl::DownloadProfileImage(const std::string& reason) {
583 if (profile_image_downloader_.get()) { 584 if (profile_image_downloader_.get()) {
584 // Another download is already in progress 585 // Another download is already in progress
585 return; 586 return;
586 } 587 }
587 588
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 742
742 if (prefs_images) { 743 if (prefs_images) {
743 // Get account image path. 744 // Get account image path.
744 // TODO(avayvod): Reading image path as a string is here for 745 // TODO(avayvod): Reading image path as a string is here for
745 // backward compatibility. 746 // backward compatibility.
746 std::string image_path; 747 std::string image_path;
747 base::DictionaryValue* image_properties; 748 base::DictionaryValue* image_properties;
748 if (prefs_images->GetStringWithoutPathExpansion(email, &image_path)) { 749 if (prefs_images->GetStringWithoutPathExpansion(email, &image_path)) {
749 int image_id = User::kInvalidImageIndex; 750 int image_id = User::kInvalidImageIndex;
750 if (IsDefaultImagePath(image_path, &image_id)) { 751 if (IsDefaultImagePath(image_path, &image_id)) {
751 user->SetImage(GetDefaultImage(image_id), image_id); 752 user->SetImage(UserImage(GetDefaultImage(image_id)), image_id);
752 } else { 753 } else {
753 int image_index = User::kExternalImageIndex; 754 int image_index = User::kExternalImageIndex;
754 // Until image has been loaded, use the stub image. 755 // Until image has been loaded, use the stub image.
755 user->SetStubImage(image_index); 756 user->SetStubImage(image_index);
756 DCHECK(!image_path.empty()); 757 DCHECK(!image_path.empty());
757 // Load user image asynchronously. 758 // Load user image asynchronously.
758 image_loader_->Start( 759 image_loader_->Start(
759 image_path, 0, 760 image_path, 0, true,
760 base::Bind(&UserManagerImpl::SetUserImage, 761 base::Bind(&UserManagerImpl::SetUserImage,
761 base::Unretained(this), email, image_index)); 762 base::Unretained(this), email, image_index));
762 } 763 }
763 } else if (prefs_images->GetDictionaryWithoutPathExpansion( 764 } else if (prefs_images->GetDictionaryWithoutPathExpansion(
764 email, &image_properties)) { 765 email, &image_properties)) {
765 int image_index = User::kInvalidImageIndex; 766 int image_index = User::kInvalidImageIndex;
766 image_properties->GetString(kImagePathNodeName, &image_path); 767 image_properties->GetString(kImagePathNodeName, &image_path);
767 image_properties->GetInteger(kImageIndexNodeName, &image_index); 768 image_properties->GetInteger(kImageIndexNodeName, &image_index);
768 if (image_index >= 0 && image_index < kDefaultImagesCount) { 769 if (image_index >= 0 && image_index < kDefaultImagesCount) {
769 user->SetImage(GetDefaultImage(image_index), image_index); 770 user->SetImage(UserImage(GetDefaultImage(image_index)),
771 image_index);
770 } else if (image_index == User::kExternalImageIndex || 772 } else if (image_index == User::kExternalImageIndex ||
771 image_index == User::kProfileImageIndex) { 773 image_index == User::kProfileImageIndex) {
772 // Path may be empty for profile images (meaning that the image 774 // Path may be empty for profile images (meaning that the image
773 // hasn't been downloaded for the first time yet, in which case a 775 // hasn't been downloaded for the first time yet, in which case a
774 // download will be scheduled for |kProfileImageDownloadDelayMs| 776 // download will be scheduled for |kProfileImageDownloadDelayMs|
775 // after user logs in). 777 // after user logs in).
776 DCHECK(!image_path.empty() || 778 DCHECK(!image_path.empty() ||
777 image_index == User::kProfileImageIndex); 779 image_index == User::kProfileImageIndex);
778 // Until image has been loaded, use the stub image (gray avatar). 780 // Until image has been loaded, use the stub image (gray avatar).
779 user->SetStubImage(image_index); 781 user->SetStubImage(image_index);
780 if (!image_path.empty()) { 782 if (!image_path.empty()) {
781 // Load user image asynchronously. 783 // Load user image asynchronously.
782 image_loader_->Start( 784 image_loader_->Start(
783 image_path, 0, 785 image_path, 0, true,
784 base::Bind(&UserManagerImpl::SetUserImage, 786 base::Bind(&UserManagerImpl::SetUserImage,
785 base::Unretained(this), email, image_index)); 787 base::Unretained(this), email, image_index));
786 } 788 }
787 } else { 789 } else {
788 NOTREACHED(); 790 NOTREACHED();
789 } 791 }
790 } 792 }
791 } 793 }
792 794
793 std::string display_email; 795 std::string display_email;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 } 981 }
980 982
981 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( 983 void UserManagerImpl::SaveLoggedInUserWallpaperProperties(
982 User::WallpaperType type, 984 User::WallpaperType type,
983 int index) { 985 int index) {
984 SaveUserWallpaperProperties(GetLoggedInUser().email(), type, index); 986 SaveUserWallpaperProperties(GetLoggedInUser().email(), type, index);
985 } 987 }
986 988
987 void UserManagerImpl::SetUserImage(const std::string& username, 989 void UserManagerImpl::SetUserImage(const std::string& username,
988 int image_index, 990 int image_index,
989 const SkBitmap& image) { 991 const UserImage& user_image) {
990 User* user = const_cast<User*>(FindUser(username)); 992 User* user = const_cast<User*>(FindUser(username));
991 // User may have been removed by now. 993 // User may have been removed by now.
992 if (user) { 994 if (user) {
993 // For existing users, a valid image index should have been set upon loading 995 // For existing users, a valid image index should have been set upon loading
994 // them from Local State. 996 // them from Local State.
995 DCHECK(user->image_index() != User::kInvalidImageIndex || 997 DCHECK(user->image_index() != User::kInvalidImageIndex ||
996 is_current_user_new_); 998 is_current_user_new_);
997 bool image_changed = user->image_index() != User::kInvalidImageIndex; 999 bool image_changed = user->image_index() != User::kInvalidImageIndex;
998 if (!image.empty()) 1000 if (!user_image.image().empty())
999 user->SetImage(image, image_index); 1001 user->SetImage(user_image, image_index);
1000 else 1002 else
1001 user->SetStubImage(image_index); 1003 user->SetStubImage(image_index);
1002 // For the logged-in user with a profile picture, initialize 1004 // For the logged-in user with a profile picture, initialize
1003 // |downloaded_profile_picture_|. 1005 // |downloaded_profile_picture_|.
1004 if (user == logged_in_user_ && image_index == User::kProfileImageIndex) 1006 if (user == logged_in_user_ && image_index == User::kProfileImageIndex)
1005 InitDownloadedProfileImage(); 1007 InitDownloadedProfileImage();
1006 if (image_changed) { 1008 if (image_changed) {
1007 // Unless this is first-time setting with |SetInitialUserImage|, 1009 // Unless this is first-time setting with |SetInitialUserImage|,
1008 // send a notification about image change. 1010 // send a notification about image change.
1009 content::NotificationService::current()->Notify( 1011 content::NotificationService::current()->Notify(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue(); 1064 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue();
1063 wallpaper_properties->Set(kWallpaperTypeNodeName, 1065 wallpaper_properties->Set(kWallpaperTypeNodeName,
1064 new base::FundamentalValue(type)); 1066 new base::FundamentalValue(type));
1065 wallpaper_properties->Set(kWallpaperIndexNodeName, 1067 wallpaper_properties->Set(kWallpaperIndexNodeName,
1066 new base::FundamentalValue(index)); 1068 new base::FundamentalValue(index));
1067 wallpaper_update->SetWithoutPathExpansion(username, wallpaper_properties); 1069 wallpaper_update->SetWithoutPathExpansion(username, wallpaper_properties);
1068 } 1070 }
1069 1071
1070 void UserManagerImpl::SaveUserImageInternal(const std::string& username, 1072 void UserManagerImpl::SaveUserImageInternal(const std::string& username,
1071 int image_index, 1073 int image_index,
1072 const SkBitmap& image) { 1074 const UserImage& user_image) {
1073 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1075 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1074 1076
1075 SetUserImage(username, image_index, image); 1077 SetUserImage(username, image_index, user_image);
1076 1078
1077 // Ignore for ephemeral users. 1079 // Ignore for ephemeral users.
1078 if (IsEphemeralUser(username)) 1080 if (IsEphemeralUser(username))
1079 return; 1081 return;
1080 1082
1081 FilePath image_path = GetImagePathForUser(username); 1083 FilePath image_path = GetImagePathForUser(username);
1082 DVLOG(1) << "Saving user image to " << image_path.value(); 1084 DVLOG(1) << "Saving user image to " << image_path.value();
1083 1085
1084 last_image_set_async_ = true; 1086 last_image_set_async_ = true;
1085 1087
1086 BrowserThread::PostTask( 1088 BrowserThread::PostTask(
1087 BrowserThread::FILE, 1089 BrowserThread::FILE,
1088 FROM_HERE, 1090 FROM_HERE,
1089 base::Bind(&UserManagerImpl::SaveImageToFile, 1091 base::Bind(&UserManagerImpl::SaveImageToFile,
1090 base::Unretained(this), 1092 base::Unretained(this),
1091 username, image, image_path, image_index)); 1093 username, user_image, image_path, image_index));
1092 } 1094 }
1093 1095
1094 void UserManagerImpl::SaveUserWallpaperInternal(const std::string& username, 1096 void UserManagerImpl::SaveUserWallpaperInternal(const std::string& username,
1095 ash::WallpaperLayout layout, 1097 ash::WallpaperLayout layout,
1096 User::WallpaperType type, 1098 User::WallpaperType type,
1097 WallpaperDelegate* delegate, 1099 WallpaperDelegate* delegate,
1098 const SkBitmap& wallpaper) { 1100 const UserImage& user_image) {
1099 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1100 1102
1103 const SkBitmap& wallpaper = user_image.image();
1101 BrowserThread::PostTask( 1104 BrowserThread::PostTask(
1102 BrowserThread::FILE, 1105 BrowserThread::FILE,
1103 FROM_HERE, 1106 FROM_HERE,
1104 base::Bind(&UserManagerImpl::GenerateUserWallpaperThumbnail, 1107 base::Bind(&UserManagerImpl::GenerateUserWallpaperThumbnail,
1105 base::Unretained(this), username, type, delegate, wallpaper)); 1108 base::Unretained(this), username, type, delegate, wallpaper));
1106 1109
1107 ash::Shell::GetInstance()->desktop_background_controller()-> 1110 ash::Shell::GetInstance()->desktop_background_controller()->
1108 SetCustomWallpaper(wallpaper, layout); 1111 SetCustomWallpaper(wallpaper, layout);
1109 1112
1110 // Ignore for ephemeral users. 1113 // Ignore for ephemeral users.
1111 if (IsEphemeralUser(username)) 1114 if (IsEphemeralUser(username))
1112 return; 1115 return;
1113 1116
1114 FilePath wallpaper_path = GetWallpaperPathForUser(username, false); 1117 FilePath wallpaper_path = GetWallpaperPathForUser(username, false);
1115 DVLOG(1) << "Saving user image to " << wallpaper_path.value(); 1118 DVLOG(1) << "Saving user image to " << wallpaper_path.value();
1116 1119
1117 last_image_set_async_ = true; 1120 last_image_set_async_ = true;
1118 1121
1119 BrowserThread::PostTask( 1122 BrowserThread::PostTask(
1120 BrowserThread::FILE, 1123 BrowserThread::FILE,
1121 FROM_HERE, 1124 FROM_HERE,
1122 base::Bind(&UserManagerImpl::SaveWallpaperToFile, 1125 base::Bind(&UserManagerImpl::SaveWallpaperToFile,
1123 base::Unretained(this), username, wallpaper, wallpaper_path, 1126 base::Unretained(this), username, wallpaper, wallpaper_path,
1124 layout, User::CUSTOMIZED)); 1127 layout, User::CUSTOMIZED));
1125 } 1128 }
1126 1129
1127 void UserManagerImpl::OnCustomWallpaperLoaded(const std::string& email, 1130 void UserManagerImpl::OnCustomWallpaperLoaded(const std::string& email,
1128 ash::WallpaperLayout layout, 1131 ash::WallpaperLayout layout,
1129 const SkBitmap& wallpaper) { 1132 const UserImage& user_image) {
1133 const SkBitmap& wallpaper = user_image.image();
1130 ash::Shell::GetInstance()->desktop_background_controller()-> 1134 ash::Shell::GetInstance()->desktop_background_controller()->
1131 SetCustomWallpaper(wallpaper, layout); 1135 SetCustomWallpaper(wallpaper, layout);
1132 // Starting to load wallpaper thumbnail 1136 // Starting to load wallpaper thumbnail
1133 std::string wallpaper_thumbnail_path = 1137 std::string wallpaper_thumbnail_path =
1134 GetWallpaperPathForUser(email, true).value(); 1138 GetWallpaperPathForUser(email, true).value();
1135 image_loader_->Start( 1139 image_loader_->Start(
1136 wallpaper_thumbnail_path, 0, 1140 wallpaper_thumbnail_path, 0, false,
1137 base::Bind(&UserManagerImpl::OnCustomWallpaperThumbnailLoaded, 1141 base::Bind(&UserManagerImpl::OnCustomWallpaperThumbnailLoaded,
1138 base::Unretained(this), email)); 1142 base::Unretained(this), email));
1139 } 1143 }
1140 1144
1141 void UserManagerImpl::OnCustomWallpaperThumbnailLoaded( 1145 void UserManagerImpl::OnCustomWallpaperThumbnailLoaded(
1142 const std::string& email, 1146 const std::string& email,
1143 const SkBitmap& wallpaper) { 1147 const UserImage& user_image) {
1148 const SkBitmap& wallpaper = user_image.image();
1144 User* user = const_cast<User*>(FindUser(email)); 1149 User* user = const_cast<User*>(FindUser(email));
1145 // User may have been removed by now. 1150 // User may have been removed by now.
1146 if (user && !wallpaper.empty()) 1151 if (user && !wallpaper.empty())
1147 user->SetWallpaperThumbnail(wallpaper); 1152 user->SetWallpaperThumbnail(wallpaper);
1148 } 1153 }
1149 1154
1150 void UserManagerImpl::OnThumbnailUpdated(WallpaperDelegate* delegate) { 1155 void UserManagerImpl::OnThumbnailUpdated(WallpaperDelegate* delegate) {
1151 if (delegate) 1156 if (delegate)
1152 delegate->SetCustomWallpaperThumbnail(); 1157 delegate->SetCustomWallpaperThumbnail();
1153 } 1158 }
(...skipping 15 matching lines...) Expand all
1169 BrowserThread::UI, 1174 BrowserThread::UI,
1170 FROM_HERE, 1175 FROM_HERE,
1171 base::Bind(&UserManagerImpl::OnThumbnailUpdated, 1176 base::Bind(&UserManagerImpl::OnThumbnailUpdated,
1172 base::Unretained(this), delegate)); 1177 base::Unretained(this), delegate));
1173 1178
1174 // Ignore for ephemeral users. 1179 // Ignore for ephemeral users.
1175 if (IsEphemeralUser(username)) 1180 if (IsEphemeralUser(username))
1176 return; 1181 return;
1177 1182
1178 FilePath thumbnail_path = GetWallpaperPathForUser(username, true); 1183 FilePath thumbnail_path = GetWallpaperPathForUser(username, true);
1179 SaveBitmapToFile(thumbnail, thumbnail_path); 1184 SaveBitmapToFile(UserImage(thumbnail), thumbnail_path);
1180 } 1185 }
1181 1186
1182 void UserManagerImpl::SaveImageToFile(const std::string& username, 1187 void UserManagerImpl::SaveImageToFile(const std::string& username,
1183 const SkBitmap& image, 1188 const UserImage& user_image,
1184 const FilePath& image_path, 1189 const FilePath& image_path,
1185 int image_index) { 1190 int image_index) {
1186 if (!SaveBitmapToFile(image, image_path)) 1191 if (!SaveBitmapToFile(user_image, image_path))
1187 return; 1192 return;
1188 1193
1189 BrowserThread::PostTask( 1194 BrowserThread::PostTask(
1190 BrowserThread::UI, 1195 BrowserThread::UI,
1191 FROM_HERE, 1196 FROM_HERE,
1192 base::Bind(&UserManagerImpl::SaveImageToLocalState, 1197 base::Bind(&UserManagerImpl::SaveImageToLocalState,
1193 base::Unretained(this), 1198 base::Unretained(this),
1194 username, image_path.value(), image_index, true)); 1199 username, image_path.value(), image_index, true));
1195 } 1200 }
1196 1201
1197 void UserManagerImpl::SaveWallpaperToFile(const std::string& username, 1202 void UserManagerImpl::SaveWallpaperToFile(const std::string& username,
1198 const SkBitmap& wallpaper, 1203 const SkBitmap& wallpaper,
1199 const FilePath& wallpaper_path, 1204 const FilePath& wallpaper_path,
1200 ash::WallpaperLayout layout, 1205 ash::WallpaperLayout layout,
1201 User::WallpaperType type) { 1206 User::WallpaperType type) {
1202 // TODO(bshe): We should save the original file unchanged instead of 1207 // TODO(bshe): We should save the original file unchanged instead of
1203 // re-encoding it and saving it. 1208 // re-encoding it and saving it.
1204 if (!SaveBitmapToFile(wallpaper, wallpaper_path)) 1209 if (!SaveBitmapToFile(UserImage(wallpaper), wallpaper_path))
1205 return; 1210 return;
1206 1211
1207 BrowserThread::PostTask( 1212 BrowserThread::PostTask(
1208 BrowserThread::UI, 1213 BrowserThread::UI,
1209 FROM_HERE, 1214 FROM_HERE,
1210 base::Bind(&UserManagerImpl::SaveWallpaperToLocalState, 1215 base::Bind(&UserManagerImpl::SaveWallpaperToLocalState,
1211 base::Unretained(this), 1216 base::Unretained(this),
1212 username, wallpaper_path.value(), layout, type)); 1217 username, wallpaper_path.value(), layout, type));
1213 } 1218 }
1214 1219
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 } 1251 }
1247 1252
1248 void UserManagerImpl::SaveWallpaperToLocalState(const std::string& username, 1253 void UserManagerImpl::SaveWallpaperToLocalState(const std::string& username,
1249 const std::string& wallpaper_path, 1254 const std::string& wallpaper_path,
1250 ash::WallpaperLayout layout, 1255 ash::WallpaperLayout layout,
1251 User::WallpaperType type) { 1256 User::WallpaperType type) {
1252 // TODO(bshe): We probably need to save wallpaper_path instead of index. 1257 // TODO(bshe): We probably need to save wallpaper_path instead of index.
1253 SaveUserWallpaperProperties(username, type, layout); 1258 SaveUserWallpaperProperties(username, type, layout);
1254 } 1259 }
1255 1260
1256 bool UserManagerImpl::SaveBitmapToFile(const SkBitmap& image, 1261 bool UserManagerImpl::SaveBitmapToFile(const UserImage& user_image,
1257 const FilePath& image_path) { 1262 const FilePath& image_path) {
1258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 1263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
1259 1264
1260 std::vector<unsigned char> encoded_image; 1265 std::vector<unsigned char> encoded_image;
1261 if (!gfx::PNGCodec::EncodeBGRASkBitmap(image, false, &encoded_image)) { 1266 if (user_image.has_raw_image()) {
1267 encoded_image = user_image.raw_image();
1268 } else if (!gfx::PNGCodec::EncodeBGRASkBitmap(user_image.image(),
1269 false,
1270 &encoded_image)) {
1262 LOG(ERROR) << "Failed to PNG encode the image."; 1271 LOG(ERROR) << "Failed to PNG encode the image.";
1263 return false; 1272 return false;
1264 } 1273 }
1265 1274
1266 if (file_util::WriteFile(image_path, 1275 if (file_util::WriteFile(image_path,
1267 reinterpret_cast<char*>(&encoded_image[0]), 1276 reinterpret_cast<char*>(&encoded_image[0]),
1268 encoded_image.size()) == -1) { 1277 encoded_image.size()) == -1) {
1269 LOG(ERROR) << "Failed to save image to file."; 1278 LOG(ERROR) << "Failed to save image to file.";
1270 return false; 1279 return false;
1271 } 1280 }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 BrowserThread::PostTask( 1470 BrowserThread::PostTask(
1462 BrowserThread::FILE, 1471 BrowserThread::FILE,
1463 FROM_HERE, 1472 FROM_HERE,
1464 base::Bind(&UserManagerImpl::DeleteUserImage, 1473 base::Bind(&UserManagerImpl::DeleteUserImage,
1465 base::Unretained(this), 1474 base::Unretained(this),
1466 image_path)); 1475 image_path));
1467 } 1476 }
1468 } 1477 }
1469 1478
1470 } // namespace chromeos 1479 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698