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 WallpaperDelegate* delegate) { | |
659 // For wallpapers, save the image without resize. | |
flackr
2012/05/09 21:26:16
s/resize/resizing
bshe
2012/05/10 16:10:26
Done.
| |
660 image_loader_->Start( | |
661 path.value(), 0 /* Original size */, | |
662 base::Bind(&UserManagerImpl::SaveUserWallpaperInternal, | |
663 base::Unretained(this), username, layout, User::CUSTOMIZED, | |
664 delegate)); | |
665 } | |
666 | |
620 void UserManagerImpl::SaveUserImageFromProfileImage( | 667 void UserManagerImpl::SaveUserImageFromProfileImage( |
621 const std::string& username) { | 668 const std::string& username) { |
622 if (!downloaded_profile_image_.empty()) { | 669 if (!downloaded_profile_image_.empty()) { |
623 // Profile image has already been downloaded, so save it to file right now. | 670 // Profile image has already been downloaded, so save it to file right now. |
624 SaveUserImageInternal(username, User::kProfileImageIndex, | 671 SaveUserImageInternal(username, User::kProfileImageIndex, |
625 downloaded_profile_image_); | 672 downloaded_profile_image_); |
626 } else { | 673 } else { |
627 // No profile image - use the stub image (gray avatar). | 674 // No profile image - use the stub image (gray avatar). |
628 SetUserImage(username, User::kProfileImageIndex, SkBitmap()); | 675 SetUserImage(username, User::kProfileImageIndex, SkBitmap()); |
629 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); | 676 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
747 LocalStateChanged(this)); | 794 LocalStateChanged(this)); |
748 } | 795 } |
749 | 796 |
750 FilePath UserManagerImpl::GetImagePathForUser(const std::string& username) { | 797 FilePath UserManagerImpl::GetImagePathForUser(const std::string& username) { |
751 std::string filename = username + ".png"; | 798 std::string filename = username + ".png"; |
752 FilePath user_data_dir; | 799 FilePath user_data_dir; |
753 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 800 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
754 return user_data_dir.AppendASCII(filename); | 801 return user_data_dir.AppendASCII(filename); |
755 } | 802 } |
756 | 803 |
804 FilePath UserManagerImpl::GetWallpaperPathForUser(const std::string& username, | |
805 bool is_thumbnail) { | |
806 std::string filename = username + | |
807 (is_thumbnail ? "_wallpaper_thumb.png" : "_wallpaper.png"); | |
808 FilePath user_data_dir; | |
809 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | |
810 return user_data_dir.AppendASCII(filename); | |
811 } | |
812 | |
757 void UserManagerImpl::EnsureUsersLoaded() { | 813 void UserManagerImpl::EnsureUsersLoaded() { |
758 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 814 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
759 if (!users_.empty()) | 815 if (!users_.empty()) |
760 return; | 816 return; |
761 if (!g_browser_process) | 817 if (!g_browser_process) |
762 return; | 818 return; |
763 | 819 |
764 PrefService* local_state = g_browser_process->local_state(); | 820 PrefService* local_state = g_browser_process->local_state(); |
765 const ListValue* prefs_users = | 821 const ListValue* prefs_users = |
766 local_state->GetList(UserManager::kLoggedInUsers); | 822 local_state->GetList(UserManager::kLoggedInUsers); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1035 } | 1091 } |
1036 | 1092 |
1037 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( | 1093 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( |
1038 User::WallpaperType type, int index) { | 1094 User::WallpaperType type, int index) { |
1039 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1095 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1040 | 1096 |
1041 current_user_wallpaper_type_ = type; | 1097 current_user_wallpaper_type_ = type; |
1042 current_user_wallpaper_index_ = index; | 1098 current_user_wallpaper_index_ = index; |
1043 // Ephemeral users can not save data to local state. We just cache the index | 1099 // Ephemeral users can not save data to local state. We just cache the index |
1044 // in memory for them. | 1100 // in memory for them. |
1045 if (IsCurrentUserEphemeral() || !IsUserLoggedIn()) { | 1101 if (IsCurrentUserEphemeral() || !IsUserLoggedIn()) |
1046 return; | 1102 return; |
1047 } | |
1048 | 1103 |
1049 const chromeos::User& user = GetLoggedInUser(); | 1104 const chromeos::User& user = GetLoggedInUser(); |
1050 std::string username = user.email(); | 1105 std::string username = user.email(); |
1051 DCHECK(!username.empty()); | 1106 DCHECK(!username.empty()); |
1052 | 1107 |
1053 SaveUserWallpaperProperties(username, type, index); | 1108 SaveUserWallpaperProperties(username, type, index); |
1054 } | 1109 } |
1055 | 1110 |
1056 void UserManagerImpl::SetUserImage(const std::string& username, | 1111 void UserManagerImpl::SetUserImage(const std::string& username, |
1057 int image_index, | 1112 int image_index, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1151 last_image_set_async_ = true; | 1206 last_image_set_async_ = true; |
1152 | 1207 |
1153 BrowserThread::PostTask( | 1208 BrowserThread::PostTask( |
1154 BrowserThread::FILE, | 1209 BrowserThread::FILE, |
1155 FROM_HERE, | 1210 FROM_HERE, |
1156 base::Bind(&UserManagerImpl::SaveImageToFile, | 1211 base::Bind(&UserManagerImpl::SaveImageToFile, |
1157 base::Unretained(this), | 1212 base::Unretained(this), |
1158 username, image, image_path, image_index)); | 1213 username, image, image_path, image_index)); |
1159 } | 1214 } |
1160 | 1215 |
1216 void UserManagerImpl::SaveUserWallpaperInternal(const std::string& username, | |
1217 ash::WallpaperLayout layout, | |
1218 User::WallpaperType type, | |
1219 WallpaperDelegate* delegate, | |
1220 const SkBitmap& wallpaper) { | |
1221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1222 | |
1223 BrowserThread::PostTask( | |
1224 BrowserThread::FILE, | |
1225 FROM_HERE, | |
1226 base::Bind(&UserManagerImpl::GenerateUserWallpaperThumbnail, | |
1227 base::Unretained(this), username, type, delegate, wallpaper)); | |
1228 | |
1229 ash::Shell::GetInstance()->desktop_background_controller()-> | |
1230 SetCustomWallpaper(wallpaper, layout); | |
1231 | |
1232 // Ignore for ephemeral users. | |
1233 if (IsEphemeralUser(username)) | |
1234 return; | |
1235 | |
1236 FilePath wallpaper_path = GetWallpaperPathForUser(username, false); | |
1237 DVLOG(1) << "Saving user image to " << wallpaper_path.value(); | |
1238 | |
1239 last_image_set_async_ = true; | |
1240 | |
1241 BrowserThread::PostTask( | |
1242 BrowserThread::FILE, | |
1243 FROM_HERE, | |
1244 base::Bind(&UserManagerImpl::SaveWallpaperToFile, | |
1245 base::Unretained(this), username, wallpaper, wallpaper_path, | |
1246 layout, User::CUSTOMIZED)); | |
1247 } | |
1248 | |
1249 void UserManagerImpl::LoadCustomWallpaperThumbnail(const std::string& email, | |
1250 ash::WallpaperLayout layout, | |
1251 const SkBitmap& wallpaper) { | |
1252 ash::Shell::GetInstance()->desktop_background_controller()-> | |
1253 SetCustomWallpaper(wallpaper, layout); | |
1254 // Load wallpaper thumbnail | |
1255 std::string wallpaper_path = GetWallpaperPathForUser(email, true).value(); | |
1256 image_loader_->Start( | |
1257 wallpaper_path, 0, | |
1258 base::Bind(&UserManagerImpl::OnCustomWallpaperThumbnailLoaded, | |
1259 base::Unretained(this), email)); | |
1260 } | |
1261 | |
1262 void UserManagerImpl::OnCustomWallpaperThumbnailLoaded( | |
1263 const std::string& email, | |
1264 const SkBitmap& wallpaper) { | |
1265 User* user = const_cast<User*>(FindUser(email)); | |
1266 // User may have been removed by now. | |
1267 if (user && !wallpaper.empty()) | |
1268 user->SetWallpaperThumbnail(wallpaper); | |
1269 } | |
1270 | |
1271 void UserManagerImpl::OnThumbnailUpdated(WallpaperDelegate* delegate) { | |
1272 if (delegate) | |
1273 delegate->SetCustomWallpaperThumbnail(); | |
1274 } | |
1275 | |
1276 void UserManagerImpl::GenerateUserWallpaperThumbnail( | |
1277 const std::string& username, | |
1278 User::WallpaperType type, | |
1279 WallpaperDelegate* delegate, | |
1280 const SkBitmap& wallpaper) { | |
1281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
1282 SkBitmap thumbnail = | |
1283 skia::ImageOperations::Resize(wallpaper, | |
1284 skia::ImageOperations::RESIZE_LANCZOS3, | |
1285 kThumbnailWidth, kThumbnailHeight); | |
flackr
2012/05/09 21:26:16
Will this be the correct aspect ratio?
bshe
2012/05/10 16:10:26
No. It just resizes the wallpaper to 128x80. Ideal
| |
1286 logged_in_user_->SetWallpaperThumbnail(thumbnail); | |
1287 | |
1288 // Notify thumbnail is ready. | |
1289 BrowserThread::PostTask( | |
1290 BrowserThread::UI, | |
1291 FROM_HERE, | |
1292 base::Bind(&UserManagerImpl::OnThumbnailUpdated, | |
1293 base::Unretained(this), delegate)); | |
1294 | |
1295 // Ignore for ephemeral users. | |
1296 if (IsEphemeralUser(username)) | |
1297 return; | |
1298 | |
1299 FilePath thumbnail_path = GetWallpaperPathForUser(username, true); | |
1300 SaveBitmapToFile(thumbnail, thumbnail_path); | |
1301 } | |
1302 | |
1161 void UserManagerImpl::SaveImageToFile(const std::string& username, | 1303 void UserManagerImpl::SaveImageToFile(const std::string& username, |
1162 const SkBitmap& image, | 1304 const SkBitmap& image, |
1163 const FilePath& image_path, | 1305 const FilePath& image_path, |
1164 int image_index) { | 1306 int image_index) { |
1165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 1307 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; | 1308 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 | 1309 |
1180 BrowserThread::PostTask( | 1310 BrowserThread::PostTask( |
1181 BrowserThread::UI, | 1311 BrowserThread::UI, |
1182 FROM_HERE, | 1312 FROM_HERE, |
1183 base::Bind(&UserManagerImpl::SaveImageToLocalState, | 1313 base::Bind(&UserManagerImpl::SaveImageToLocalState, |
1184 base::Unretained(this), | 1314 base::Unretained(this), |
1185 username, image_path.value(), image_index, true)); | 1315 username, image_path.value(), image_index, true)); |
1186 } | 1316 } |
1187 | 1317 |
1318 void UserManagerImpl::SaveWallpaperToFile(const std::string& username, | |
1319 const SkBitmap& wallpaper, | |
1320 const FilePath& wallpaper_path, | |
1321 ash::WallpaperLayout layout, | |
1322 User::WallpaperType type) { | |
1323 // TODO(bshe): We should save the original file unchanged instead of re-encode | |
flackr
2012/05/09 21:26:16
s/re-encode/re-encoding
bshe
2012/05/10 16:10:26
Done.
| |
1324 // it and save it. | |
flackr
2012/05/09 21:26:16
s/it and save/and saving
bshe
2012/05/10 16:10:26
Done.
| |
1325 if (!SaveBitmapToFile(wallpaper, wallpaper_path)) | |
1326 return; | |
1327 | |
1328 BrowserThread::PostTask( | |
1329 BrowserThread::UI, | |
1330 FROM_HERE, | |
1331 base::Bind(&UserManagerImpl::SaveWallpaperToLocalState, | |
1332 base::Unretained(this), | |
1333 username, wallpaper_path.value(), layout, type)); | |
1334 } | |
1335 | |
1188 void UserManagerImpl::SaveImageToLocalState(const std::string& username, | 1336 void UserManagerImpl::SaveImageToLocalState(const std::string& username, |
1189 const std::string& image_path, | 1337 const std::string& image_path, |
1190 int image_index, | 1338 int image_index, |
1191 bool is_async) { | 1339 bool is_async) { |
1192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1193 | 1341 |
1194 // Ignore for ephemeral users. | 1342 // Ignore for ephemeral users. |
1195 if (IsEphemeralUser(username)) | 1343 if (IsEphemeralUser(username)) |
1196 return; | 1344 return; |
1197 | 1345 |
(...skipping 13 matching lines...) Expand all Loading... | |
1211 base::DictionaryValue* image_properties = new base::DictionaryValue(); | 1359 base::DictionaryValue* image_properties = new base::DictionaryValue(); |
1212 image_properties->Set(kImagePathNodeName, new StringValue(image_path)); | 1360 image_properties->Set(kImagePathNodeName, new StringValue(image_path)); |
1213 image_properties->Set(kImageIndexNodeName, | 1361 image_properties->Set(kImageIndexNodeName, |
1214 new base::FundamentalValue(image_index)); | 1362 new base::FundamentalValue(image_index)); |
1215 images_update->SetWithoutPathExpansion(username, image_properties); | 1363 images_update->SetWithoutPathExpansion(username, image_properties); |
1216 DVLOG(1) << "Saving path to user image in Local State."; | 1364 DVLOG(1) << "Saving path to user image in Local State."; |
1217 | 1365 |
1218 NotifyLocalStateChanged(); | 1366 NotifyLocalStateChanged(); |
1219 } | 1367 } |
1220 | 1368 |
1369 void UserManagerImpl::SaveWallpaperToLocalState(const std::string& username, | |
1370 const std::string& wallpaper_path, | |
1371 ash::WallpaperLayout layout, | |
1372 User::WallpaperType type) { | |
1373 // TODO(bshe): we probably need to save wallpaper_path instead of index. | |
flackr
2012/05/09 21:26:16
s/we/We
bshe
2012/05/10 16:10:26
Done.
| |
1374 SaveUserWallpaperProperties(username, type, layout); | |
1375 } | |
1376 | |
1377 bool UserManagerImpl::SaveBitmapToFile(const SkBitmap& image, | |
1378 const FilePath& image_path) { | |
1379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
1380 | |
1381 std::vector<unsigned char> encoded_image; | |
1382 if (!gfx::PNGCodec::EncodeBGRASkBitmap(image, false, &encoded_image)) { | |
1383 LOG(ERROR) << "Failed to PNG encode the image."; | |
1384 return false; | |
1385 } | |
1386 | |
1387 if (file_util::WriteFile(image_path, | |
1388 reinterpret_cast<char*>(&encoded_image[0]), | |
1389 encoded_image.size()) == -1) { | |
1390 LOG(ERROR) << "Failed to save image to file."; | |
1391 return false; | |
1392 } | |
1393 return true; | |
1394 } | |
1395 | |
1221 void UserManagerImpl::InitDownloadedProfileImage() { | 1396 void UserManagerImpl::InitDownloadedProfileImage() { |
1222 DCHECK(logged_in_user_); | 1397 DCHECK(logged_in_user_); |
1223 if (downloaded_profile_image_.empty() && !logged_in_user_->image_is_stub()) { | 1398 if (downloaded_profile_image_.empty() && !logged_in_user_->image_is_stub()) { |
1224 VLOG(1) << "Profile image initialized"; | 1399 VLOG(1) << "Profile image initialized"; |
1225 downloaded_profile_image_ = logged_in_user_->image(); | 1400 downloaded_profile_image_ = logged_in_user_->image(); |
1226 downloaded_profile_image_data_url_ = | 1401 downloaded_profile_image_data_url_ = |
1227 web_ui_util::GetImageDataUrl(downloaded_profile_image_); | 1402 web_ui_util::GetImageDataUrl(downloaded_profile_image_); |
1228 } | 1403 } |
1229 } | 1404 } |
1230 | 1405 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1357 if (email != user_email) | 1532 if (email != user_email) |
1358 prefs_users_update->Append(Value::CreateStringValue(user_email)); | 1533 prefs_users_update->Append(Value::CreateStringValue(user_email)); |
1359 else | 1534 else |
1360 user_to_remove = it; | 1535 user_to_remove = it; |
1361 } | 1536 } |
1362 | 1537 |
1363 DictionaryPrefUpdate prefs_wallpapers_update(prefs, | 1538 DictionaryPrefUpdate prefs_wallpapers_update(prefs, |
1364 kUserWallpapersProperties); | 1539 kUserWallpapersProperties); |
1365 prefs_wallpapers_update->RemoveWithoutPathExpansion(email, NULL); | 1540 prefs_wallpapers_update->RemoveWithoutPathExpansion(email, NULL); |
1366 | 1541 |
1542 // Remove user wallpaper thumbnail | |
1543 FilePath wallpaper_thumb_path = GetWallpaperPathForUser(email, true); | |
1544 BrowserThread::PostTask( | |
1545 BrowserThread::FILE, | |
1546 FROM_HERE, | |
1547 base::Bind(&UserManagerImpl::DeleteUserImage, | |
1548 base::Unretained(this), | |
1549 wallpaper_thumb_path)); | |
1550 // Remove user wallpaper | |
1551 FilePath wallpaper_path = GetWallpaperPathForUser(email, false); | |
1552 BrowserThread::PostTask( | |
1553 BrowserThread::FILE, | |
1554 FROM_HERE, | |
1555 base::Bind(&UserManagerImpl::DeleteUserImage, | |
1556 base::Unretained(this), | |
1557 wallpaper_path)); | |
1558 | |
1367 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages); | 1559 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages); |
1368 std::string image_path_string; | 1560 std::string image_path_string; |
1369 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string); | 1561 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string); |
1370 prefs_images_update->RemoveWithoutPathExpansion(email, NULL); | 1562 prefs_images_update->RemoveWithoutPathExpansion(email, NULL); |
1371 | 1563 |
1372 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); | 1564 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); |
1373 int oauth_status; | 1565 int oauth_status; |
1374 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); | 1566 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); |
1375 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); | 1567 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); |
1376 | 1568 |
(...skipping 13 matching lines...) Expand all Loading... | |
1390 BrowserThread::PostTask( | 1582 BrowserThread::PostTask( |
1391 BrowserThread::FILE, | 1583 BrowserThread::FILE, |
1392 FROM_HERE, | 1584 FROM_HERE, |
1393 base::Bind(&UserManagerImpl::DeleteUserImage, | 1585 base::Bind(&UserManagerImpl::DeleteUserImage, |
1394 base::Unretained(this), | 1586 base::Unretained(this), |
1395 image_path)); | 1587 image_path)); |
1396 } | 1588 } |
1397 } | 1589 } |
1398 | 1590 |
1399 } // namespace chromeos | 1591 } // namespace chromeos |
OLD | NEW |