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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 index = ash::GetNextWallpaperIndex(index); | 413 index = ash::GetNextWallpaperIndex(index); |
414 SaveUserWallpaperProperties(email, User::DAILY, index); | 414 SaveUserWallpaperProperties(email, User::DAILY, index); |
415 } else if (type == User::CUSTOMIZED) { | 415 } else if (type == User::CUSTOMIZED) { |
416 std::string wallpaper_path = | 416 std::string wallpaper_path = |
417 GetWallpaperPathForUser(email, false).value(); | 417 GetWallpaperPathForUser(email, false).value(); |
418 // In customized mode, we use index pref to save the user selected | 418 // In customized mode, we use index pref to save the user selected |
419 // wallpaper layout. See function SaveWallpaperToLocalState(). | 419 // wallpaper layout. See function SaveWallpaperToLocalState(). |
420 ash::WallpaperLayout layout = static_cast<ash::WallpaperLayout>(index); | 420 ash::WallpaperLayout layout = static_cast<ash::WallpaperLayout>(index); |
421 // Load user image asynchronously. | 421 // Load user image asynchronously. |
422 image_loader_->Start( | 422 image_loader_->Start( |
423 wallpaper_path, 0, false, | 423 wallpaper_path, 0, |
424 base::Bind(&UserManagerImpl::OnCustomWallpaperLoaded, | 424 base::Bind(&UserManagerImpl::OnCustomWallpaperLoaded, |
425 base::Unretained(this), email, layout)); | 425 base::Unretained(this), email, layout)); |
426 return; | 426 return; |
427 } | 427 } |
428 ash::Shell::GetInstance()->desktop_background_controller()-> | 428 ash::Shell::GetInstance()->desktop_background_controller()-> |
429 SetDefaultWallpaper(index); | 429 SetDefaultWallpaper(index); |
430 WallpaperManager::Get()->SetLastSelectedUser(email); | 430 WallpaperManager::Get()->SetLastSelectedUser(email); |
431 } | 431 } |
432 } | 432 } |
433 | 433 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 std::string file_path = GetWallpaperPathForUser(username, false).value(); | 624 std::string file_path = GetWallpaperPathForUser(username, false).value(); |
625 SaveWallpaperToLocalState(username, file_path, layout, User::CUSTOMIZED); | 625 SaveWallpaperToLocalState(username, file_path, layout, User::CUSTOMIZED); |
626 // Load wallpaper from file. | 626 // Load wallpaper from file. |
627 UserSelected(username); | 627 UserSelected(username); |
628 } | 628 } |
629 | 629 |
630 void UserManagerImpl::SaveUserImageFromFile(const std::string& username, | 630 void UserManagerImpl::SaveUserImageFromFile(const std::string& username, |
631 const FilePath& path) { | 631 const FilePath& path) { |
632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
633 image_loader_->Start( | 633 image_loader_->Start( |
634 path.value(), login::kMaxUserImageSize, true, | 634 path.value(), login::kMaxUserImageSize, |
635 base::Bind(&UserManagerImpl::SaveUserImage, | 635 base::Bind(&UserManagerImpl::SaveUserImage, |
636 base::Unretained(this), username)); | 636 base::Unretained(this), username)); |
637 } | 637 } |
638 | 638 |
639 void UserManagerImpl::SaveUserWallpaperFromFile( | 639 void UserManagerImpl::SaveUserWallpaperFromFile( |
640 const std::string& username, | 640 const std::string& username, |
641 const FilePath& path, | 641 const FilePath& path, |
642 ash::WallpaperLayout layout, | 642 ash::WallpaperLayout layout, |
643 base::WeakPtr<WallpaperDelegate> delegate) { | 643 base::WeakPtr<WallpaperDelegate> delegate) { |
644 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 644 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
645 // For wallpapers, save the image without resizing. | 645 // For wallpapers, save the image without resizing. |
646 image_loader_->Start( | 646 image_loader_->Start( |
647 path.value(), 0 /* Original size */, false, | 647 path.value(), 0 /* Original size */, |
648 base::Bind(&UserManagerImpl::SaveUserWallpaperInternal, | 648 base::Bind(&UserManagerImpl::SaveUserWallpaperInternal, |
649 base::Unretained(this), username, layout, User::CUSTOMIZED, | 649 base::Unretained(this), username, layout, User::CUSTOMIZED, |
650 delegate)); | 650 delegate)); |
651 } | 651 } |
652 | 652 |
653 void UserManagerImpl::SaveUserImageFromProfileImage( | 653 void UserManagerImpl::SaveUserImageFromProfileImage( |
654 const std::string& username) { | 654 const std::string& username) { |
655 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 655 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
656 if (!downloaded_profile_image_.empty()) { | 656 if (!downloaded_profile_image_.empty()) { |
657 // Profile image has already been downloaded, so save it to file right now. | 657 // Profile image has already been downloaded, so save it to file right now. |
658 DCHECK(profile_image_url_.is_valid()); | 658 DCHECK(profile_image_url_.is_valid()); |
659 SaveUserImageInternal(username, | 659 SaveUserImageInternal( |
660 User::kProfileImageIndex, profile_image_url_, | 660 username, |
661 UserImage(downloaded_profile_image_)); | 661 User::kProfileImageIndex, profile_image_url_, |
| 662 UserImage::CreateAndEncode(downloaded_profile_image_)); |
662 } else { | 663 } else { |
663 // No profile image - use the stub image (gray avatar). | 664 // No profile image - use the stub image (gray avatar). |
664 SetUserImage(username, User::kProfileImageIndex, | 665 SetUserImage(username, User::kProfileImageIndex, |
665 GURL(), UserImage(SkBitmap())); | 666 GURL(), UserImage(SkBitmap())); |
666 SaveImageToLocalState(username, "", User::kProfileImageIndex, | 667 SaveImageToLocalState(username, "", User::kProfileImageIndex, |
667 GURL(), false); | 668 GURL(), false); |
668 } | 669 } |
669 } | 670 } |
670 | 671 |
671 void UserManagerImpl::DownloadProfileImage(const std::string& reason) { | 672 void UserManagerImpl::DownloadProfileImage(const std::string& reason) { |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 int image_id = User::kInvalidImageIndex; | 843 int image_id = User::kInvalidImageIndex; |
843 if (IsDefaultImagePath(image_path, &image_id)) { | 844 if (IsDefaultImagePath(image_path, &image_id)) { |
844 user->SetImage(UserImage(GetDefaultImage(image_id)), image_id); | 845 user->SetImage(UserImage(GetDefaultImage(image_id)), image_id); |
845 } else { | 846 } else { |
846 int image_index = User::kExternalImageIndex; | 847 int image_index = User::kExternalImageIndex; |
847 // Until image has been loaded, use the stub image. | 848 // Until image has been loaded, use the stub image. |
848 user->SetStubImage(image_index); | 849 user->SetStubImage(image_index); |
849 DCHECK(!image_path.empty()); | 850 DCHECK(!image_path.empty()); |
850 // Load user image asynchronously. | 851 // Load user image asynchronously. |
851 image_loader_->Start( | 852 image_loader_->Start( |
852 image_path, user_image_size, true, | 853 image_path, user_image_size, |
853 base::Bind(&UserManagerImpl::SetUserImage, | 854 base::Bind(&UserManagerImpl::SetUserImage, |
854 base::Unretained(this), | 855 base::Unretained(this), |
855 email, image_index, GURL())); | 856 email, image_index, GURL())); |
856 } | 857 } |
857 } else if (prefs_images->GetDictionaryWithoutPathExpansion( | 858 } else if (prefs_images->GetDictionaryWithoutPathExpansion( |
858 email, &image_properties)) { | 859 email, &image_properties)) { |
859 int image_index = User::kInvalidImageIndex; | 860 int image_index = User::kInvalidImageIndex; |
860 image_properties->GetString(kImagePathNodeName, &image_path); | 861 image_properties->GetString(kImagePathNodeName, &image_path); |
861 image_properties->GetInteger(kImageIndexNodeName, &image_index); | 862 image_properties->GetInteger(kImageIndexNodeName, &image_index); |
862 if (image_index >= 0 && image_index < kDefaultImagesCount) { | 863 if (image_index >= 0 && image_index < kDefaultImagesCount) { |
863 user->SetImage(UserImage(GetDefaultImage(image_index)), | 864 user->SetImage(UserImage(GetDefaultImage(image_index)), |
864 image_index); | 865 image_index); |
865 } else if (image_index == User::kExternalImageIndex || | 866 } else if (image_index == User::kExternalImageIndex || |
866 image_index == User::kProfileImageIndex) { | 867 image_index == User::kProfileImageIndex) { |
867 // Path may be empty for profile images (meaning that the image | 868 // Path may be empty for profile images (meaning that the image |
868 // hasn't been downloaded for the first time yet, in which case a | 869 // hasn't been downloaded for the first time yet, in which case a |
869 // download will be scheduled for |kProfileDataDownloadDelayMs| | 870 // download will be scheduled for |kProfileDataDownloadDelayMs| |
870 // after user logs in). | 871 // after user logs in). |
871 DCHECK(!image_path.empty() || | 872 DCHECK(!image_path.empty() || |
872 image_index == User::kProfileImageIndex); | 873 image_index == User::kProfileImageIndex); |
873 std::string image_url; | 874 std::string image_url; |
874 image_properties->GetString(kImageURLNodeName, &image_url); | 875 image_properties->GetString(kImageURLNodeName, &image_url); |
875 GURL image_gurl(image_url); | 876 GURL image_gurl(image_url); |
876 // Until image has been loaded, use the stub image (gray avatar). | 877 // Until image has been loaded, use the stub image (gray avatar). |
877 user->SetStubImage(image_index); | 878 user->SetStubImage(image_index); |
878 user->SetImageURL(image_gurl); | 879 user->SetImageURL(image_gurl); |
879 if (!image_path.empty()) { | 880 if (!image_path.empty()) { |
880 // Load user image asynchronously. | 881 // Load user image asynchronously. |
881 image_loader_->Start( | 882 image_loader_->Start( |
882 image_path, user_image_size, true, | 883 image_path, user_image_size, |
883 base::Bind(&UserManagerImpl::SetUserImage, | 884 base::Bind(&UserManagerImpl::SetUserImage, |
884 base::Unretained(this), | 885 base::Unretained(this), |
885 email, image_index, image_gurl)); | 886 email, image_index, image_gurl)); |
886 } | 887 } |
887 } else { | 888 } else { |
888 NOTREACHED(); | 889 NOTREACHED(); |
889 } | 890 } |
890 } | 891 } |
891 } | 892 } |
892 | 893 |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1263 void UserManagerImpl::OnCustomWallpaperLoaded(const std::string& email, | 1264 void UserManagerImpl::OnCustomWallpaperLoaded(const std::string& email, |
1264 ash::WallpaperLayout layout, | 1265 ash::WallpaperLayout layout, |
1265 const UserImage& user_image) { | 1266 const UserImage& user_image) { |
1266 const SkBitmap& wallpaper = user_image.image(); | 1267 const SkBitmap& wallpaper = user_image.image(); |
1267 ash::Shell::GetInstance()->desktop_background_controller()-> | 1268 ash::Shell::GetInstance()->desktop_background_controller()-> |
1268 SetCustomWallpaper(wallpaper, layout); | 1269 SetCustomWallpaper(wallpaper, layout); |
1269 // Starting to load wallpaper thumbnail | 1270 // Starting to load wallpaper thumbnail |
1270 std::string wallpaper_thumbnail_path = | 1271 std::string wallpaper_thumbnail_path = |
1271 GetWallpaperPathForUser(email, true).value(); | 1272 GetWallpaperPathForUser(email, true).value(); |
1272 image_loader_->Start( | 1273 image_loader_->Start( |
1273 wallpaper_thumbnail_path, 0, false, | 1274 wallpaper_thumbnail_path, 0, |
1274 base::Bind(&UserManagerImpl::OnCustomWallpaperThumbnailLoaded, | 1275 base::Bind(&UserManagerImpl::OnCustomWallpaperThumbnailLoaded, |
1275 base::Unretained(this), email)); | 1276 base::Unretained(this), email)); |
1276 } | 1277 } |
1277 | 1278 |
1278 void UserManagerImpl::OnCustomWallpaperThumbnailLoaded( | 1279 void UserManagerImpl::OnCustomWallpaperThumbnailLoaded( |
1279 const std::string& email, | 1280 const std::string& email, |
1280 const UserImage& user_image) { | 1281 const UserImage& user_image) { |
1281 const SkBitmap& wallpaper = user_image.image(); | 1282 const SkBitmap& wallpaper = user_image.image(); |
1282 User* user = const_cast<User*>(FindUser(email)); | 1283 User* user = const_cast<User*>(FindUser(email)); |
1283 // User may have been removed by now. | 1284 // User may have been removed by now. |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1689 BrowserThread::PostTask( | 1690 BrowserThread::PostTask( |
1690 BrowserThread::FILE, | 1691 BrowserThread::FILE, |
1691 FROM_HERE, | 1692 FROM_HERE, |
1692 base::Bind(&UserManagerImpl::DeleteUserImage, | 1693 base::Bind(&UserManagerImpl::DeleteUserImage, |
1693 base::Unretained(this), | 1694 base::Unretained(this), |
1694 image_path)); | 1695 image_path)); |
1695 } | 1696 } |
1696 } | 1697 } |
1697 | 1698 |
1698 } // namespace chromeos | 1699 } // namespace chromeos |
OLD | NEW |