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

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

Issue 10375010: Implement user selected wallpaper feature. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 "third_party/skia/include/core/SkBitmap.h" 57 #include "third_party/skia/include/core/SkBitmap.h"
58 #include "ui/gfx/codec/png_codec.h" 58 #include "ui/gfx/codec/png_codec.h"
59 #include "skia/ext/image_operations.h"
flackr 2012/05/04 19:06:17 Sort
bshe 2012/05/08 22:22:18 Done.
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
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), email, layout));
478 return;
463 } 479 }
464 ash::Shell::GetInstance()->desktop_background_controller()-> 480 ash::Shell::GetInstance()->desktop_background_controller()->
465 SetDefaultWallpaper(index); 481 SetDefaultWallpaper(index);
466 } 482 }
467 } 483 }
468 484
469 void UserManagerImpl::RemoveUser(const std::string& email, 485 void UserManagerImpl::RemoveUser(const std::string& email,
470 RemoveUserDelegate* delegate) { 486 RemoveUserDelegate* delegate) {
471 if (!IsKnownUser(email)) 487 if (!IsKnownUser(email))
472 return; 488 return;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 DCHECK(image_index >= 0 && image_index < kDefaultImagesCount); 610 DCHECK(image_index >= 0 && image_index < kDefaultImagesCount);
595 SetUserImage(username, image_index, GetDefaultImage(image_index)); 611 SetUserImage(username, image_index, GetDefaultImage(image_index));
596 SaveImageToLocalState(username, "", image_index, false); 612 SaveImageToLocalState(username, "", image_index, false);
597 } 613 }
598 614
599 void UserManagerImpl::SaveUserImage(const std::string& username, 615 void UserManagerImpl::SaveUserImage(const std::string& username,
600 const SkBitmap& image) { 616 const SkBitmap& image) {
601 SaveUserImageInternal(username, User::kExternalImageIndex, image); 617 SaveUserImageInternal(username, User::kExternalImageIndex, image);
602 } 618 }
603 619
620 void UserManagerImpl::SetLoggedInUserCustomWallpaperLayout(
621 ash::WallpaperLayout layout) {
622 // TODO(bshe): We current disabled the customized wallpaper feature for
623 // Ephemeral user. As we dont want to keep a copy of customized wallpaper in
624 // memory. Need a smarter way to solve this.
625 if (IsCurrentUserEphemeral())
626 return;
627 const chromeos::User& user = GetLoggedInUser();
628 std::string username = user.email();
629 DCHECK(!username.empty());
630
631 std::string file_path = GetWallpaperPathForUser(username, false).value();
632 SaveWallpaperToLocalState(username, file_path, layout, User::CUSTOMIZED);
Nikita (slow) 2012/05/05 14:32:12 So we've agreed to store custom wallpaper in Local
bshe 2012/05/08 22:22:18 Done.
633 // Load wallpaper from file.
634 UserSelected(username);
635 }
636
604 void UserManagerImpl::SaveUserImageFromFile(const std::string& username, 637 void UserManagerImpl::SaveUserImageFromFile(const std::string& username,
605 const FilePath& path) { 638 const FilePath& path) {
606 image_loader_->Start( 639 image_loader_->Start(
607 path.value(), login::kUserImageSize, 640 path.value(), login::kUserImageSize,
608 base::Bind(&UserManagerImpl::SaveUserImage, 641 base::Bind(&UserManagerImpl::SaveUserImage,
609 base::Unretained(this), username)); 642 base::Unretained(this), username));
610 } 643 }
611 644
645 void UserManagerImpl::SaveUserWallpaperFromFile(const std::string& username,
646 const FilePath& path,
647 ash::WallpaperLayout layout) {
648 // For wallpapers, save the image without resize.
649 image_loader_->Start(
650 path.value(), 0 /* Original size */,
651 base::Bind(&UserManagerImpl::SaveUserWallpaperInternal,
652 base::Unretained(this), username, layout, User::CUSTOMIZED));
653 }
654
612 void UserManagerImpl::SaveUserImageFromProfileImage( 655 void UserManagerImpl::SaveUserImageFromProfileImage(
613 const std::string& username) { 656 const std::string& username) {
614 if (!downloaded_profile_image_.empty()) { 657 if (!downloaded_profile_image_.empty()) {
615 // Profile image has already been downloaded, so save it to file right now. 658 // Profile image has already been downloaded, so save it to file right now.
616 SaveUserImageInternal(username, User::kProfileImageIndex, 659 SaveUserImageInternal(username, User::kProfileImageIndex,
617 downloaded_profile_image_); 660 downloaded_profile_image_);
618 } else { 661 } else {
619 // No profile image - use the stub image (gray avatar). 662 // No profile image - use the stub image (gray avatar).
620 SetUserImage(username, User::kProfileImageIndex, SkBitmap()); 663 SetUserImage(username, User::kProfileImageIndex, SkBitmap());
621 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); 664 SaveImageToLocalState(username, "", User::kProfileImageIndex, false);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 LocalStateChanged(this)); 778 LocalStateChanged(this));
736 } 779 }
737 780
738 FilePath UserManagerImpl::GetImagePathForUser(const std::string& username) { 781 FilePath UserManagerImpl::GetImagePathForUser(const std::string& username) {
739 std::string filename = username + ".png"; 782 std::string filename = username + ".png";
740 FilePath user_data_dir; 783 FilePath user_data_dir;
741 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 784 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
742 return user_data_dir.AppendASCII(filename); 785 return user_data_dir.AppendASCII(filename);
743 } 786 }
744 787
788 FilePath UserManagerImpl::GetWallpaperPathForUser(const std::string& username,
789 bool is_thumbnail) {
790 std::string filename = username +
791 (is_thumbnail ? "_wallpaper_thumb.png" : "_wallpaper.png");
792 FilePath user_data_dir;
793 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
794 return user_data_dir.AppendASCII(filename);
795 }
796
745 void UserManagerImpl::EnsureUsersLoaded() { 797 void UserManagerImpl::EnsureUsersLoaded() {
746 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 798 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
747 if (!users_.empty()) 799 if (!users_.empty())
748 return; 800 return;
749 if (!g_browser_process) 801 if (!g_browser_process)
750 return; 802 return;
751 803
752 PrefService* local_state = g_browser_process->local_state(); 804 PrefService* local_state = g_browser_process->local_state();
753 const ListValue* prefs_users = 805 const ListValue* prefs_users =
754 local_state->GetList(UserManager::kLoggedInUsers); 806 local_state->GetList(UserManager::kLoggedInUsers);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 content::Details<const User>(logged_in_user_)); 960 content::Details<const User>(logged_in_user_));
909 961
910 LoadKeyStore(); 962 LoadKeyStore();
911 963
912 // Schedules current user ownership check on file thread. 964 // Schedules current user ownership check on file thread.
913 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 965 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
914 base::Bind(&UserManagerImpl::CheckOwnership, 966 base::Bind(&UserManagerImpl::CheckOwnership,
915 base::Unretained(this))); 967 base::Unretained(this)));
916 } 968 }
917 969
970 void UserManagerImpl::NotifyThumbnailUpdated() {
971 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
972 content::NotificationService::current()->Notify(
973 chrome::NOTIFICATION_LOGIN_USER_WALLPAPER_THUMBNAIL_UPDATED,
974 content::Source<UserManagerImpl>(this),
975 content::NotificationService::NoDetails());
976 }
977
918 void UserManagerImpl::LoadKeyStore() { 978 void UserManagerImpl::LoadKeyStore() {
919 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 979 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
920 if (key_store_loaded_) 980 if (key_store_loaded_)
921 return; 981 return;
922 982
923 // Ensure we've opened the real user's key/certificate database. 983 // Ensure we've opened the real user's key/certificate database.
924 crypto::OpenPersistentNSSDB(); 984 crypto::OpenPersistentNSSDB();
925 985
926 // Only load the Opencryptoki library into NSS if we have this switch. 986 // Only load the Opencryptoki library into NSS if we have this switch.
927 // TODO(gspencer): Remove this switch once cryptohomed work is finished: 987 // TODO(gspencer): Remove this switch once cryptohomed work is finished:
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 } 1077 }
1018 1078
1019 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( 1079 void UserManagerImpl::SaveLoggedInUserWallpaperProperties(
1020 User::WallpaperType type, int index) { 1080 User::WallpaperType type, int index) {
1021 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1081 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1022 1082
1023 current_user_wallpaper_type_ = type; 1083 current_user_wallpaper_type_ = type;
1024 current_user_wallpaper_index_ = index; 1084 current_user_wallpaper_index_ = index;
1025 // Ephemeral users can not save data to local state. We just cache the index 1085 // Ephemeral users can not save data to local state. We just cache the index
1026 // in memory for them. 1086 // in memory for them.
1027 if (IsCurrentUserEphemeral() || !IsUserLoggedIn()) { 1087 if (IsCurrentUserEphemeral() || !IsUserLoggedIn())
1028 return; 1088 return;
1029 }
1030 1089
1031 const chromeos::User& user = GetLoggedInUser(); 1090 const chromeos::User& user = GetLoggedInUser();
1032 std::string username = user.email(); 1091 std::string username = user.email();
1033 DCHECK(!username.empty()); 1092 DCHECK(!username.empty());
1034 1093
1035 SaveUserWallpaperProperties(username, type, index); 1094 SaveUserWallpaperProperties(username, type, index);
1036 } 1095 }
1037 1096
1038 void UserManagerImpl::SetUserImage(const std::string& username, 1097 void UserManagerImpl::SetUserImage(const std::string& username,
1039 int image_index, 1098 int image_index,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 last_image_set_async_ = true; 1190 last_image_set_async_ = true;
1132 1191
1133 BrowserThread::PostTask( 1192 BrowserThread::PostTask(
1134 BrowserThread::FILE, 1193 BrowserThread::FILE,
1135 FROM_HERE, 1194 FROM_HERE,
1136 base::Bind(&UserManagerImpl::SaveImageToFile, 1195 base::Bind(&UserManagerImpl::SaveImageToFile,
1137 base::Unretained(this), 1196 base::Unretained(this),
1138 username, image, image_path, image_index)); 1197 username, image, image_path, image_index));
1139 } 1198 }
1140 1199
1200 void UserManagerImpl::SaveUserWallpaperInternal(const std::string& username,
1201 ash::WallpaperLayout layout,
1202 User::WallpaperType type,
1203 const SkBitmap& wallpaper) {
1204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1205
1206 BrowserThread::PostTask(
1207 BrowserThread::FILE,
1208 FROM_HERE,
1209 base::Bind(&UserManagerImpl::GenerateUserWallpaperThumbnail,
1210 base::Unretained(this),
1211 username, type, wallpaper));
1212
1213 ash::Shell::GetInstance()->desktop_background_controller()->
1214 SetCustomWallpaper(wallpaper, layout);
1215
1216 // Ignore for ephemeral users.
1217 if (IsEphemeralUser(username))
1218 return;
1219
1220 FilePath wallpaper_path = GetWallpaperPathForUser(username, false);
1221 DVLOG(1) << "Saving user image to " << wallpaper_path.value();
1222
1223 last_image_set_async_ = true;
1224
1225 BrowserThread::PostTask(
1226 BrowserThread::FILE,
1227 FROM_HERE,
1228 base::Bind(&UserManagerImpl::SaveWallpaperToFile,
1229 base::Unretained(this),
1230 username, wallpaper,
1231 wallpaper_path,
1232 layout,
1233 User::CUSTOMIZED));
1234 }
1235
1236 void UserManagerImpl::LoadCustomWallpaperThumbnail(const std::string& email,
1237 ash::WallpaperLayout layout,
1238 const SkBitmap& wallpaper) {
1239 ash::Shell::GetInstance()->desktop_background_controller()->
1240 SetCustomWallpaper(wallpaper, layout);
1241 // Load wallpaper thumbnail
1242 std::string wallpaper_path = GetWallpaperPathForUser(email, true).value();
1243 image_loader_->Start(
1244 wallpaper_path, 0,
1245 base::Bind(&UserManagerImpl::OnCustomWallpaperThumbnailLoaded,
1246 base::Unretained(this), email));
1247 }
1248
1249 void UserManagerImpl::OnCustomWallpaperThumbnailLoaded(const std::string& email,
flackr 2012/05/04 19:06:17 Push email to new line and line up arguments
bshe 2012/05/08 22:22:18 Done.
1250 const SkBitmap& wallpaper) {
1251 User* user = const_cast<User*>(FindUser(email));
1252 // User may have been removed by now.
1253 if (user && !wallpaper.empty())
1254 user->SetWallpaperThumbnail(wallpaper);
1255 }
1256
1257 void UserManagerImpl::GenerateUserWallpaperThumbnail(
1258 const std::string& username,
1259 User::WallpaperType type,
1260 const SkBitmap& wallpaper) {
1261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
1262 SkBitmap thumbnail =
1263 skia::ImageOperations::Resize(wallpaper,
1264 skia::ImageOperations::RESIZE_LANCZOS3,
1265 kThumbnailWidth, kThumbnailHeight);
1266 logged_in_user_->SetWallpaperThumbnail(thumbnail);
1267
1268 // Notify thumbnail is ready.
1269 BrowserThread::PostTask(
1270 BrowserThread::UI,
1271 FROM_HERE,
1272 base::Bind(&UserManagerImpl::NotifyThumbnailUpdated,
1273 base::Unretained(this)));
1274
1275 // Ignore for ephemeral users.
1276 if (IsEphemeralUser(username))
1277 return;
1278
1279 FilePath thumbnail_path = GetWallpaperPathForUser(username, true);
1280 SaveBitmapToFile(thumbnail, thumbnail_path);
1281 }
1282
1141 void UserManagerImpl::SaveImageToFile(const std::string& username, 1283 void UserManagerImpl::SaveImageToFile(const std::string& username,
1142 const SkBitmap& image, 1284 const SkBitmap& image,
1143 const FilePath& image_path, 1285 const FilePath& image_path,
1144 int image_index) { 1286 int image_index) {
1145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 1287 if (!SaveBitmapToFile(image, image_path))
1146
1147 std::vector<unsigned char> encoded_image;
1148 if (!gfx::PNGCodec::EncodeBGRASkBitmap(image, false, &encoded_image)) {
1149 LOG(ERROR) << "Failed to PNG encode the image.";
1150 return; 1288 return;
1151 }
1152
1153 if (file_util::WriteFile(image_path,
1154 reinterpret_cast<char*>(&encoded_image[0]),
1155 encoded_image.size()) == -1) {
1156 LOG(ERROR) << "Failed to save image to file.";
1157 return;
1158 }
1159 1289
1160 BrowserThread::PostTask( 1290 BrowserThread::PostTask(
1161 BrowserThread::UI, 1291 BrowserThread::UI,
1162 FROM_HERE, 1292 FROM_HERE,
1163 base::Bind(&UserManagerImpl::SaveImageToLocalState, 1293 base::Bind(&UserManagerImpl::SaveImageToLocalState,
1164 base::Unretained(this), 1294 base::Unretained(this),
1165 username, image_path.value(), image_index, true)); 1295 username, image_path.value(), image_index, true));
1166 } 1296 }
1167 1297
1298 void UserManagerImpl::SaveWallpaperToFile(const std::string& username,
1299 const SkBitmap& wallpaper,
1300 const FilePath& wallpaper_path,
1301 ash::WallpaperLayout layout,
1302 User::WallpaperType type) {
1303 if (!SaveBitmapToFile(wallpaper, wallpaper_path))
flackr 2012/05/04 19:06:17 So when you set a custom wallpaper we decode it, a
bshe 2012/05/08 22:22:18 Make sense. Could I do it in a separate CL (this i
1304 return;
1305
1306 BrowserThread::PostTask(
1307 BrowserThread::UI,
1308 FROM_HERE,
1309 base::Bind(&UserManagerImpl::SaveWallpaperToLocalState,
1310 base::Unretained(this),
1311 username, wallpaper_path.value(), layout, type));
1312 }
1313
1168 void UserManagerImpl::SaveImageToLocalState(const std::string& username, 1314 void UserManagerImpl::SaveImageToLocalState(const std::string& username,
1169 const std::string& image_path, 1315 const std::string& image_path,
1170 int image_index, 1316 int image_index,
1171 bool is_async) { 1317 bool is_async) {
1172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1173 1319
1174 // Ignore for ephemeral users. 1320 // Ignore for ephemeral users.
1175 if (IsEphemeralUser(username)) 1321 if (IsEphemeralUser(username))
1176 return; 1322 return;
1177 1323
(...skipping 13 matching lines...) Expand all
1191 base::DictionaryValue* image_properties = new base::DictionaryValue(); 1337 base::DictionaryValue* image_properties = new base::DictionaryValue();
1192 image_properties->Set(kImagePathNodeName, new StringValue(image_path)); 1338 image_properties->Set(kImagePathNodeName, new StringValue(image_path));
1193 image_properties->Set(kImageIndexNodeName, 1339 image_properties->Set(kImageIndexNodeName,
1194 new base::FundamentalValue(image_index)); 1340 new base::FundamentalValue(image_index));
1195 images_update->SetWithoutPathExpansion(username, image_properties); 1341 images_update->SetWithoutPathExpansion(username, image_properties);
1196 DVLOG(1) << "Saving path to user image in Local State."; 1342 DVLOG(1) << "Saving path to user image in Local State.";
1197 1343
1198 NotifyLocalStateChanged(); 1344 NotifyLocalStateChanged();
1199 } 1345 }
1200 1346
1347 void UserManagerImpl::SaveWallpaperToLocalState(const std::string& username,
1348 const std::string& wallpaper_path,
1349 ash::WallpaperLayout layout,
1350 User::WallpaperType type) {
1351 // TODO(bshe): we probably need to save wallpaper_path instead of index.
1352 SaveUserWallpaperProperties(username, type, layout);
1353 }
1354
1355 bool UserManagerImpl::SaveBitmapToFile(const SkBitmap& image,
1356 const FilePath& image_path) {
1357 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
1358
1359 std::vector<unsigned char> encoded_image;
1360 if (!gfx::PNGCodec::EncodeBGRASkBitmap(image, false, &encoded_image)) {
1361 LOG(ERROR) << "Failed to PNG encode the image.";
1362 return false;
1363 }
1364
1365 if (file_util::WriteFile(image_path,
1366 reinterpret_cast<char*>(&encoded_image[0]),
1367 encoded_image.size()) == -1) {
1368 LOG(ERROR) << "Failed to save image to file.";
1369 return false;
1370 }
1371 return true;
1372 }
1373
1201 void UserManagerImpl::InitDownloadedProfileImage() { 1374 void UserManagerImpl::InitDownloadedProfileImage() {
1202 DCHECK(logged_in_user_); 1375 DCHECK(logged_in_user_);
1203 if (downloaded_profile_image_.empty() && !logged_in_user_->image_is_stub()) { 1376 if (downloaded_profile_image_.empty() && !logged_in_user_->image_is_stub()) {
1204 VLOG(1) << "Profile image initialized"; 1377 VLOG(1) << "Profile image initialized";
1205 downloaded_profile_image_ = logged_in_user_->image(); 1378 downloaded_profile_image_ = logged_in_user_->image();
1206 downloaded_profile_image_data_url_ = 1379 downloaded_profile_image_data_url_ =
1207 web_ui_util::GetImageDataUrl(downloaded_profile_image_); 1380 web_ui_util::GetImageDataUrl(downloaded_profile_image_);
1208 } 1381 }
1209 } 1382 }
1210 1383
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 if (email != user_email) 1510 if (email != user_email)
1338 prefs_users_update->Append(Value::CreateStringValue(user_email)); 1511 prefs_users_update->Append(Value::CreateStringValue(user_email));
1339 else 1512 else
1340 user_to_remove = it; 1513 user_to_remove = it;
1341 } 1514 }
1342 1515
1343 DictionaryPrefUpdate prefs_wallpapers_update(prefs, 1516 DictionaryPrefUpdate prefs_wallpapers_update(prefs,
1344 kUserWallpapersProperties); 1517 kUserWallpapersProperties);
1345 prefs_wallpapers_update->RemoveWithoutPathExpansion(email, NULL); 1518 prefs_wallpapers_update->RemoveWithoutPathExpansion(email, NULL);
1346 1519
1520 /*
flackr 2012/05/04 19:06:17 Remove testing code.
bshe 2012/05/08 22:22:18 Done.
1521 FilePath image_path(image_path_string);
1522 BrowserThread::PostTask(
1523 BrowserThread::FILE,
1524 FROM_HERE,
1525 base::Bind(&UserManagerImpl::DeleteUserImage,
1526 base::Unretained(this),
1527 image_path));
1528 */
1529
1347 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages); 1530 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages);
1348 std::string image_path_string; 1531 std::string image_path_string;
1349 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string); 1532 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string);
1350 prefs_images_update->RemoveWithoutPathExpansion(email, NULL); 1533 prefs_images_update->RemoveWithoutPathExpansion(email, NULL);
1351 1534
1352 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); 1535 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus);
1353 int oauth_status; 1536 int oauth_status;
1354 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); 1537 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status);
1355 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); 1538 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL);
1356 1539
(...skipping 13 matching lines...) Expand all
1370 BrowserThread::PostTask( 1553 BrowserThread::PostTask(
1371 BrowserThread::FILE, 1554 BrowserThread::FILE,
1372 FROM_HERE, 1555 FROM_HERE,
1373 base::Bind(&UserManagerImpl::DeleteUserImage, 1556 base::Bind(&UserManagerImpl::DeleteUserImage,
1374 base::Unretained(this), 1557 base::Unretained(this),
1375 image_path)); 1558 image_path));
1376 } 1559 }
1377 } 1560 }
1378 1561
1379 } // namespace chromeos 1562 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698