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 17 matching lines...) Expand all Loading... |
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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 is_current_user_ephemeral_ = true; | 345 is_current_user_ephemeral_ = true; |
345 logged_in_user_ = CreateUser(email); | 346 logged_in_user_ = CreateUser(email); |
346 SetInitialUserImage(email); | 347 SetInitialUserImage(email); |
347 SetInitialUserWallpaper(email); | 348 SetInitialUserWallpaper(email); |
348 NotifyOnLogin(); | 349 NotifyOnLogin(); |
349 } | 350 } |
350 | 351 |
351 void UserManagerImpl::StubUserLoggedIn() { | 352 void UserManagerImpl::StubUserLoggedIn() { |
352 is_current_user_ephemeral_ = true; | 353 is_current_user_ephemeral_ = true; |
353 logged_in_user_ = new User(kStubUser, false); | 354 logged_in_user_ = new User(kStubUser, false); |
354 logged_in_user_->SetImage(GetDefaultImage(kStubDefaultImageIndex), | 355 logged_in_user_->SetImage(UserImage(GetDefaultImage(kStubDefaultImageIndex)), |
355 kStubDefaultImageIndex); | 356 kStubDefaultImageIndex); |
356 } | 357 } |
357 | 358 |
358 void UserManagerImpl::UserSelected(const std::string& email) { | 359 void UserManagerImpl::UserSelected(const std::string& email) { |
359 if (IsKnownUser(email)) { | 360 if (IsKnownUser(email)) { |
360 User::WallpaperType type; | 361 User::WallpaperType type; |
361 int index; | 362 int index; |
362 GetUserWallpaperProperties(email, &type, &index); | 363 GetUserWallpaperProperties(email, &type, &index); |
363 if (type == User::RANDOM) { | 364 if (type == User::RANDOM) { |
364 // Generate a new random wallpaper index if the selected user chose | 365 // Generate a new random wallpaper index if the selected user chose |
365 // RANDOM wallpaper. | 366 // RANDOM wallpaper. |
366 index = ash::GetRandomWallpaperIndex(); | 367 index = ash::GetRandomWallpaperIndex(); |
367 SaveUserWallpaperProperties(email, User::RANDOM, index); | 368 SaveUserWallpaperProperties(email, User::RANDOM, index); |
368 } else if (type == User::CUSTOMIZED) { | 369 } else if (type == User::CUSTOMIZED) { |
369 std::string wallpaper_path = | 370 std::string wallpaper_path = |
370 GetWallpaperPathForUser(email, false).value(); | 371 GetWallpaperPathForUser(email, false).value(); |
371 // In customized mode, we use index pref to save the user selected | 372 // In customized mode, we use index pref to save the user selected |
372 // wallpaper layout. See function SaveWallpaperToLocalState(). | 373 // wallpaper layout. See function SaveWallpaperToLocalState(). |
373 ash::WallpaperLayout layout = static_cast<ash::WallpaperLayout>(index); | 374 ash::WallpaperLayout layout = static_cast<ash::WallpaperLayout>(index); |
374 // Load user image asynchronously. | 375 // Load user image asynchronously. |
375 image_loader_->Start( | 376 image_loader_->Start( |
376 wallpaper_path, 0, | 377 wallpaper_path, 0, false, |
377 base::Bind(&UserManagerImpl::LoadCustomWallpaperThumbnail, | 378 base::Bind(&UserManagerImpl::LoadCustomWallpaperThumbnail, |
378 base::Unretained(this), email, layout)); | 379 base::Unretained(this), email, layout)); |
379 return; | 380 return; |
380 } | 381 } |
381 ash::Shell::GetInstance()->desktop_background_controller()-> | 382 ash::Shell::GetInstance()->desktop_background_controller()-> |
382 SetDefaultWallpaper(index); | 383 SetDefaultWallpaper(index); |
383 } | 384 } |
384 } | 385 } |
385 | 386 |
386 void UserManagerImpl::SessionStarted() { | 387 void UserManagerImpl::SessionStarted() { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 | 511 |
511 std::string UserManagerImpl::GetUserDisplayEmail( | 512 std::string UserManagerImpl::GetUserDisplayEmail( |
512 const std::string& username) const { | 513 const std::string& username) const { |
513 const User* user = FindUser(username); | 514 const User* user = FindUser(username); |
514 return user ? user->display_email() : username; | 515 return user ? user->display_email() : username; |
515 } | 516 } |
516 | 517 |
517 void UserManagerImpl::SaveUserDefaultImageIndex(const std::string& username, | 518 void UserManagerImpl::SaveUserDefaultImageIndex(const std::string& username, |
518 int image_index) { | 519 int image_index) { |
519 DCHECK(image_index >= 0 && image_index < kDefaultImagesCount); | 520 DCHECK(image_index >= 0 && image_index < kDefaultImagesCount); |
520 SetUserImage(username, image_index, GetDefaultImage(image_index)); | 521 SetUserImage(username, image_index, UserImage(GetDefaultImage(image_index))); |
521 SaveImageToLocalState(username, "", image_index, false); | 522 SaveImageToLocalState(username, "", image_index, false); |
522 } | 523 } |
523 | 524 |
524 void UserManagerImpl::SaveUserImage(const std::string& username, | 525 void UserManagerImpl::SaveUserImage(const std::string& username, |
525 const SkBitmap& image) { | 526 const UserImage& user_image) { |
526 SaveUserImageInternal(username, User::kExternalImageIndex, image); | 527 SaveUserImageInternal(username, User::kExternalImageIndex, user_image); |
527 } | 528 } |
528 | 529 |
529 void UserManagerImpl::SetLoggedInUserCustomWallpaperLayout( | 530 void UserManagerImpl::SetLoggedInUserCustomWallpaperLayout( |
530 ash::WallpaperLayout layout) { | 531 ash::WallpaperLayout layout) { |
531 // TODO(bshe): We current disabled the customized wallpaper feature for | 532 // TODO(bshe): We current disabled the customized wallpaper feature for |
532 // Ephemeral user. As we dont want to keep a copy of customized wallpaper in | 533 // Ephemeral user. As we dont want to keep a copy of customized wallpaper in |
533 // memory. Need a smarter way to solve this. | 534 // memory. Need a smarter way to solve this. |
534 if (IsCurrentUserEphemeral()) | 535 if (IsCurrentUserEphemeral()) |
535 return; | 536 return; |
536 const chromeos::User& user = GetLoggedInUser(); | 537 const chromeos::User& user = GetLoggedInUser(); |
537 std::string username = user.email(); | 538 std::string username = user.email(); |
538 DCHECK(!username.empty()); | 539 DCHECK(!username.empty()); |
539 | 540 |
540 std::string file_path = GetWallpaperPathForUser(username, false).value(); | 541 std::string file_path = GetWallpaperPathForUser(username, false).value(); |
541 SaveWallpaperToLocalState(username, file_path, layout, User::CUSTOMIZED); | 542 SaveWallpaperToLocalState(username, file_path, layout, User::CUSTOMIZED); |
542 // Load wallpaper from file. | 543 // Load wallpaper from file. |
543 UserSelected(username); | 544 UserSelected(username); |
544 } | 545 } |
545 | 546 |
546 void UserManagerImpl::SaveUserImageFromFile(const std::string& username, | 547 void UserManagerImpl::SaveUserImageFromFile(const std::string& username, |
547 const FilePath& path) { | 548 const FilePath& path) { |
548 image_loader_->Start( | 549 image_loader_->Start( |
549 path.value(), login::kUserImageSize, | 550 path.value(), login::kUserImageSize, true, |
550 base::Bind(&UserManagerImpl::SaveUserImage, | 551 base::Bind(&UserManagerImpl::SaveUserImage, |
551 base::Unretained(this), username)); | 552 base::Unretained(this), username)); |
552 } | 553 } |
553 | 554 |
554 void UserManagerImpl::SaveUserWallpaperFromFile(const std::string& username, | 555 void UserManagerImpl::SaveUserWallpaperFromFile(const std::string& username, |
555 const FilePath& path, | 556 const FilePath& path, |
556 ash::WallpaperLayout layout, | 557 ash::WallpaperLayout layout, |
557 WallpaperDelegate* delegate) { | 558 WallpaperDelegate* delegate) { |
558 // For wallpapers, save the image without resizing. | 559 // For wallpapers, save the image without resizing. |
559 image_loader_->Start( | 560 image_loader_->Start( |
560 path.value(), 0 /* Original size */, | 561 path.value(), 0 /* Original size */, false, |
561 base::Bind(&UserManagerImpl::SaveUserWallpaperInternal, | 562 base::Bind(&UserManagerImpl::SaveUserWallpaperInternal, |
562 base::Unretained(this), username, layout, User::CUSTOMIZED, | 563 base::Unretained(this), username, layout, User::CUSTOMIZED, |
563 delegate)); | 564 delegate)); |
564 } | 565 } |
565 | 566 |
566 void UserManagerImpl::SaveUserImageFromProfileImage( | 567 void UserManagerImpl::SaveUserImageFromProfileImage( |
567 const std::string& username) { | 568 const std::string& username) { |
568 if (!downloaded_profile_image_.empty()) { | 569 if (!downloaded_profile_image_.empty()) { |
569 // Profile image has already been downloaded, so save it to file right now. | 570 // Profile image has already been downloaded, so save it to file right now. |
570 SaveUserImageInternal(username, User::kProfileImageIndex, | 571 SaveUserImageInternal(username, User::kProfileImageIndex, |
571 downloaded_profile_image_); | 572 UserImage(downloaded_profile_image_)); |
572 } else { | 573 } else { |
573 // No profile image - use the stub image (gray avatar). | 574 // No profile image - use the stub image (gray avatar). |
574 SetUserImage(username, User::kProfileImageIndex, SkBitmap()); | 575 SetUserImage(username, User::kProfileImageIndex, UserImage(SkBitmap())); |
575 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); | 576 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); |
576 } | 577 } |
577 } | 578 } |
578 | 579 |
579 void UserManagerImpl::DownloadProfileImage(const std::string& reason) { | 580 void UserManagerImpl::DownloadProfileImage(const std::string& reason) { |
580 if (profile_image_downloader_.get()) { | 581 if (profile_image_downloader_.get()) { |
581 // Another download is already in progress | 582 // Another download is already in progress |
582 return; | 583 return; |
583 } | 584 } |
584 | 585 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 | 735 |
735 if (prefs_images) { | 736 if (prefs_images) { |
736 // Get account image path. | 737 // Get account image path. |
737 // TODO(avayvod): Reading image path as a string is here for | 738 // TODO(avayvod): Reading image path as a string is here for |
738 // backward compatibility. | 739 // backward compatibility. |
739 std::string image_path; | 740 std::string image_path; |
740 base::DictionaryValue* image_properties; | 741 base::DictionaryValue* image_properties; |
741 if (prefs_images->GetStringWithoutPathExpansion(email, &image_path)) { | 742 if (prefs_images->GetStringWithoutPathExpansion(email, &image_path)) { |
742 int image_id = User::kInvalidImageIndex; | 743 int image_id = User::kInvalidImageIndex; |
743 if (IsDefaultImagePath(image_path, &image_id)) { | 744 if (IsDefaultImagePath(image_path, &image_id)) { |
744 user->SetImage(GetDefaultImage(image_id), image_id); | 745 user->SetImage(UserImage(GetDefaultImage(image_id)), image_id); |
745 } else { | 746 } else { |
746 int image_index = User::kExternalImageIndex; | 747 int image_index = User::kExternalImageIndex; |
747 // Until image has been loaded, use the stub image. | 748 // Until image has been loaded, use the stub image. |
748 user->SetStubImage(image_index); | 749 user->SetStubImage(image_index); |
749 DCHECK(!image_path.empty()); | 750 DCHECK(!image_path.empty()); |
750 // Load user image asynchronously. | 751 // Load user image asynchronously. |
751 image_loader_->Start( | 752 image_loader_->Start( |
752 image_path, 0, | 753 image_path, 0, true, |
753 base::Bind(&UserManagerImpl::SetUserImage, | 754 base::Bind(&UserManagerImpl::SetUserImage, |
754 base::Unretained(this), email, image_index)); | 755 base::Unretained(this), email, image_index)); |
755 } | 756 } |
756 } else if (prefs_images->GetDictionaryWithoutPathExpansion( | 757 } else if (prefs_images->GetDictionaryWithoutPathExpansion( |
757 email, &image_properties)) { | 758 email, &image_properties)) { |
758 int image_index = User::kInvalidImageIndex; | 759 int image_index = User::kInvalidImageIndex; |
759 image_properties->GetString(kImagePathNodeName, &image_path); | 760 image_properties->GetString(kImagePathNodeName, &image_path); |
760 image_properties->GetInteger(kImageIndexNodeName, &image_index); | 761 image_properties->GetInteger(kImageIndexNodeName, &image_index); |
761 if (image_index >= 0 && image_index < kDefaultImagesCount) { | 762 if (image_index >= 0 && image_index < kDefaultImagesCount) { |
762 user->SetImage(GetDefaultImage(image_index), image_index); | 763 user->SetImage(UserImage(GetDefaultImage(image_index)), |
| 764 image_index); |
763 } else if (image_index == User::kExternalImageIndex || | 765 } else if (image_index == User::kExternalImageIndex || |
764 image_index == User::kProfileImageIndex) { | 766 image_index == User::kProfileImageIndex) { |
765 // Path may be empty for profile images (meaning that the image | 767 // Path may be empty for profile images (meaning that the image |
766 // hasn't been downloaded for the first time yet, in which case a | 768 // hasn't been downloaded for the first time yet, in which case a |
767 // download will be scheduled for |kProfileImageDownloadDelayMs| | 769 // download will be scheduled for |kProfileImageDownloadDelayMs| |
768 // after user logs in). | 770 // after user logs in). |
769 DCHECK(!image_path.empty() || | 771 DCHECK(!image_path.empty() || |
770 image_index == User::kProfileImageIndex); | 772 image_index == User::kProfileImageIndex); |
771 // Until image has been loaded, use the stub image (gray avatar). | 773 // Until image has been loaded, use the stub image (gray avatar). |
772 user->SetStubImage(image_index); | 774 user->SetStubImage(image_index); |
773 if (!image_path.empty()) { | 775 if (!image_path.empty()) { |
774 // Load user image asynchronously. | 776 // Load user image asynchronously. |
775 image_loader_->Start( | 777 image_loader_->Start( |
776 image_path, 0, | 778 image_path, 0, true, |
777 base::Bind(&UserManagerImpl::SetUserImage, | 779 base::Bind(&UserManagerImpl::SetUserImage, |
778 base::Unretained(this), email, image_index)); | 780 base::Unretained(this), email, image_index)); |
779 } | 781 } |
780 } else { | 782 } else { |
781 NOTREACHED(); | 783 NOTREACHED(); |
782 } | 784 } |
783 } | 785 } |
784 } | 786 } |
785 | 787 |
786 std::string display_email; | 788 std::string display_email; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 } | 964 } |
963 | 965 |
964 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( | 966 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( |
965 User::WallpaperType type, | 967 User::WallpaperType type, |
966 int index) { | 968 int index) { |
967 SaveUserWallpaperProperties(GetLoggedInUser().email(), type, index); | 969 SaveUserWallpaperProperties(GetLoggedInUser().email(), type, index); |
968 } | 970 } |
969 | 971 |
970 void UserManagerImpl::SetUserImage(const std::string& username, | 972 void UserManagerImpl::SetUserImage(const std::string& username, |
971 int image_index, | 973 int image_index, |
972 const SkBitmap& image) { | 974 const UserImage& user_image) { |
973 User* user = const_cast<User*>(FindUser(username)); | 975 User* user = const_cast<User*>(FindUser(username)); |
974 // User may have been removed by now. | 976 // User may have been removed by now. |
975 if (user) { | 977 if (user) { |
976 // For existing users, a valid image index should have been set upon loading | 978 // For existing users, a valid image index should have been set upon loading |
977 // them from Local State. | 979 // them from Local State. |
978 DCHECK(user->image_index() != User::kInvalidImageIndex || | 980 DCHECK(user->image_index() != User::kInvalidImageIndex || |
979 is_current_user_new_); | 981 is_current_user_new_); |
980 bool image_changed = user->image_index() != User::kInvalidImageIndex; | 982 bool image_changed = user->image_index() != User::kInvalidImageIndex; |
981 if (!image.empty()) | 983 if (!user_image.image().empty()) |
982 user->SetImage(image, image_index); | 984 user->SetImage(user_image, image_index); |
983 else | 985 else |
984 user->SetStubImage(image_index); | 986 user->SetStubImage(image_index); |
985 // For the logged-in user with a profile picture, initialize | 987 // For the logged-in user with a profile picture, initialize |
986 // |downloaded_profile_picture_|. | 988 // |downloaded_profile_picture_|. |
987 if (user == logged_in_user_ && image_index == User::kProfileImageIndex) | 989 if (user == logged_in_user_ && image_index == User::kProfileImageIndex) |
988 InitDownloadedProfileImage(); | 990 InitDownloadedProfileImage(); |
989 if (image_changed) { | 991 if (image_changed) { |
990 // Unless this is first-time setting with |SetInitialUserImage|, | 992 // Unless this is first-time setting with |SetInitialUserImage|, |
991 // send a notification about image change. | 993 // send a notification about image change. |
992 content::NotificationService::current()->Notify( | 994 content::NotificationService::current()->Notify( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue(); | 1047 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue(); |
1046 wallpaper_properties->Set(kWallpaperTypeNodeName, | 1048 wallpaper_properties->Set(kWallpaperTypeNodeName, |
1047 new base::FundamentalValue(type)); | 1049 new base::FundamentalValue(type)); |
1048 wallpaper_properties->Set(kWallpaperIndexNodeName, | 1050 wallpaper_properties->Set(kWallpaperIndexNodeName, |
1049 new base::FundamentalValue(index)); | 1051 new base::FundamentalValue(index)); |
1050 wallpaper_update->SetWithoutPathExpansion(username, wallpaper_properties); | 1052 wallpaper_update->SetWithoutPathExpansion(username, wallpaper_properties); |
1051 } | 1053 } |
1052 | 1054 |
1053 void UserManagerImpl::SaveUserImageInternal(const std::string& username, | 1055 void UserManagerImpl::SaveUserImageInternal(const std::string& username, |
1054 int image_index, | 1056 int image_index, |
1055 const SkBitmap& image) { | 1057 const UserImage& user_image) { |
1056 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1058 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1057 | 1059 |
1058 SetUserImage(username, image_index, image); | 1060 SetUserImage(username, image_index, user_image); |
1059 | 1061 |
1060 // Ignore for ephemeral users. | 1062 // Ignore for ephemeral users. |
1061 if (IsEphemeralUser(username)) | 1063 if (IsEphemeralUser(username)) |
1062 return; | 1064 return; |
1063 | 1065 |
1064 FilePath image_path = GetImagePathForUser(username); | 1066 FilePath image_path = GetImagePathForUser(username); |
1065 DVLOG(1) << "Saving user image to " << image_path.value(); | 1067 DVLOG(1) << "Saving user image to " << image_path.value(); |
1066 | 1068 |
1067 last_image_set_async_ = true; | 1069 last_image_set_async_ = true; |
1068 | 1070 |
1069 BrowserThread::PostTask( | 1071 BrowserThread::PostTask( |
1070 BrowserThread::FILE, | 1072 BrowserThread::FILE, |
1071 FROM_HERE, | 1073 FROM_HERE, |
1072 base::Bind(&UserManagerImpl::SaveImageToFile, | 1074 base::Bind(&UserManagerImpl::SaveImageToFile, |
1073 base::Unretained(this), | 1075 base::Unretained(this), |
1074 username, image, image_path, image_index)); | 1076 username, user_image, image_path, image_index)); |
1075 } | 1077 } |
1076 | 1078 |
1077 void UserManagerImpl::SaveUserWallpaperInternal(const std::string& username, | 1079 void UserManagerImpl::SaveUserWallpaperInternal(const std::string& username, |
1078 ash::WallpaperLayout layout, | 1080 ash::WallpaperLayout layout, |
1079 User::WallpaperType type, | 1081 User::WallpaperType type, |
1080 WallpaperDelegate* delegate, | 1082 WallpaperDelegate* delegate, |
1081 const SkBitmap& wallpaper) { | 1083 const UserImage& user_image) { |
1082 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1084 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1083 | 1085 |
| 1086 const SkBitmap& wallpaper = user_image.image(); |
1084 BrowserThread::PostTask( | 1087 BrowserThread::PostTask( |
1085 BrowserThread::FILE, | 1088 BrowserThread::FILE, |
1086 FROM_HERE, | 1089 FROM_HERE, |
1087 base::Bind(&UserManagerImpl::GenerateUserWallpaperThumbnail, | 1090 base::Bind(&UserManagerImpl::GenerateUserWallpaperThumbnail, |
1088 base::Unretained(this), username, type, delegate, wallpaper)); | 1091 base::Unretained(this), username, type, delegate, wallpaper)); |
1089 | 1092 |
1090 ash::Shell::GetInstance()->desktop_background_controller()-> | 1093 ash::Shell::GetInstance()->desktop_background_controller()-> |
1091 SetCustomWallpaper(wallpaper, layout); | 1094 SetCustomWallpaper(wallpaper, layout); |
1092 | 1095 |
1093 // Ignore for ephemeral users. | 1096 // Ignore for ephemeral users. |
1094 if (IsEphemeralUser(username)) | 1097 if (IsEphemeralUser(username)) |
1095 return; | 1098 return; |
1096 | 1099 |
1097 FilePath wallpaper_path = GetWallpaperPathForUser(username, false); | 1100 FilePath wallpaper_path = GetWallpaperPathForUser(username, false); |
1098 DVLOG(1) << "Saving user image to " << wallpaper_path.value(); | 1101 DVLOG(1) << "Saving user image to " << wallpaper_path.value(); |
1099 | 1102 |
1100 last_image_set_async_ = true; | 1103 last_image_set_async_ = true; |
1101 | 1104 |
1102 BrowserThread::PostTask( | 1105 BrowserThread::PostTask( |
1103 BrowserThread::FILE, | 1106 BrowserThread::FILE, |
1104 FROM_HERE, | 1107 FROM_HERE, |
1105 base::Bind(&UserManagerImpl::SaveWallpaperToFile, | 1108 base::Bind(&UserManagerImpl::SaveWallpaperToFile, |
1106 base::Unretained(this), username, wallpaper, wallpaper_path, | 1109 base::Unretained(this), username, wallpaper, wallpaper_path, |
1107 layout, User::CUSTOMIZED)); | 1110 layout, User::CUSTOMIZED)); |
1108 } | 1111 } |
1109 | 1112 |
1110 void UserManagerImpl::LoadCustomWallpaperThumbnail(const std::string& email, | 1113 void UserManagerImpl::LoadCustomWallpaperThumbnail( |
1111 ash::WallpaperLayout layout, | 1114 const std::string& email, |
1112 const SkBitmap& wallpaper) { | 1115 ash::WallpaperLayout layout, |
| 1116 const UserImage& user_image) { |
| 1117 const SkBitmap& wallpaper = user_image.image(); |
1113 ash::Shell::GetInstance()->desktop_background_controller()-> | 1118 ash::Shell::GetInstance()->desktop_background_controller()-> |
1114 SetCustomWallpaper(wallpaper, layout); | 1119 SetCustomWallpaper(wallpaper, layout); |
1115 // Load wallpaper thumbnail | 1120 // Load wallpaper thumbnail |
1116 std::string wallpaper_path = GetWallpaperPathForUser(email, true).value(); | 1121 std::string wallpaper_path = GetWallpaperPathForUser(email, true).value(); |
1117 image_loader_->Start( | 1122 image_loader_->Start( |
1118 wallpaper_path, 0, | 1123 wallpaper_path, 0, false, |
1119 base::Bind(&UserManagerImpl::OnCustomWallpaperThumbnailLoaded, | 1124 base::Bind(&UserManagerImpl::OnCustomWallpaperThumbnailLoaded, |
1120 base::Unretained(this), email)); | 1125 base::Unretained(this), email)); |
1121 } | 1126 } |
1122 | 1127 |
1123 void UserManagerImpl::OnCustomWallpaperThumbnailLoaded( | 1128 void UserManagerImpl::OnCustomWallpaperThumbnailLoaded( |
1124 const std::string& email, | 1129 const std::string& email, |
1125 const SkBitmap& wallpaper) { | 1130 const UserImage& user_image) { |
| 1131 const SkBitmap& wallpaper = user_image.image(); |
1126 User* user = const_cast<User*>(FindUser(email)); | 1132 User* user = const_cast<User*>(FindUser(email)); |
1127 // User may have been removed by now. | 1133 // User may have been removed by now. |
1128 if (user && !wallpaper.empty()) | 1134 if (user && !wallpaper.empty()) |
1129 user->SetWallpaperThumbnail(wallpaper); | 1135 user->SetWallpaperThumbnail(wallpaper); |
1130 } | 1136 } |
1131 | 1137 |
1132 void UserManagerImpl::OnThumbnailUpdated(WallpaperDelegate* delegate) { | 1138 void UserManagerImpl::OnThumbnailUpdated(WallpaperDelegate* delegate) { |
1133 if (delegate) | 1139 if (delegate) |
1134 delegate->SetCustomWallpaperThumbnail(); | 1140 delegate->SetCustomWallpaperThumbnail(); |
1135 } | 1141 } |
(...skipping 15 matching lines...) Expand all Loading... |
1151 BrowserThread::UI, | 1157 BrowserThread::UI, |
1152 FROM_HERE, | 1158 FROM_HERE, |
1153 base::Bind(&UserManagerImpl::OnThumbnailUpdated, | 1159 base::Bind(&UserManagerImpl::OnThumbnailUpdated, |
1154 base::Unretained(this), delegate)); | 1160 base::Unretained(this), delegate)); |
1155 | 1161 |
1156 // Ignore for ephemeral users. | 1162 // Ignore for ephemeral users. |
1157 if (IsEphemeralUser(username)) | 1163 if (IsEphemeralUser(username)) |
1158 return; | 1164 return; |
1159 | 1165 |
1160 FilePath thumbnail_path = GetWallpaperPathForUser(username, true); | 1166 FilePath thumbnail_path = GetWallpaperPathForUser(username, true); |
1161 SaveBitmapToFile(thumbnail, thumbnail_path); | 1167 SaveBitmapToFile(UserImage(thumbnail), thumbnail_path); |
1162 } | 1168 } |
1163 | 1169 |
1164 void UserManagerImpl::SaveImageToFile(const std::string& username, | 1170 void UserManagerImpl::SaveImageToFile(const std::string& username, |
1165 const SkBitmap& image, | 1171 const UserImage& user_image, |
1166 const FilePath& image_path, | 1172 const FilePath& image_path, |
1167 int image_index) { | 1173 int image_index) { |
1168 if (!SaveBitmapToFile(image, image_path)) | 1174 if (!SaveBitmapToFile(user_image, image_path)) |
1169 return; | 1175 return; |
1170 | 1176 |
1171 BrowserThread::PostTask( | 1177 BrowserThread::PostTask( |
1172 BrowserThread::UI, | 1178 BrowserThread::UI, |
1173 FROM_HERE, | 1179 FROM_HERE, |
1174 base::Bind(&UserManagerImpl::SaveImageToLocalState, | 1180 base::Bind(&UserManagerImpl::SaveImageToLocalState, |
1175 base::Unretained(this), | 1181 base::Unretained(this), |
1176 username, image_path.value(), image_index, true)); | 1182 username, image_path.value(), image_index, true)); |
1177 } | 1183 } |
1178 | 1184 |
1179 void UserManagerImpl::SaveWallpaperToFile(const std::string& username, | 1185 void UserManagerImpl::SaveWallpaperToFile(const std::string& username, |
1180 const SkBitmap& wallpaper, | 1186 const SkBitmap& wallpaper, |
1181 const FilePath& wallpaper_path, | 1187 const FilePath& wallpaper_path, |
1182 ash::WallpaperLayout layout, | 1188 ash::WallpaperLayout layout, |
1183 User::WallpaperType type) { | 1189 User::WallpaperType type) { |
1184 // TODO(bshe): We should save the original file unchanged instead of | 1190 // TODO(bshe): We should save the original file unchanged instead of |
1185 // re-encoding it and saving it. | 1191 // re-encoding it and saving it. |
1186 if (!SaveBitmapToFile(wallpaper, wallpaper_path)) | 1192 if (!SaveBitmapToFile(UserImage(wallpaper), wallpaper_path)) |
1187 return; | 1193 return; |
1188 | 1194 |
1189 BrowserThread::PostTask( | 1195 BrowserThread::PostTask( |
1190 BrowserThread::UI, | 1196 BrowserThread::UI, |
1191 FROM_HERE, | 1197 FROM_HERE, |
1192 base::Bind(&UserManagerImpl::SaveWallpaperToLocalState, | 1198 base::Bind(&UserManagerImpl::SaveWallpaperToLocalState, |
1193 base::Unretained(this), | 1199 base::Unretained(this), |
1194 username, wallpaper_path.value(), layout, type)); | 1200 username, wallpaper_path.value(), layout, type)); |
1195 } | 1201 } |
1196 | 1202 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 } | 1234 } |
1229 | 1235 |
1230 void UserManagerImpl::SaveWallpaperToLocalState(const std::string& username, | 1236 void UserManagerImpl::SaveWallpaperToLocalState(const std::string& username, |
1231 const std::string& wallpaper_path, | 1237 const std::string& wallpaper_path, |
1232 ash::WallpaperLayout layout, | 1238 ash::WallpaperLayout layout, |
1233 User::WallpaperType type) { | 1239 User::WallpaperType type) { |
1234 // TODO(bshe): We probably need to save wallpaper_path instead of index. | 1240 // TODO(bshe): We probably need to save wallpaper_path instead of index. |
1235 SaveUserWallpaperProperties(username, type, layout); | 1241 SaveUserWallpaperProperties(username, type, layout); |
1236 } | 1242 } |
1237 | 1243 |
1238 bool UserManagerImpl::SaveBitmapToFile(const SkBitmap& image, | 1244 bool UserManagerImpl::SaveBitmapToFile(const UserImage& user_image, |
1239 const FilePath& image_path) { | 1245 const FilePath& image_path) { |
1240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 1246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
1241 | 1247 |
1242 std::vector<unsigned char> encoded_image; | 1248 std::vector<unsigned char> encoded_image; |
1243 if (!gfx::PNGCodec::EncodeBGRASkBitmap(image, false, &encoded_image)) { | 1249 if (user_image.has_raw_image()) { |
| 1250 encoded_image = user_image.raw_image(); |
| 1251 } else if (!gfx::PNGCodec::EncodeBGRASkBitmap(user_image.image(), |
| 1252 false, |
| 1253 &encoded_image)) { |
1244 LOG(ERROR) << "Failed to PNG encode the image."; | 1254 LOG(ERROR) << "Failed to PNG encode the image."; |
1245 return false; | 1255 return false; |
1246 } | 1256 } |
1247 | 1257 |
1248 if (file_util::WriteFile(image_path, | 1258 if (file_util::WriteFile(image_path, |
1249 reinterpret_cast<char*>(&encoded_image[0]), | 1259 reinterpret_cast<char*>(&encoded_image[0]), |
1250 encoded_image.size()) == -1) { | 1260 encoded_image.size()) == -1) { |
1251 LOG(ERROR) << "Failed to save image to file."; | 1261 LOG(ERROR) << "Failed to save image to file."; |
1252 return false; | 1262 return false; |
1253 } | 1263 } |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 BrowserThread::PostTask( | 1453 BrowserThread::PostTask( |
1444 BrowserThread::FILE, | 1454 BrowserThread::FILE, |
1445 FROM_HERE, | 1455 FROM_HERE, |
1446 base::Bind(&UserManagerImpl::DeleteUserImage, | 1456 base::Bind(&UserManagerImpl::DeleteUserImage, |
1447 base::Unretained(this), | 1457 base::Unretained(this), |
1448 image_path)); | 1458 image_path)); |
1449 } | 1459 } |
1450 } | 1460 } |
1451 | 1461 |
1452 } // namespace chromeos | 1462 } // namespace chromeos |
OLD | NEW |