Chromium Code Reviews| Index: chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.cc |
| diff --git a/chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.cc b/chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.cc |
| index eac4ab8f45341ff25769a07253a02f001113e7dc..5d29c2e82881b179393750a51ba6ddc46c7b8362 100644 |
| --- a/chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.cc |
| +++ b/chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.cc |
| @@ -36,6 +36,7 @@ |
| #include "chrome/browser/chromeos/login/startup_utils.h" |
| #include "chrome/browser/chromeos/login/wizard_controller.h" |
| #include "chrome/browser/chromeos/settings/cros_settings.h" |
| +#include "chrome/browser/ui/ash/ash_util.h" |
| #include "chrome/common/chrome_paths.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/pref_names.h" |
| @@ -57,11 +58,18 @@ |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/common/content_switches.h" |
| +#include "content/public/common/mojo_shell_connection.h" |
| +#include "services/shell/public/cpp/connector.h" |
| +#include "skia/public/type_converters.h" |
| #include "third_party/skia/include/core/SkColor.h" |
| #include "ui/gfx/codec/jpeg_codec.h" |
| #include "ui/gfx/image/image_skia_operations.h" |
| #include "ui/gfx/skia_util.h" |
| +#if defined(MOJO_SHELL_CLIENT) |
| +#include "ash/mus/public/interfaces/wallpaper.mojom.h" |
| +#endif |
| + |
| using content::BrowserThread; |
| using wallpaper::WallpaperManagerBase; |
| using wallpaper::WallpaperInfo; |
| @@ -172,6 +180,29 @@ void SetKnownUserWallpaperFilesId( |
| wallpaper_files_id.id()); |
| } |
| +// A helper to set the wallpaper image for Ash and Mash. |
| +void SetWallpaper(const gfx::ImageSkia& image, |
| + wallpaper::WallpaperLayout layout) { |
| +#if defined(MOJO_SHELL_CLIENT) |
| + if (chrome::IsRunningInMash()) { |
| + shell::Connector* connector = |
| + content::MojoShellConnection::Get()->GetConnector(); |
| + ash::mus::mojom::WallpaperControllerPtr wallpaper_controller; |
| + connector->ConnectToInterface("mojo:ash_sysui", &wallpaper_controller); |
| + wallpaper_controller->SetWallpaper( |
| + skia::mojom::Bitmap::From(*image.bitmap()), |
|
dcheng
2016/05/24 18:53:37
Can we do this with a StructTraits instead? My wor
msw
2016/05/24 22:06:37
Yeah, Yuzhu gave me an intro to StructTraits, and
dcheng
2016/05/25 17:31:26
We can add the StructTraits without removing all u
msw
2016/05/25 18:16:41
I'd rather not pollute this wallpaper CL with the
dcheng
2016/05/25 19:56:40
I'd strongly prefer to see that. I thought it'd be
|
| + static_cast<ash::mus::mojom::WallpaperLayout>(layout)); |
|
dcheng
2016/05/24 18:53:37
Similarly, do StructTraits work for enums yet?
yzshen1
2016/05/24 22:04:42
Yes. For example:
module mojom;
enum SomeEnum {};
msw
2016/05/24 22:06:37
We can support enums within a struct, but I don't
msw
2016/05/24 22:06:37
Right, but in this case, I'm passing an enum value
dcheng
2016/05/25 19:56:40
and maybe in the meantime we can figure out someth
|
| + return; |
| + } |
| +#endif |
| + // Avoid loading unnecessary wallpapers in tests without a shell instance. |
| + if (ash::Shell::HasInstance()) { |
| + ash::Shell::GetInstance() |
| + ->desktop_background_controller() |
| + ->SetWallpaperImage(image, layout); |
| + } |
| +} |
| + |
| } // namespace |
| // This is "wallpaper either scheduled to load, or loading right now". |
| @@ -202,8 +233,7 @@ class WallpaperManager::PendingWallpaper : |
| // There are 4 cases in SetUserWallpaper: |
| // 1) gfx::ImageSkia is found in cache. |
| // - Schedule task to (probably) resize it and install: |
| - // call ash::Shell::GetInstance()->desktop_background_controller()-> |
| - // SetCustomWallpaper(user_wallpaper, layout); |
| + // call SetWallpaper(user_wallpaper, layout); |
| // 2) WallpaperInfo is found in cache |
| // - need to LoadWallpaper(), resize and install. |
| // 3) wallpaper path is not NULL, load image URL, then resize, etc... |
| @@ -257,9 +287,7 @@ class WallpaperManager::PendingWallpaper : |
| if (default_) { |
| manager->DoSetDefaultWallpaper(account_id_, std::move(on_finish_)); |
| } else if (!user_wallpaper_.isNull()) { |
| - ash::Shell::GetInstance() |
| - ->desktop_background_controller() |
| - ->SetWallpaperImage(user_wallpaper_, info_.layout); |
| + SetWallpaper(user_wallpaper_, info_.layout); |
| } else if (!wallpaper_path_.empty()) { |
| manager->task_runner_->PostTask( |
| FROM_HERE, |
| @@ -598,11 +626,6 @@ void WallpaperManager::DoSetDefaultWallpaper( |
| if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) |
| return; |
| wallpaper_cache_.erase(account_id); |
| - // Some browser tests do not have a shell instance. As no wallpaper is needed |
| - // in these tests anyway, avoid loading one, preventing crashes and speeding |
| - // up the tests. |
| - if (!ash::Shell::HasInstance()) |
| - return; |
| WallpaperResolution resolution = GetAppropriateResolution(); |
| const bool use_small = (resolution == WALLPAPER_RESOLUTION_SMALL); |
| @@ -643,8 +666,7 @@ void WallpaperManager::DoSetDefaultWallpaper( |
| default_wallpaper_image_->image().height() == 1) |
| layout = wallpaper::WALLPAPER_LAYOUT_STRETCH; |
| - ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( |
| - default_wallpaper_image_->image(), layout); |
| + SetWallpaper(default_wallpaper_image_->image(), layout); |
| } |
| void WallpaperManager::SetUserWallpaperInfo(const AccountId& account_id, |
| @@ -959,11 +981,8 @@ void WallpaperManager::OnWallpaperDecoded( |
| // Update the image, but keep the path which was set earlier. |
| wallpaper_cache_[account_id].second = user_image->image(); |
| - if (update_wallpaper) { |
| - ash::Shell::GetInstance() |
| - ->desktop_background_controller() |
| - ->SetWallpaperImage(user_image->image(), layout); |
| - } |
| + if (update_wallpaper) |
| + SetWallpaper(user_image->image(), layout); |
| } |
| void WallpaperManager::StartLoad(const AccountId& account_id, |
| @@ -1068,8 +1087,7 @@ void WallpaperManager::OnDefaultWallpaperDecoded( |
| MovableOnDestroyCallbackHolder on_finish, |
| std::unique_ptr<user_manager::UserImage> user_image) { |
| *result_out = std::move(user_image); |
| - ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( |
| - (*result_out)->image(), layout); |
| + SetWallpaper((*result_out)->image(), layout); |
| } |
| void WallpaperManager::StartLoadAndSetDefaultWallpaper( |