| 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/desktop_background/desktop_background_controller.h" | 9 #include "ash/desktop_background/desktop_background_controller.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 logged_in_user_ = *logged_in_user; | 269 logged_in_user_ = *logged_in_user; |
| 270 users_.erase(logged_in_user); | 270 users_.erase(logged_in_user); |
| 271 } | 271 } |
| 272 // This user must be in the front of the user list. | 272 // This user must be in the front of the user list. |
| 273 users_.insert(users_.begin(), logged_in_user_); | 273 users_.insert(users_.begin(), logged_in_user_); |
| 274 | 274 |
| 275 if (is_current_user_new_) { | 275 if (is_current_user_new_) { |
| 276 SaveUserDisplayName(GetLoggedInUser().email(), | 276 SaveUserDisplayName(GetLoggedInUser().email(), |
| 277 UTF8ToUTF16(GetLoggedInUser().GetAccountName(true))); | 277 UTF8ToUTF16(GetLoggedInUser().GetAccountName(true))); |
| 278 SetInitialUserImage(email); | 278 SetInitialUserImage(email); |
| 279 WallpaperManager::Get()->SetInitialUserWallpaper(email); | 279 WallpaperManager::Get()->SetInitialUserWallpaper(email, true); |
| 280 } else { | 280 } else { |
| 281 int image_index = logged_in_user_->image_index(); | 281 int image_index = logged_in_user_->image_index(); |
| 282 // If current user image is profile image, it needs to be refreshed. | 282 // If current user image is profile image, it needs to be refreshed. |
| 283 bool download_profile_image = image_index == User::kProfileImageIndex; | 283 bool download_profile_image = image_index == User::kProfileImageIndex; |
| 284 if (download_profile_image) | 284 if (download_profile_image) |
| 285 InitDownloadedProfileImage(); | 285 InitDownloadedProfileImage(); |
| 286 | 286 |
| 287 // Download user's profile data (full name and optionally image) to see if | 287 // Download user's profile data (full name and optionally image) to see if |
| 288 // it has changed. | 288 // it has changed. |
| 289 BrowserThread::PostDelayedTask( | 289 BrowserThread::PostDelayedTask( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 | 323 |
| 324 NotifyOnLogin(); | 324 NotifyOnLogin(); |
| 325 } | 325 } |
| 326 | 326 |
| 327 void UserManagerImpl::DemoUserLoggedIn() { | 327 void UserManagerImpl::DemoUserLoggedIn() { |
| 328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 329 is_current_user_new_ = true; | 329 is_current_user_new_ = true; |
| 330 is_current_user_ephemeral_ = true; | 330 is_current_user_ephemeral_ = true; |
| 331 logged_in_user_ = CreateUser(kDemoUser, /* is_ephemeral= */ true); | 331 logged_in_user_ = CreateUser(kDemoUser, /* is_ephemeral= */ true); |
| 332 SetInitialUserImage(kDemoUser); | 332 SetInitialUserImage(kDemoUser); |
| 333 WallpaperManager::Get()->SetInitialUserWallpaper(kDemoUser); | 333 WallpaperManager::Get()->SetInitialUserWallpaper(kDemoUser, false); |
| 334 NotifyOnLogin(); | 334 NotifyOnLogin(); |
| 335 } | 335 } |
| 336 | 336 |
| 337 void UserManagerImpl::GuestUserLoggedIn() { | 337 void UserManagerImpl::GuestUserLoggedIn() { |
| 338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 339 is_current_user_ephemeral_ = true; | 339 is_current_user_ephemeral_ = true; |
| 340 WallpaperManager::Get()->SetInitialUserWallpaper(kGuestUser); | 340 WallpaperManager::Get()->SetInitialUserWallpaper(kGuestUser, false); |
| 341 logged_in_user_ = CreateUser(kGuestUser, /* is_ephemeral= */ true); | 341 logged_in_user_ = CreateUser(kGuestUser, /* is_ephemeral= */ true); |
| 342 NotifyOnLogin(); | 342 NotifyOnLogin(); |
| 343 } | 343 } |
| 344 | 344 |
| 345 void UserManagerImpl::EphemeralUserLoggedIn(const std::string& email) { | 345 void UserManagerImpl::EphemeralUserLoggedIn(const std::string& email) { |
| 346 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 346 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 347 is_current_user_new_ = true; | 347 is_current_user_new_ = true; |
| 348 is_current_user_ephemeral_ = true; | 348 is_current_user_ephemeral_ = true; |
| 349 logged_in_user_ = CreateUser(email, /* is_ephemeral= */ true); | 349 logged_in_user_ = CreateUser(email, /* is_ephemeral= */ true); |
| 350 SetInitialUserImage(email); | 350 SetInitialUserImage(email); |
| 351 WallpaperManager::Get()->SetInitialUserWallpaper(email); | 351 WallpaperManager::Get()->SetInitialUserWallpaper(email, false); |
| 352 NotifyOnLogin(); | 352 NotifyOnLogin(); |
| 353 } | 353 } |
| 354 | 354 |
| 355 void UserManagerImpl::SessionStarted() { | 355 void UserManagerImpl::SessionStarted() { |
| 356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 357 session_started_ = true; | 357 session_started_ = true; |
| 358 content::NotificationService::current()->Notify( | 358 content::NotificationService::current()->Notify( |
| 359 chrome::NOTIFICATION_SESSION_STARTED, | 359 chrome::NOTIFICATION_SESSION_STARTED, |
| 360 content::NotificationService::AllSources(), | 360 content::NotificationService::AllSources(), |
| 361 content::NotificationService::NoDetails()); | 361 content::NotificationService::NoDetails()); |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 921 const UserList& users = GetUsers(); | 921 const UserList& users = GetUsers(); |
| 922 for (UserList::const_iterator it = users.begin(); | 922 for (UserList::const_iterator it = users.begin(); |
| 923 it != users.end(); | 923 it != users.end(); |
| 924 ++it) { | 924 ++it) { |
| 925 std::string username = (*it)->email(); | 925 std::string username = (*it)->email(); |
| 926 if (user_wallpapers->GetIntegerWithoutPathExpansion((username), | 926 if (user_wallpapers->GetIntegerWithoutPathExpansion((username), |
| 927 &index)) { | 927 &index)) { |
| 928 DictionaryPrefUpdate prefs_wallpapers_update(local_state, | 928 DictionaryPrefUpdate prefs_wallpapers_update(local_state, |
| 929 kUserWallpapers); | 929 kUserWallpapers); |
| 930 prefs_wallpapers_update->RemoveWithoutPathExpansion(username, NULL); | 930 prefs_wallpapers_update->RemoveWithoutPathExpansion(username, NULL); |
| 931 WallpaperManager::Get()->SaveUserWallpaperProperties(username, | 931 WallpaperManager::Get()->SetUserWallpaperProperties(username, |
| 932 User::DEFAULT, | 932 User::DEFAULT, |
| 933 index); | 933 index, |
| 934 true); |
| 934 } else { | 935 } else { |
| 935 // Before M20, wallpaper index is not saved into LocalState unless | 936 // Before M20, wallpaper index is not saved into LocalState unless |
| 936 // user specifically sets a wallpaper. After M20, the default | 937 // user specifically sets a wallpaper. After M20, the default |
| 937 // wallpaper index is saved to LocalState as soon as a new user login. | 938 // wallpaper index is saved to LocalState as soon as a new user login. |
| 938 // When migrating wallpaper index from M20 to M21, we only migrate | 939 // When migrating wallpaper index from M20 to M21, we only migrate |
| 939 // data that is in LocalState. This cause a problem when users login | 940 // data that is in LocalState. This cause a problem when users login |
| 940 // on a M20 device and then update the device to M21. The default | 941 // on a M20 device and then update the device to M21. The default |
| 941 // wallpaper index failed to migrate because it was not saved into | 942 // wallpaper index failed to migrate because it was not saved into |
| 942 // LocalState. Then we assume that all users have index saved in | 943 // LocalState. Then we assume that all users have index saved in |
| 943 // LocalState in M21. This is not true and it results an empty | 944 // LocalState in M21. This is not true and it results an empty |
| 944 // wallpaper for those users as described in cr/130685. So here we use | 945 // wallpaper for those users as described in cr/130685. So here we use |
| 945 // default wallpaper for users that exist in user list but does not | 946 // default wallpaper for users that exist in user list but does not |
| 946 // have an index saved in LocalState. | 947 // have an index saved in LocalState. |
| 947 WallpaperManager::Get()->SaveUserWallpaperProperties(username, | 948 WallpaperManager::Get()->SetUserWallpaperProperties(username, |
| 948 User::DEFAULT, ash::GetDefaultWallpaperIndex()); | 949 User::DEFAULT, ash::GetDefaultWallpaperIndex(), true); |
| 949 } | 950 } |
| 950 } | 951 } |
| 951 } | 952 } |
| 952 } | 953 } |
| 953 } | 954 } |
| 954 | 955 |
| 955 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( | 956 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( |
| 956 User::WallpaperType type, int index) { | 957 User::WallpaperType type, int index) { |
| 957 WallpaperManager::Get()->SaveUserWallpaperProperties( | 958 // Ephemeral users can not save data to local state. |
| 958 GetLoggedInUser().email(), type, index); | 959 // We just cache the index in memory for them. |
| 960 bool is_persistent = !IsCurrentUserEphemeral(); |
| 961 WallpaperManager::Get()->SetUserWallpaperProperties( |
| 962 GetLoggedInUser().email(), type, index, is_persistent); |
| 959 } | 963 } |
| 960 | 964 |
| 961 void UserManagerImpl::SetUserImage(const std::string& username, | 965 void UserManagerImpl::SetUserImage(const std::string& username, |
| 962 int image_index, | 966 int image_index, |
| 963 const GURL& image_url, | 967 const GURL& image_url, |
| 964 const UserImage& user_image) { | 968 const UserImage& user_image) { |
| 965 User* user = const_cast<User*>(FindUser(username)); | 969 User* user = const_cast<User*>(FindUser(username)); |
| 966 // User may have been removed by now. | 970 // User may have been removed by now. |
| 967 if (user) { | 971 if (user) { |
| 968 // For existing users, a valid image index should have been set upon loading | 972 // For existing users, a valid image index should have been set upon loading |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 DVLOG(1) << "Saving path to user image in Local State."; | 1073 DVLOG(1) << "Saving path to user image in Local State."; |
| 1070 | 1074 |
| 1071 NotifyLocalStateChanged(); | 1075 NotifyLocalStateChanged(); |
| 1072 } | 1076 } |
| 1073 | 1077 |
| 1074 void UserManagerImpl::SaveWallpaperToLocalState(const std::string& username, | 1078 void UserManagerImpl::SaveWallpaperToLocalState(const std::string& username, |
| 1075 const std::string& wallpaper_path, | 1079 const std::string& wallpaper_path, |
| 1076 ash::WallpaperLayout layout, | 1080 ash::WallpaperLayout layout, |
| 1077 User::WallpaperType type) { | 1081 User::WallpaperType type) { |
| 1078 // TODO(bshe): We probably need to save wallpaper_path instead of index. | 1082 // TODO(bshe): We probably need to save wallpaper_path instead of index. |
| 1079 WallpaperManager::Get()->SaveUserWallpaperProperties(username, type, layout); | 1083 WallpaperManager::Get()->SetUserWallpaperProperties( |
| 1084 username, type, layout, true); |
| 1080 } | 1085 } |
| 1081 | 1086 |
| 1082 bool UserManagerImpl::SaveBitmapToFile(const UserImage& user_image, | 1087 bool UserManagerImpl::SaveBitmapToFile(const UserImage& user_image, |
| 1083 const FilePath& image_path) { | 1088 const FilePath& image_path) { |
| 1084 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 1089 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 1085 | 1090 |
| 1086 const UserImage::RawImage* encoded_image = NULL; | 1091 const UserImage::RawImage* encoded_image = NULL; |
| 1087 if (user_image.has_animated_image()) { | 1092 if (user_image.has_animated_image()) { |
| 1088 encoded_image = &user_image.animated_image(); | 1093 encoded_image = &user_image.animated_image(); |
| 1089 } else if (user_image.has_raw_image()) { | 1094 } else if (user_image.has_raw_image()) { |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1368 BrowserThread::PostTask( | 1373 BrowserThread::PostTask( |
| 1369 BrowserThread::FILE, | 1374 BrowserThread::FILE, |
| 1370 FROM_HERE, | 1375 FROM_HERE, |
| 1371 base::Bind(&UserManagerImpl::DeleteUserImage, | 1376 base::Bind(&UserManagerImpl::DeleteUserImage, |
| 1372 base::Unretained(this), | 1377 base::Unretained(this), |
| 1373 image_path)); | 1378 image_path)); |
| 1374 } | 1379 } |
| 1375 } | 1380 } |
| 1376 | 1381 |
| 1377 } // namespace chromeos | 1382 } // namespace chromeos |
| OLD | NEW |