| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 #include "components/user_manager/known_user.h" | 50 #include "components/user_manager/known_user.h" |
| 51 #include "components/user_manager/user.h" | 51 #include "components/user_manager/user.h" |
| 52 #include "components/user_manager/user_image/user_image.h" | 52 #include "components/user_manager/user_image/user_image.h" |
| 53 #include "components/user_manager/user_manager.h" | 53 #include "components/user_manager/user_manager.h" |
| 54 #include "components/user_manager/user_type.h" | 54 #include "components/user_manager/user_type.h" |
| 55 #include "components/wallpaper/wallpaper_files_id.h" | 55 #include "components/wallpaper/wallpaper_files_id.h" |
| 56 #include "components/wallpaper/wallpaper_layout.h" | 56 #include "components/wallpaper/wallpaper_layout.h" |
| 57 #include "content/public/browser/browser_thread.h" | 57 #include "content/public/browser/browser_thread.h" |
| 58 #include "content/public/browser/notification_service.h" | 58 #include "content/public/browser/notification_service.h" |
| 59 #include "content/public/common/content_switches.h" | 59 #include "content/public/common/content_switches.h" |
| 60 #include "content/public/common/mojo_shell_connection.h" |
| 61 #include "mash/public/interfaces/wallpaper.mojom.h" |
| 62 #include "services/shell/public/cpp/connector.h" |
| 63 #include "skia/public/type_converters.h" |
| 60 #include "third_party/skia/include/core/SkColor.h" | 64 #include "third_party/skia/include/core/SkColor.h" |
| 61 #include "ui/gfx/codec/jpeg_codec.h" | 65 #include "ui/gfx/codec/jpeg_codec.h" |
| 62 #include "ui/gfx/image/image_skia_operations.h" | 66 #include "ui/gfx/image/image_skia_operations.h" |
| 63 #include "ui/gfx/skia_util.h" | 67 #include "ui/gfx/skia_util.h" |
| 64 | 68 |
| 65 using content::BrowserThread; | 69 using content::BrowserThread; |
| 66 using wallpaper::WallpaperManagerBase; | 70 using wallpaper::WallpaperManagerBase; |
| 67 using wallpaper::WallpaperInfo; | 71 using wallpaper::WallpaperInfo; |
| 68 using wallpaper::MovableOnDestroyCallback; | 72 using wallpaper::MovableOnDestroyCallback; |
| 69 using wallpaper::MovableOnDestroyCallbackHolder; | 73 using wallpaper::MovableOnDestroyCallbackHolder; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 return wallpaper::WallpaperFilesId::FromString(result); | 169 return wallpaper::WallpaperFilesId::FromString(result); |
| 166 } | 170 } |
| 167 | 171 |
| 168 void SetKnownUserWallpaperFilesId( | 172 void SetKnownUserWallpaperFilesId( |
| 169 const AccountId& account_id, | 173 const AccountId& account_id, |
| 170 const wallpaper::WallpaperFilesId& wallpaper_files_id) { | 174 const wallpaper::WallpaperFilesId& wallpaper_files_id) { |
| 171 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, | 175 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, |
| 172 wallpaper_files_id.id()); | 176 wallpaper_files_id.id()); |
| 173 } | 177 } |
| 174 | 178 |
| 179 // A helper to set the wallpaper image for Ash and Mash. |
| 180 void SetWallpaper(const gfx::ImageSkia& image, |
| 181 wallpaper::WallpaperLayout layout) { |
| 182 if (ash::Shell::HasInstance() && !ash::Shell::GetInstance()->in_mus()) { |
| 183 ash::Shell::GetInstance() |
| 184 ->desktop_background_controller() |
| 185 ->SetWallpaperImage(image, layout); |
| 186 } else { |
| 187 shell::Connector* connector = |
| 188 content::MojoShellConnection::Get()->GetConnector(); |
| 189 mash::mojom::WallpaperControllerPtr wallpaper_controller; |
| 190 connector->ConnectToInterface("mojo:ash_sysui", &wallpaper_controller); |
| 191 wallpaper_controller->SetWallpaper( |
| 192 skia::mojom::Bitmap::From(*image.bitmap()), |
| 193 static_cast<int32_t>(layout)); |
| 194 } |
| 195 } |
| 196 |
| 175 } // namespace | 197 } // namespace |
| 176 | 198 |
| 177 // This is "wallpaper either scheduled to load, or loading right now". | 199 // This is "wallpaper either scheduled to load, or loading right now". |
| 178 // | 200 // |
| 179 // While enqueued, it defines moment in the future, when it will be loaded. | 201 // 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 | 202 // Enqueued but not started request might be updated by subsequent load |
| 181 // request. Therefore it's created empty, and updated being enqueued. | 203 // request. Therefore it's created empty, and updated being enqueued. |
| 182 // | 204 // |
| 183 // PendingWallpaper is owned by WallpaperManager, but reference to this object | 205 // PendingWallpaper is owned by WallpaperManager, but reference to this object |
| 184 // is passed to other threads by PostTask() calls, therefore it is | 206 // is passed to other threads by PostTask() calls, therefore it is |
| (...skipping 10 matching lines...) Expand all Loading... |
| 195 this))) { | 217 this))) { |
| 196 timer.Start( | 218 timer.Start( |
| 197 FROM_HERE, | 219 FROM_HERE, |
| 198 delay, | 220 delay, |
| 199 base::Bind(&WallpaperManager::PendingWallpaper::ProcessRequest, this)); | 221 base::Bind(&WallpaperManager::PendingWallpaper::ProcessRequest, this)); |
| 200 } | 222 } |
| 201 | 223 |
| 202 // There are 4 cases in SetUserWallpaper: | 224 // There are 4 cases in SetUserWallpaper: |
| 203 // 1) gfx::ImageSkia is found in cache. | 225 // 1) gfx::ImageSkia is found in cache. |
| 204 // - Schedule task to (probably) resize it and install: | 226 // - Schedule task to (probably) resize it and install: |
| 205 // call ash::Shell::GetInstance()->desktop_background_controller()-> | 227 // call SetWallpaper(user_wallpaper, layout); |
| 206 // SetCustomWallpaper(user_wallpaper, layout); | |
| 207 // 2) WallpaperInfo is found in cache | 228 // 2) WallpaperInfo is found in cache |
| 208 // - need to LoadWallpaper(), resize and install. | 229 // - need to LoadWallpaper(), resize and install. |
| 209 // 3) wallpaper path is not NULL, load image URL, then resize, etc... | 230 // 3) wallpaper path is not NULL, load image URL, then resize, etc... |
| 210 // 4) SetDefaultWallpaper (either on some error, or when user is new). | 231 // 4) SetDefaultWallpaper (either on some error, or when user is new). |
| 211 void ResetSetWallpaperImage(const gfx::ImageSkia& image, | 232 void ResetSetWallpaperImage(const gfx::ImageSkia& image, |
| 212 const wallpaper::WallpaperInfo& info) { | 233 const wallpaper::WallpaperInfo& info) { |
| 213 SetMode(image, info, base::FilePath(), false); | 234 SetMode(image, info, base::FilePath(), false); |
| 214 } | 235 } |
| 215 | 236 |
| 216 void ResetLoadWallpaper(const wallpaper::WallpaperInfo& info) { | 237 void ResetLoadWallpaper(const wallpaper::WallpaperInfo& info) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 271 |
| 251 WallpaperManager* manager = WallpaperManager::Get(); | 272 WallpaperManager* manager = WallpaperManager::Get(); |
| 252 if (manager->pending_inactive_ == this) | 273 if (manager->pending_inactive_ == this) |
| 253 manager->pending_inactive_ = NULL; | 274 manager->pending_inactive_ = NULL; |
| 254 | 275 |
| 255 started_load_at_ = base::Time::Now(); | 276 started_load_at_ = base::Time::Now(); |
| 256 | 277 |
| 257 if (default_) { | 278 if (default_) { |
| 258 manager->DoSetDefaultWallpaper(account_id_, std::move(on_finish_)); | 279 manager->DoSetDefaultWallpaper(account_id_, std::move(on_finish_)); |
| 259 } else if (!user_wallpaper_.isNull()) { | 280 } else if (!user_wallpaper_.isNull()) { |
| 260 ash::Shell::GetInstance() | 281 SetWallpaper(user_wallpaper_, info_.layout); |
| 261 ->desktop_background_controller() | |
| 262 ->SetWallpaperImage(user_wallpaper_, info_.layout); | |
| 263 } else if (!wallpaper_path_.empty()) { | 282 } else if (!wallpaper_path_.empty()) { |
| 264 manager->task_runner_->PostTask( | 283 manager->task_runner_->PostTask( |
| 265 FROM_HERE, | 284 FROM_HERE, |
| 266 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, account_id_, | 285 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, account_id_, |
| 267 info_, wallpaper_path_, true /* update wallpaper */, | 286 info_, wallpaper_path_, true /* update wallpaper */, |
| 268 base::ThreadTaskRunnerHandle::Get(), | 287 base::ThreadTaskRunnerHandle::Get(), |
| 269 base::Passed(std::move(on_finish_)), | 288 base::Passed(std::move(on_finish_)), |
| 270 manager->weak_factory_.GetWeakPtr())); | 289 manager->weak_factory_.GetWeakPtr())); |
| 271 } else if (!info_.location.empty()) { | 290 } else if (!info_.location.empty()) { |
| 272 manager->LoadWallpaper(account_id_, info_, true, std::move(on_finish_)); | 291 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(); | 610 GetPendingWallpaper(account_id, true)->ResetSetDefaultWallpaper(); |
| 592 } | 611 } |
| 593 | 612 |
| 594 void WallpaperManager::DoSetDefaultWallpaper( | 613 void WallpaperManager::DoSetDefaultWallpaper( |
| 595 const AccountId& account_id, | 614 const AccountId& account_id, |
| 596 MovableOnDestroyCallbackHolder on_finish) { | 615 MovableOnDestroyCallbackHolder on_finish) { |
| 597 // There is no visible background in kiosk mode. | 616 // There is no visible background in kiosk mode. |
| 598 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) | 617 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) |
| 599 return; | 618 return; |
| 600 wallpaper_cache_.erase(account_id); | 619 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 | 620 |
| 607 WallpaperResolution resolution = GetAppropriateResolution(); | 621 WallpaperResolution resolution = GetAppropriateResolution(); |
| 608 const bool use_small = (resolution == WALLPAPER_RESOLUTION_SMALL); | 622 const bool use_small = (resolution == WALLPAPER_RESOLUTION_SMALL); |
| 609 | 623 |
| 610 const base::FilePath* file = NULL; | 624 const base::FilePath* file = NULL; |
| 611 | 625 |
| 612 const user_manager::User* user = | 626 const user_manager::User* user = |
| 613 user_manager::UserManager::Get()->FindUser(account_id); | 627 user_manager::UserManager::Get()->FindUser(account_id); |
| 614 | 628 |
| 615 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) { | 629 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 636 return; | 650 return; |
| 637 } | 651 } |
| 638 | 652 |
| 639 CreateSolidDefaultWallpaper(); | 653 CreateSolidDefaultWallpaper(); |
| 640 } | 654 } |
| 641 // 1x1 wallpaper is actually solid color, so it should be stretched. | 655 // 1x1 wallpaper is actually solid color, so it should be stretched. |
| 642 if (default_wallpaper_image_->image().width() == 1 && | 656 if (default_wallpaper_image_->image().width() == 1 && |
| 643 default_wallpaper_image_->image().height() == 1) | 657 default_wallpaper_image_->image().height() == 1) |
| 644 layout = wallpaper::WALLPAPER_LAYOUT_STRETCH; | 658 layout = wallpaper::WALLPAPER_LAYOUT_STRETCH; |
| 645 | 659 |
| 646 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( | 660 SetWallpaper(default_wallpaper_image_->image(), layout); |
| 647 default_wallpaper_image_->image(), layout); | |
| 648 } | 661 } |
| 649 | 662 |
| 650 void WallpaperManager::SetUserWallpaperInfo(const AccountId& account_id, | 663 void WallpaperManager::SetUserWallpaperInfo(const AccountId& account_id, |
| 651 const WallpaperInfo& info, | 664 const WallpaperInfo& info, |
| 652 bool is_persistent) { | 665 bool is_persistent) { |
| 653 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 666 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 654 current_user_wallpaper_info_ = info; | 667 current_user_wallpaper_info_ = info; |
| 655 if (!is_persistent) | 668 if (!is_persistent) |
| 656 return; | 669 return; |
| 657 | 670 |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 SetUserWallpaperInfo(account_id, info, true); | 965 SetUserWallpaperInfo(account_id, info, true); |
| 953 | 966 |
| 954 if (update_wallpaper) | 967 if (update_wallpaper) |
| 955 DoSetDefaultWallpaper(account_id, std::move(on_finish)); | 968 DoSetDefaultWallpaper(account_id, std::move(on_finish)); |
| 956 return; | 969 return; |
| 957 } | 970 } |
| 958 | 971 |
| 959 // Update the image, but keep the path which was set earlier. | 972 // Update the image, but keep the path which was set earlier. |
| 960 wallpaper_cache_[account_id].second = user_image->image(); | 973 wallpaper_cache_[account_id].second = user_image->image(); |
| 961 | 974 |
| 962 if (update_wallpaper) { | 975 if (update_wallpaper) |
| 963 ash::Shell::GetInstance() | 976 SetWallpaper(user_image->image(), layout); |
| 964 ->desktop_background_controller() | |
| 965 ->SetWallpaperImage(user_image->image(), layout); | |
| 966 } | |
| 967 } | 977 } |
| 968 | 978 |
| 969 void WallpaperManager::StartLoad(const AccountId& account_id, | 979 void WallpaperManager::StartLoad(const AccountId& account_id, |
| 970 const WallpaperInfo& info, | 980 const WallpaperInfo& info, |
| 971 bool update_wallpaper, | 981 bool update_wallpaper, |
| 972 const base::FilePath& wallpaper_path, | 982 const base::FilePath& wallpaper_path, |
| 973 MovableOnDestroyCallbackHolder on_finish) { | 983 MovableOnDestroyCallbackHolder on_finish) { |
| 974 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 984 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 975 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); | 985 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); |
| 976 if (update_wallpaper) { | 986 if (update_wallpaper) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 default_wallpaper_image_.reset(); | 1071 default_wallpaper_image_.reset(); |
| 1062 } | 1072 } |
| 1063 | 1073 |
| 1064 void WallpaperManager::OnDefaultWallpaperDecoded( | 1074 void WallpaperManager::OnDefaultWallpaperDecoded( |
| 1065 const base::FilePath& path, | 1075 const base::FilePath& path, |
| 1066 const wallpaper::WallpaperLayout layout, | 1076 const wallpaper::WallpaperLayout layout, |
| 1067 std::unique_ptr<user_manager::UserImage>* result_out, | 1077 std::unique_ptr<user_manager::UserImage>* result_out, |
| 1068 MovableOnDestroyCallbackHolder on_finish, | 1078 MovableOnDestroyCallbackHolder on_finish, |
| 1069 std::unique_ptr<user_manager::UserImage> user_image) { | 1079 std::unique_ptr<user_manager::UserImage> user_image) { |
| 1070 *result_out = std::move(user_image); | 1080 *result_out = std::move(user_image); |
| 1071 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( | 1081 SetWallpaper((*result_out)->image(), layout); |
| 1072 (*result_out)->image(), layout); | |
| 1073 } | 1082 } |
| 1074 | 1083 |
| 1075 void WallpaperManager::StartLoadAndSetDefaultWallpaper( | 1084 void WallpaperManager::StartLoadAndSetDefaultWallpaper( |
| 1076 const base::FilePath& path, | 1085 const base::FilePath& path, |
| 1077 const wallpaper::WallpaperLayout layout, | 1086 const wallpaper::WallpaperLayout layout, |
| 1078 MovableOnDestroyCallbackHolder on_finish, | 1087 MovableOnDestroyCallbackHolder on_finish, |
| 1079 std::unique_ptr<user_manager::UserImage>* result_out) { | 1088 std::unique_ptr<user_manager::UserImage>* result_out) { |
| 1080 user_image_loader::StartWithFilePath( | 1089 user_image_loader::StartWithFilePath( |
| 1081 task_runner_, path, ImageDecoder::ROBUST_JPEG_CODEC, | 1090 task_runner_, path, ImageDecoder::ROBUST_JPEG_CODEC, |
| 1082 0, // Do not crop. | 1091 0, // Do not crop. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 &stored_value)) { | 1144 &stored_value)) { |
| 1136 return wallpaper::WallpaperFilesId::FromString(stored_value); | 1145 return wallpaper::WallpaperFilesId::FromString(stored_value); |
| 1137 } | 1146 } |
| 1138 const std::string& old_id = account_id.GetUserEmail(); // Migrated | 1147 const std::string& old_id = account_id.GetUserEmail(); // Migrated |
| 1139 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); | 1148 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); |
| 1140 SetKnownUserWallpaperFilesId(account_id, files_id); | 1149 SetKnownUserWallpaperFilesId(account_id, files_id); |
| 1141 return files_id; | 1150 return files_id; |
| 1142 } | 1151 } |
| 1143 | 1152 |
| 1144 } // namespace chromeos | 1153 } // namespace chromeos |
| OLD | NEW |