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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 // Incognito user is represented by an empty string (since some code already | 67 // Incognito user is represented by an empty string (since some code already |
68 // depends on that and it's hard to figure out what). | 68 // depends on that and it's hard to figure out what). |
69 const char kGuestUser[] = ""; | 69 const char kGuestUser[] = ""; |
70 | 70 |
71 // Stub user email (for test paths). | 71 // Stub user email (for test paths). |
72 const char kStubUser[] = "stub-user@example.com"; | 72 const char kStubUser[] = "stub-user@example.com"; |
73 | 73 |
74 // Names of nodes with info about user image. | 74 // Names of nodes with info about user image. |
75 const char kImagePathNodeName[] = "path"; | 75 const char kImagePathNodeName[] = "path"; |
76 const char kImageIndexNodeName[] = "index"; | 76 const char kImageIndexNodeName[] = "index"; |
| 77 const char kImageURLNodeName[] = "url"; |
77 | 78 |
78 const char kWallpaperTypeNodeName[] = "type"; | 79 const char kWallpaperTypeNodeName[] = "type"; |
79 const char kWallpaperIndexNodeName[] = "index"; | 80 const char kWallpaperIndexNodeName[] = "index"; |
80 | 81 |
81 const int kThumbnailWidth = 128; | 82 const int kThumbnailWidth = 128; |
82 const int kThumbnailHeight = 80; | 83 const int kThumbnailHeight = 80; |
83 | 84 |
84 // Index of the default image used for the |kStubUser| user. | 85 // Index of the default image used for the |kStubUser| user. |
85 const int kStubDefaultImageIndex = 0; | 86 const int kStubDefaultImageIndex = 0; |
86 | 87 |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 | 584 |
584 std::string UserManagerImpl::GetUserDisplayEmail( | 585 std::string UserManagerImpl::GetUserDisplayEmail( |
585 const std::string& username) const { | 586 const std::string& username) const { |
586 const User* user = FindUser(username); | 587 const User* user = FindUser(username); |
587 return user ? user->display_email() : username; | 588 return user ? user->display_email() : username; |
588 } | 589 } |
589 | 590 |
590 void UserManagerImpl::SaveUserDefaultImageIndex(const std::string& username, | 591 void UserManagerImpl::SaveUserDefaultImageIndex(const std::string& username, |
591 int image_index) { | 592 int image_index) { |
592 DCHECK(image_index >= 0 && image_index < kDefaultImagesCount); | 593 DCHECK(image_index >= 0 && image_index < kDefaultImagesCount); |
593 SetUserImage(username, image_index, UserImage(GetDefaultImage(image_index))); | 594 SetUserImage(username, image_index, GURL(), |
594 SaveImageToLocalState(username, "", image_index, false); | 595 UserImage(GetDefaultImage(image_index))); |
| 596 SaveImageToLocalState(username, "", image_index, GURL(), false); |
595 } | 597 } |
596 | 598 |
597 void UserManagerImpl::SaveUserImage(const std::string& username, | 599 void UserManagerImpl::SaveUserImage(const std::string& username, |
598 const UserImage& user_image) { | 600 const UserImage& user_image) { |
599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 601 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
600 SaveUserImageInternal(username, User::kExternalImageIndex, user_image); | 602 SaveUserImageInternal(username, User::kExternalImageIndex, |
| 603 GURL(), user_image); |
601 } | 604 } |
602 | 605 |
603 void UserManagerImpl::SetLoggedInUserCustomWallpaperLayout( | 606 void UserManagerImpl::SetLoggedInUserCustomWallpaperLayout( |
604 ash::WallpaperLayout layout) { | 607 ash::WallpaperLayout layout) { |
605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 608 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
606 | 609 |
607 // TODO(bshe): We current disabled the customized wallpaper feature for | 610 // TODO(bshe): We current disabled the customized wallpaper feature for |
608 // Ephemeral user. As we dont want to keep a copy of customized wallpaper in | 611 // Ephemeral user. As we dont want to keep a copy of customized wallpaper in |
609 // memory. Need a smarter way to solve this. | 612 // memory. Need a smarter way to solve this. |
610 if (IsCurrentUserEphemeral()) | 613 if (IsCurrentUserEphemeral()) |
(...skipping 28 matching lines...) Expand all Loading... |
639 base::Bind(&UserManagerImpl::SaveUserWallpaperInternal, | 642 base::Bind(&UserManagerImpl::SaveUserWallpaperInternal, |
640 base::Unretained(this), username, layout, User::CUSTOMIZED, | 643 base::Unretained(this), username, layout, User::CUSTOMIZED, |
641 delegate)); | 644 delegate)); |
642 } | 645 } |
643 | 646 |
644 void UserManagerImpl::SaveUserImageFromProfileImage( | 647 void UserManagerImpl::SaveUserImageFromProfileImage( |
645 const std::string& username) { | 648 const std::string& username) { |
646 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 649 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
647 if (!downloaded_profile_image_.empty()) { | 650 if (!downloaded_profile_image_.empty()) { |
648 // Profile image has already been downloaded, so save it to file right now. | 651 // Profile image has already been downloaded, so save it to file right now. |
649 SaveUserImageInternal(username, User::kProfileImageIndex, | 652 DCHECK(profile_image_url_.is_valid()); |
| 653 SaveUserImageInternal(username, |
| 654 User::kProfileImageIndex, profile_image_url_, |
650 UserImage(downloaded_profile_image_)); | 655 UserImage(downloaded_profile_image_)); |
651 } else { | 656 } else { |
652 // No profile image - use the stub image (gray avatar). | 657 // No profile image - use the stub image (gray avatar). |
653 SetUserImage(username, User::kProfileImageIndex, UserImage(SkBitmap())); | 658 SetUserImage(username, User::kProfileImageIndex, |
654 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); | 659 GURL(), UserImage(SkBitmap())); |
| 660 SaveImageToLocalState(username, "", User::kProfileImageIndex, |
| 661 GURL(), false); |
655 } | 662 } |
656 } | 663 } |
657 | 664 |
658 void UserManagerImpl::DownloadProfileImage(const std::string& reason) { | 665 void UserManagerImpl::DownloadProfileImage(const std::string& reason) { |
659 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 666 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
660 | 667 |
661 if (profile_image_downloader_.get()) { | 668 if (profile_image_downloader_.get()) { |
662 // Another download is already in progress | 669 // Another download is already in progress |
663 return; | 670 return; |
664 } | 671 } |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 user->SetImage(UserImage(GetDefaultImage(image_id)), image_id); | 852 user->SetImage(UserImage(GetDefaultImage(image_id)), image_id); |
846 } else { | 853 } else { |
847 int image_index = User::kExternalImageIndex; | 854 int image_index = User::kExternalImageIndex; |
848 // Until image has been loaded, use the stub image. | 855 // Until image has been loaded, use the stub image. |
849 user->SetStubImage(image_index); | 856 user->SetStubImage(image_index); |
850 DCHECK(!image_path.empty()); | 857 DCHECK(!image_path.empty()); |
851 // Load user image asynchronously. | 858 // Load user image asynchronously. |
852 image_loader_->Start( | 859 image_loader_->Start( |
853 image_path, user_image_size, true, | 860 image_path, user_image_size, true, |
854 base::Bind(&UserManagerImpl::SetUserImage, | 861 base::Bind(&UserManagerImpl::SetUserImage, |
855 base::Unretained(this), email, image_index)); | 862 base::Unretained(this), |
| 863 email, image_index, GURL())); |
856 } | 864 } |
857 } else if (prefs_images->GetDictionaryWithoutPathExpansion( | 865 } else if (prefs_images->GetDictionaryWithoutPathExpansion( |
858 email, &image_properties)) { | 866 email, &image_properties)) { |
859 int image_index = User::kInvalidImageIndex; | 867 int image_index = User::kInvalidImageIndex; |
860 image_properties->GetString(kImagePathNodeName, &image_path); | 868 image_properties->GetString(kImagePathNodeName, &image_path); |
861 image_properties->GetInteger(kImageIndexNodeName, &image_index); | 869 image_properties->GetInteger(kImageIndexNodeName, &image_index); |
862 if (image_index >= 0 && image_index < kDefaultImagesCount) { | 870 if (image_index >= 0 && image_index < kDefaultImagesCount) { |
863 user->SetImage(UserImage(GetDefaultImage(image_index)), | 871 user->SetImage(UserImage(GetDefaultImage(image_index)), |
864 image_index); | 872 image_index); |
865 } else if (image_index == User::kExternalImageIndex || | 873 } else if (image_index == User::kExternalImageIndex || |
866 image_index == User::kProfileImageIndex) { | 874 image_index == User::kProfileImageIndex) { |
867 // Path may be empty for profile images (meaning that the image | 875 // Path may be empty for profile images (meaning that the image |
868 // hasn't been downloaded for the first time yet, in which case a | 876 // hasn't been downloaded for the first time yet, in which case a |
869 // download will be scheduled for |kProfileImageDownloadDelayMs| | 877 // download will be scheduled for |kProfileImageDownloadDelayMs| |
870 // after user logs in). | 878 // after user logs in). |
871 DCHECK(!image_path.empty() || | 879 DCHECK(!image_path.empty() || |
872 image_index == User::kProfileImageIndex); | 880 image_index == User::kProfileImageIndex); |
| 881 std::string image_url; |
| 882 image_properties->GetString(kImageURLNodeName, &image_url); |
| 883 GURL image_gurl(image_url); |
873 // Until image has been loaded, use the stub image (gray avatar). | 884 // Until image has been loaded, use the stub image (gray avatar). |
874 user->SetStubImage(image_index); | 885 user->SetStubImage(image_index); |
| 886 user->SetImageURL(image_gurl); |
875 if (!image_path.empty()) { | 887 if (!image_path.empty()) { |
876 // Load user image asynchronously. | 888 // Load user image asynchronously. |
877 image_loader_->Start( | 889 image_loader_->Start( |
878 image_path, user_image_size, true, | 890 image_path, user_image_size, true, |
879 base::Bind(&UserManagerImpl::SetUserImage, | 891 base::Bind(&UserManagerImpl::SetUserImage, |
880 base::Unretained(this), email, image_index)); | 892 base::Unretained(this), |
| 893 email, image_index, image_gurl)); |
881 } | 894 } |
882 } else { | 895 } else { |
883 NOTREACHED(); | 896 NOTREACHED(); |
884 } | 897 } |
885 } | 898 } |
886 } | 899 } |
887 | 900 |
888 string16 display_name; | 901 string16 display_name; |
889 if (prefs_display_names && | 902 if (prefs_display_names && |
890 prefs_display_names->GetStringWithoutPathExpansion( | 903 prefs_display_names->GetStringWithoutPathExpansion( |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 } | 1105 } |
1093 | 1106 |
1094 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( | 1107 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( |
1095 User::WallpaperType type, | 1108 User::WallpaperType type, |
1096 int index) { | 1109 int index) { |
1097 SaveUserWallpaperProperties(GetLoggedInUser().email(), type, index); | 1110 SaveUserWallpaperProperties(GetLoggedInUser().email(), type, index); |
1098 } | 1111 } |
1099 | 1112 |
1100 void UserManagerImpl::SetUserImage(const std::string& username, | 1113 void UserManagerImpl::SetUserImage(const std::string& username, |
1101 int image_index, | 1114 int image_index, |
| 1115 const GURL& image_url, |
1102 const UserImage& user_image) { | 1116 const UserImage& user_image) { |
1103 User* user = const_cast<User*>(FindUser(username)); | 1117 User* user = const_cast<User*>(FindUser(username)); |
1104 // User may have been removed by now. | 1118 // User may have been removed by now. |
1105 if (user) { | 1119 if (user) { |
1106 // For existing users, a valid image index should have been set upon loading | 1120 // For existing users, a valid image index should have been set upon loading |
1107 // them from Local State. | 1121 // them from Local State. |
1108 DCHECK(user->image_index() != User::kInvalidImageIndex || | 1122 DCHECK(user->image_index() != User::kInvalidImageIndex || |
1109 is_current_user_new_); | 1123 is_current_user_new_); |
1110 bool image_changed = user->image_index() != User::kInvalidImageIndex; | 1124 bool image_changed = user->image_index() != User::kInvalidImageIndex; |
1111 if (!user_image.image().empty()) | 1125 if (!user_image.image().empty()) |
1112 user->SetImage(user_image, image_index); | 1126 user->SetImage(user_image, image_index); |
1113 else | 1127 else |
1114 user->SetStubImage(image_index); | 1128 user->SetStubImage(image_index); |
| 1129 user->SetImageURL(image_url); |
1115 // For the logged-in user with a profile picture, initialize | 1130 // For the logged-in user with a profile picture, initialize |
1116 // |downloaded_profile_picture_|. | 1131 // |downloaded_profile_picture_|. |
1117 if (user == logged_in_user_ && image_index == User::kProfileImageIndex) | 1132 if (user == logged_in_user_ && image_index == User::kProfileImageIndex) |
1118 InitDownloadedProfileImage(); | 1133 InitDownloadedProfileImage(); |
1119 if (image_changed) { | 1134 if (image_changed) { |
1120 // Unless this is first-time setting with |SetInitialUserImage|, | 1135 // Unless this is first-time setting with |SetInitialUserImage|, |
1121 // send a notification about image change. | 1136 // send a notification about image change. |
1122 content::NotificationService::current()->Notify( | 1137 content::NotificationService::current()->Notify( |
1123 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | 1138 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, |
1124 content::Source<UserManagerImpl>(this), | 1139 content::Source<UserManagerImpl>(this), |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue(); | 1188 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue(); |
1174 wallpaper_properties->Set(kWallpaperTypeNodeName, | 1189 wallpaper_properties->Set(kWallpaperTypeNodeName, |
1175 new base::FundamentalValue(type)); | 1190 new base::FundamentalValue(type)); |
1176 wallpaper_properties->Set(kWallpaperIndexNodeName, | 1191 wallpaper_properties->Set(kWallpaperIndexNodeName, |
1177 new base::FundamentalValue(index)); | 1192 new base::FundamentalValue(index)); |
1178 wallpaper_update->SetWithoutPathExpansion(username, wallpaper_properties); | 1193 wallpaper_update->SetWithoutPathExpansion(username, wallpaper_properties); |
1179 } | 1194 } |
1180 | 1195 |
1181 void UserManagerImpl::SaveUserImageInternal(const std::string& username, | 1196 void UserManagerImpl::SaveUserImageInternal(const std::string& username, |
1182 int image_index, | 1197 int image_index, |
| 1198 const GURL& image_url, |
1183 const UserImage& user_image) { | 1199 const UserImage& user_image) { |
1184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1185 | 1201 |
1186 SetUserImage(username, image_index, user_image); | 1202 SetUserImage(username, image_index, image_url, user_image); |
1187 | 1203 |
1188 // Ignore for ephemeral users. | 1204 // Ignore for ephemeral users. |
1189 if (IsEphemeralUser(username)) | 1205 if (IsEphemeralUser(username)) |
1190 return; | 1206 return; |
1191 | 1207 |
1192 FilePath image_path = GetImagePathForUser(username); | 1208 FilePath image_path = GetImagePathForUser(username); |
1193 DVLOG(1) << "Saving user image to " << image_path.value(); | 1209 DVLOG(1) << "Saving user image to " << image_path.value(); |
1194 | 1210 |
1195 last_image_set_async_ = true; | 1211 last_image_set_async_ = true; |
1196 | 1212 |
1197 BrowserThread::PostTask( | 1213 BrowserThread::PostTask( |
1198 BrowserThread::FILE, | 1214 BrowserThread::FILE, |
1199 FROM_HERE, | 1215 FROM_HERE, |
1200 base::Bind(&UserManagerImpl::SaveImageToFile, | 1216 base::Bind(&UserManagerImpl::SaveImageToFile, |
1201 base::Unretained(this), | 1217 base::Unretained(this), |
1202 username, user_image, image_path, image_index)); | 1218 username, user_image, image_path, image_index, image_url)); |
1203 } | 1219 } |
1204 | 1220 |
1205 void UserManagerImpl::SaveUserWallpaperInternal(const std::string& username, | 1221 void UserManagerImpl::SaveUserWallpaperInternal(const std::string& username, |
1206 ash::WallpaperLayout layout, | 1222 ash::WallpaperLayout layout, |
1207 User::WallpaperType type, | 1223 User::WallpaperType type, |
1208 WallpaperDelegate* delegate, | 1224 WallpaperDelegate* delegate, |
1209 const UserImage& user_image) { | 1225 const UserImage& user_image) { |
1210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1211 | 1227 |
1212 const SkBitmap& wallpaper = user_image.image(); | 1228 const SkBitmap& wallpaper = user_image.image(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1289 if (IsEphemeralUser(username)) | 1305 if (IsEphemeralUser(username)) |
1290 return; | 1306 return; |
1291 | 1307 |
1292 FilePath thumbnail_path = GetWallpaperPathForUser(username, true); | 1308 FilePath thumbnail_path = GetWallpaperPathForUser(username, true); |
1293 SaveBitmapToFile(UserImage(thumbnail), thumbnail_path); | 1309 SaveBitmapToFile(UserImage(thumbnail), thumbnail_path); |
1294 } | 1310 } |
1295 | 1311 |
1296 void UserManagerImpl::SaveImageToFile(const std::string& username, | 1312 void UserManagerImpl::SaveImageToFile(const std::string& username, |
1297 const UserImage& user_image, | 1313 const UserImage& user_image, |
1298 const FilePath& image_path, | 1314 const FilePath& image_path, |
1299 int image_index) { | 1315 int image_index, |
| 1316 const GURL& image_url) { |
1300 if (!SaveBitmapToFile(user_image, image_path)) | 1317 if (!SaveBitmapToFile(user_image, image_path)) |
1301 return; | 1318 return; |
1302 | 1319 |
1303 BrowserThread::PostTask( | 1320 BrowserThread::PostTask( |
1304 BrowserThread::UI, | 1321 BrowserThread::UI, |
1305 FROM_HERE, | 1322 FROM_HERE, |
1306 base::Bind(&UserManagerImpl::SaveImageToLocalState, | 1323 base::Bind(&UserManagerImpl::SaveImageToLocalState, |
1307 base::Unretained(this), | 1324 base::Unretained(this), |
1308 username, image_path.value(), image_index, true)); | 1325 username, image_path.value(), image_index, image_url, true)); |
1309 } | 1326 } |
1310 | 1327 |
1311 void UserManagerImpl::SaveWallpaperToFile(const std::string& username, | 1328 void UserManagerImpl::SaveWallpaperToFile(const std::string& username, |
1312 const SkBitmap& wallpaper, | 1329 const SkBitmap& wallpaper, |
1313 const FilePath& wallpaper_path, | 1330 const FilePath& wallpaper_path, |
1314 ash::WallpaperLayout layout, | 1331 ash::WallpaperLayout layout, |
1315 User::WallpaperType type) { | 1332 User::WallpaperType type) { |
1316 // TODO(bshe): We should save the original file unchanged instead of | 1333 // TODO(bshe): We should save the original file unchanged instead of |
1317 // re-encoding it and saving it. | 1334 // re-encoding it and saving it. |
1318 if (!SaveBitmapToFile(UserImage(wallpaper), wallpaper_path)) | 1335 if (!SaveBitmapToFile(UserImage(wallpaper), wallpaper_path)) |
1319 return; | 1336 return; |
1320 | 1337 |
1321 BrowserThread::PostTask( | 1338 BrowserThread::PostTask( |
1322 BrowserThread::UI, | 1339 BrowserThread::UI, |
1323 FROM_HERE, | 1340 FROM_HERE, |
1324 base::Bind(&UserManagerImpl::SaveWallpaperToLocalState, | 1341 base::Bind(&UserManagerImpl::SaveWallpaperToLocalState, |
1325 base::Unretained(this), | 1342 base::Unretained(this), |
1326 username, wallpaper_path.value(), layout, type)); | 1343 username, wallpaper_path.value(), layout, type)); |
1327 } | 1344 } |
1328 | 1345 |
1329 void UserManagerImpl::SaveImageToLocalState(const std::string& username, | 1346 void UserManagerImpl::SaveImageToLocalState(const std::string& username, |
1330 const std::string& image_path, | 1347 const std::string& image_path, |
1331 int image_index, | 1348 int image_index, |
| 1349 const GURL& image_url, |
1332 bool is_async) { | 1350 bool is_async) { |
1333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1334 | 1352 |
1335 // Ignore for ephemeral users. | 1353 // Ignore for ephemeral users. |
1336 if (IsEphemeralUser(username)) | 1354 if (IsEphemeralUser(username)) |
1337 return; | 1355 return; |
1338 | 1356 |
1339 // TODO(ivankr): use unique filenames for user images each time | 1357 // TODO(ivankr): use unique filenames for user images each time |
1340 // a new image is set so that only the last image update is saved | 1358 // a new image is set so that only the last image update is saved |
1341 // to Local State and notified. | 1359 // to Local State and notified. |
1342 if (is_async && !last_image_set_async_) { | 1360 if (is_async && !last_image_set_async_) { |
1343 DVLOG(1) << "Ignoring saved image because it has changed"; | 1361 DVLOG(1) << "Ignoring saved image because it has changed"; |
1344 return; | 1362 return; |
1345 } else if (!is_async) { | 1363 } else if (!is_async) { |
1346 // Reset the async image save flag if called directly from the UI thread. | 1364 // Reset the async image save flag if called directly from the UI thread. |
1347 last_image_set_async_ = false; | 1365 last_image_set_async_ = false; |
1348 } | 1366 } |
1349 | 1367 |
1350 PrefService* local_state = g_browser_process->local_state(); | 1368 PrefService* local_state = g_browser_process->local_state(); |
1351 DictionaryPrefUpdate images_update(local_state, UserManager::kUserImages); | 1369 DictionaryPrefUpdate images_update(local_state, UserManager::kUserImages); |
1352 base::DictionaryValue* image_properties = new base::DictionaryValue(); | 1370 base::DictionaryValue* image_properties = new base::DictionaryValue(); |
1353 image_properties->Set(kImagePathNodeName, new StringValue(image_path)); | 1371 image_properties->Set(kImagePathNodeName, new StringValue(image_path)); |
1354 image_properties->Set(kImageIndexNodeName, | 1372 image_properties->Set(kImageIndexNodeName, |
1355 new base::FundamentalValue(image_index)); | 1373 new base::FundamentalValue(image_index)); |
| 1374 if (!image_url.is_empty()) { |
| 1375 image_properties->Set(kImageURLNodeName, |
| 1376 new StringValue(image_url.spec())); |
| 1377 } else { |
| 1378 image_properties->Remove(kImageURLNodeName, NULL); |
| 1379 } |
1356 images_update->SetWithoutPathExpansion(username, image_properties); | 1380 images_update->SetWithoutPathExpansion(username, image_properties); |
1357 DVLOG(1) << "Saving path to user image in Local State."; | 1381 DVLOG(1) << "Saving path to user image in Local State."; |
1358 | 1382 |
1359 NotifyLocalStateChanged(); | 1383 NotifyLocalStateChanged(); |
1360 } | 1384 } |
1361 | 1385 |
1362 void UserManagerImpl::SaveWallpaperToLocalState(const std::string& username, | 1386 void UserManagerImpl::SaveWallpaperToLocalState(const std::string& username, |
1363 const std::string& wallpaper_path, | 1387 const std::string& wallpaper_path, |
1364 ash::WallpaperLayout layout, | 1388 ash::WallpaperLayout layout, |
1365 User::WallpaperType type) { | 1389 User::WallpaperType type) { |
(...skipping 25 matching lines...) Expand all Loading... |
1391 return true; | 1415 return true; |
1392 } | 1416 } |
1393 | 1417 |
1394 void UserManagerImpl::InitDownloadedProfileImage() { | 1418 void UserManagerImpl::InitDownloadedProfileImage() { |
1395 DCHECK(logged_in_user_); | 1419 DCHECK(logged_in_user_); |
1396 if (downloaded_profile_image_.empty() && !logged_in_user_->image_is_stub()) { | 1420 if (downloaded_profile_image_.empty() && !logged_in_user_->image_is_stub()) { |
1397 VLOG(1) << "Profile image initialized"; | 1421 VLOG(1) << "Profile image initialized"; |
1398 downloaded_profile_image_ = logged_in_user_->image(); | 1422 downloaded_profile_image_ = logged_in_user_->image(); |
1399 downloaded_profile_image_data_url_ = | 1423 downloaded_profile_image_data_url_ = |
1400 web_ui_util::GetImageDataUrl(gfx::ImageSkia(downloaded_profile_image_)); | 1424 web_ui_util::GetImageDataUrl(gfx::ImageSkia(downloaded_profile_image_)); |
| 1425 profile_image_url_ = logged_in_user_->image_url(); |
1401 } | 1426 } |
1402 } | 1427 } |
1403 | 1428 |
1404 void UserManagerImpl::DeleteUserImage(const FilePath& image_path) { | 1429 void UserManagerImpl::DeleteUserImage(const FilePath& image_path) { |
1405 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 1430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
1406 if (!file_util::Delete(image_path, false)) { | 1431 if (!file_util::Delete(image_path, false)) { |
1407 LOG(ERROR) << "Failed to remove user image."; | 1432 LOG(ERROR) << "Failed to remove user image."; |
1408 return; | 1433 return; |
1409 } | 1434 } |
1410 } | 1435 } |
(...skipping 21 matching lines...) Expand all Loading... |
1432 | 1457 |
1433 // UserManagerImpl should be accessed only on UI thread. | 1458 // UserManagerImpl should be accessed only on UI thread. |
1434 BrowserThread::PostTask( | 1459 BrowserThread::PostTask( |
1435 BrowserThread::UI, | 1460 BrowserThread::UI, |
1436 FROM_HERE, | 1461 FROM_HERE, |
1437 base::Bind(&UserManagerImpl::UpdateOwnership, | 1462 base::Bind(&UserManagerImpl::UpdateOwnership, |
1438 base::Unretained(this), | 1463 base::Unretained(this), |
1439 is_owner)); | 1464 is_owner)); |
1440 } | 1465 } |
1441 | 1466 |
| 1467 // ProfileDownloaderDelegate override. |
1442 int UserManagerImpl::GetDesiredImageSideLength() const { | 1468 int UserManagerImpl::GetDesiredImageSideLength() const { |
1443 return GetCurrentUserImageSize(); | 1469 return GetCurrentUserImageSize(); |
1444 } | 1470 } |
1445 | 1471 |
| 1472 // ProfileDownloaderDelegate override. |
| 1473 std::string UserManagerImpl::GetCachedPictureURL() const { |
| 1474 return profile_image_url_.spec(); |
| 1475 } |
| 1476 |
1446 Profile* UserManagerImpl::GetBrowserProfile() { | 1477 Profile* UserManagerImpl::GetBrowserProfile() { |
1447 return ProfileManager::GetDefaultProfile(); | 1478 return ProfileManager::GetDefaultProfile(); |
1448 } | 1479 } |
1449 | 1480 |
1450 std::string UserManagerImpl::GetCachedPictureURL() const { | |
1451 // Currently the profile picture URL is not cached on ChromeOS. | |
1452 return std::string(); | |
1453 } | |
1454 | |
1455 void UserManagerImpl::OnDownloadComplete(ProfileDownloader* downloader, | 1481 void UserManagerImpl::OnDownloadComplete(ProfileDownloader* downloader, |
1456 bool success) { | 1482 bool success) { |
1457 // Make sure that |ProfileDownloader| gets deleted after return. | 1483 // Make sure that |ProfileDownloader| gets deleted after return. |
1458 scoped_ptr<ProfileDownloader> profile_image_downloader( | 1484 scoped_ptr<ProfileDownloader> profile_image_downloader( |
1459 profile_image_downloader_.release()); | 1485 profile_image_downloader_.release()); |
1460 DCHECK(profile_image_downloader.get() == downloader); | 1486 DCHECK(profile_image_downloader.get() == downloader); |
1461 | 1487 |
1462 ProfileDownloadResult result; | 1488 ProfileDownloadResult result; |
1463 if (!success) { | 1489 if (!success) { |
1464 SaveUserDisplayName(GetLoggedInUser().email(), | 1490 SaveUserDisplayName(GetLoggedInUser().email(), |
(...skipping 23 matching lines...) Expand all Loading... |
1488 // Check if this image is not the same as already downloaded. | 1514 // Check if this image is not the same as already downloaded. |
1489 std::string new_image_data_url = | 1515 std::string new_image_data_url = |
1490 web_ui_util::GetImageDataUrl(gfx::ImageSkia( | 1516 web_ui_util::GetImageDataUrl(gfx::ImageSkia( |
1491 downloader->GetProfilePicture())); | 1517 downloader->GetProfilePicture())); |
1492 if (!downloaded_profile_image_data_url_.empty() && | 1518 if (!downloaded_profile_image_data_url_.empty() && |
1493 new_image_data_url == downloaded_profile_image_data_url_) | 1519 new_image_data_url == downloaded_profile_image_data_url_) |
1494 return; | 1520 return; |
1495 | 1521 |
1496 downloaded_profile_image_data_url_ = new_image_data_url; | 1522 downloaded_profile_image_data_url_ = new_image_data_url; |
1497 downloaded_profile_image_ = downloader->GetProfilePicture(); | 1523 downloaded_profile_image_ = downloader->GetProfilePicture(); |
| 1524 profile_image_url_ = GURL(downloader->GetProfilePictureURL()); |
1498 | 1525 |
1499 if (GetLoggedInUser().image_index() == User::kProfileImageIndex) { | 1526 if (GetLoggedInUser().image_index() == User::kProfileImageIndex) { |
1500 VLOG(1) << "Updating profile image for logged-in user"; | 1527 VLOG(1) << "Updating profile image for logged-in user"; |
1501 UMA_HISTOGRAM_ENUMERATION("UserImage.ProfileDownloadResult", | 1528 UMA_HISTOGRAM_ENUMERATION("UserImage.ProfileDownloadResult", |
1502 kDownloadSuccessChanged, | 1529 kDownloadSuccessChanged, |
1503 kDownloadResultsCount); | 1530 kDownloadResultsCount); |
1504 | 1531 |
1505 // This will persist |downloaded_profile_image_| to file. | 1532 // This will persist |downloaded_profile_image_| to file. |
1506 SaveUserImageFromProfileImage(GetLoggedInUser().email()); | 1533 SaveUserImageFromProfileImage(GetLoggedInUser().email()); |
1507 } | 1534 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1594 BrowserThread::PostTask( | 1621 BrowserThread::PostTask( |
1595 BrowserThread::FILE, | 1622 BrowserThread::FILE, |
1596 FROM_HERE, | 1623 FROM_HERE, |
1597 base::Bind(&UserManagerImpl::DeleteUserImage, | 1624 base::Bind(&UserManagerImpl::DeleteUserImage, |
1598 base::Unretained(this), | 1625 base::Unretained(this), |
1599 image_path)); | 1626 image_path)); |
1600 } | 1627 } |
1601 } | 1628 } |
1602 | 1629 |
1603 } // namespace chromeos | 1630 } // namespace chromeos |
OLD | NEW |