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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 is_current_user_ephemeral_ = true; | 351 is_current_user_ephemeral_ = true; |
351 logged_in_user_ = CreateUser(email); | 352 logged_in_user_ = CreateUser(email); |
352 SetInitialUserImage(email); | 353 SetInitialUserImage(email); |
353 SetInitialUserWallpaper(email); | 354 SetInitialUserWallpaper(email); |
354 NotifyOnLogin(); | 355 NotifyOnLogin(); |
355 } | 356 } |
356 | 357 |
357 void UserManagerImpl::StubUserLoggedIn() { | 358 void UserManagerImpl::StubUserLoggedIn() { |
358 is_current_user_ephemeral_ = true; | 359 is_current_user_ephemeral_ = true; |
359 logged_in_user_ = new User(kStubUser, false); | 360 logged_in_user_ = new User(kStubUser, false); |
360 logged_in_user_->SetImage(GetDefaultImage(kStubDefaultImageIndex), | 361 logged_in_user_->SetImage(UserImage(GetDefaultImage(kStubDefaultImageIndex)), |
361 kStubDefaultImageIndex); | 362 kStubDefaultImageIndex); |
362 } | 363 } |
363 | 364 |
364 void UserManagerImpl::SetLoggedInUserWallpaper() { | 365 void UserManagerImpl::SetLoggedInUserWallpaper() { |
365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
366 | 367 |
367 if (!IsUserLoggedIn() || IsLoggedInAsStub()) { | 368 if (!IsUserLoggedIn() || IsLoggedInAsStub()) { |
368 ash::Shell::GetInstance()->desktop_background_controller()-> | 369 ash::Shell::GetInstance()->desktop_background_controller()-> |
369 SetDefaultWallpaper(ash::GetInvalidWallpaperIndex()); | 370 SetDefaultWallpaper(ash::GetInvalidWallpaperIndex()); |
370 return; | 371 return; |
(...skipping 12 matching lines...) Expand all Loading... |
383 index = ash::GetRandomWallpaperIndex(); | 384 index = ash::GetRandomWallpaperIndex(); |
384 SaveUserWallpaperProperties(email, User::RANDOM, index); | 385 SaveUserWallpaperProperties(email, User::RANDOM, index); |
385 } else if (type == User::CUSTOMIZED) { | 386 } else if (type == User::CUSTOMIZED) { |
386 std::string wallpaper_path = | 387 std::string wallpaper_path = |
387 GetWallpaperPathForUser(email, false).value(); | 388 GetWallpaperPathForUser(email, false).value(); |
388 // In customized mode, we use index pref to save the user selected | 389 // In customized mode, we use index pref to save the user selected |
389 // wallpaper layout. See function SaveWallpaperToLocalState(). | 390 // wallpaper layout. See function SaveWallpaperToLocalState(). |
390 ash::WallpaperLayout layout = static_cast<ash::WallpaperLayout>(index); | 391 ash::WallpaperLayout layout = static_cast<ash::WallpaperLayout>(index); |
391 // Load user image asynchronously. | 392 // Load user image asynchronously. |
392 image_loader_->Start( | 393 image_loader_->Start( |
393 wallpaper_path, 0, | 394 wallpaper_path, 0, false, |
394 base::Bind(&UserManagerImpl::OnCustomWallpaperLoaded, | 395 base::Bind(&UserManagerImpl::OnCustomWallpaperLoaded, |
395 base::Unretained(this), email, layout)); | 396 base::Unretained(this), email, layout)); |
396 return; | 397 return; |
397 } | 398 } |
398 ash::Shell::GetInstance()->desktop_background_controller()-> | 399 ash::Shell::GetInstance()->desktop_background_controller()-> |
399 SetDefaultWallpaper(index); | 400 SetDefaultWallpaper(index); |
400 } | 401 } |
401 } | 402 } |
402 | 403 |
403 void UserManagerImpl::SessionStarted() { | 404 void UserManagerImpl::SessionStarted() { |
404 session_started_ = true; | 405 session_started_ = true; |
405 content::NotificationService::current()->Notify( | 406 content::NotificationService::current()->Notify( |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 | 552 |
552 std::string UserManagerImpl::GetUserDisplayEmail( | 553 std::string UserManagerImpl::GetUserDisplayEmail( |
553 const std::string& username) const { | 554 const std::string& username) const { |
554 const User* user = FindUser(username); | 555 const User* user = FindUser(username); |
555 return user ? user->display_email() : username; | 556 return user ? user->display_email() : username; |
556 } | 557 } |
557 | 558 |
558 void UserManagerImpl::SaveUserDefaultImageIndex(const std::string& username, | 559 void UserManagerImpl::SaveUserDefaultImageIndex(const std::string& username, |
559 int image_index) { | 560 int image_index) { |
560 DCHECK(image_index >= 0 && image_index < kDefaultImagesCount); | 561 DCHECK(image_index >= 0 && image_index < kDefaultImagesCount); |
561 SetUserImage(username, image_index, GetDefaultImage(image_index)); | 562 SetUserImage(username, image_index, UserImage(GetDefaultImage(image_index))); |
562 SaveImageToLocalState(username, "", image_index, false); | 563 SaveImageToLocalState(username, "", image_index, false); |
563 } | 564 } |
564 | 565 |
565 void UserManagerImpl::SaveUserImage(const std::string& username, | 566 void UserManagerImpl::SaveUserImage(const std::string& username, |
566 const SkBitmap& image) { | 567 const UserImage& user_image) { |
567 SaveUserImageInternal(username, User::kExternalImageIndex, image); | 568 SaveUserImageInternal(username, User::kExternalImageIndex, user_image); |
568 } | 569 } |
569 | 570 |
570 void UserManagerImpl::SetLoggedInUserCustomWallpaperLayout( | 571 void UserManagerImpl::SetLoggedInUserCustomWallpaperLayout( |
571 ash::WallpaperLayout layout) { | 572 ash::WallpaperLayout layout) { |
572 // TODO(bshe): We current disabled the customized wallpaper feature for | 573 // TODO(bshe): We current disabled the customized wallpaper feature for |
573 // Ephemeral user. As we dont want to keep a copy of customized wallpaper in | 574 // Ephemeral user. As we dont want to keep a copy of customized wallpaper in |
574 // memory. Need a smarter way to solve this. | 575 // memory. Need a smarter way to solve this. |
575 if (IsCurrentUserEphemeral()) | 576 if (IsCurrentUserEphemeral()) |
576 return; | 577 return; |
577 const chromeos::User& user = GetLoggedInUser(); | 578 const chromeos::User& user = GetLoggedInUser(); |
578 std::string username = user.email(); | 579 std::string username = user.email(); |
579 DCHECK(!username.empty()); | 580 DCHECK(!username.empty()); |
580 | 581 |
581 std::string file_path = GetWallpaperPathForUser(username, false).value(); | 582 std::string file_path = GetWallpaperPathForUser(username, false).value(); |
582 SaveWallpaperToLocalState(username, file_path, layout, User::CUSTOMIZED); | 583 SaveWallpaperToLocalState(username, file_path, layout, User::CUSTOMIZED); |
583 // Load wallpaper from file. | 584 // Load wallpaper from file. |
584 UserSelected(username); | 585 UserSelected(username); |
585 } | 586 } |
586 | 587 |
587 void UserManagerImpl::SaveUserImageFromFile(const std::string& username, | 588 void UserManagerImpl::SaveUserImageFromFile(const std::string& username, |
588 const FilePath& path) { | 589 const FilePath& path) { |
589 image_loader_->Start( | 590 image_loader_->Start( |
590 path.value(), login::kUserImageSize, | 591 path.value(), login::kUserImageSize, true, |
591 base::Bind(&UserManagerImpl::SaveUserImage, | 592 base::Bind(&UserManagerImpl::SaveUserImage, |
592 base::Unretained(this), username)); | 593 base::Unretained(this), username)); |
593 } | 594 } |
594 | 595 |
595 void UserManagerImpl::SaveUserWallpaperFromFile(const std::string& username, | 596 void UserManagerImpl::SaveUserWallpaperFromFile(const std::string& username, |
596 const FilePath& path, | 597 const FilePath& path, |
597 ash::WallpaperLayout layout, | 598 ash::WallpaperLayout layout, |
598 WallpaperDelegate* delegate) { | 599 WallpaperDelegate* delegate) { |
599 // For wallpapers, save the image without resizing. | 600 // For wallpapers, save the image without resizing. |
600 image_loader_->Start( | 601 image_loader_->Start( |
601 path.value(), 0 /* Original size */, | 602 path.value(), 0 /* Original size */, false, |
602 base::Bind(&UserManagerImpl::SaveUserWallpaperInternal, | 603 base::Bind(&UserManagerImpl::SaveUserWallpaperInternal, |
603 base::Unretained(this), username, layout, User::CUSTOMIZED, | 604 base::Unretained(this), username, layout, User::CUSTOMIZED, |
604 delegate)); | 605 delegate)); |
605 } | 606 } |
606 | 607 |
607 void UserManagerImpl::SaveUserImageFromProfileImage( | 608 void UserManagerImpl::SaveUserImageFromProfileImage( |
608 const std::string& username) { | 609 const std::string& username) { |
609 if (!downloaded_profile_image_.empty()) { | 610 if (!downloaded_profile_image_.empty()) { |
610 // Profile image has already been downloaded, so save it to file right now. | 611 // Profile image has already been downloaded, so save it to file right now. |
611 SaveUserImageInternal(username, User::kProfileImageIndex, | 612 SaveUserImageInternal(username, User::kProfileImageIndex, |
612 downloaded_profile_image_); | 613 UserImage(downloaded_profile_image_)); |
613 } else { | 614 } else { |
614 // No profile image - use the stub image (gray avatar). | 615 // No profile image - use the stub image (gray avatar). |
615 SetUserImage(username, User::kProfileImageIndex, SkBitmap()); | 616 SetUserImage(username, User::kProfileImageIndex, UserImage(SkBitmap())); |
616 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); | 617 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); |
617 } | 618 } |
618 } | 619 } |
619 | 620 |
620 void UserManagerImpl::DownloadProfileImage(const std::string& reason) { | 621 void UserManagerImpl::DownloadProfileImage(const std::string& reason) { |
621 if (profile_image_downloader_.get()) { | 622 if (profile_image_downloader_.get()) { |
622 // Another download is already in progress | 623 // Another download is already in progress |
623 return; | 624 return; |
624 } | 625 } |
625 | 626 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 | 782 |
782 if (prefs_images) { | 783 if (prefs_images) { |
783 // Get account image path. | 784 // Get account image path. |
784 // TODO(avayvod): Reading image path as a string is here for | 785 // TODO(avayvod): Reading image path as a string is here for |
785 // backward compatibility. | 786 // backward compatibility. |
786 std::string image_path; | 787 std::string image_path; |
787 base::DictionaryValue* image_properties; | 788 base::DictionaryValue* image_properties; |
788 if (prefs_images->GetStringWithoutPathExpansion(email, &image_path)) { | 789 if (prefs_images->GetStringWithoutPathExpansion(email, &image_path)) { |
789 int image_id = User::kInvalidImageIndex; | 790 int image_id = User::kInvalidImageIndex; |
790 if (IsDefaultImagePath(image_path, &image_id)) { | 791 if (IsDefaultImagePath(image_path, &image_id)) { |
791 user->SetImage(GetDefaultImage(image_id), image_id); | 792 user->SetImage(UserImage(GetDefaultImage(image_id)), image_id); |
792 } else { | 793 } else { |
793 int image_index = User::kExternalImageIndex; | 794 int image_index = User::kExternalImageIndex; |
794 // Until image has been loaded, use the stub image. | 795 // Until image has been loaded, use the stub image. |
795 user->SetStubImage(image_index); | 796 user->SetStubImage(image_index); |
796 DCHECK(!image_path.empty()); | 797 DCHECK(!image_path.empty()); |
797 // Load user image asynchronously. | 798 // Load user image asynchronously. |
798 image_loader_->Start( | 799 image_loader_->Start( |
799 image_path, 0, | 800 image_path, 0, true, |
800 base::Bind(&UserManagerImpl::SetUserImage, | 801 base::Bind(&UserManagerImpl::SetUserImage, |
801 base::Unretained(this), email, image_index)); | 802 base::Unretained(this), email, image_index)); |
802 } | 803 } |
803 } else if (prefs_images->GetDictionaryWithoutPathExpansion( | 804 } else if (prefs_images->GetDictionaryWithoutPathExpansion( |
804 email, &image_properties)) { | 805 email, &image_properties)) { |
805 int image_index = User::kInvalidImageIndex; | 806 int image_index = User::kInvalidImageIndex; |
806 image_properties->GetString(kImagePathNodeName, &image_path); | 807 image_properties->GetString(kImagePathNodeName, &image_path); |
807 image_properties->GetInteger(kImageIndexNodeName, &image_index); | 808 image_properties->GetInteger(kImageIndexNodeName, &image_index); |
808 if (image_index >= 0 && image_index < kDefaultImagesCount) { | 809 if (image_index >= 0 && image_index < kDefaultImagesCount) { |
809 user->SetImage(GetDefaultImage(image_index), image_index); | 810 user->SetImage(UserImage(GetDefaultImage(image_index)), |
| 811 image_index); |
810 } else if (image_index == User::kExternalImageIndex || | 812 } else if (image_index == User::kExternalImageIndex || |
811 image_index == User::kProfileImageIndex) { | 813 image_index == User::kProfileImageIndex) { |
812 // Path may be empty for profile images (meaning that the image | 814 // Path may be empty for profile images (meaning that the image |
813 // hasn't been downloaded for the first time yet, in which case a | 815 // hasn't been downloaded for the first time yet, in which case a |
814 // download will be scheduled for |kProfileImageDownloadDelayMs| | 816 // download will be scheduled for |kProfileImageDownloadDelayMs| |
815 // after user logs in). | 817 // after user logs in). |
816 DCHECK(!image_path.empty() || | 818 DCHECK(!image_path.empty() || |
817 image_index == User::kProfileImageIndex); | 819 image_index == User::kProfileImageIndex); |
818 // Until image has been loaded, use the stub image (gray avatar). | 820 // Until image has been loaded, use the stub image (gray avatar). |
819 user->SetStubImage(image_index); | 821 user->SetStubImage(image_index); |
820 if (!image_path.empty()) { | 822 if (!image_path.empty()) { |
821 // Load user image asynchronously. | 823 // Load user image asynchronously. |
822 image_loader_->Start( | 824 image_loader_->Start( |
823 image_path, 0, | 825 image_path, 0, true, |
824 base::Bind(&UserManagerImpl::SetUserImage, | 826 base::Bind(&UserManagerImpl::SetUserImage, |
825 base::Unretained(this), email, image_index)); | 827 base::Unretained(this), email, image_index)); |
826 } | 828 } |
827 } else { | 829 } else { |
828 NOTREACHED(); | 830 NOTREACHED(); |
829 } | 831 } |
830 } | 832 } |
831 } | 833 } |
832 | 834 |
833 string16 display_name; | 835 string16 display_name; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 } | 1033 } |
1032 | 1034 |
1033 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( | 1035 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( |
1034 User::WallpaperType type, | 1036 User::WallpaperType type, |
1035 int index) { | 1037 int index) { |
1036 SaveUserWallpaperProperties(GetLoggedInUser().email(), type, index); | 1038 SaveUserWallpaperProperties(GetLoggedInUser().email(), type, index); |
1037 } | 1039 } |
1038 | 1040 |
1039 void UserManagerImpl::SetUserImage(const std::string& username, | 1041 void UserManagerImpl::SetUserImage(const std::string& username, |
1040 int image_index, | 1042 int image_index, |
1041 const SkBitmap& image) { | 1043 const UserImage& user_image) { |
1042 User* user = const_cast<User*>(FindUser(username)); | 1044 User* user = const_cast<User*>(FindUser(username)); |
1043 // User may have been removed by now. | 1045 // User may have been removed by now. |
1044 if (user) { | 1046 if (user) { |
1045 // For existing users, a valid image index should have been set upon loading | 1047 // For existing users, a valid image index should have been set upon loading |
1046 // them from Local State. | 1048 // them from Local State. |
1047 DCHECK(user->image_index() != User::kInvalidImageIndex || | 1049 DCHECK(user->image_index() != User::kInvalidImageIndex || |
1048 is_current_user_new_); | 1050 is_current_user_new_); |
1049 bool image_changed = user->image_index() != User::kInvalidImageIndex; | 1051 bool image_changed = user->image_index() != User::kInvalidImageIndex; |
1050 if (!image.empty()) | 1052 if (!user_image.image().empty()) |
1051 user->SetImage(image, image_index); | 1053 user->SetImage(user_image, image_index); |
1052 else | 1054 else |
1053 user->SetStubImage(image_index); | 1055 user->SetStubImage(image_index); |
1054 // For the logged-in user with a profile picture, initialize | 1056 // For the logged-in user with a profile picture, initialize |
1055 // |downloaded_profile_picture_|. | 1057 // |downloaded_profile_picture_|. |
1056 if (user == logged_in_user_ && image_index == User::kProfileImageIndex) | 1058 if (user == logged_in_user_ && image_index == User::kProfileImageIndex) |
1057 InitDownloadedProfileImage(); | 1059 InitDownloadedProfileImage(); |
1058 if (image_changed) { | 1060 if (image_changed) { |
1059 // Unless this is first-time setting with |SetInitialUserImage|, | 1061 // Unless this is first-time setting with |SetInitialUserImage|, |
1060 // send a notification about image change. | 1062 // send a notification about image change. |
1061 content::NotificationService::current()->Notify( | 1063 content::NotificationService::current()->Notify( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue(); | 1114 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue(); |
1113 wallpaper_properties->Set(kWallpaperTypeNodeName, | 1115 wallpaper_properties->Set(kWallpaperTypeNodeName, |
1114 new base::FundamentalValue(type)); | 1116 new base::FundamentalValue(type)); |
1115 wallpaper_properties->Set(kWallpaperIndexNodeName, | 1117 wallpaper_properties->Set(kWallpaperIndexNodeName, |
1116 new base::FundamentalValue(index)); | 1118 new base::FundamentalValue(index)); |
1117 wallpaper_update->SetWithoutPathExpansion(username, wallpaper_properties); | 1119 wallpaper_update->SetWithoutPathExpansion(username, wallpaper_properties); |
1118 } | 1120 } |
1119 | 1121 |
1120 void UserManagerImpl::SaveUserImageInternal(const std::string& username, | 1122 void UserManagerImpl::SaveUserImageInternal(const std::string& username, |
1121 int image_index, | 1123 int image_index, |
1122 const SkBitmap& image) { | 1124 const UserImage& user_image) { |
1123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1124 | 1126 |
1125 SetUserImage(username, image_index, image); | 1127 SetUserImage(username, image_index, user_image); |
1126 | 1128 |
1127 // Ignore for ephemeral users. | 1129 // Ignore for ephemeral users. |
1128 if (IsEphemeralUser(username)) | 1130 if (IsEphemeralUser(username)) |
1129 return; | 1131 return; |
1130 | 1132 |
1131 FilePath image_path = GetImagePathForUser(username); | 1133 FilePath image_path = GetImagePathForUser(username); |
1132 DVLOG(1) << "Saving user image to " << image_path.value(); | 1134 DVLOG(1) << "Saving user image to " << image_path.value(); |
1133 | 1135 |
1134 last_image_set_async_ = true; | 1136 last_image_set_async_ = true; |
1135 | 1137 |
1136 BrowserThread::PostTask( | 1138 BrowserThread::PostTask( |
1137 BrowserThread::FILE, | 1139 BrowserThread::FILE, |
1138 FROM_HERE, | 1140 FROM_HERE, |
1139 base::Bind(&UserManagerImpl::SaveImageToFile, | 1141 base::Bind(&UserManagerImpl::SaveImageToFile, |
1140 base::Unretained(this), | 1142 base::Unretained(this), |
1141 username, image, image_path, image_index)); | 1143 username, user_image, image_path, image_index)); |
1142 } | 1144 } |
1143 | 1145 |
1144 void UserManagerImpl::SaveUserWallpaperInternal(const std::string& username, | 1146 void UserManagerImpl::SaveUserWallpaperInternal(const std::string& username, |
1145 ash::WallpaperLayout layout, | 1147 ash::WallpaperLayout layout, |
1146 User::WallpaperType type, | 1148 User::WallpaperType type, |
1147 WallpaperDelegate* delegate, | 1149 WallpaperDelegate* delegate, |
1148 const SkBitmap& wallpaper) { | 1150 const UserImage& user_image) { |
1149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1150 | 1152 |
| 1153 const SkBitmap& wallpaper = user_image.image(); |
1151 BrowserThread::PostTask( | 1154 BrowserThread::PostTask( |
1152 BrowserThread::FILE, | 1155 BrowserThread::FILE, |
1153 FROM_HERE, | 1156 FROM_HERE, |
1154 base::Bind(&UserManagerImpl::GenerateUserWallpaperThumbnail, | 1157 base::Bind(&UserManagerImpl::GenerateUserWallpaperThumbnail, |
1155 base::Unretained(this), username, type, delegate, wallpaper)); | 1158 base::Unretained(this), username, type, delegate, wallpaper)); |
1156 | 1159 |
1157 ash::Shell::GetInstance()->desktop_background_controller()-> | 1160 ash::Shell::GetInstance()->desktop_background_controller()-> |
1158 SetCustomWallpaper(wallpaper, layout); | 1161 SetCustomWallpaper(wallpaper, layout); |
1159 | 1162 |
1160 // Ignore for ephemeral users. | 1163 // Ignore for ephemeral users. |
1161 if (IsEphemeralUser(username)) | 1164 if (IsEphemeralUser(username)) |
1162 return; | 1165 return; |
1163 | 1166 |
1164 FilePath wallpaper_path = GetWallpaperPathForUser(username, false); | 1167 FilePath wallpaper_path = GetWallpaperPathForUser(username, false); |
1165 DVLOG(1) << "Saving user image to " << wallpaper_path.value(); | 1168 DVLOG(1) << "Saving user image to " << wallpaper_path.value(); |
1166 | 1169 |
1167 last_image_set_async_ = true; | 1170 last_image_set_async_ = true; |
1168 | 1171 |
1169 BrowserThread::PostTask( | 1172 BrowserThread::PostTask( |
1170 BrowserThread::FILE, | 1173 BrowserThread::FILE, |
1171 FROM_HERE, | 1174 FROM_HERE, |
1172 base::Bind(&UserManagerImpl::SaveWallpaperToFile, | 1175 base::Bind(&UserManagerImpl::SaveWallpaperToFile, |
1173 base::Unretained(this), username, wallpaper, wallpaper_path, | 1176 base::Unretained(this), username, wallpaper, wallpaper_path, |
1174 layout, User::CUSTOMIZED)); | 1177 layout, User::CUSTOMIZED)); |
1175 } | 1178 } |
1176 | 1179 |
1177 void UserManagerImpl::OnCustomWallpaperLoaded(const std::string& email, | 1180 void UserManagerImpl::OnCustomWallpaperLoaded(const std::string& email, |
1178 ash::WallpaperLayout layout, | 1181 ash::WallpaperLayout layout, |
1179 const SkBitmap& wallpaper) { | 1182 const UserImage& user_image) { |
| 1183 const SkBitmap& wallpaper = user_image.image(); |
1180 ash::Shell::GetInstance()->desktop_background_controller()-> | 1184 ash::Shell::GetInstance()->desktop_background_controller()-> |
1181 SetCustomWallpaper(wallpaper, layout); | 1185 SetCustomWallpaper(wallpaper, layout); |
1182 // Starting to load wallpaper thumbnail | 1186 // Starting to load wallpaper thumbnail |
1183 std::string wallpaper_thumbnail_path = | 1187 std::string wallpaper_thumbnail_path = |
1184 GetWallpaperPathForUser(email, true).value(); | 1188 GetWallpaperPathForUser(email, true).value(); |
1185 image_loader_->Start( | 1189 image_loader_->Start( |
1186 wallpaper_thumbnail_path, 0, | 1190 wallpaper_thumbnail_path, 0, false, |
1187 base::Bind(&UserManagerImpl::OnCustomWallpaperThumbnailLoaded, | 1191 base::Bind(&UserManagerImpl::OnCustomWallpaperThumbnailLoaded, |
1188 base::Unretained(this), email)); | 1192 base::Unretained(this), email)); |
1189 } | 1193 } |
1190 | 1194 |
1191 void UserManagerImpl::OnCustomWallpaperThumbnailLoaded( | 1195 void UserManagerImpl::OnCustomWallpaperThumbnailLoaded( |
1192 const std::string& email, | 1196 const std::string& email, |
1193 const SkBitmap& wallpaper) { | 1197 const UserImage& user_image) { |
| 1198 const SkBitmap& wallpaper = user_image.image(); |
1194 User* user = const_cast<User*>(FindUser(email)); | 1199 User* user = const_cast<User*>(FindUser(email)); |
1195 // User may have been removed by now. | 1200 // User may have been removed by now. |
1196 if (user && !wallpaper.empty()) | 1201 if (user && !wallpaper.empty()) |
1197 user->SetWallpaperThumbnail(wallpaper); | 1202 user->SetWallpaperThumbnail(wallpaper); |
1198 } | 1203 } |
1199 | 1204 |
1200 void UserManagerImpl::OnThumbnailUpdated(WallpaperDelegate* delegate) { | 1205 void UserManagerImpl::OnThumbnailUpdated(WallpaperDelegate* delegate) { |
1201 if (delegate) | 1206 if (delegate) |
1202 delegate->SetCustomWallpaperThumbnail(); | 1207 delegate->SetCustomWallpaperThumbnail(); |
1203 } | 1208 } |
(...skipping 15 matching lines...) Expand all Loading... |
1219 BrowserThread::UI, | 1224 BrowserThread::UI, |
1220 FROM_HERE, | 1225 FROM_HERE, |
1221 base::Bind(&UserManagerImpl::OnThumbnailUpdated, | 1226 base::Bind(&UserManagerImpl::OnThumbnailUpdated, |
1222 base::Unretained(this), delegate)); | 1227 base::Unretained(this), delegate)); |
1223 | 1228 |
1224 // Ignore for ephemeral users. | 1229 // Ignore for ephemeral users. |
1225 if (IsEphemeralUser(username)) | 1230 if (IsEphemeralUser(username)) |
1226 return; | 1231 return; |
1227 | 1232 |
1228 FilePath thumbnail_path = GetWallpaperPathForUser(username, true); | 1233 FilePath thumbnail_path = GetWallpaperPathForUser(username, true); |
1229 SaveBitmapToFile(thumbnail, thumbnail_path); | 1234 SaveBitmapToFile(UserImage(thumbnail), thumbnail_path); |
1230 } | 1235 } |
1231 | 1236 |
1232 void UserManagerImpl::SaveImageToFile(const std::string& username, | 1237 void UserManagerImpl::SaveImageToFile(const std::string& username, |
1233 const SkBitmap& image, | 1238 const UserImage& user_image, |
1234 const FilePath& image_path, | 1239 const FilePath& image_path, |
1235 int image_index) { | 1240 int image_index) { |
1236 if (!SaveBitmapToFile(image, image_path)) | 1241 if (!SaveBitmapToFile(user_image, image_path)) |
1237 return; | 1242 return; |
1238 | 1243 |
1239 BrowserThread::PostTask( | 1244 BrowserThread::PostTask( |
1240 BrowserThread::UI, | 1245 BrowserThread::UI, |
1241 FROM_HERE, | 1246 FROM_HERE, |
1242 base::Bind(&UserManagerImpl::SaveImageToLocalState, | 1247 base::Bind(&UserManagerImpl::SaveImageToLocalState, |
1243 base::Unretained(this), | 1248 base::Unretained(this), |
1244 username, image_path.value(), image_index, true)); | 1249 username, image_path.value(), image_index, true)); |
1245 } | 1250 } |
1246 | 1251 |
1247 void UserManagerImpl::SaveWallpaperToFile(const std::string& username, | 1252 void UserManagerImpl::SaveWallpaperToFile(const std::string& username, |
1248 const SkBitmap& wallpaper, | 1253 const SkBitmap& wallpaper, |
1249 const FilePath& wallpaper_path, | 1254 const FilePath& wallpaper_path, |
1250 ash::WallpaperLayout layout, | 1255 ash::WallpaperLayout layout, |
1251 User::WallpaperType type) { | 1256 User::WallpaperType type) { |
1252 // TODO(bshe): We should save the original file unchanged instead of | 1257 // TODO(bshe): We should save the original file unchanged instead of |
1253 // re-encoding it and saving it. | 1258 // re-encoding it and saving it. |
1254 if (!SaveBitmapToFile(wallpaper, wallpaper_path)) | 1259 if (!SaveBitmapToFile(UserImage(wallpaper), wallpaper_path)) |
1255 return; | 1260 return; |
1256 | 1261 |
1257 BrowserThread::PostTask( | 1262 BrowserThread::PostTask( |
1258 BrowserThread::UI, | 1263 BrowserThread::UI, |
1259 FROM_HERE, | 1264 FROM_HERE, |
1260 base::Bind(&UserManagerImpl::SaveWallpaperToLocalState, | 1265 base::Bind(&UserManagerImpl::SaveWallpaperToLocalState, |
1261 base::Unretained(this), | 1266 base::Unretained(this), |
1262 username, wallpaper_path.value(), layout, type)); | 1267 username, wallpaper_path.value(), layout, type)); |
1263 } | 1268 } |
1264 | 1269 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 } | 1301 } |
1297 | 1302 |
1298 void UserManagerImpl::SaveWallpaperToLocalState(const std::string& username, | 1303 void UserManagerImpl::SaveWallpaperToLocalState(const std::string& username, |
1299 const std::string& wallpaper_path, | 1304 const std::string& wallpaper_path, |
1300 ash::WallpaperLayout layout, | 1305 ash::WallpaperLayout layout, |
1301 User::WallpaperType type) { | 1306 User::WallpaperType type) { |
1302 // TODO(bshe): We probably need to save wallpaper_path instead of index. | 1307 // TODO(bshe): We probably need to save wallpaper_path instead of index. |
1303 SaveUserWallpaperProperties(username, type, layout); | 1308 SaveUserWallpaperProperties(username, type, layout); |
1304 } | 1309 } |
1305 | 1310 |
1306 bool UserManagerImpl::SaveBitmapToFile(const SkBitmap& image, | 1311 bool UserManagerImpl::SaveBitmapToFile(const UserImage& user_image, |
1307 const FilePath& image_path) { | 1312 const FilePath& image_path) { |
1308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 1313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
1309 | 1314 |
1310 std::vector<unsigned char> encoded_image; | 1315 std::vector<unsigned char> encoded_image; |
1311 if (!gfx::PNGCodec::EncodeBGRASkBitmap(image, false, &encoded_image)) { | 1316 if (user_image.has_raw_image()) { |
| 1317 encoded_image = user_image.raw_image(); |
| 1318 } else if (!gfx::PNGCodec::EncodeBGRASkBitmap(user_image.image(), |
| 1319 false, |
| 1320 &encoded_image)) { |
1312 LOG(ERROR) << "Failed to PNG encode the image."; | 1321 LOG(ERROR) << "Failed to PNG encode the image."; |
1313 return false; | 1322 return false; |
1314 } | 1323 } |
1315 | 1324 |
1316 if (file_util::WriteFile(image_path, | 1325 if (file_util::WriteFile(image_path, |
1317 reinterpret_cast<char*>(&encoded_image[0]), | 1326 reinterpret_cast<char*>(&encoded_image[0]), |
1318 encoded_image.size()) == -1) { | 1327 encoded_image.size()) == -1) { |
1319 LOG(ERROR) << "Failed to save image to file."; | 1328 LOG(ERROR) << "Failed to save image to file."; |
1320 return false; | 1329 return false; |
1321 } | 1330 } |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1525 BrowserThread::PostTask( | 1534 BrowserThread::PostTask( |
1526 BrowserThread::FILE, | 1535 BrowserThread::FILE, |
1527 FROM_HERE, | 1536 FROM_HERE, |
1528 base::Bind(&UserManagerImpl::DeleteUserImage, | 1537 base::Bind(&UserManagerImpl::DeleteUserImage, |
1529 base::Unretained(this), | 1538 base::Unretained(this), |
1530 image_path)); | 1539 image_path)); |
1531 } | 1540 } |
1532 } | 1541 } |
1533 | 1542 |
1534 } // namespace chromeos | 1543 } // namespace chromeos |
OLD | NEW |