| 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 18 matching lines...) Expand all Loading... |
| 29 #include "base/threading/worker_pool.h" | 29 #include "base/threading/worker_pool.h" |
| 30 #include "base/time/time.h" | 30 #include "base/time/time.h" |
| 31 #include "base/trace_event/trace_event.h" | 31 #include "base/trace_event/trace_event.h" |
| 32 #include "base/values.h" | 32 #include "base/values.h" |
| 33 #include "chrome/browser/browser_process.h" | 33 #include "chrome/browser/browser_process.h" |
| 34 #include "chrome/browser/chrome_notification_types.h" | 34 #include "chrome/browser/chrome_notification_types.h" |
| 35 #include "chrome/browser/chromeos/customization/customization_document.h" | 35 #include "chrome/browser/chromeos/customization/customization_document.h" |
| 36 #include "chrome/browser/chromeos/login/startup_utils.h" | 36 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 37 #include "chrome/browser/chromeos/login/wizard_controller.h" | 37 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 38 #include "chrome/browser/chromeos/settings/cros_settings.h" | 38 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 39 #include "chrome/browser/ui/ash/ash_util.h" |
| 39 #include "chrome/common/chrome_paths.h" | 40 #include "chrome/common/chrome_paths.h" |
| 40 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
| 41 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
| 42 #include "chromeos/chromeos_switches.h" | 43 #include "chromeos/chromeos_switches.h" |
| 43 #include "chromeos/cryptohome/system_salt_getter.h" | 44 #include "chromeos/cryptohome/system_salt_getter.h" |
| 44 #include "chromeos/dbus/dbus_thread_manager.h" | 45 #include "chromeos/dbus/dbus_thread_manager.h" |
| 45 #include "chromeos/login/user_names.h" | 46 #include "chromeos/login/user_names.h" |
| 46 #include "components/prefs/pref_registry_simple.h" | 47 #include "components/prefs/pref_registry_simple.h" |
| 47 #include "components/prefs/pref_service.h" | 48 #include "components/prefs/pref_service.h" |
| 48 #include "components/prefs/scoped_user_pref_update.h" | 49 #include "components/prefs/scoped_user_pref_update.h" |
| 49 #include "components/signin/core/account_id/account_id.h" | 50 #include "components/signin/core/account_id/account_id.h" |
| 50 #include "components/user_manager/known_user.h" | 51 #include "components/user_manager/known_user.h" |
| 51 #include "components/user_manager/user.h" | 52 #include "components/user_manager/user.h" |
| 52 #include "components/user_manager/user_image/user_image.h" | 53 #include "components/user_manager/user_image/user_image.h" |
| 53 #include "components/user_manager/user_manager.h" | 54 #include "components/user_manager/user_manager.h" |
| 54 #include "components/user_manager/user_type.h" | 55 #include "components/user_manager/user_type.h" |
| 55 #include "components/wallpaper/wallpaper_files_id.h" | 56 #include "components/wallpaper/wallpaper_files_id.h" |
| 56 #include "components/wallpaper/wallpaper_layout.h" | 57 #include "components/wallpaper/wallpaper_layout.h" |
| 57 #include "content/public/browser/browser_thread.h" | 58 #include "content/public/browser/browser_thread.h" |
| 58 #include "content/public/browser/notification_service.h" | 59 #include "content/public/browser/notification_service.h" |
| 59 #include "content/public/common/content_switches.h" | 60 #include "content/public/common/content_switches.h" |
| 61 #include "content/public/common/mojo_shell_connection.h" |
| 62 #include "services/shell/public/cpp/connector.h" |
| 60 #include "third_party/skia/include/core/SkColor.h" | 63 #include "third_party/skia/include/core/SkColor.h" |
| 61 #include "ui/gfx/codec/jpeg_codec.h" | 64 #include "ui/gfx/codec/jpeg_codec.h" |
| 62 #include "ui/gfx/image/image_skia_operations.h" | 65 #include "ui/gfx/image/image_skia_operations.h" |
| 63 #include "ui/gfx/skia_util.h" | 66 #include "ui/gfx/skia_util.h" |
| 64 | 67 |
| 68 #if defined(MOJO_SHELL_CLIENT) |
| 69 #include "ash/sysui/public/interfaces/wallpaper.mojom.h" |
| 70 #endif |
| 71 |
| 65 using content::BrowserThread; | 72 using content::BrowserThread; |
| 66 using wallpaper::WallpaperManagerBase; | 73 using wallpaper::WallpaperManagerBase; |
| 67 using wallpaper::WallpaperInfo; | 74 using wallpaper::WallpaperInfo; |
| 68 using wallpaper::MovableOnDestroyCallback; | 75 using wallpaper::MovableOnDestroyCallback; |
| 69 using wallpaper::MovableOnDestroyCallbackHolder; | 76 using wallpaper::MovableOnDestroyCallbackHolder; |
| 70 | 77 |
| 71 namespace chromeos { | 78 namespace chromeos { |
| 72 | 79 |
| 73 namespace { | 80 namespace { |
| 74 | 81 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 return wallpaper::WallpaperFilesId::FromString(result); | 172 return wallpaper::WallpaperFilesId::FromString(result); |
| 166 } | 173 } |
| 167 | 174 |
| 168 void SetKnownUserWallpaperFilesId( | 175 void SetKnownUserWallpaperFilesId( |
| 169 const AccountId& account_id, | 176 const AccountId& account_id, |
| 170 const wallpaper::WallpaperFilesId& wallpaper_files_id) { | 177 const wallpaper::WallpaperFilesId& wallpaper_files_id) { |
| 171 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, | 178 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, |
| 172 wallpaper_files_id.id()); | 179 wallpaper_files_id.id()); |
| 173 } | 180 } |
| 174 | 181 |
| 182 // A helper to set the wallpaper image for Ash and Mash. |
| 183 void SetWallpaper(const gfx::ImageSkia& image, |
| 184 wallpaper::WallpaperLayout layout) { |
| 185 #if defined(MOJO_SHELL_CLIENT) |
| 186 if (chrome::IsRunningInMash()) { |
| 187 shell::Connector* connector = |
| 188 content::MojoShellConnection::Get()->GetConnector(); |
| 189 ash::sysui::mojom::WallpaperControllerPtr wallpaper_controller; |
| 190 connector->ConnectToInterface("mojo:ash_sysui", &wallpaper_controller); |
| 191 wallpaper_controller->SetWallpaper( |
| 192 *image.bitmap(), |
| 193 static_cast<ash::sysui::mojom::WallpaperLayout>(layout)); |
| 194 return; |
| 195 } |
| 196 #endif |
| 197 // Avoid loading unnecessary wallpapers in tests without a shell instance. |
| 198 if (ash::Shell::HasInstance()) { |
| 199 ash::Shell::GetInstance() |
| 200 ->desktop_background_controller() |
| 201 ->SetWallpaperImage(image, layout); |
| 202 } |
| 203 } |
| 204 |
| 175 } // namespace | 205 } // namespace |
| 176 | 206 |
| 177 // This is "wallpaper either scheduled to load, or loading right now". | 207 // This is "wallpaper either scheduled to load, or loading right now". |
| 178 // | 208 // |
| 179 // While enqueued, it defines moment in the future, when it will be loaded. | 209 // While enqueued, it defines moment in the future, when it will be loaded. |
| 180 // Enqueued but not started request might be updated by subsequent load | 210 // Enqueued but not started request might be updated by subsequent load |
| 181 // request. Therefore it's created empty, and updated being enqueued. | 211 // request. Therefore it's created empty, and updated being enqueued. |
| 182 // | 212 // |
| 183 // PendingWallpaper is owned by WallpaperManager, but reference to this object | 213 // PendingWallpaper is owned by WallpaperManager, but reference to this object |
| 184 // is passed to other threads by PostTask() calls, therefore it is | 214 // is passed to other threads by PostTask() calls, therefore it is |
| (...skipping 10 matching lines...) Expand all Loading... |
| 195 this))) { | 225 this))) { |
| 196 timer.Start( | 226 timer.Start( |
| 197 FROM_HERE, | 227 FROM_HERE, |
| 198 delay, | 228 delay, |
| 199 base::Bind(&WallpaperManager::PendingWallpaper::ProcessRequest, this)); | 229 base::Bind(&WallpaperManager::PendingWallpaper::ProcessRequest, this)); |
| 200 } | 230 } |
| 201 | 231 |
| 202 // There are 4 cases in SetUserWallpaper: | 232 // There are 4 cases in SetUserWallpaper: |
| 203 // 1) gfx::ImageSkia is found in cache. | 233 // 1) gfx::ImageSkia is found in cache. |
| 204 // - Schedule task to (probably) resize it and install: | 234 // - Schedule task to (probably) resize it and install: |
| 205 // call ash::Shell::GetInstance()->desktop_background_controller()-> | 235 // call SetWallpaper(user_wallpaper, layout); |
| 206 // SetCustomWallpaper(user_wallpaper, layout); | |
| 207 // 2) WallpaperInfo is found in cache | 236 // 2) WallpaperInfo is found in cache |
| 208 // - need to LoadWallpaper(), resize and install. | 237 // - need to LoadWallpaper(), resize and install. |
| 209 // 3) wallpaper path is not NULL, load image URL, then resize, etc... | 238 // 3) wallpaper path is not NULL, load image URL, then resize, etc... |
| 210 // 4) SetDefaultWallpaper (either on some error, or when user is new). | 239 // 4) SetDefaultWallpaper (either on some error, or when user is new). |
| 211 void ResetSetWallpaperImage(const gfx::ImageSkia& image, | 240 void ResetSetWallpaperImage(const gfx::ImageSkia& image, |
| 212 const wallpaper::WallpaperInfo& info) { | 241 const wallpaper::WallpaperInfo& info) { |
| 213 SetMode(image, info, base::FilePath(), false); | 242 SetMode(image, info, base::FilePath(), false); |
| 214 } | 243 } |
| 215 | 244 |
| 216 void ResetLoadWallpaper(const wallpaper::WallpaperInfo& info) { | 245 void ResetLoadWallpaper(const wallpaper::WallpaperInfo& info) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 279 |
| 251 WallpaperManager* manager = WallpaperManager::Get(); | 280 WallpaperManager* manager = WallpaperManager::Get(); |
| 252 if (manager->pending_inactive_ == this) | 281 if (manager->pending_inactive_ == this) |
| 253 manager->pending_inactive_ = NULL; | 282 manager->pending_inactive_ = NULL; |
| 254 | 283 |
| 255 started_load_at_ = base::Time::Now(); | 284 started_load_at_ = base::Time::Now(); |
| 256 | 285 |
| 257 if (default_) { | 286 if (default_) { |
| 258 manager->DoSetDefaultWallpaper(account_id_, std::move(on_finish_)); | 287 manager->DoSetDefaultWallpaper(account_id_, std::move(on_finish_)); |
| 259 } else if (!user_wallpaper_.isNull()) { | 288 } else if (!user_wallpaper_.isNull()) { |
| 260 ash::Shell::GetInstance() | 289 SetWallpaper(user_wallpaper_, info_.layout); |
| 261 ->desktop_background_controller() | |
| 262 ->SetWallpaperImage(user_wallpaper_, info_.layout); | |
| 263 } else if (!wallpaper_path_.empty()) { | 290 } else if (!wallpaper_path_.empty()) { |
| 264 manager->task_runner_->PostTask( | 291 manager->task_runner_->PostTask( |
| 265 FROM_HERE, | 292 FROM_HERE, |
| 266 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, account_id_, | 293 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, account_id_, |
| 267 info_, wallpaper_path_, true /* update wallpaper */, | 294 info_, wallpaper_path_, true /* update wallpaper */, |
| 268 base::ThreadTaskRunnerHandle::Get(), | 295 base::ThreadTaskRunnerHandle::Get(), |
| 269 base::Passed(std::move(on_finish_)), | 296 base::Passed(std::move(on_finish_)), |
| 270 manager->weak_factory_.GetWeakPtr())); | 297 manager->weak_factory_.GetWeakPtr())); |
| 271 } else if (!info_.location.empty()) { | 298 } else if (!info_.location.empty()) { |
| 272 manager->LoadWallpaper(account_id_, info_, true, std::move(on_finish_)); | 299 manager->LoadWallpaper(account_id_, info_, true, std::move(on_finish_)); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 GetPendingWallpaper(account_id, true)->ResetSetDefaultWallpaper(); | 618 GetPendingWallpaper(account_id, true)->ResetSetDefaultWallpaper(); |
| 592 } | 619 } |
| 593 | 620 |
| 594 void WallpaperManager::DoSetDefaultWallpaper( | 621 void WallpaperManager::DoSetDefaultWallpaper( |
| 595 const AccountId& account_id, | 622 const AccountId& account_id, |
| 596 MovableOnDestroyCallbackHolder on_finish) { | 623 MovableOnDestroyCallbackHolder on_finish) { |
| 597 // There is no visible background in kiosk mode. | 624 // There is no visible background in kiosk mode. |
| 598 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) | 625 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) |
| 599 return; | 626 return; |
| 600 wallpaper_cache_.erase(account_id); | 627 wallpaper_cache_.erase(account_id); |
| 601 // Some browser tests do not have a shell instance. As no wallpaper is needed | |
| 602 // in these tests anyway, avoid loading one, preventing crashes and speeding | |
| 603 // up the tests. | |
| 604 if (!ash::Shell::HasInstance()) | |
| 605 return; | |
| 606 | 628 |
| 607 WallpaperResolution resolution = GetAppropriateResolution(); | 629 WallpaperResolution resolution = GetAppropriateResolution(); |
| 608 const bool use_small = (resolution == WALLPAPER_RESOLUTION_SMALL); | 630 const bool use_small = (resolution == WALLPAPER_RESOLUTION_SMALL); |
| 609 | 631 |
| 610 const base::FilePath* file = NULL; | 632 const base::FilePath* file = NULL; |
| 611 | 633 |
| 612 const user_manager::User* user = | 634 const user_manager::User* user = |
| 613 user_manager::UserManager::Get()->FindUser(account_id); | 635 user_manager::UserManager::Get()->FindUser(account_id); |
| 614 | 636 |
| 615 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) { | 637 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 636 return; | 658 return; |
| 637 } | 659 } |
| 638 | 660 |
| 639 CreateSolidDefaultWallpaper(); | 661 CreateSolidDefaultWallpaper(); |
| 640 } | 662 } |
| 641 // 1x1 wallpaper is actually solid color, so it should be stretched. | 663 // 1x1 wallpaper is actually solid color, so it should be stretched. |
| 642 if (default_wallpaper_image_->image().width() == 1 && | 664 if (default_wallpaper_image_->image().width() == 1 && |
| 643 default_wallpaper_image_->image().height() == 1) | 665 default_wallpaper_image_->image().height() == 1) |
| 644 layout = wallpaper::WALLPAPER_LAYOUT_STRETCH; | 666 layout = wallpaper::WALLPAPER_LAYOUT_STRETCH; |
| 645 | 667 |
| 646 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( | 668 SetWallpaper(default_wallpaper_image_->image(), layout); |
| 647 default_wallpaper_image_->image(), layout); | |
| 648 } | 669 } |
| 649 | 670 |
| 650 void WallpaperManager::SetUserWallpaperInfo(const AccountId& account_id, | 671 void WallpaperManager::SetUserWallpaperInfo(const AccountId& account_id, |
| 651 const WallpaperInfo& info, | 672 const WallpaperInfo& info, |
| 652 bool is_persistent) { | 673 bool is_persistent) { |
| 653 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 674 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 654 current_user_wallpaper_info_ = info; | 675 current_user_wallpaper_info_ = info; |
| 655 if (!is_persistent) | 676 if (!is_persistent) |
| 656 return; | 677 return; |
| 657 | 678 |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 SetUserWallpaperInfo(account_id, info, true); | 973 SetUserWallpaperInfo(account_id, info, true); |
| 953 | 974 |
| 954 if (update_wallpaper) | 975 if (update_wallpaper) |
| 955 DoSetDefaultWallpaper(account_id, std::move(on_finish)); | 976 DoSetDefaultWallpaper(account_id, std::move(on_finish)); |
| 956 return; | 977 return; |
| 957 } | 978 } |
| 958 | 979 |
| 959 // Update the image, but keep the path which was set earlier. | 980 // Update the image, but keep the path which was set earlier. |
| 960 wallpaper_cache_[account_id].second = user_image->image(); | 981 wallpaper_cache_[account_id].second = user_image->image(); |
| 961 | 982 |
| 962 if (update_wallpaper) { | 983 if (update_wallpaper) |
| 963 ash::Shell::GetInstance() | 984 SetWallpaper(user_image->image(), layout); |
| 964 ->desktop_background_controller() | |
| 965 ->SetWallpaperImage(user_image->image(), layout); | |
| 966 } | |
| 967 } | 985 } |
| 968 | 986 |
| 969 void WallpaperManager::StartLoad(const AccountId& account_id, | 987 void WallpaperManager::StartLoad(const AccountId& account_id, |
| 970 const WallpaperInfo& info, | 988 const WallpaperInfo& info, |
| 971 bool update_wallpaper, | 989 bool update_wallpaper, |
| 972 const base::FilePath& wallpaper_path, | 990 const base::FilePath& wallpaper_path, |
| 973 MovableOnDestroyCallbackHolder on_finish) { | 991 MovableOnDestroyCallbackHolder on_finish) { |
| 974 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 992 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 975 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); | 993 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); |
| 976 if (update_wallpaper) { | 994 if (update_wallpaper) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 default_wallpaper_image_.reset(); | 1079 default_wallpaper_image_.reset(); |
| 1062 } | 1080 } |
| 1063 | 1081 |
| 1064 void WallpaperManager::OnDefaultWallpaperDecoded( | 1082 void WallpaperManager::OnDefaultWallpaperDecoded( |
| 1065 const base::FilePath& path, | 1083 const base::FilePath& path, |
| 1066 const wallpaper::WallpaperLayout layout, | 1084 const wallpaper::WallpaperLayout layout, |
| 1067 std::unique_ptr<user_manager::UserImage>* result_out, | 1085 std::unique_ptr<user_manager::UserImage>* result_out, |
| 1068 MovableOnDestroyCallbackHolder on_finish, | 1086 MovableOnDestroyCallbackHolder on_finish, |
| 1069 std::unique_ptr<user_manager::UserImage> user_image) { | 1087 std::unique_ptr<user_manager::UserImage> user_image) { |
| 1070 *result_out = std::move(user_image); | 1088 *result_out = std::move(user_image); |
| 1071 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( | 1089 SetWallpaper((*result_out)->image(), layout); |
| 1072 (*result_out)->image(), layout); | |
| 1073 } | 1090 } |
| 1074 | 1091 |
| 1075 void WallpaperManager::StartLoadAndSetDefaultWallpaper( | 1092 void WallpaperManager::StartLoadAndSetDefaultWallpaper( |
| 1076 const base::FilePath& path, | 1093 const base::FilePath& path, |
| 1077 const wallpaper::WallpaperLayout layout, | 1094 const wallpaper::WallpaperLayout layout, |
| 1078 MovableOnDestroyCallbackHolder on_finish, | 1095 MovableOnDestroyCallbackHolder on_finish, |
| 1079 std::unique_ptr<user_manager::UserImage>* result_out) { | 1096 std::unique_ptr<user_manager::UserImage>* result_out) { |
| 1080 user_image_loader::StartWithFilePath( | 1097 user_image_loader::StartWithFilePath( |
| 1081 task_runner_, path, ImageDecoder::ROBUST_JPEG_CODEC, | 1098 task_runner_, path, ImageDecoder::ROBUST_JPEG_CODEC, |
| 1082 0, // Do not crop. | 1099 0, // Do not crop. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 &stored_value)) { | 1152 &stored_value)) { |
| 1136 return wallpaper::WallpaperFilesId::FromString(stored_value); | 1153 return wallpaper::WallpaperFilesId::FromString(stored_value); |
| 1137 } | 1154 } |
| 1138 const std::string& old_id = account_id.GetUserEmail(); // Migrated | 1155 const std::string& old_id = account_id.GetUserEmail(); // Migrated |
| 1139 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); | 1156 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); |
| 1140 SetKnownUserWallpaperFilesId(account_id, files_id); | 1157 SetKnownUserWallpaperFilesId(account_id, files_id); |
| 1141 return files_id; | 1158 return files_id; |
| 1142 } | 1159 } |
| 1143 | 1160 |
| 1144 } // namespace chromeos | 1161 } // namespace chromeos |
| OLD | NEW |