| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/users/wallpaper/wallpaper_manager.h" | 5 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <numeric> | 8 #include <numeric> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 break; | 820 break; |
| 821 } | 821 } |
| 822 } | 822 } |
| 823 | 823 |
| 824 if (loading_.empty()) | 824 if (loading_.empty()) |
| 825 FOR_EACH_OBSERVER(Observer, observers_, OnPendingListEmptyForTesting()); | 825 FOR_EACH_OBSERVER(Observer, observers_, OnPendingListEmptyForTesting()); |
| 826 } | 826 } |
| 827 | 827 |
| 828 void WallpaperManager::SetPolicyControlledWallpaper( | 828 void WallpaperManager::SetPolicyControlledWallpaper( |
| 829 const AccountId& account_id, | 829 const AccountId& account_id, |
| 830 const user_manager::UserImage& user_image) { | 830 scoped_ptr<user_manager::UserImage> user_image) { |
| 831 const user_manager::User* user = | 831 const user_manager::User* user = |
| 832 user_manager::UserManager::Get()->FindUser(account_id); | 832 user_manager::UserManager::Get()->FindUser(account_id); |
| 833 if (!user) { | 833 if (!user) { |
| 834 NOTREACHED() << "Unknown user."; | 834 NOTREACHED() << "Unknown user."; |
| 835 return; | 835 return; |
| 836 } | 836 } |
| 837 | 837 |
| 838 const wallpaper::WallpaperFilesId wallpaper_files_id = | 838 const wallpaper::WallpaperFilesId wallpaper_files_id = |
| 839 GetKnownUserWallpaperFilesId(*user); | 839 GetKnownUserWallpaperFilesId(*user); |
| 840 if (!wallpaper_files_id.is_valid()) { | 840 if (!wallpaper_files_id.is_valid()) { |
| 841 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( | 841 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( |
| 842 GetUnhashedSourceForWallpaperFilesId(*user), | 842 GetUnhashedSourceForWallpaperFilesId(*user), |
| 843 base::Bind(&WallpaperManager::SetCustomWallpaperOnSanitizedUsername, | 843 base::Bind(&WallpaperManager::SetCustomWallpaperOnSanitizedUsername, |
| 844 weak_factory_.GetWeakPtr(), account_id, user_image.image(), | 844 weak_factory_.GetWeakPtr(), account_id, user_image->image(), |
| 845 true /* update wallpaper */)); | 845 true /* update wallpaper */)); |
| 846 } else { | 846 } else { |
| 847 SetCustomWallpaper(account_id, wallpaper_files_id, "policy-controlled.jpeg", | 847 SetCustomWallpaper(account_id, wallpaper_files_id, "policy-controlled.jpeg", |
| 848 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED, | 848 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED, |
| 849 user_manager::User::POLICY, user_image.image(), | 849 user_manager::User::POLICY, user_image->image(), |
| 850 true /* update wallpaper */); | 850 true /* update wallpaper */); |
| 851 } | 851 } |
| 852 } | 852 } |
| 853 | 853 |
| 854 void WallpaperManager::SetCustomWallpaperOnSanitizedUsername( | 854 void WallpaperManager::SetCustomWallpaperOnSanitizedUsername( |
| 855 const AccountId& account_id, | 855 const AccountId& account_id, |
| 856 const gfx::ImageSkia& image, | 856 const gfx::ImageSkia& image, |
| 857 bool update_wallpaper, | 857 bool update_wallpaper, |
| 858 bool cryptohome_success, | 858 bool cryptohome_success, |
| 859 const std::string& wallpaper_files_id_str) { | 859 const std::string& wallpaper_files_id_str) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 info->type = static_cast<user_manager::User::WallpaperType>(type); | 940 info->type = static_cast<user_manager::User::WallpaperType>(type); |
| 941 info->date = base::Time::FromInternalValue(date_val); | 941 info->date = base::Time::FromInternalValue(date_val); |
| 942 return true; | 942 return true; |
| 943 } | 943 } |
| 944 | 944 |
| 945 void WallpaperManager::OnWallpaperDecoded( | 945 void WallpaperManager::OnWallpaperDecoded( |
| 946 const AccountId& account_id, | 946 const AccountId& account_id, |
| 947 wallpaper::WallpaperLayout layout, | 947 wallpaper::WallpaperLayout layout, |
| 948 bool update_wallpaper, | 948 bool update_wallpaper, |
| 949 MovableOnDestroyCallbackHolder on_finish, | 949 MovableOnDestroyCallbackHolder on_finish, |
| 950 const user_manager::UserImage& user_image) { | 950 scoped_ptr<user_manager::UserImage> user_image) { |
| 951 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 951 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 952 TRACE_EVENT_ASYNC_END0("ui", "LoadAndDecodeWallpaper", this); | 952 TRACE_EVENT_ASYNC_END0("ui", "LoadAndDecodeWallpaper", this); |
| 953 | 953 |
| 954 // If decoded wallpaper is empty, we have probably failed to decode the file. | 954 // If decoded wallpaper is empty, we have probably failed to decode the file. |
| 955 // Use default wallpaper in this case. | 955 // Use default wallpaper in this case. |
| 956 if (user_image.image().isNull()) { | 956 if (user_image->image().isNull()) { |
| 957 // Updates user pref to default wallpaper. | 957 // Updates user pref to default wallpaper. |
| 958 WallpaperInfo info = {"", | 958 WallpaperInfo info = {"", |
| 959 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED, | 959 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED, |
| 960 user_manager::User::DEFAULT, | 960 user_manager::User::DEFAULT, |
| 961 base::Time::Now().LocalMidnight()}; | 961 base::Time::Now().LocalMidnight()}; |
| 962 SetUserWallpaperInfo(account_id, info, true); | 962 SetUserWallpaperInfo(account_id, info, true); |
| 963 | 963 |
| 964 if (update_wallpaper) | 964 if (update_wallpaper) |
| 965 DoSetDefaultWallpaper(account_id, std::move(on_finish)); | 965 DoSetDefaultWallpaper(account_id, std::move(on_finish)); |
| 966 return; | 966 return; |
| 967 } | 967 } |
| 968 | 968 |
| 969 // Update the image, but keep the path which was set earlier. | 969 // Update the image, but keep the path which was set earlier. |
| 970 wallpaper_cache_[account_id].second = user_image.image(); | 970 wallpaper_cache_[account_id].second = user_image->image(); |
| 971 | 971 |
| 972 if (update_wallpaper) { | 972 if (update_wallpaper) { |
| 973 ash::Shell::GetInstance() | 973 ash::Shell::GetInstance() |
| 974 ->desktop_background_controller() | 974 ->desktop_background_controller() |
| 975 ->SetWallpaperImage(user_image.image(), layout); | 975 ->SetWallpaperImage(user_image->image(), layout); |
| 976 } | 976 } |
| 977 } | 977 } |
| 978 | 978 |
| 979 void WallpaperManager::StartLoad(const AccountId& account_id, | 979 void WallpaperManager::StartLoad(const AccountId& account_id, |
| 980 const WallpaperInfo& info, | 980 const WallpaperInfo& info, |
| 981 bool update_wallpaper, | 981 bool update_wallpaper, |
| 982 const base::FilePath& wallpaper_path, | 982 const base::FilePath& wallpaper_path, |
| 983 MovableOnDestroyCallbackHolder on_finish) { | 983 MovableOnDestroyCallbackHolder on_finish) { |
| 984 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 984 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 985 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); | 985 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 child_large_wallpaper_file_ = command_line->GetSwitchValuePath( | 1068 child_large_wallpaper_file_ = command_line->GetSwitchValuePath( |
| 1069 chromeos::switches::kChildWallpaperLarge); | 1069 chromeos::switches::kChildWallpaperLarge); |
| 1070 default_wallpaper_image_.reset(); | 1070 default_wallpaper_image_.reset(); |
| 1071 } | 1071 } |
| 1072 | 1072 |
| 1073 void WallpaperManager::OnDefaultWallpaperDecoded( | 1073 void WallpaperManager::OnDefaultWallpaperDecoded( |
| 1074 const base::FilePath& path, | 1074 const base::FilePath& path, |
| 1075 const wallpaper::WallpaperLayout layout, | 1075 const wallpaper::WallpaperLayout layout, |
| 1076 scoped_ptr<user_manager::UserImage>* result_out, | 1076 scoped_ptr<user_manager::UserImage>* result_out, |
| 1077 MovableOnDestroyCallbackHolder on_finish, | 1077 MovableOnDestroyCallbackHolder on_finish, |
| 1078 const user_manager::UserImage& user_image) { | 1078 scoped_ptr<user_manager::UserImage> user_image) { |
| 1079 result_out->reset(new user_manager::UserImage(user_image)); | 1079 *result_out = std::move(user_image); |
| 1080 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( | 1080 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( |
| 1081 user_image.image(), layout); | 1081 (*result_out)->image(), layout); |
| 1082 } | 1082 } |
| 1083 | 1083 |
| 1084 void WallpaperManager::StartLoadAndSetDefaultWallpaper( | 1084 void WallpaperManager::StartLoadAndSetDefaultWallpaper( |
| 1085 const base::FilePath& path, | 1085 const base::FilePath& path, |
| 1086 const wallpaper::WallpaperLayout layout, | 1086 const wallpaper::WallpaperLayout layout, |
| 1087 MovableOnDestroyCallbackHolder on_finish, | 1087 MovableOnDestroyCallbackHolder on_finish, |
| 1088 scoped_ptr<user_manager::UserImage>* result_out) { | 1088 scoped_ptr<user_manager::UserImage>* result_out) { |
| 1089 user_image_loader::StartWithFilePath( | 1089 user_image_loader::StartWithFilePath( |
| 1090 task_runner_, path, ImageDecoder::ROBUST_JPEG_CODEC, | 1090 task_runner_, path, ImageDecoder::ROBUST_JPEG_CODEC, |
| 1091 0, // Do not crop. | 1091 0, // Do not crop. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 DoSetDefaultWallpaper(EmptyAccountId(), MovableOnDestroyCallbackHolder()); | 1136 DoSetDefaultWallpaper(EmptyAccountId(), MovableOnDestroyCallbackHolder()); |
| 1137 } | 1137 } |
| 1138 } | 1138 } |
| 1139 | 1139 |
| 1140 wallpaper::WallpaperFilesId WallpaperManager::GetFilesId( | 1140 wallpaper::WallpaperFilesId WallpaperManager::GetFilesId( |
| 1141 const user_manager::User& user) const { | 1141 const user_manager::User& user) const { |
| 1142 return GetKnownUserWallpaperFilesId(user); | 1142 return GetKnownUserWallpaperFilesId(user); |
| 1143 } | 1143 } |
| 1144 | 1144 |
| 1145 } // namespace chromeos | 1145 } // namespace chromeos |
| OLD | NEW |