| 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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 void UserManagerImpl::UserSelected(const std::string& email) { | 458 void UserManagerImpl::UserSelected(const std::string& email) { |
| 455 if (IsKnownUser(email)) { | 459 if (IsKnownUser(email)) { |
| 456 int index; | 460 int index; |
| 457 User::WallpaperType type; | 461 User::WallpaperType type; |
| 458 GetUserWallpaperProperties(email, type, index); | 462 GetUserWallpaperProperties(email, type, index); |
| 459 if (type == User::RANDOM) { | 463 if (type == User::RANDOM) { |
| 460 // Generate a new random wallpaper index if the selected user chose | 464 // Generate a new random wallpaper index if the selected user chose |
| 461 // RANDOM wallpaper. | 465 // RANDOM wallpaper. |
| 462 index = ash::GetRandomWallpaperIndex(); | 466 index = ash::GetRandomWallpaperIndex(); |
| 463 SaveUserWallpaperProperties(email, User::RANDOM, index); | 467 SaveUserWallpaperProperties(email, User::RANDOM, index); |
| 468 } else if (type == User::CUSTOMIZED) { |
| 469 std::string wallpaper_path = |
| 470 GetWallpaperPathForUser(email, false).value(); |
| 471 // In customized mode, we use index pref to save the user selected |
| 472 // wallpaper layout. See function SaveWallpaperToLocalState(). |
| 473 ash::WallpaperLayout layout = static_cast<ash::WallpaperLayout>(index); |
| 474 // Load user image asynchronously. |
| 475 image_loader_->Start( |
| 476 wallpaper_path, 0, |
| 477 base::Bind(&UserManagerImpl::LoadCustomWallpaperThumbnail, |
| 478 base::Unretained(this), email, layout)); |
| 479 return; |
| 464 } | 480 } |
| 465 ash::Shell::GetInstance()->desktop_background_controller()-> | 481 ash::Shell::GetInstance()->desktop_background_controller()-> |
| 466 SetDefaultWallpaper(index); | 482 SetDefaultWallpaper(index); |
| 467 } | 483 } |
| 468 } | 484 } |
| 469 | 485 |
| 470 void UserManagerImpl::SessionStarted() { | 486 void UserManagerImpl::SessionStarted() { |
| 471 session_started_ = true; | 487 session_started_ = true; |
| 472 content::NotificationService::current()->Notify( | 488 content::NotificationService::current()->Notify( |
| 473 chrome::NOTIFICATION_SESSION_STARTED, | 489 chrome::NOTIFICATION_SESSION_STARTED, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 DCHECK(image_index >= 0 && image_index < kDefaultImagesCount); | 619 DCHECK(image_index >= 0 && image_index < kDefaultImagesCount); |
| 604 SetUserImage(username, image_index, GetDefaultImage(image_index)); | 620 SetUserImage(username, image_index, GetDefaultImage(image_index)); |
| 605 SaveImageToLocalState(username, "", image_index, false); | 621 SaveImageToLocalState(username, "", image_index, false); |
| 606 } | 622 } |
| 607 | 623 |
| 608 void UserManagerImpl::SaveUserImage(const std::string& username, | 624 void UserManagerImpl::SaveUserImage(const std::string& username, |
| 609 const SkBitmap& image) { | 625 const SkBitmap& image) { |
| 610 SaveUserImageInternal(username, User::kExternalImageIndex, image); | 626 SaveUserImageInternal(username, User::kExternalImageIndex, image); |
| 611 } | 627 } |
| 612 | 628 |
| 629 void UserManagerImpl::SetLoggedInUserCustomWallpaperLayout( |
| 630 ash::WallpaperLayout layout) { |
| 631 // TODO(bshe): We current disabled the customized wallpaper feature for |
| 632 // Ephemeral user. As we dont want to keep a copy of customized wallpaper in |
| 633 // memory. Need a smarter way to solve this. |
| 634 if (IsCurrentUserEphemeral()) |
| 635 return; |
| 636 const chromeos::User& user = GetLoggedInUser(); |
| 637 std::string username = user.email(); |
| 638 DCHECK(!username.empty()); |
| 639 |
| 640 std::string file_path = GetWallpaperPathForUser(username, false).value(); |
| 641 SaveWallpaperToLocalState(username, file_path, layout, User::CUSTOMIZED); |
| 642 // Load wallpaper from file. |
| 643 UserSelected(username); |
| 644 } |
| 645 |
| 613 void UserManagerImpl::SaveUserImageFromFile(const std::string& username, | 646 void UserManagerImpl::SaveUserImageFromFile(const std::string& username, |
| 614 const FilePath& path) { | 647 const FilePath& path) { |
| 615 image_loader_->Start( | 648 image_loader_->Start( |
| 616 path.value(), login::kUserImageSize, | 649 path.value(), login::kUserImageSize, |
| 617 base::Bind(&UserManagerImpl::SaveUserImage, | 650 base::Bind(&UserManagerImpl::SaveUserImage, |
| 618 base::Unretained(this), username)); | 651 base::Unretained(this), username)); |
| 619 } | 652 } |
| 620 | 653 |
| 654 void UserManagerImpl::SaveUserWallpaperFromFile(const std::string& username, |
| 655 const FilePath& path, |
| 656 ash::WallpaperLayout layout, |
| 657 WallpaperDelegate* delegate) { |
| 658 // For wallpapers, save the image without resizing. |
| 659 image_loader_->Start( |
| 660 path.value(), 0 /* Original size */, |
| 661 base::Bind(&UserManagerImpl::SaveUserWallpaperInternal, |
| 662 base::Unretained(this), username, layout, User::CUSTOMIZED, |
| 663 delegate)); |
| 664 } |
| 665 |
| 621 void UserManagerImpl::SaveUserImageFromProfileImage( | 666 void UserManagerImpl::SaveUserImageFromProfileImage( |
| 622 const std::string& username) { | 667 const std::string& username) { |
| 623 if (!downloaded_profile_image_.empty()) { | 668 if (!downloaded_profile_image_.empty()) { |
| 624 // 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. |
| 625 SaveUserImageInternal(username, User::kProfileImageIndex, | 670 SaveUserImageInternal(username, User::kProfileImageIndex, |
| 626 downloaded_profile_image_); | 671 downloaded_profile_image_); |
| 627 } else { | 672 } else { |
| 628 // No profile image - use the stub image (gray avatar). | 673 // No profile image - use the stub image (gray avatar). |
| 629 SetUserImage(username, User::kProfileImageIndex, SkBitmap()); | 674 SetUserImage(username, User::kProfileImageIndex, SkBitmap()); |
| 630 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); | 675 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 LocalStateChanged(this)); | 793 LocalStateChanged(this)); |
| 749 } | 794 } |
| 750 | 795 |
| 751 FilePath UserManagerImpl::GetImagePathForUser(const std::string& username) { | 796 FilePath UserManagerImpl::GetImagePathForUser(const std::string& username) { |
| 752 std::string filename = username + ".png"; | 797 std::string filename = username + ".png"; |
| 753 FilePath user_data_dir; | 798 FilePath user_data_dir; |
| 754 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 799 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 755 return user_data_dir.AppendASCII(filename); | 800 return user_data_dir.AppendASCII(filename); |
| 756 } | 801 } |
| 757 | 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 |
| 758 void UserManagerImpl::EnsureUsersLoaded() { | 812 void UserManagerImpl::EnsureUsersLoaded() { |
| 759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 813 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 760 if (!users_.empty()) | 814 if (!users_.empty()) |
| 761 return; | 815 return; |
| 762 if (!g_browser_process) | 816 if (!g_browser_process) |
| 763 return; | 817 return; |
| 764 | 818 |
| 765 PrefService* local_state = g_browser_process->local_state(); | 819 PrefService* local_state = g_browser_process->local_state(); |
| 766 const ListValue* prefs_users = | 820 const ListValue* prefs_users = |
| 767 local_state->GetList(UserManager::kLoggedInUsers); | 821 local_state->GetList(UserManager::kLoggedInUsers); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 } | 1016 } |
| 963 | 1017 |
| 964 void UserManagerImpl::SetInitialUserWallpaper(const std::string& username) { | 1018 void UserManagerImpl::SetInitialUserWallpaper(const std::string& username) { |
| 965 current_user_wallpaper_type_ = User::DEFAULT; | 1019 current_user_wallpaper_type_ = User::DEFAULT; |
| 966 // TODO(bshe): Ideally, wallpaper should start to load as soon as user click | 1020 // TODO(bshe): Ideally, wallpaper should start to load as soon as user click |
| 967 // "Add user". | 1021 // "Add user". |
| 968 if (username == kGuestUser) | 1022 if (username == kGuestUser) |
| 969 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex(); | 1023 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex(); |
| 970 else | 1024 else |
| 971 current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex(); | 1025 current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex(); |
| 972 | |
| 973 SaveUserWallpaperProperties(username, | 1026 SaveUserWallpaperProperties(username, |
| 974 current_user_wallpaper_type_, | 1027 current_user_wallpaper_type_, |
| 975 current_user_wallpaper_index_); | 1028 current_user_wallpaper_index_); |
| 976 | 1029 |
| 977 // Some browser tests do not have shell instance. And it is not necessary to | 1030 // Some browser tests do not have shell instance. And it is not necessary to |
| 978 // create a wallpaper for these tests. Add HasInstance check to prevent tests | 1031 // create a wallpaper for these tests. Add HasInstance check to prevent tests |
| 979 // crash and speed up the tests by avoid loading wallpaper. | 1032 // crash and speed up the tests by avoid loading wallpaper. |
| 980 if (ash::Shell::HasInstance()) { | 1033 if (ash::Shell::HasInstance()) { |
| 981 ash::Shell::GetInstance()->desktop_background_controller()-> | 1034 ash::Shell::GetInstance()->desktop_background_controller()-> |
| 982 SetDefaultWallpaper(current_user_wallpaper_index_); | 1035 SetDefaultWallpaper(current_user_wallpaper_index_); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 } | 1095 } |
| 1043 | 1096 |
| 1044 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( | 1097 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( |
| 1045 User::WallpaperType type, int index) { | 1098 User::WallpaperType type, int index) { |
| 1046 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1099 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1047 | 1100 |
| 1048 current_user_wallpaper_type_ = type; | 1101 current_user_wallpaper_type_ = type; |
| 1049 current_user_wallpaper_index_ = index; | 1102 current_user_wallpaper_index_ = index; |
| 1050 // Ephemeral users can not save data to local state. We just cache the index | 1103 // Ephemeral users can not save data to local state. We just cache the index |
| 1051 // in memory for them. | 1104 // in memory for them. |
| 1052 if (IsCurrentUserEphemeral() || !IsUserLoggedIn()) { | 1105 if (IsCurrentUserEphemeral() || !IsUserLoggedIn()) |
| 1053 return; | 1106 return; |
| 1054 } | |
| 1055 | 1107 |
| 1056 const chromeos::User& user = GetLoggedInUser(); | 1108 const chromeos::User& user = GetLoggedInUser(); |
| 1057 std::string username = user.email(); | 1109 std::string username = user.email(); |
| 1058 DCHECK(!username.empty()); | 1110 DCHECK(!username.empty()); |
| 1059 | 1111 |
| 1060 SaveUserWallpaperProperties(username, type, index); | 1112 SaveUserWallpaperProperties(username, type, index); |
| 1061 } | 1113 } |
| 1062 | 1114 |
| 1063 void UserManagerImpl::SetUserImage(const std::string& username, | 1115 void UserManagerImpl::SetUserImage(const std::string& username, |
| 1064 int image_index, | 1116 int image_index, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1158 last_image_set_async_ = true; | 1210 last_image_set_async_ = true; |
| 1159 | 1211 |
| 1160 BrowserThread::PostTask( | 1212 BrowserThread::PostTask( |
| 1161 BrowserThread::FILE, | 1213 BrowserThread::FILE, |
| 1162 FROM_HERE, | 1214 FROM_HERE, |
| 1163 base::Bind(&UserManagerImpl::SaveImageToFile, | 1215 base::Bind(&UserManagerImpl::SaveImageToFile, |
| 1164 base::Unretained(this), | 1216 base::Unretained(this), |
| 1165 username, image, image_path, image_index)); | 1217 username, image, image_path, image_index)); |
| 1166 } | 1218 } |
| 1167 | 1219 |
| 1220 void UserManagerImpl::SaveUserWallpaperInternal(const std::string& username, |
| 1221 ash::WallpaperLayout layout, |
| 1222 User::WallpaperType type, |
| 1223 WallpaperDelegate* delegate, |
| 1224 const SkBitmap& wallpaper) { |
| 1225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1226 |
| 1227 BrowserThread::PostTask( |
| 1228 BrowserThread::FILE, |
| 1229 FROM_HERE, |
| 1230 base::Bind(&UserManagerImpl::GenerateUserWallpaperThumbnail, |
| 1231 base::Unretained(this), username, type, delegate, wallpaper)); |
| 1232 |
| 1233 ash::Shell::GetInstance()->desktop_background_controller()-> |
| 1234 SetCustomWallpaper(wallpaper, layout); |
| 1235 |
| 1236 // Ignore for ephemeral users. |
| 1237 if (IsEphemeralUser(username)) |
| 1238 return; |
| 1239 |
| 1240 FilePath wallpaper_path = GetWallpaperPathForUser(username, false); |
| 1241 DVLOG(1) << "Saving user image to " << wallpaper_path.value(); |
| 1242 |
| 1243 last_image_set_async_ = true; |
| 1244 |
| 1245 BrowserThread::PostTask( |
| 1246 BrowserThread::FILE, |
| 1247 FROM_HERE, |
| 1248 base::Bind(&UserManagerImpl::SaveWallpaperToFile, |
| 1249 base::Unretained(this), username, wallpaper, wallpaper_path, |
| 1250 layout, User::CUSTOMIZED)); |
| 1251 } |
| 1252 |
| 1253 void UserManagerImpl::LoadCustomWallpaperThumbnail(const std::string& email, |
| 1254 ash::WallpaperLayout layout, |
| 1255 const SkBitmap& wallpaper) { |
| 1256 ash::Shell::GetInstance()->desktop_background_controller()-> |
| 1257 SetCustomWallpaper(wallpaper, layout); |
| 1258 // Load wallpaper thumbnail |
| 1259 std::string wallpaper_path = GetWallpaperPathForUser(email, true).value(); |
| 1260 image_loader_->Start( |
| 1261 wallpaper_path, 0, |
| 1262 base::Bind(&UserManagerImpl::OnCustomWallpaperThumbnailLoaded, |
| 1263 base::Unretained(this), email)); |
| 1264 } |
| 1265 |
| 1266 void UserManagerImpl::OnCustomWallpaperThumbnailLoaded( |
| 1267 const std::string& email, |
| 1268 const SkBitmap& wallpaper) { |
| 1269 User* user = const_cast<User*>(FindUser(email)); |
| 1270 // User may have been removed by now. |
| 1271 if (user && !wallpaper.empty()) |
| 1272 user->SetWallpaperThumbnail(wallpaper); |
| 1273 } |
| 1274 |
| 1275 void UserManagerImpl::OnThumbnailUpdated(WallpaperDelegate* delegate) { |
| 1276 if (delegate) |
| 1277 delegate->SetCustomWallpaperThumbnail(); |
| 1278 } |
| 1279 |
| 1280 void UserManagerImpl::GenerateUserWallpaperThumbnail( |
| 1281 const std::string& username, |
| 1282 User::WallpaperType type, |
| 1283 WallpaperDelegate* delegate, |
| 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::OnThumbnailUpdated, |
| 1297 base::Unretained(this), delegate)); |
| 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 |
| 1168 void UserManagerImpl::SaveImageToFile(const std::string& username, | 1307 void UserManagerImpl::SaveImageToFile(const std::string& username, |
| 1169 const SkBitmap& image, | 1308 const SkBitmap& image, |
| 1170 const FilePath& image_path, | 1309 const FilePath& image_path, |
| 1171 int image_index) { | 1310 int image_index) { |
| 1172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 1311 if (!SaveBitmapToFile(image, image_path)) |
| 1173 | |
| 1174 std::vector<unsigned char> encoded_image; | |
| 1175 if (!gfx::PNGCodec::EncodeBGRASkBitmap(image, false, &encoded_image)) { | |
| 1176 LOG(ERROR) << "Failed to PNG encode the image."; | |
| 1177 return; | 1312 return; |
| 1178 } | |
| 1179 | |
| 1180 if (file_util::WriteFile(image_path, | |
| 1181 reinterpret_cast<char*>(&encoded_image[0]), | |
| 1182 encoded_image.size()) == -1) { | |
| 1183 LOG(ERROR) << "Failed to save image to file."; | |
| 1184 return; | |
| 1185 } | |
| 1186 | 1313 |
| 1187 BrowserThread::PostTask( | 1314 BrowserThread::PostTask( |
| 1188 BrowserThread::UI, | 1315 BrowserThread::UI, |
| 1189 FROM_HERE, | 1316 FROM_HERE, |
| 1190 base::Bind(&UserManagerImpl::SaveImageToLocalState, | 1317 base::Bind(&UserManagerImpl::SaveImageToLocalState, |
| 1191 base::Unretained(this), | 1318 base::Unretained(this), |
| 1192 username, image_path.value(), image_index, true)); | 1319 username, image_path.value(), image_index, true)); |
| 1193 } | 1320 } |
| 1194 | 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 |
| 1328 // re-encoding it and saving 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 |
| 1195 void UserManagerImpl::SaveImageToLocalState(const std::string& username, | 1340 void UserManagerImpl::SaveImageToLocalState(const std::string& username, |
| 1196 const std::string& image_path, | 1341 const std::string& image_path, |
| 1197 int image_index, | 1342 int image_index, |
| 1198 bool is_async) { | 1343 bool is_async) { |
| 1199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1200 | 1345 |
| 1201 // Ignore for ephemeral users. | 1346 // Ignore for ephemeral users. |
| 1202 if (IsEphemeralUser(username)) | 1347 if (IsEphemeralUser(username)) |
| 1203 return; | 1348 return; |
| 1204 | 1349 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1218 base::DictionaryValue* image_properties = new base::DictionaryValue(); | 1363 base::DictionaryValue* image_properties = new base::DictionaryValue(); |
| 1219 image_properties->Set(kImagePathNodeName, new StringValue(image_path)); | 1364 image_properties->Set(kImagePathNodeName, new StringValue(image_path)); |
| 1220 image_properties->Set(kImageIndexNodeName, | 1365 image_properties->Set(kImageIndexNodeName, |
| 1221 new base::FundamentalValue(image_index)); | 1366 new base::FundamentalValue(image_index)); |
| 1222 images_update->SetWithoutPathExpansion(username, image_properties); | 1367 images_update->SetWithoutPathExpansion(username, image_properties); |
| 1223 DVLOG(1) << "Saving path to user image in Local State."; | 1368 DVLOG(1) << "Saving path to user image in Local State."; |
| 1224 | 1369 |
| 1225 NotifyLocalStateChanged(); | 1370 NotifyLocalStateChanged(); |
| 1226 } | 1371 } |
| 1227 | 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 |
| 1228 void UserManagerImpl::InitDownloadedProfileImage() { | 1400 void UserManagerImpl::InitDownloadedProfileImage() { |
| 1229 DCHECK(logged_in_user_); | 1401 DCHECK(logged_in_user_); |
| 1230 if (downloaded_profile_image_.empty() && !logged_in_user_->image_is_stub()) { | 1402 if (downloaded_profile_image_.empty() && !logged_in_user_->image_is_stub()) { |
| 1231 VLOG(1) << "Profile image initialized"; | 1403 VLOG(1) << "Profile image initialized"; |
| 1232 downloaded_profile_image_ = logged_in_user_->image(); | 1404 downloaded_profile_image_ = logged_in_user_->image(); |
| 1233 downloaded_profile_image_data_url_ = | 1405 downloaded_profile_image_data_url_ = |
| 1234 web_ui_util::GetImageDataUrl(downloaded_profile_image_); | 1406 web_ui_util::GetImageDataUrl(downloaded_profile_image_); |
| 1235 } | 1407 } |
| 1236 } | 1408 } |
| 1237 | 1409 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1364 if (email != user_email) | 1536 if (email != user_email) |
| 1365 prefs_users_update->Append(Value::CreateStringValue(user_email)); | 1537 prefs_users_update->Append(Value::CreateStringValue(user_email)); |
| 1366 else | 1538 else |
| 1367 user_to_remove = it; | 1539 user_to_remove = it; |
| 1368 } | 1540 } |
| 1369 | 1541 |
| 1370 DictionaryPrefUpdate prefs_wallpapers_update(prefs, | 1542 DictionaryPrefUpdate prefs_wallpapers_update(prefs, |
| 1371 kUserWallpapersProperties); | 1543 kUserWallpapersProperties); |
| 1372 prefs_wallpapers_update->RemoveWithoutPathExpansion(email, NULL); | 1544 prefs_wallpapers_update->RemoveWithoutPathExpansion(email, NULL); |
| 1373 | 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 |
| 1374 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages); | 1563 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages); |
| 1375 std::string image_path_string; | 1564 std::string image_path_string; |
| 1376 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string); | 1565 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string); |
| 1377 prefs_images_update->RemoveWithoutPathExpansion(email, NULL); | 1566 prefs_images_update->RemoveWithoutPathExpansion(email, NULL); |
| 1378 | 1567 |
| 1379 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); | 1568 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); |
| 1380 int oauth_status; | 1569 int oauth_status; |
| 1381 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); | 1570 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); |
| 1382 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); | 1571 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); |
| 1383 | 1572 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1397 BrowserThread::PostTask( | 1586 BrowserThread::PostTask( |
| 1398 BrowserThread::FILE, | 1587 BrowserThread::FILE, |
| 1399 FROM_HERE, | 1588 FROM_HERE, |
| 1400 base::Bind(&UserManagerImpl::DeleteUserImage, | 1589 base::Bind(&UserManagerImpl::DeleteUserImage, |
| 1401 base::Unretained(this), | 1590 base::Unretained(this), |
| 1402 image_path)); | 1591 image_path)); |
| 1403 } | 1592 } |
| 1404 } | 1593 } |
| 1405 | 1594 |
| 1406 } // namespace chromeos | 1595 } // namespace chromeos |
| OLD | NEW |