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

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

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

Powered by Google App Engine
This is Rietveld 408576698