| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "chrome/common/chrome_notification_types.h" | 47 #include "chrome/common/chrome_notification_types.h" |
| 48 #include "chrome/common/chrome_paths.h" | 48 #include "chrome/common/chrome_paths.h" |
| 49 #include "chrome/common/chrome_switches.h" | 49 #include "chrome/common/chrome_switches.h" |
| 50 #include "chrome/common/net/gaia/google_service_auth_error.h" | 50 #include "chrome/common/net/gaia/google_service_auth_error.h" |
| 51 #include "chromeos/dbus/cryptohome_client.h" | 51 #include "chromeos/dbus/cryptohome_client.h" |
| 52 #include "chromeos/dbus/dbus_thread_manager.h" | 52 #include "chromeos/dbus/dbus_thread_manager.h" |
| 53 #include "content/public/browser/browser_thread.h" | 53 #include "content/public/browser/browser_thread.h" |
| 54 #include "content/public/browser/notification_service.h" | 54 #include "content/public/browser/notification_service.h" |
| 55 #include "content/public/common/url_constants.h" | 55 #include "content/public/common/url_constants.h" |
| 56 #include "crypto/nss_util.h" | 56 #include "crypto/nss_util.h" |
| 57 #include "skia/ext/image_operations.h" |
| 57 #include "third_party/skia/include/core/SkBitmap.h" | 58 #include "third_party/skia/include/core/SkBitmap.h" |
| 58 #include "ui/gfx/codec/png_codec.h" | 59 #include "ui/gfx/codec/png_codec.h" |
| 59 | 60 |
| 60 using content::BrowserThread; | 61 using content::BrowserThread; |
| 61 | 62 |
| 62 typedef GoogleServiceAuthError AuthError; | 63 typedef GoogleServiceAuthError AuthError; |
| 63 | 64 |
| 64 namespace chromeos { | 65 namespace chromeos { |
| 65 | 66 |
| 66 namespace { | 67 namespace { |
| 67 | 68 |
| 68 // Incognito user is represented by an empty string (since some code already | 69 // Incognito user is represented by an empty string (since some code already |
| 69 // depends on that and it's hard to figure out what). | 70 // depends on that and it's hard to figure out what). |
| 70 const char kGuestUser[] = ""; | 71 const char kGuestUser[] = ""; |
| 71 | 72 |
| 72 // Stub user email (for test paths). | 73 // Stub user email (for test paths). |
| 73 const char kStubUser[] = "stub-user@example.com"; | 74 const char kStubUser[] = "stub-user@example.com"; |
| 74 | 75 |
| 75 // Names of nodes with info about user image. | 76 // Names of nodes with info about user image. |
| 76 const char kImagePathNodeName[] = "path"; | 77 const char kImagePathNodeName[] = "path"; |
| 77 const char kImageIndexNodeName[] = "index"; | 78 const char kImageIndexNodeName[] = "index"; |
| 78 | 79 |
| 79 const char kWallpaperTypeNodeName[] = "type"; | 80 const char kWallpaperTypeNodeName[] = "type"; |
| 80 const char kWallpaperIndexNodeName[] = "index"; | 81 const char kWallpaperIndexNodeName[] = "index"; |
| 81 | 82 |
| 83 const int kThumbnailWidth = 128; |
| 84 const int kThumbnailHeight = 80; |
| 85 |
| 82 // Index of the default image used for the |kStubUser| user. | 86 // Index of the default image used for the |kStubUser| user. |
| 83 const int kStubDefaultImageIndex = 0; | 87 const int kStubDefaultImageIndex = 0; |
| 84 | 88 |
| 85 // Delay betweeen user login and attempt to update user's profile image. | 89 // Delay betweeen user login and attempt to update user's profile image. |
| 86 const long kProfileImageDownloadDelayMs = 10000; | 90 const long kProfileImageDownloadDelayMs = 10000; |
| 87 | 91 |
| 88 // Enum for reporting histograms about profile picture download. | 92 // Enum for reporting histograms about profile picture download. |
| 89 enum ProfileDownloadResult { | 93 enum ProfileDownloadResult { |
| 90 kDownloadSuccessChanged, | 94 kDownloadSuccessChanged, |
| 91 kDownloadSuccess, | 95 kDownloadSuccess, |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 void UserManagerImpl::UserSelected(const std::string& email) { | 457 void UserManagerImpl::UserSelected(const std::string& email) { |
| 454 if (IsKnownUser(email)) { | 458 if (IsKnownUser(email)) { |
| 455 int index; | 459 int index; |
| 456 User::WallpaperType type; | 460 User::WallpaperType type; |
| 457 GetUserWallpaperProperties(email, type, index); | 461 GetUserWallpaperProperties(email, type, index); |
| 458 if (type == User::RANDOM) { | 462 if (type == User::RANDOM) { |
| 459 // Generate a new random wallpaper index if the selected user chose | 463 // Generate a new random wallpaper index if the selected user chose |
| 460 // RANDOM wallpaper. | 464 // RANDOM wallpaper. |
| 461 index = ash::GetRandomWallpaperIndex(); | 465 index = ash::GetRandomWallpaperIndex(); |
| 462 SaveUserWallpaperProperties(email, User::RANDOM, index); | 466 SaveUserWallpaperProperties(email, User::RANDOM, index); |
| 467 } else if (type == User::CUSTOMIZED) { |
| 468 std::string wallpaper_path = |
| 469 GetWallpaperPathForUser(email, false).value(); |
| 470 // In customized mode, we use index pref to save the user selected |
| 471 // wallpaper layout. See function SaveWallpaperToLocalState(). |
| 472 ash::WallpaperLayout layout = static_cast<ash::WallpaperLayout>(index); |
| 473 // Load user image asynchronously. |
| 474 image_loader_->Start( |
| 475 wallpaper_path, 0, |
| 476 base::Bind(&UserManagerImpl::LoadCustomWallpaperThumbnail, |
| 477 base::Unretained(this), |
| 478 email, |
| 479 layout)); |
| 480 return; |
| 463 } | 481 } |
| 464 ash::Shell::GetInstance()->desktop_background_controller()-> | 482 ash::Shell::GetInstance()->desktop_background_controller()-> |
| 465 SetDefaultWallpaper(index); | 483 SetDefaultWallpaper(index); |
| 466 } | 484 } |
| 467 } | 485 } |
| 468 | 486 |
| 469 void UserManagerImpl::SessionStarted() { | 487 void UserManagerImpl::SessionStarted() { |
| 470 session_started_ = true; | 488 session_started_ = true; |
| 471 content::NotificationService::current()->Notify( | 489 content::NotificationService::current()->Notify( |
| 472 chrome::NOTIFICATION_SESSION_STARTED, | 490 chrome::NOTIFICATION_SESSION_STARTED, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 DCHECK(image_index >= 0 && image_index < kDefaultImagesCount); | 620 DCHECK(image_index >= 0 && image_index < kDefaultImagesCount); |
| 603 SetUserImage(username, image_index, GetDefaultImage(image_index)); | 621 SetUserImage(username, image_index, GetDefaultImage(image_index)); |
| 604 SaveImageToLocalState(username, "", image_index, false); | 622 SaveImageToLocalState(username, "", image_index, false); |
| 605 } | 623 } |
| 606 | 624 |
| 607 void UserManagerImpl::SaveUserImage(const std::string& username, | 625 void UserManagerImpl::SaveUserImage(const std::string& username, |
| 608 const SkBitmap& image) { | 626 const SkBitmap& image) { |
| 609 SaveUserImageInternal(username, User::kExternalImageIndex, image); | 627 SaveUserImageInternal(username, User::kExternalImageIndex, image); |
| 610 } | 628 } |
| 611 | 629 |
| 630 void UserManagerImpl::SetLoggedInUserCustomWallpaperLayout( |
| 631 ash::WallpaperLayout layout) { |
| 632 // TODO(bshe): We current disabled the customized wallpaper feature for |
| 633 // Ephemeral user. As we dont want to keep a copy of customized wallpaper in |
| 634 // memory. Need a smarter way to solve this. |
| 635 if (IsCurrentUserEphemeral()) |
| 636 return; |
| 637 const chromeos::User& user = GetLoggedInUser(); |
| 638 std::string username = user.email(); |
| 639 DCHECK(!username.empty()); |
| 640 |
| 641 std::string file_path = GetWallpaperPathForUser(username, false).value(); |
| 642 SaveWallpaperToLocalState(username, file_path, layout, User::CUSTOMIZED); |
| 643 // Load wallpaper from file. |
| 644 UserSelected(username); |
| 645 } |
| 646 |
| 612 void UserManagerImpl::SaveUserImageFromFile(const std::string& username, | 647 void UserManagerImpl::SaveUserImageFromFile(const std::string& username, |
| 613 const FilePath& path) { | 648 const FilePath& path) { |
| 614 image_loader_->Start( | 649 image_loader_->Start( |
| 615 path.value(), login::kUserImageSize, | 650 path.value(), login::kUserImageSize, |
| 616 base::Bind(&UserManagerImpl::SaveUserImage, | 651 base::Bind(&UserManagerImpl::SaveUserImage, |
| 617 base::Unretained(this), username)); | 652 base::Unretained(this), username)); |
| 618 } | 653 } |
| 619 | 654 |
| 655 void UserManagerImpl::SaveUserWallpaperFromFile(const std::string& username, |
| 656 const FilePath& path, |
| 657 ash::WallpaperLayout layout) { |
| 658 // For wallpapers, save the image without resize. |
| 659 LOG(ERROR) << "---------------Start to load file--------" << path.value(); |
| 660 image_loader_->Start( |
| 661 path.value(), 0 /* Original size */, |
| 662 base::Bind(&UserManagerImpl::SaveUserWallpaperInternal, |
| 663 base::Unretained(this), username, layout, User::CUSTOMIZED)); |
| 664 } |
| 665 |
| 620 void UserManagerImpl::SaveUserImageFromProfileImage( | 666 void UserManagerImpl::SaveUserImageFromProfileImage( |
| 621 const std::string& username) { | 667 const std::string& username) { |
| 622 if (!downloaded_profile_image_.empty()) { | 668 if (!downloaded_profile_image_.empty()) { |
| 623 // Profile image has already been downloaded, so save it to file right now. | 669 // Profile image has already been downloaded, so save it to file right now. |
| 624 SaveUserImageInternal(username, User::kProfileImageIndex, | 670 SaveUserImageInternal(username, User::kProfileImageIndex, |
| 625 downloaded_profile_image_); | 671 downloaded_profile_image_); |
| 626 } else { | 672 } else { |
| 627 // No profile image - use the stub image (gray avatar). | 673 // No profile image - use the stub image (gray avatar). |
| 628 SetUserImage(username, User::kProfileImageIndex, SkBitmap()); | 674 SetUserImage(username, User::kProfileImageIndex, SkBitmap()); |
| 629 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); | 675 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 LocalStateChanged(this)); | 793 LocalStateChanged(this)); |
| 748 } | 794 } |
| 749 | 795 |
| 750 FilePath UserManagerImpl::GetImagePathForUser(const std::string& username) { | 796 FilePath UserManagerImpl::GetImagePathForUser(const std::string& username) { |
| 751 std::string filename = username + ".png"; | 797 std::string filename = username + ".png"; |
| 752 FilePath user_data_dir; | 798 FilePath user_data_dir; |
| 753 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 799 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 754 return user_data_dir.AppendASCII(filename); | 800 return user_data_dir.AppendASCII(filename); |
| 755 } | 801 } |
| 756 | 802 |
| 803 FilePath UserManagerImpl::GetWallpaperPathForUser(const std::string& username, |
| 804 bool is_thumbnail) { |
| 805 std::string filename = username + |
| 806 (is_thumbnail ? "_wallpaper_thumb.png" : "_wallpaper.png"); |
| 807 FilePath user_data_dir; |
| 808 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 809 return user_data_dir.AppendASCII(filename); |
| 810 } |
| 811 |
| 757 void UserManagerImpl::EnsureUsersLoaded() { | 812 void UserManagerImpl::EnsureUsersLoaded() { |
| 758 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 813 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 759 if (!users_.empty()) | 814 if (!users_.empty()) |
| 760 return; | 815 return; |
| 761 if (!g_browser_process) | 816 if (!g_browser_process) |
| 762 return; | 817 return; |
| 763 | 818 |
| 764 PrefService* local_state = g_browser_process->local_state(); | 819 PrefService* local_state = g_browser_process->local_state(); |
| 765 const ListValue* prefs_users = | 820 const ListValue* prefs_users = |
| 766 local_state->GetList(UserManager::kLoggedInUsers); | 821 local_state->GetList(UserManager::kLoggedInUsers); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 content::Details<const User>(logged_in_user_)); | 975 content::Details<const User>(logged_in_user_)); |
| 921 | 976 |
| 922 LoadKeyStore(); | 977 LoadKeyStore(); |
| 923 | 978 |
| 924 // Schedules current user ownership check on file thread. | 979 // Schedules current user ownership check on file thread. |
| 925 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 980 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 926 base::Bind(&UserManagerImpl::CheckOwnership, | 981 base::Bind(&UserManagerImpl::CheckOwnership, |
| 927 base::Unretained(this))); | 982 base::Unretained(this))); |
| 928 } | 983 } |
| 929 | 984 |
| 985 void UserManagerImpl::NotifyThumbnailUpdated() { |
| 986 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 987 content::NotificationService::current()->Notify( |
| 988 chrome::NOTIFICATION_LOGIN_USER_WALLPAPER_THUMBNAIL_UPDATED, |
| 989 content::Source<UserManagerImpl>(this), |
| 990 content::NotificationService::NoDetails()); |
| 991 } |
| 992 |
| 930 void UserManagerImpl::LoadKeyStore() { | 993 void UserManagerImpl::LoadKeyStore() { |
| 931 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 994 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 932 if (key_store_loaded_) | 995 if (key_store_loaded_) |
| 933 return; | 996 return; |
| 934 | 997 |
| 935 // Ensure we've opened the real user's key/certificate database. | 998 // Ensure we've opened the real user's key/certificate database. |
| 936 crypto::OpenPersistentNSSDB(); | 999 crypto::OpenPersistentNSSDB(); |
| 937 | 1000 |
| 938 // Only load the Opencryptoki library into NSS if we have this switch. | 1001 // Only load the Opencryptoki library into NSS if we have this switch. |
| 939 // TODO(gspencer): Remove this switch once cryptohomed work is finished: | 1002 // TODO(gspencer): Remove this switch once cryptohomed work is finished: |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1035 } | 1098 } |
| 1036 | 1099 |
| 1037 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( | 1100 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( |
| 1038 User::WallpaperType type, int index) { | 1101 User::WallpaperType type, int index) { |
| 1039 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1040 | 1103 |
| 1041 current_user_wallpaper_type_ = type; | 1104 current_user_wallpaper_type_ = type; |
| 1042 current_user_wallpaper_index_ = index; | 1105 current_user_wallpaper_index_ = index; |
| 1043 // Ephemeral users can not save data to local state. We just cache the index | 1106 // Ephemeral users can not save data to local state. We just cache the index |
| 1044 // in memory for them. | 1107 // in memory for them. |
| 1045 if (IsCurrentUserEphemeral() || !IsUserLoggedIn()) { | 1108 if (IsCurrentUserEphemeral() || !IsUserLoggedIn()) |
| 1046 return; | 1109 return; |
| 1047 } | |
| 1048 | 1110 |
| 1049 const chromeos::User& user = GetLoggedInUser(); | 1111 const chromeos::User& user = GetLoggedInUser(); |
| 1050 std::string username = user.email(); | 1112 std::string username = user.email(); |
| 1051 DCHECK(!username.empty()); | 1113 DCHECK(!username.empty()); |
| 1052 | 1114 |
| 1053 SaveUserWallpaperProperties(username, type, index); | 1115 SaveUserWallpaperProperties(username, type, index); |
| 1054 } | 1116 } |
| 1055 | 1117 |
| 1056 void UserManagerImpl::SetUserImage(const std::string& username, | 1118 void UserManagerImpl::SetUserImage(const std::string& username, |
| 1057 int image_index, | 1119 int image_index, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1151 last_image_set_async_ = true; | 1213 last_image_set_async_ = true; |
| 1152 | 1214 |
| 1153 BrowserThread::PostTask( | 1215 BrowserThread::PostTask( |
| 1154 BrowserThread::FILE, | 1216 BrowserThread::FILE, |
| 1155 FROM_HERE, | 1217 FROM_HERE, |
| 1156 base::Bind(&UserManagerImpl::SaveImageToFile, | 1218 base::Bind(&UserManagerImpl::SaveImageToFile, |
| 1157 base::Unretained(this), | 1219 base::Unretained(this), |
| 1158 username, image, image_path, image_index)); | 1220 username, image, image_path, image_index)); |
| 1159 } | 1221 } |
| 1160 | 1222 |
| 1223 void UserManagerImpl::SaveUserWallpaperInternal(const std::string& username, |
| 1224 ash::WallpaperLayout layout, |
| 1225 User::WallpaperType type, |
| 1226 const SkBitmap& wallpaper) { |
| 1227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1228 |
| 1229 BrowserThread::PostTask( |
| 1230 BrowserThread::FILE, |
| 1231 FROM_HERE, |
| 1232 base::Bind(&UserManagerImpl::GenerateUserWallpaperThumbnail, |
| 1233 base::Unretained(this), |
| 1234 username, type, wallpaper)); |
| 1235 |
| 1236 ash::Shell::GetInstance()->desktop_background_controller()-> |
| 1237 SetCustomWallpaper(wallpaper, layout); |
| 1238 |
| 1239 // Ignore for ephemeral users. |
| 1240 if (IsEphemeralUser(username)) |
| 1241 return; |
| 1242 |
| 1243 FilePath wallpaper_path = GetWallpaperPathForUser(username, false); |
| 1244 DVLOG(1) << "Saving user image to " << wallpaper_path.value(); |
| 1245 |
| 1246 last_image_set_async_ = true; |
| 1247 |
| 1248 BrowserThread::PostTask( |
| 1249 BrowserThread::FILE, |
| 1250 FROM_HERE, |
| 1251 base::Bind(&UserManagerImpl::SaveWallpaperToFile, |
| 1252 base::Unretained(this), |
| 1253 username, wallpaper, |
| 1254 wallpaper_path, |
| 1255 layout, |
| 1256 User::CUSTOMIZED)); |
| 1257 } |
| 1258 |
| 1259 void UserManagerImpl::LoadCustomWallpaperThumbnail(const std::string& email, |
| 1260 ash::WallpaperLayout layout, |
| 1261 const SkBitmap& wallpaper) { |
| 1262 ash::Shell::GetInstance()->desktop_background_controller()-> |
| 1263 SetCustomWallpaper(wallpaper, layout); |
| 1264 // Load wallpaper thumbnail |
| 1265 std::string wallpaper_path = GetWallpaperPathForUser(email, true).value(); |
| 1266 image_loader_->Start( |
| 1267 wallpaper_path, 0, |
| 1268 base::Bind(&UserManagerImpl::OnCustomWallpaperThumbnailLoaded, |
| 1269 base::Unretained(this), email)); |
| 1270 } |
| 1271 |
| 1272 void UserManagerImpl::OnCustomWallpaperThumbnailLoaded( |
| 1273 const std::string& email, |
| 1274 const SkBitmap& wallpaper) { |
| 1275 User* user = const_cast<User*>(FindUser(email)); |
| 1276 // User may have been removed by now. |
| 1277 if (user && !wallpaper.empty()) |
| 1278 user->SetWallpaperThumbnail(wallpaper); |
| 1279 } |
| 1280 |
| 1281 void UserManagerImpl::GenerateUserWallpaperThumbnail( |
| 1282 const std::string& username, |
| 1283 User::WallpaperType type, |
| 1284 const SkBitmap& wallpaper) { |
| 1285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 1286 SkBitmap thumbnail = |
| 1287 skia::ImageOperations::Resize(wallpaper, |
| 1288 skia::ImageOperations::RESIZE_LANCZOS3, |
| 1289 kThumbnailWidth, kThumbnailHeight); |
| 1290 logged_in_user_->SetWallpaperThumbnail(thumbnail); |
| 1291 |
| 1292 // Notify thumbnail is ready. |
| 1293 BrowserThread::PostTask( |
| 1294 BrowserThread::UI, |
| 1295 FROM_HERE, |
| 1296 base::Bind(&UserManagerImpl::NotifyThumbnailUpdated, |
| 1297 base::Unretained(this))); |
| 1298 |
| 1299 // Ignore for ephemeral users. |
| 1300 if (IsEphemeralUser(username)) |
| 1301 return; |
| 1302 |
| 1303 FilePath thumbnail_path = GetWallpaperPathForUser(username, true); |
| 1304 SaveBitmapToFile(thumbnail, thumbnail_path); |
| 1305 } |
| 1306 |
| 1161 void UserManagerImpl::SaveImageToFile(const std::string& username, | 1307 void UserManagerImpl::SaveImageToFile(const std::string& username, |
| 1162 const SkBitmap& image, | 1308 const SkBitmap& image, |
| 1163 const FilePath& image_path, | 1309 const FilePath& image_path, |
| 1164 int image_index) { | 1310 int image_index) { |
| 1165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 1311 if (!SaveBitmapToFile(image, image_path)) |
| 1166 | |
| 1167 std::vector<unsigned char> encoded_image; | |
| 1168 if (!gfx::PNGCodec::EncodeBGRASkBitmap(image, false, &encoded_image)) { | |
| 1169 LOG(ERROR) << "Failed to PNG encode the image."; | |
| 1170 return; | 1312 return; |
| 1171 } | |
| 1172 | |
| 1173 if (file_util::WriteFile(image_path, | |
| 1174 reinterpret_cast<char*>(&encoded_image[0]), | |
| 1175 encoded_image.size()) == -1) { | |
| 1176 LOG(ERROR) << "Failed to save image to file."; | |
| 1177 return; | |
| 1178 } | |
| 1179 | 1313 |
| 1180 BrowserThread::PostTask( | 1314 BrowserThread::PostTask( |
| 1181 BrowserThread::UI, | 1315 BrowserThread::UI, |
| 1182 FROM_HERE, | 1316 FROM_HERE, |
| 1183 base::Bind(&UserManagerImpl::SaveImageToLocalState, | 1317 base::Bind(&UserManagerImpl::SaveImageToLocalState, |
| 1184 base::Unretained(this), | 1318 base::Unretained(this), |
| 1185 username, image_path.value(), image_index, true)); | 1319 username, image_path.value(), image_index, true)); |
| 1186 } | 1320 } |
| 1187 | 1321 |
| 1322 void UserManagerImpl::SaveWallpaperToFile(const std::string& username, |
| 1323 const SkBitmap& wallpaper, |
| 1324 const FilePath& wallpaper_path, |
| 1325 ash::WallpaperLayout layout, |
| 1326 User::WallpaperType type) { |
| 1327 // TODO(bshe): We should save the original file unchanged instead of re-encode |
| 1328 // it and save it. |
| 1329 if (!SaveBitmapToFile(wallpaper, wallpaper_path)) |
| 1330 return; |
| 1331 |
| 1332 BrowserThread::PostTask( |
| 1333 BrowserThread::UI, |
| 1334 FROM_HERE, |
| 1335 base::Bind(&UserManagerImpl::SaveWallpaperToLocalState, |
| 1336 base::Unretained(this), |
| 1337 username, wallpaper_path.value(), layout, type)); |
| 1338 } |
| 1339 |
| 1188 void UserManagerImpl::SaveImageToLocalState(const std::string& username, | 1340 void UserManagerImpl::SaveImageToLocalState(const std::string& username, |
| 1189 const std::string& image_path, | 1341 const std::string& image_path, |
| 1190 int image_index, | 1342 int image_index, |
| 1191 bool is_async) { | 1343 bool is_async) { |
| 1192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1193 | 1345 |
| 1194 // Ignore for ephemeral users. | 1346 // Ignore for ephemeral users. |
| 1195 if (IsEphemeralUser(username)) | 1347 if (IsEphemeralUser(username)) |
| 1196 return; | 1348 return; |
| 1197 | 1349 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1211 base::DictionaryValue* image_properties = new base::DictionaryValue(); | 1363 base::DictionaryValue* image_properties = new base::DictionaryValue(); |
| 1212 image_properties->Set(kImagePathNodeName, new StringValue(image_path)); | 1364 image_properties->Set(kImagePathNodeName, new StringValue(image_path)); |
| 1213 image_properties->Set(kImageIndexNodeName, | 1365 image_properties->Set(kImageIndexNodeName, |
| 1214 new base::FundamentalValue(image_index)); | 1366 new base::FundamentalValue(image_index)); |
| 1215 images_update->SetWithoutPathExpansion(username, image_properties); | 1367 images_update->SetWithoutPathExpansion(username, image_properties); |
| 1216 DVLOG(1) << "Saving path to user image in Local State."; | 1368 DVLOG(1) << "Saving path to user image in Local State."; |
| 1217 | 1369 |
| 1218 NotifyLocalStateChanged(); | 1370 NotifyLocalStateChanged(); |
| 1219 } | 1371 } |
| 1220 | 1372 |
| 1373 void UserManagerImpl::SaveWallpaperToLocalState(const std::string& username, |
| 1374 const std::string& wallpaper_path, |
| 1375 ash::WallpaperLayout layout, |
| 1376 User::WallpaperType type) { |
| 1377 // TODO(bshe): we probably need to save wallpaper_path instead of index. |
| 1378 SaveUserWallpaperProperties(username, type, layout); |
| 1379 } |
| 1380 |
| 1381 bool UserManagerImpl::SaveBitmapToFile(const SkBitmap& image, |
| 1382 const FilePath& image_path) { |
| 1383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 1384 |
| 1385 std::vector<unsigned char> encoded_image; |
| 1386 if (!gfx::PNGCodec::EncodeBGRASkBitmap(image, false, &encoded_image)) { |
| 1387 LOG(ERROR) << "Failed to PNG encode the image."; |
| 1388 return false; |
| 1389 } |
| 1390 |
| 1391 if (file_util::WriteFile(image_path, |
| 1392 reinterpret_cast<char*>(&encoded_image[0]), |
| 1393 encoded_image.size()) == -1) { |
| 1394 LOG(ERROR) << "Failed to save image to file."; |
| 1395 return false; |
| 1396 } |
| 1397 return true; |
| 1398 } |
| 1399 |
| 1221 void UserManagerImpl::InitDownloadedProfileImage() { | 1400 void UserManagerImpl::InitDownloadedProfileImage() { |
| 1222 DCHECK(logged_in_user_); | 1401 DCHECK(logged_in_user_); |
| 1223 if (downloaded_profile_image_.empty() && !logged_in_user_->image_is_stub()) { | 1402 if (downloaded_profile_image_.empty() && !logged_in_user_->image_is_stub()) { |
| 1224 VLOG(1) << "Profile image initialized"; | 1403 VLOG(1) << "Profile image initialized"; |
| 1225 downloaded_profile_image_ = logged_in_user_->image(); | 1404 downloaded_profile_image_ = logged_in_user_->image(); |
| 1226 downloaded_profile_image_data_url_ = | 1405 downloaded_profile_image_data_url_ = |
| 1227 web_ui_util::GetImageDataUrl(downloaded_profile_image_); | 1406 web_ui_util::GetImageDataUrl(downloaded_profile_image_); |
| 1228 } | 1407 } |
| 1229 } | 1408 } |
| 1230 | 1409 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1357 if (email != user_email) | 1536 if (email != user_email) |
| 1358 prefs_users_update->Append(Value::CreateStringValue(user_email)); | 1537 prefs_users_update->Append(Value::CreateStringValue(user_email)); |
| 1359 else | 1538 else |
| 1360 user_to_remove = it; | 1539 user_to_remove = it; |
| 1361 } | 1540 } |
| 1362 | 1541 |
| 1363 DictionaryPrefUpdate prefs_wallpapers_update(prefs, | 1542 DictionaryPrefUpdate prefs_wallpapers_update(prefs, |
| 1364 kUserWallpapersProperties); | 1543 kUserWallpapersProperties); |
| 1365 prefs_wallpapers_update->RemoveWithoutPathExpansion(email, NULL); | 1544 prefs_wallpapers_update->RemoveWithoutPathExpansion(email, NULL); |
| 1366 | 1545 |
| 1546 // Remove user wallpaper thumbnail |
| 1547 FilePath wallpaper_thumb_path = GetWallpaperPathForUser(email, true); |
| 1548 BrowserThread::PostTask( |
| 1549 BrowserThread::FILE, |
| 1550 FROM_HERE, |
| 1551 base::Bind(&UserManagerImpl::DeleteUserImage, |
| 1552 base::Unretained(this), |
| 1553 wallpaper_thumb_path)); |
| 1554 // Remove user wallpaper |
| 1555 FilePath wallpaper_path = GetWallpaperPathForUser(email, false); |
| 1556 BrowserThread::PostTask( |
| 1557 BrowserThread::FILE, |
| 1558 FROM_HERE, |
| 1559 base::Bind(&UserManagerImpl::DeleteUserImage, |
| 1560 base::Unretained(this), |
| 1561 wallpaper_path)); |
| 1562 |
| 1367 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages); | 1563 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages); |
| 1368 std::string image_path_string; | 1564 std::string image_path_string; |
| 1369 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string); | 1565 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string); |
| 1370 prefs_images_update->RemoveWithoutPathExpansion(email, NULL); | 1566 prefs_images_update->RemoveWithoutPathExpansion(email, NULL); |
| 1371 | 1567 |
| 1372 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); | 1568 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); |
| 1373 int oauth_status; | 1569 int oauth_status; |
| 1374 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); | 1570 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); |
| 1375 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); | 1571 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); |
| 1376 | 1572 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1390 BrowserThread::PostTask( | 1586 BrowserThread::PostTask( |
| 1391 BrowserThread::FILE, | 1587 BrowserThread::FILE, |
| 1392 FROM_HERE, | 1588 FROM_HERE, |
| 1393 base::Bind(&UserManagerImpl::DeleteUserImage, | 1589 base::Bind(&UserManagerImpl::DeleteUserImage, |
| 1394 base::Unretained(this), | 1590 base::Unretained(this), |
| 1395 image_path)); | 1591 image_path)); |
| 1396 } | 1592 } |
| 1397 } | 1593 } |
| 1398 | 1594 |
| 1399 } // namespace chromeos | 1595 } // namespace chromeos |
| OLD | NEW |