Commit 04b9ab64 authored by Wenzhao Zang's avatar Wenzhao Zang Committed by Commit Bot

cros: Some cleanup in ash::WallpaperController

1) Moved public functions (which don't have to be public) to private
   or anonymous namespace. (During the refactoring these functions
   were made public in order to be used by //chrome).

2) Does not change any logic.

3) May need a follow-up CL to make the anonymous namespace functions to
   a separate file to make the class slimmer.

Bug: NONE
Change-Id: Ib67016cef0e8654ed8b8a674c24118a7f2f9b519
Reviewed-on: https://chromium-review.googlesource.com/1111571Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Commit-Queue: Wenzhao (Colin) Zang <wzang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569774}
parent 0ce8b22e
...@@ -59,6 +59,32 @@ namespace ash { ...@@ -59,6 +59,32 @@ namespace ash {
namespace { namespace {
// Names of nodes with wallpaper info in |kUserWallpaperInfo| dictionary.
constexpr char kNewWallpaperDateNodeName[] = "date";
constexpr char kNewWallpaperLayoutNodeName[] = "layout";
constexpr char kNewWallpaperLocationNodeName[] = "file";
constexpr char kNewWallpaperTypeNodeName[] = "type";
// The file name of the policy wallpaper.
constexpr char kPolicyWallpaperFile[] = "policy-controlled.jpeg";
// File path suffix of resized small wallpapers.
constexpr char kSmallWallpaperSuffix[] = "_small";
// How long to wait reloading the wallpaper after the display size has changed.
constexpr base::TimeDelta kWallpaperReloadDelay =
base::TimeDelta::FromMilliseconds(100);
// How long to wait for resizing of the the wallpaper.
constexpr base::TimeDelta kCompositorLockTimeout =
base::TimeDelta::FromMilliseconds(750);
// Default quality for encoding wallpaper.
constexpr int kDefaultEncodingQuality = 90;
// The color of the wallpaper if no other wallpaper images are available.
constexpr SkColor kDefaultWallpaperColor = SK_ColorGRAY;
// The paths of wallpaper directories. // The paths of wallpaper directories.
base::FilePath& GlobalUserDataDir() { base::FilePath& GlobalUserDataDir() {
static base::NoDestructor<base::FilePath> dir_user_data; static base::NoDestructor<base::FilePath> dir_user_data;
...@@ -101,28 +127,127 @@ void SetGlobalDevicePolicyWallpaperFile(const base::FilePath& path) { ...@@ -101,28 +127,127 @@ void SetGlobalDevicePolicyWallpaperFile(const base::FilePath& path) {
global_path = path; global_path = path;
} }
// Names of nodes with wallpaper info in |kUserWallpaperInfo| dictionary. // Returns the appropriate wallpaper resolution for all root windows.
constexpr char kNewWallpaperDateNodeName[] = "date"; WallpaperController::WallpaperResolution GetAppropriateResolution() {
constexpr char kNewWallpaperLayoutNodeName[] = "layout"; gfx::Size size = WallpaperController::GetMaxDisplaySizeInNative();
constexpr char kNewWallpaperLocationNodeName[] = "file"; return (size.width() > kSmallWallpaperMaxWidth ||
constexpr char kNewWallpaperTypeNodeName[] = "type"; size.height() > kSmallWallpaperMaxHeight)
? WallpaperController::WALLPAPER_RESOLUTION_LARGE
: WallpaperController::WALLPAPER_RESOLUTION_SMALL;
}
// The file name of the policy wallpaper. // Returns the path of the online wallpaper corresponding to |url| and
constexpr char kPolicyWallpaperFile[] = "policy-controlled.jpeg"; // |resolution|.
base::FilePath GetOnlineWallpaperPath(
const std::string& url,
WallpaperController::WallpaperResolution resolution) {
std::string file_name = GURL(url).ExtractFileName();
if (resolution == WallpaperController::WALLPAPER_RESOLUTION_SMALL) {
file_name = base::FilePath(file_name)
.InsertBeforeExtension(kSmallWallpaperSuffix)
.value();
}
DCHECK(!GlobalChromeOSWallpapersDir().empty());
return GlobalChromeOSWallpapersDir().Append(file_name);
}
// File path suffix of resized small wallpapers. // Returns wallpaper subdirectory name for current resolution.
constexpr char kSmallWallpaperSuffix[] = "_small"; std::string GetCustomWallpaperSubdirForCurrentResolution() {
WallpaperController::WallpaperResolution resolution =
GetAppropriateResolution();
return resolution == WallpaperController::WALLPAPER_RESOLUTION_SMALL
? WallpaperController::kSmallWallpaperSubDir
: WallpaperController::kLargeWallpaperSubDir;
}
// How long to wait reloading the wallpaper after the display size has changed. // Resizes |image| to a resolution which is nearest to |preferred_width| and
constexpr base::TimeDelta kWallpaperReloadDelay = // |preferred_height| while respecting the |layout| choice. |output_skia| is
base::TimeDelta::FromMilliseconds(100); // optional (may be null). Returns true on success.
bool ResizeImage(const gfx::ImageSkia& image,
WallpaperLayout layout,
int preferred_width,
int preferred_height,
scoped_refptr<base::RefCountedBytes>* output,
gfx::ImageSkia* output_skia) {
int width = image.width();
int height = image.height();
int resized_width;
int resized_height;
*output = base::MakeRefCounted<base::RefCountedBytes>();
// How long to wait for resizing of the the wallpaper. if (layout == WALLPAPER_LAYOUT_CENTER_CROPPED) {
constexpr base::TimeDelta kCompositorLockTimeout = // Do not resize wallpaper if it is smaller than preferred size.
base::TimeDelta::FromMilliseconds(750); if (width < preferred_width || height < preferred_height)
return false;
// Default quality for encoding wallpaper. double horizontal_ratio = static_cast<double>(preferred_width) / width;
constexpr int kDefaultEncodingQuality = 90; double vertical_ratio = static_cast<double>(preferred_height) / height;
if (vertical_ratio > horizontal_ratio) {
resized_width =
gfx::ToRoundedInt(static_cast<double>(width) * vertical_ratio);
resized_height = preferred_height;
} else {
resized_width = preferred_width;
resized_height =
gfx::ToRoundedInt(static_cast<double>(height) * horizontal_ratio);
}
} else if (layout == WALLPAPER_LAYOUT_STRETCH) {
resized_width = preferred_width;
resized_height = preferred_height;
} else {
resized_width = width;
resized_height = height;
}
gfx::ImageSkia resized_image = gfx::ImageSkiaOperations::CreateResizedImage(
image, skia::ImageOperations::RESIZE_LANCZOS3,
gfx::Size(resized_width, resized_height));
SkBitmap bitmap = *(resized_image.bitmap());
gfx::JPEGCodec::Encode(bitmap, kDefaultEncodingQuality, &(*output)->data());
if (output_skia) {
resized_image.MakeThreadSafe();
*output_skia = resized_image;
}
return true;
}
// Resizes |image| to a resolution which is nearest to |preferred_width| and
// |preferred_height| while respecting the |layout| choice and saves the
// resized wallpaper to |path|. |output_skia| is optional (may be
// null). Returns true on success.
bool ResizeAndSaveWallpaper(const gfx::ImageSkia& image,
const base::FilePath& path,
WallpaperLayout layout,
int preferred_width,
int preferred_height,
gfx::ImageSkia* output_skia) {
if (layout == WALLPAPER_LAYOUT_CENTER) {
if (base::PathExists(path))
base::DeleteFile(path, false);
return false;
}
scoped_refptr<base::RefCountedBytes> data;
if (!ResizeImage(image, layout, preferred_width, preferred_height, &data,
output_skia)) {
return false;
}
// Saves |data| to |path| in local file system.
size_t written_bytes =
base::WriteFile(path, data->front_as<const char>(), data->size());
return written_bytes == data->size();
}
// Creates a 1x1 solid color image to be used as the backup default wallpaper.
gfx::ImageSkia CreateSolidColorWallpaper() {
SkBitmap bitmap;
bitmap.allocN32Pixels(1, 1);
bitmap.eraseColor(kDefaultWallpaperColor);
return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
}
// Returns true if a color should be extracted from the wallpaper based on the // Returns true if a color should be extracted from the wallpaper based on the
// command kAshShelfColor line arg. // command kAshShelfColor line arg.
...@@ -255,69 +380,14 @@ void SaveCustomWallpaper(const std::string& wallpaper_files_id, ...@@ -255,69 +380,14 @@ void SaveCustomWallpaper(const std::string& wallpaper_files_id,
// Re-encode orginal file to jpeg format and saves the result in case that // Re-encode orginal file to jpeg format and saves the result in case that
// resized wallpaper is not generated (i.e. chrome shutdown before resized // resized wallpaper is not generated (i.e. chrome shutdown before resized
// wallpaper is saved). // wallpaper is saved).
WallpaperController::ResizeAndSaveWallpaper( ResizeAndSaveWallpaper(*image, original_path, WALLPAPER_LAYOUT_STRETCH,
*image, original_path, WALLPAPER_LAYOUT_STRETCH, image->width(), image->width(), image->height(), nullptr);
image->height(), nullptr); ResizeAndSaveWallpaper(*image, small_wallpaper_path, layout,
WallpaperController::ResizeAndSaveWallpaper( kSmallWallpaperMaxWidth, kSmallWallpaperMaxHeight,
*image, small_wallpaper_path, layout, kSmallWallpaperMaxWidth, nullptr);
kSmallWallpaperMaxHeight, nullptr); ResizeAndSaveWallpaper(*image, large_wallpaper_path, layout,
WallpaperController::ResizeAndSaveWallpaper( kLargeWallpaperMaxWidth, kLargeWallpaperMaxHeight,
*image, large_wallpaper_path, layout, kLargeWallpaperMaxWidth, nullptr);
kLargeWallpaperMaxHeight, nullptr);
}
// Resizes |image| to a resolution which is nearest to |preferred_width| and
// |preferred_height| while respecting the |layout| choice. |output_skia| is
// optional (may be null). Returns true on success.
bool ResizeImage(const gfx::ImageSkia& image,
WallpaperLayout layout,
int preferred_width,
int preferred_height,
scoped_refptr<base::RefCountedBytes>* output,
gfx::ImageSkia* output_skia) {
int width = image.width();
int height = image.height();
int resized_width;
int resized_height;
*output = base::MakeRefCounted<base::RefCountedBytes>();
if (layout == WALLPAPER_LAYOUT_CENTER_CROPPED) {
// Do not resize wallpaper if it is smaller than preferred size.
if (width < preferred_width || height < preferred_height)
return false;
double horizontal_ratio = static_cast<double>(preferred_width) / width;
double vertical_ratio = static_cast<double>(preferred_height) / height;
if (vertical_ratio > horizontal_ratio) {
resized_width =
gfx::ToRoundedInt(static_cast<double>(width) * vertical_ratio);
resized_height = preferred_height;
} else {
resized_width = preferred_width;
resized_height =
gfx::ToRoundedInt(static_cast<double>(height) * horizontal_ratio);
}
} else if (layout == WALLPAPER_LAYOUT_STRETCH) {
resized_width = preferred_width;
resized_height = preferred_height;
} else {
resized_width = width;
resized_height = height;
}
gfx::ImageSkia resized_image = gfx::ImageSkiaOperations::CreateResizedImage(
image, skia::ImageOperations::RESIZE_LANCZOS3,
gfx::Size(resized_width, resized_height));
SkBitmap bitmap = *(resized_image.bitmap());
gfx::JPEGCodec::Encode(bitmap, kDefaultEncodingQuality, &(*output)->data());
if (output_skia) {
resized_image.MakeThreadSafe();
*output_skia = resized_image;
}
return true;
} }
// Checks if kiosk app is running. Note: it returns false either when there's // Checks if kiosk app is running. Note: it returns false either when there's
...@@ -343,15 +413,14 @@ bool IsActiveUser(const AccountId& account_id) { ...@@ -343,15 +413,14 @@ bool IsActiveUser(const AccountId& account_id) {
// local file system, otherwise returns an empty file path. // local file system, otherwise returns an empty file path.
base::FilePath GetExistingOnlineWallpaperPath(const std::string& url) { base::FilePath GetExistingOnlineWallpaperPath(const std::string& url) {
WallpaperController::WallpaperResolution resolution = WallpaperController::WallpaperResolution resolution =
WallpaperController::GetAppropriateResolution(); GetAppropriateResolution();
base::FilePath wallpaper_path = base::FilePath wallpaper_path = GetOnlineWallpaperPath(url, resolution);
WallpaperController::GetOnlineWallpaperPath(url, resolution);
if (base::PathExists(wallpaper_path)) if (base::PathExists(wallpaper_path))
return wallpaper_path; return wallpaper_path;
// Falls back to the large wallpaper if the small one doesn't exist. // Falls back to the large wallpaper if the small one doesn't exist.
if (resolution == WallpaperController::WALLPAPER_RESOLUTION_SMALL) { if (resolution == WallpaperController::WALLPAPER_RESOLUTION_SMALL) {
wallpaper_path = WallpaperController::GetOnlineWallpaperPath( wallpaper_path = GetOnlineWallpaperPath(
url, WallpaperController::WALLPAPER_RESOLUTION_LARGE); url, WallpaperController::WALLPAPER_RESOLUTION_LARGE);
if (base::PathExists(wallpaper_path)) if (base::PathExists(wallpaper_path))
return wallpaper_path; return wallpaper_path;
...@@ -369,15 +438,15 @@ void SaveOnlineWallpaper(const std::string& url, ...@@ -369,15 +438,15 @@ void SaveOnlineWallpaper(const std::string& url,
!base::CreateDirectory(GlobalChromeOSWallpapersDir())) { !base::CreateDirectory(GlobalChromeOSWallpapersDir())) {
return; return;
} }
WallpaperController::ResizeAndSaveWallpaper( ResizeAndSaveWallpaper(
*image, *image,
WallpaperController::GetOnlineWallpaperPath( GetOnlineWallpaperPath(url,
url, WallpaperController::WALLPAPER_RESOLUTION_LARGE), WallpaperController::WALLPAPER_RESOLUTION_LARGE),
layout, image->width(), image->height(), nullptr); layout, image->width(), image->height(), nullptr);
WallpaperController::ResizeAndSaveWallpaper( ResizeAndSaveWallpaper(
*image, *image,
WallpaperController::GetOnlineWallpaperPath( GetOnlineWallpaperPath(url,
url, WallpaperController::WALLPAPER_RESOLUTION_SMALL), WallpaperController::WALLPAPER_RESOLUTION_SMALL),
WALLPAPER_LAYOUT_CENTER_CROPPED, kSmallWallpaperMaxWidth, WALLPAPER_LAYOUT_CENTER_CROPPED, kSmallWallpaperMaxWidth,
kSmallWallpaperMaxHeight, nullptr); kSmallWallpaperMaxHeight, nullptr);
} }
...@@ -409,8 +478,6 @@ const char WallpaperController::kSmallWallpaperSubDir[] = "small"; ...@@ -409,8 +478,6 @@ const char WallpaperController::kSmallWallpaperSubDir[] = "small";
const char WallpaperController::kLargeWallpaperSubDir[] = "large"; const char WallpaperController::kLargeWallpaperSubDir[] = "large";
const char WallpaperController::kOriginalWallpaperSubDir[] = "original"; const char WallpaperController::kOriginalWallpaperSubDir[] = "original";
const SkColor WallpaperController::kDefaultWallpaperColor = SK_ColorGRAY;
WallpaperController::WallpaperController() WallpaperController::WallpaperController()
: locked_(false), : locked_(false),
wallpaper_mode_(WALLPAPER_NONE), wallpaper_mode_(WALLPAPER_NONE),
...@@ -474,38 +541,6 @@ gfx::Size WallpaperController::GetMaxDisplaySizeInNative() { ...@@ -474,38 +541,6 @@ gfx::Size WallpaperController::GetMaxDisplaySizeInNative() {
return max; return max;
} }
// static
WallpaperController::WallpaperResolution
WallpaperController::GetAppropriateResolution() {
gfx::Size size = GetMaxDisplaySizeInNative();
return (size.width() > kSmallWallpaperMaxWidth ||
size.height() > kSmallWallpaperMaxHeight)
? WALLPAPER_RESOLUTION_LARGE
: WALLPAPER_RESOLUTION_SMALL;
}
// static
base::FilePath WallpaperController::GetOnlineWallpaperPath(
const std::string& url,
WallpaperResolution resolution) {
std::string file_name = GURL(url).ExtractFileName();
if (resolution == WALLPAPER_RESOLUTION_SMALL) {
file_name = base::FilePath(file_name)
.InsertBeforeExtension(kSmallWallpaperSuffix)
.value();
}
DCHECK(!GlobalChromeOSWallpapersDir().empty());
return GlobalChromeOSWallpapersDir().Append(file_name);
}
// static
std::string
WallpaperController::GetCustomWallpaperSubdirForCurrentResolution() {
WallpaperResolution resolution = GetAppropriateResolution();
return resolution == WALLPAPER_RESOLUTION_SMALL ? kSmallWallpaperSubDir
: kLargeWallpaperSubDir;
}
// static // static
base::FilePath WallpaperController::GetCustomWallpaperPath( base::FilePath WallpaperController::GetCustomWallpaperPath(
const std::string& sub_dir, const std::string& sub_dir,
...@@ -522,30 +557,6 @@ base::FilePath WallpaperController::GetCustomWallpaperDir( ...@@ -522,30 +557,6 @@ base::FilePath WallpaperController::GetCustomWallpaperDir(
return GlobalChromeOSCustomWallpapersDir().Append(sub_dir); return GlobalChromeOSCustomWallpapersDir().Append(sub_dir);
} }
// static
bool WallpaperController::ResizeAndSaveWallpaper(const gfx::ImageSkia& image,
const base::FilePath& path,
WallpaperLayout layout,
int preferred_width,
int preferred_height,
gfx::ImageSkia* output_skia) {
if (layout == WALLPAPER_LAYOUT_CENTER) {
if (base::PathExists(path))
base::DeleteFile(path, false);
return false;
}
scoped_refptr<base::RefCountedBytes> data;
if (!ResizeImage(image, layout, preferred_width, preferred_height, &data,
output_skia)) {
return false;
}
// Saves |data| to |path| in local file system.
size_t written_bytes =
base::WriteFile(path, data->front_as<const char>(), data->size());
return written_bytes == data->size();
}
// static // static
void WallpaperController::SetWallpaperFromPath( void WallpaperController::SetWallpaperFromPath(
const AccountId& account_id, const AccountId& account_id,
...@@ -579,14 +590,6 @@ void WallpaperController::SetWallpaperFromPath( ...@@ -579,14 +590,6 @@ void WallpaperController::SetWallpaperFromPath(
} }
} }
// static
gfx::ImageSkia WallpaperController::CreateSolidColorWallpaper() {
SkBitmap bitmap;
bitmap.allocN32Pixels(1, 1);
bitmap.eraseColor(kDefaultWallpaperColor);
return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
}
void WallpaperController::BindRequest( void WallpaperController::BindRequest(
mojom::WallpaperControllerRequest request) { mojom::WallpaperControllerRequest request) {
bindings_.AddBinding(this, std::move(request)); bindings_.AddBinding(this, std::move(request));
...@@ -611,10 +614,6 @@ gfx::ImageSkia WallpaperController::GetWallpaper() const { ...@@ -611,10 +614,6 @@ gfx::ImageSkia WallpaperController::GetWallpaper() const {
return current_wallpaper_ ? current_wallpaper_->image() : gfx::ImageSkia(); return current_wallpaper_ ? current_wallpaper_->image() : gfx::ImageSkia();
} }
uint32_t WallpaperController::GetWallpaperOriginalImageId() const {
return current_wallpaper_ ? current_wallpaper_->original_image_id() : 0;
}
WallpaperLayout WallpaperController::GetWallpaperLayout() const { WallpaperLayout WallpaperController::GetWallpaperLayout() const {
return current_wallpaper_ ? current_wallpaper_->wallpaper_info().layout return current_wallpaper_ ? current_wallpaper_->wallpaper_info().layout
: NUM_WALLPAPER_LAYOUT; : NUM_WALLPAPER_LAYOUT;
...@@ -654,67 +653,6 @@ void WallpaperController::OnWallpaperAnimationFinished() { ...@@ -654,67 +653,6 @@ void WallpaperController::OnWallpaperAnimationFinished() {
} }
} }
void WallpaperController::SetDefaultWallpaperImpl(
const AccountId& account_id,
const user_manager::UserType& user_type,
bool show_wallpaper) {
// There is no visible wallpaper in kiosk mode.
if (IsInKioskMode())
return;
wallpaper_cache_map_.erase(account_id);
const bool use_small =
(GetAppropriateResolution() == WALLPAPER_RESOLUTION_SMALL);
WallpaperLayout layout =
use_small ? WALLPAPER_LAYOUT_CENTER : WALLPAPER_LAYOUT_CENTER_CROPPED;
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
base::FilePath file_path;
base::Optional<user_manager::UserType> active_user_type =
Shell::Get()->session_controller()->GetUserType();
// The wallpaper is determined in the following order:
// Guest wallpaper, child wallpaper, customized default wallpaper, and regular
// default wallpaper.
// TODO(wzang|xdai): The current code intentionally distinguishes between
// |active_user_type| and |user_type|. We should try to unify them.
if (active_user_type && *active_user_type == user_manager::USER_TYPE_GUEST) {
const std::string switch_string =
use_small ? chromeos::switches::kGuestWallpaperSmall
: chromeos::switches::kGuestWallpaperLarge;
file_path = command_line->GetSwitchValuePath(switch_string);
} else if (user_type == user_manager::USER_TYPE_CHILD) {
const std::string switch_string =
use_small ? chromeos::switches::kChildWallpaperSmall
: chromeos::switches::kChildWallpaperLarge;
file_path = command_line->GetSwitchValuePath(switch_string);
} else if (!customized_default_small_path_.empty()) {
DCHECK(!customized_default_large_path_.empty());
file_path = use_small ? customized_default_small_path_
: customized_default_large_path_;
} else {
const std::string switch_string =
use_small ? chromeos::switches::kDefaultWallpaperSmall
: chromeos::switches::kDefaultWallpaperLarge;
file_path = command_line->GetSwitchValuePath(switch_string);
}
// We need to decode the image if there's no cache, or if the file path
// doesn't match the cached value (i.e. the cache is outdated). Otherwise,
// directly run the callback with the cached image.
if (!cached_default_wallpaper_.image.isNull() &&
cached_default_wallpaper_.file_path == file_path) {
OnDefaultWallpaperDecoded(file_path, layout, show_wallpaper,
cached_default_wallpaper_.image);
} else {
ReadAndDecodeWallpaper(
base::BindOnce(&WallpaperController::OnDefaultWallpaperDecoded,
weak_factory_.GetWeakPtr(), file_path, layout,
show_wallpaper),
sequenced_task_runner_, file_path);
}
}
bool WallpaperController::CanOpenWallpaperPicker() { bool WallpaperController::CanOpenWallpaperPicker() {
return ShouldShowWallpaperSettingImpl() && return ShouldShowWallpaperSettingImpl() &&
!IsActiveUserWallpaperControlledByPolicyImpl(); !IsActiveUserWallpaperControlledByPolicyImpl();
...@@ -777,17 +715,6 @@ bool WallpaperController::IsPolicyControlled(const AccountId& account_id, ...@@ -777,17 +715,6 @@ bool WallpaperController::IsPolicyControlled(const AccountId& account_id,
info.type == POLICY; info.type == POLICY;
} }
bool WallpaperController::CanSetUserWallpaper(const AccountId& account_id,
bool is_ephemeral) const {
// There is no visible wallpaper in kiosk mode.
if (IsInKioskMode())
return false;
// Don't allow user wallpapers while policy is in effect.
if (IsPolicyControlled(account_id, is_ephemeral))
return false;
return true;
}
void WallpaperController::PrepareWallpaperForLockScreenChange(bool locking) { void WallpaperController::PrepareWallpaperForLockScreenChange(bool locking) {
bool needs_blur = locking && IsBlurEnabled(); bool needs_blur = locking && IsBlurEnabled();
if (needs_blur == is_wallpaper_blurred_) if (needs_blur == is_wallpaper_blurred_)
...@@ -803,109 +730,7 @@ void WallpaperController::PrepareWallpaperForLockScreenChange(bool locking) { ...@@ -803,109 +730,7 @@ void WallpaperController::PrepareWallpaperForLockScreenChange(bool locking) {
observer.OnWallpaperBlurChanged(); observer.OnWallpaperBlurChanged();
mojo_observers_.ForAllPtrs([this](mojom::WallpaperObserver* observer) { mojo_observers_.ForAllPtrs([this](mojom::WallpaperObserver* observer) {
observer->OnWallpaperBlurChanged(is_wallpaper_blurred_); observer->OnWallpaperBlurChanged(is_wallpaper_blurred_);
}); });
}
void WallpaperController::OnDisplayConfigurationChanged() {
gfx::Size max_display_size = GetMaxDisplaySizeInNative();
if (current_max_display_size_ == max_display_size)
return;
current_max_display_size_ = max_display_size;
if (wallpaper_mode_ == WALLPAPER_IMAGE && current_wallpaper_) {
timer_.Stop();
GetInternalDisplayCompositorLock();
timer_.Start(
FROM_HERE, wallpaper_reload_delay_,
base::BindRepeating(&WallpaperController::ReloadWallpaper,
weak_factory_.GetWeakPtr(), /*clear_cache=*/false));
}
}
void WallpaperController::OnRootWindowAdded(aura::Window* root_window) {
// The wallpaper hasn't been set yet.
if (wallpaper_mode_ == WALLPAPER_NONE)
return;
// Handle resolution change for "built-in" images.
gfx::Size max_display_size = GetMaxDisplaySizeInNative();
if (current_max_display_size_ != max_display_size) {
current_max_display_size_ = max_display_size;
if (wallpaper_mode_ == WALLPAPER_IMAGE && current_wallpaper_)
ReloadWallpaper(/*clear_cache=*/true);
}
InstallDesktopController(root_window);
}
void WallpaperController::OnLocalStatePrefServiceInitialized(
PrefService* pref_service) {
local_state_ = pref_service;
if (wallpaper_controller_client_) {
wallpaper_controller_client_->OnReadyToSetWallpaper();
} else {
// Ensure unit tests have a wallpaper as placeholder.
CreateEmptyWallpaperForTesting();
}
}
void WallpaperController::OnSessionStateChanged(
session_manager::SessionState state) {
// Replace the device policy wallpaper with a user wallpaper if necessary.
if (IsDevicePolicyWallpaper() && !ShouldSetDevicePolicyWallpaper())
ReloadWallpaper(/*clear_cache=*/false);
CalculateWallpaperColors();
// The wallpaper may be dimmed/blurred based on session state. The color of
// the dimming overlay depends on the prominent color cached from a previous
// calculation, or a default color if cache is not available. It should never
// depend on any in-flight color calculation.
if (wallpaper_mode_ == WALLPAPER_IMAGE &&
(state == session_manager::SessionState::ACTIVE ||
state == session_manager::SessionState::LOCKED ||
state == session_manager::SessionState::LOGIN_SECONDARY)) {
// TODO(crbug.com/753518): Reuse the existing WallpaperWidgetController for
// dimming/blur purpose.
InstallDesktopControllerForAllWindows();
}
if (state == session_manager::SessionState::ACTIVE)
MoveToUnlockedContainer();
else
MoveToLockedContainer();
}
bool WallpaperController::WallpaperIsAlreadyLoaded(
const gfx::ImageSkia& image,
bool compare_layouts,
WallpaperLayout layout) const {
if (!current_wallpaper_)
return false;
// Compare layouts only if necessary.
if (compare_layouts && layout != current_wallpaper_->wallpaper_info().layout)
return false;
return WallpaperResizer::GetImageId(image) ==
current_wallpaper_->original_image_id();
}
void WallpaperController::ReadAndDecodeWallpaper(
LoadedCallback callback,
scoped_refptr<base::SequencedTaskRunner> task_runner,
const base::FilePath& file_path) {
decode_requests_for_testing_.push_back(file_path);
if (bypass_decode_for_testing_) {
std::move(callback).Run(CreateSolidColorWallpaper());
return;
}
std::string* data = new std::string;
base::PostTaskAndReplyWithResult(
task_runner.get(), FROM_HERE,
base::BindOnce(&base::ReadFileToString, file_path, data),
base::BindOnce(&OnWallpaperDataRead, std::move(callback),
base::Passed(base::WrapUnique(data))));
} }
bool WallpaperController::ShouldApplyDimming() const { bool WallpaperController::ShouldApplyDimming() const {
...@@ -1001,14 +826,6 @@ bool WallpaperController::GetUserWallpaperInfo(const AccountId& account_id, ...@@ -1001,14 +826,6 @@ bool WallpaperController::GetUserWallpaperInfo(const AccountId& account_id,
return true; return true;
} }
bool WallpaperController::InitializeUserWallpaperInfo(
const AccountId& account_id,
bool is_ephemeral) {
const WallpaperInfo info = {std::string(), WALLPAPER_LAYOUT_CENTER_CROPPED,
DEFAULT, base::Time::Now().LocalMidnight()};
return SetUserWallpaperInfo(account_id, info, is_ephemeral);
}
bool WallpaperController::GetWallpaperFromCache(const AccountId& account_id, bool WallpaperController::GetWallpaperFromCache(const AccountId& account_id,
gfx::ImageSkia* image) { gfx::ImageSkia* image) {
CustomWallpaperMap::const_iterator it = wallpaper_cache_map_.find(account_id); CustomWallpaperMap::const_iterator it = wallpaper_cache_map_.find(account_id);
...@@ -1029,21 +846,6 @@ bool WallpaperController::GetPathFromCache(const AccountId& account_id, ...@@ -1029,21 +846,6 @@ bool WallpaperController::GetPathFromCache(const AccountId& account_id,
return false; return false;
} }
bool WallpaperController::ShouldSetDevicePolicyWallpaper() const {
// Only allow the device wallpaper if the policy is in effect for enterprise
// managed devices.
if (!is_device_wallpaper_policy_enforced_)
return false;
// Only set the device wallpaper if we're at the login screen.
if (Shell::Get()->session_controller()->GetSessionState() !=
session_manager::SessionState::LOGIN_PRIMARY) {
return false;
}
return true;
}
void WallpaperController::AddFirstWallpaperAnimationEndCallback( void WallpaperController::AddFirstWallpaperAnimationEndCallback(
base::OnceClosure callback, base::OnceClosure callback,
aura::Window* window) { aura::Window* window) {
...@@ -1058,6 +860,19 @@ void WallpaperController::AddFirstWallpaperAnimationEndCallback( ...@@ -1058,6 +860,19 @@ void WallpaperController::AddFirstWallpaperAnimationEndCallback(
} }
} }
void WallpaperController::StartDecodeFromPath(
const AccountId& account_id,
const user_manager::UserType& user_type,
const base::FilePath& wallpaper_path,
const WallpaperInfo& info,
bool show_wallpaper) {
ReadAndDecodeWallpaper(
base::BindOnce(&WallpaperController::OnWallpaperDecoded,
weak_factory_.GetWeakPtr(), account_id, user_type,
wallpaper_path, info, show_wallpaper),
sequenced_task_runner_, wallpaper_path);
}
void WallpaperController::Init( void WallpaperController::Init(
mojom::WallpaperControllerClientPtr client, mojom::WallpaperControllerClientPtr client,
const base::FilePath& user_data_path, const base::FilePath& user_data_path,
...@@ -1376,9 +1191,9 @@ void WallpaperController::ShowUserWallpaper( ...@@ -1376,9 +1191,9 @@ void WallpaperController::ShowUserWallpaper(
CustomWallpaperElement(wallpaper_path, gfx::ImageSkia()); CustomWallpaperElement(wallpaper_path, gfx::ImageSkia());
sequenced_task_runner_->PostTask( sequenced_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&WallpaperController::SetWallpaperFromPath, FROM_HERE,
account_id, current_user_->type, info, base::BindOnce(&SetWallpaperFromPath, account_id, current_user_->type,
wallpaper_path, /*show_wallpaper=*/true, info, wallpaper_path, /*show_wallpaper=*/true,
base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(),
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
...@@ -1492,6 +1307,49 @@ void WallpaperController::ShouldShowWallpaperSetting( ...@@ -1492,6 +1307,49 @@ void WallpaperController::ShouldShowWallpaperSetting(
std::move(callback).Run(ShouldShowWallpaperSettingImpl()); std::move(callback).Run(ShouldShowWallpaperSettingImpl());
} }
void WallpaperController::OnDisplayConfigurationChanged() {
gfx::Size max_display_size = GetMaxDisplaySizeInNative();
if (current_max_display_size_ == max_display_size)
return;
current_max_display_size_ = max_display_size;
if (wallpaper_mode_ == WALLPAPER_IMAGE && current_wallpaper_) {
timer_.Stop();
GetInternalDisplayCompositorLock();
timer_.Start(
FROM_HERE, wallpaper_reload_delay_,
base::BindRepeating(&WallpaperController::ReloadWallpaper,
weak_factory_.GetWeakPtr(), /*clear_cache=*/false));
}
}
void WallpaperController::OnRootWindowAdded(aura::Window* root_window) {
// The wallpaper hasn't been set yet.
if (wallpaper_mode_ == WALLPAPER_NONE)
return;
// Handle resolution change for "built-in" images.
gfx::Size max_display_size = GetMaxDisplaySizeInNative();
if (current_max_display_size_ != max_display_size) {
current_max_display_size_ = max_display_size;
if (wallpaper_mode_ == WALLPAPER_IMAGE && current_wallpaper_)
ReloadWallpaper(/*clear_cache=*/true);
}
InstallDesktopController(root_window);
}
void WallpaperController::OnLocalStatePrefServiceInitialized(
PrefService* pref_service) {
local_state_ = pref_service;
if (wallpaper_controller_client_) {
wallpaper_controller_client_->OnReadyToSetWallpaper();
} else {
// Ensure unit tests have a wallpaper as placeholder.
CreateEmptyWallpaperForTesting();
}
}
void WallpaperController::OnWallpaperResized() { void WallpaperController::OnWallpaperResized() {
CalculateWallpaperColors(); CalculateWallpaperColors();
compositor_lock_.reset(); compositor_lock_.reset();
...@@ -1510,6 +1368,37 @@ void WallpaperController::OnColorCalculationComplete() { ...@@ -1510,6 +1368,37 @@ void WallpaperController::OnColorCalculationComplete() {
SetProminentColors(colors); SetProminentColors(colors);
} }
void WallpaperController::OnSessionStateChanged(
session_manager::SessionState state) {
// Replace the device policy wallpaper with a user wallpaper if necessary.
if (IsDevicePolicyWallpaper() && !ShouldSetDevicePolicyWallpaper())
ReloadWallpaper(/*clear_cache=*/false);
CalculateWallpaperColors();
// The wallpaper may be dimmed/blurred based on session state. The color of
// the dimming overlay depends on the prominent color cached from a previous
// calculation, or a default color if cache is not available. It should never
// depend on any in-flight color calculation.
if (wallpaper_mode_ == WALLPAPER_IMAGE &&
(state == session_manager::SessionState::ACTIVE ||
state == session_manager::SessionState::LOCKED ||
state == session_manager::SessionState::LOGIN_SECONDARY)) {
// TODO(crbug.com/753518): Reuse the existing WallpaperWidgetController for
// dimming/blur purpose.
InstallDesktopControllerForAllWindows();
}
if (state == session_manager::SessionState::ACTIVE)
MoveToUnlockedContainer();
else
MoveToLockedContainer();
}
void WallpaperController::CompositorLockTimedOut() {
compositor_lock_.reset();
}
void WallpaperController::InitializePathsForTesting( void WallpaperController::InitializePathsForTesting(
const base::FilePath& user_data_path, const base::FilePath& user_data_path,
const base::FilePath& chromeos_wallpapers_path, const base::FilePath& chromeos_wallpapers_path,
...@@ -1635,6 +1524,118 @@ void WallpaperController::RemoveUserWallpaperImpl( ...@@ -1635,6 +1524,118 @@ void WallpaperController::RemoveUserWallpaperImpl(
base::BindOnce(&DeleteWallpaperInList, std::move(files_to_remove))); base::BindOnce(&DeleteWallpaperInList, std::move(files_to_remove)));
} }
void WallpaperController::SetDefaultWallpaperImpl(
const AccountId& account_id,
const user_manager::UserType& user_type,
bool show_wallpaper) {
// There is no visible wallpaper in kiosk mode.
if (IsInKioskMode())
return;
wallpaper_cache_map_.erase(account_id);
const bool use_small =
(GetAppropriateResolution() == WALLPAPER_RESOLUTION_SMALL);
WallpaperLayout layout =
use_small ? WALLPAPER_LAYOUT_CENTER : WALLPAPER_LAYOUT_CENTER_CROPPED;
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
base::FilePath file_path;
base::Optional<user_manager::UserType> active_user_type =
Shell::Get()->session_controller()->GetUserType();
// The wallpaper is determined in the following order:
// Guest wallpaper, child wallpaper, customized default wallpaper, and regular
// default wallpaper.
// TODO(wzang|xdai): The current code intentionally distinguishes between
// |active_user_type| and |user_type|. We should try to unify them.
if (active_user_type && *active_user_type == user_manager::USER_TYPE_GUEST) {
const std::string switch_string =
use_small ? chromeos::switches::kGuestWallpaperSmall
: chromeos::switches::kGuestWallpaperLarge;
file_path = command_line->GetSwitchValuePath(switch_string);
} else if (user_type == user_manager::USER_TYPE_CHILD) {
const std::string switch_string =
use_small ? chromeos::switches::kChildWallpaperSmall
: chromeos::switches::kChildWallpaperLarge;
file_path = command_line->GetSwitchValuePath(switch_string);
} else if (!customized_default_small_path_.empty()) {
DCHECK(!customized_default_large_path_.empty());
file_path = use_small ? customized_default_small_path_
: customized_default_large_path_;
} else {
const std::string switch_string =
use_small ? chromeos::switches::kDefaultWallpaperSmall
: chromeos::switches::kDefaultWallpaperLarge;
file_path = command_line->GetSwitchValuePath(switch_string);
}
// We need to decode the image if there's no cache, or if the file path
// doesn't match the cached value (i.e. the cache is outdated). Otherwise,
// directly run the callback with the cached image.
if (!cached_default_wallpaper_.image.isNull() &&
cached_default_wallpaper_.file_path == file_path) {
OnDefaultWallpaperDecoded(file_path, layout, show_wallpaper,
cached_default_wallpaper_.image);
} else {
ReadAndDecodeWallpaper(
base::BindOnce(&WallpaperController::OnDefaultWallpaperDecoded,
weak_factory_.GetWeakPtr(), file_path, layout,
show_wallpaper),
sequenced_task_runner_, file_path);
}
}
bool WallpaperController::CanSetUserWallpaper(const AccountId& account_id,
bool is_ephemeral) const {
// There is no visible wallpaper in kiosk mode.
if (IsInKioskMode())
return false;
// Don't allow user wallpapers while policy is in effect.
if (IsPolicyControlled(account_id, is_ephemeral))
return false;
return true;
}
bool WallpaperController::WallpaperIsAlreadyLoaded(
const gfx::ImageSkia& image,
bool compare_layouts,
WallpaperLayout layout) const {
if (!current_wallpaper_)
return false;
// Compare layouts only if necessary.
if (compare_layouts && layout != current_wallpaper_->wallpaper_info().layout)
return false;
return WallpaperResizer::GetImageId(image) ==
current_wallpaper_->original_image_id();
}
void WallpaperController::ReadAndDecodeWallpaper(
LoadedCallback callback,
scoped_refptr<base::SequencedTaskRunner> task_runner,
const base::FilePath& file_path) {
decode_requests_for_testing_.push_back(file_path);
if (bypass_decode_for_testing_) {
std::move(callback).Run(CreateSolidColorWallpaper());
return;
}
std::string* data = new std::string;
base::PostTaskAndReplyWithResult(
task_runner.get(), FROM_HERE,
base::BindOnce(&base::ReadFileToString, file_path, data),
base::BindOnce(&OnWallpaperDataRead, std::move(callback),
base::Passed(base::WrapUnique(data))));
}
bool WallpaperController::InitializeUserWallpaperInfo(
const AccountId& account_id,
bool is_ephemeral) {
const WallpaperInfo info = {std::string(), WALLPAPER_LAYOUT_CENTER_CROPPED,
DEFAULT, base::Time::Now().LocalMidnight()};
return SetUserWallpaperInfo(account_id, info, is_ephemeral);
}
void WallpaperController::SetOnlineWallpaperFromPath( void WallpaperController::SetOnlineWallpaperFromPath(
SetOnlineWallpaperIfExistsCallback callback, SetOnlineWallpaperIfExistsCallback callback,
const OnlineWallpaperParams& params, const OnlineWallpaperParams& params,
...@@ -1848,19 +1849,6 @@ void WallpaperController::SaveAndSetWallpaper( ...@@ -1848,19 +1849,6 @@ void WallpaperController::SaveAndSetWallpaper(
CustomWallpaperElement(wallpaper_path, image); CustomWallpaperElement(wallpaper_path, image);
} }
void WallpaperController::StartDecodeFromPath(
const AccountId& account_id,
const user_manager::UserType& user_type,
const base::FilePath& wallpaper_path,
const WallpaperInfo& info,
bool show_wallpaper) {
ReadAndDecodeWallpaper(
base::BindOnce(&WallpaperController::OnWallpaperDecoded,
weak_factory_.GetWeakPtr(), account_id, user_type,
wallpaper_path, info, show_wallpaper),
sequenced_task_runner_, wallpaper_path);
}
void WallpaperController::OnWallpaperDecoded( void WallpaperController::OnWallpaperDecoded(
const AccountId& account_id, const AccountId& account_id,
const user_manager::UserType& user_type, const user_manager::UserType& user_type,
...@@ -2010,6 +1998,21 @@ bool WallpaperController::IsDevicePolicyWallpaper() const { ...@@ -2010,6 +1998,21 @@ bool WallpaperController::IsDevicePolicyWallpaper() const {
current_wallpaper_->wallpaper_info().type == WallpaperType::DEVICE; current_wallpaper_->wallpaper_info().type == WallpaperType::DEVICE;
} }
bool WallpaperController::ShouldSetDevicePolicyWallpaper() const {
// Only allow the device wallpaper if the policy is in effect for enterprise
// managed devices.
if (!is_device_wallpaper_policy_enforced_)
return false;
// Only set the device wallpaper if we're at the login screen.
if (Shell::Get()->session_controller()->GetSessionState() !=
session_manager::SessionState::LOGIN_PRIMARY) {
return false;
}
return true;
}
void WallpaperController::SetDevicePolicyWallpaper() { void WallpaperController::SetDevicePolicyWallpaper() {
DCHECK(ShouldSetDevicePolicyWallpaper()); DCHECK(ShouldSetDevicePolicyWallpaper());
ReadAndDecodeWallpaper( ReadAndDecodeWallpaper(
...@@ -2092,8 +2095,4 @@ void WallpaperController::GetInternalDisplayCompositorLock() { ...@@ -2092,8 +2095,4 @@ void WallpaperController::GetInternalDisplayCompositorLock() {
this, kCompositorLockTimeout); this, kCompositorLockTimeout);
} }
void WallpaperController::CompositorLockTimedOut() {
compositor_lock_.reset();
}
} // namespace ash } // namespace ash
...@@ -70,8 +70,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -70,8 +70,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
public SessionObserver, public SessionObserver,
public ui::CompositorLockClient { public ui::CompositorLockClient {
public: public:
enum WallpaperMode { WALLPAPER_NONE, WALLPAPER_IMAGE };
enum WallpaperResolution { enum WallpaperResolution {
WALLPAPER_RESOLUTION_LARGE, WALLPAPER_RESOLUTION_LARGE,
WALLPAPER_RESOLUTION_SMALL WALLPAPER_RESOLUTION_SMALL
...@@ -82,9 +80,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -82,9 +80,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
static const char kLargeWallpaperSubDir[]; static const char kLargeWallpaperSubDir[];
static const char kOriginalWallpaperSubDir[]; static const char kOriginalWallpaperSubDir[];
// The color of the wallpaper if no other wallpaper images are available.
static const SkColor kDefaultWallpaperColor;
WallpaperController(); WallpaperController();
~WallpaperController() override; ~WallpaperController() override;
...@@ -96,17 +91,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -96,17 +91,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
// maximum width of all displays, and the maximum height of all displays. // maximum width of all displays, and the maximum height of all displays.
static gfx::Size GetMaxDisplaySizeInNative(); static gfx::Size GetMaxDisplaySizeInNative();
// Returns the appropriate wallpaper resolution for all root windows.
static WallpaperResolution GetAppropriateResolution();
// Returns the path of the online wallpaper corresponding to |url| and
// |resolution|.
static base::FilePath GetOnlineWallpaperPath(const std::string& url,
WallpaperResolution resolution);
// Returns wallpaper subdirectory name for current resolution.
static std::string GetCustomWallpaperSubdirForCurrentResolution();
// Returns custom wallpaper path. Appends |sub_dir|, |wallpaper_files_id| and // Returns custom wallpaper path. Appends |sub_dir|, |wallpaper_files_id| and
// |file_name| to custom wallpaper directory. // |file_name| to custom wallpaper directory.
static base::FilePath GetCustomWallpaperPath( static base::FilePath GetCustomWallpaperPath(
...@@ -117,17 +101,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -117,17 +101,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
// Returns custom wallpaper directory by appending corresponding |sub_dir|. // Returns custom wallpaper directory by appending corresponding |sub_dir|.
static base::FilePath GetCustomWallpaperDir(const std::string& sub_dir); static base::FilePath GetCustomWallpaperDir(const std::string& sub_dir);
// Resizes |image| to a resolution which is nearest to |preferred_width| and
// |preferred_height| while respecting the |layout| choice and saves the
// resized wallpaper to |path|. |output_skia| is optional (may be
// null). Returns true on success.
static bool ResizeAndSaveWallpaper(const gfx::ImageSkia& image,
const base::FilePath& path,
WallpaperLayout layout,
int preferred_width,
int preferred_height,
gfx::ImageSkia* output_skia);
// Gets |account_id|'s custom wallpaper at |wallpaper_path|. Falls back to the // Gets |account_id|'s custom wallpaper at |wallpaper_path|. Falls back to the
// original custom wallpaper. When |show_wallpaper| is true, shows the // original custom wallpaper. When |show_wallpaper| is true, shows the
// wallpaper immediately. Must run on wallpaper sequenced worker thread. // wallpaper immediately. Must run on wallpaper sequenced worker thread.
...@@ -140,9 +113,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -140,9 +113,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
const scoped_refptr<base::SingleThreadTaskRunner>& reply_task_runner, const scoped_refptr<base::SingleThreadTaskRunner>& reply_task_runner,
base::WeakPtr<WallpaperController> weak_ptr); base::WeakPtr<WallpaperController> weak_ptr);
// Creates a 1x1 solid color image to be used as the backup default wallpaper.
static gfx::ImageSkia CreateSolidColorWallpaper();
// Binds the mojom::WallpaperController interface request to this object. // Binds the mojom::WallpaperController interface request to this object.
void BindRequest(mojom::WallpaperControllerRequest request); void BindRequest(mojom::WallpaperControllerRequest request);
...@@ -157,10 +127,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -157,10 +127,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
// wallpaper. // wallpaper.
gfx::ImageSkia GetWallpaper() const; gfx::ImageSkia GetWallpaper() const;
// Returns the original image id of the wallpaper before resizing, or 0 if
// there's no wallpaper.
uint32_t GetWallpaperOriginalImageId() const;
// Returns the layout of the current wallpaper, or an invalid value if there's // Returns the layout of the current wallpaper, or an invalid value if there's
// no wallpaper. // no wallpaper.
WallpaperLayout GetWallpaperLayout() const; WallpaperLayout GetWallpaperLayout() const;
...@@ -189,54 +155,14 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -189,54 +155,14 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
WallpaperInfo info, WallpaperInfo info,
bool preview_mode); bool preview_mode);
// Implementation of |SetDefaultWallpaper|. Sets wallpaper to default if
// |show_wallpaper| is true. Otherwise just save the defaut wallpaper to
// cache. |user_type| is the type of the user initiating the wallpaper
// request; may be different from the active user.
void SetDefaultWallpaperImpl(const AccountId& account_id,
const user_manager::UserType& user_type,
bool show_wallpaper);
// Returns whether a wallpaper policy is enforced for |account_id| (not // Returns whether a wallpaper policy is enforced for |account_id| (not
// including device policy). // including device policy).
bool IsPolicyControlled(const AccountId& account_id, bool is_ephemeral) const; bool IsPolicyControlled(const AccountId& account_id, bool is_ephemeral) const;
// When kiosk app is running or policy is enforced, setting a user wallpaper
// is not allowed.
bool CanSetUserWallpaper(const AccountId& account_id,
bool is_ephemeral) const;
// Prepares wallpaper to lock screen transition. Will apply blur if // Prepares wallpaper to lock screen transition. Will apply blur if
// |locking| is true and remove it otherwise. // |locking| is true and remove it otherwise.
void PrepareWallpaperForLockScreenChange(bool locking); void PrepareWallpaperForLockScreenChange(bool locking);
// WindowTreeHostManager::Observer:
void OnDisplayConfigurationChanged() override;
// ShellObserver:
void OnRootWindowAdded(aura::Window* root_window) override;
void OnLocalStatePrefServiceInitialized(PrefService* pref_service) override;
// SessionObserver:
void OnSessionStateChanged(session_manager::SessionState state) override;
// Returns true if the specified wallpaper is already stored in
// |current_wallpaper_|. If |compare_layouts| is false, layout is ignored.
bool WallpaperIsAlreadyLoaded(const gfx::ImageSkia& image,
bool compare_layouts,
WallpaperLayout layout) const;
// Reads image from |file_path| on disk, and calls |OnWallpaperDataRead|
// with the result of |ReadFileToString|.
void ReadAndDecodeWallpaper(
LoadedCallback callback,
scoped_refptr<base::SequencedTaskRunner> task_runner,
const base::FilePath& file_path);
void set_wallpaper_reload_no_delay_for_test() {
wallpaper_reload_delay_ = base::TimeDelta::FromMilliseconds(0);
}
// Wallpaper should be dimmed for login, lock, OOBE and add user screens. // Wallpaper should be dimmed for login, lock, OOBE and add user screens.
bool ShouldApplyDimming() const; bool ShouldApplyDimming() const;
...@@ -260,11 +186,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -260,11 +186,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
WallpaperInfo* info, WallpaperInfo* info,
bool is_ephemeral) const; bool is_ephemeral) const;
// Initializes wallpaper info for the user to default and saves it to local
// state if |is_ephemeral| is false. Returns false if initialization fails.
bool InitializeUserWallpaperInfo(const AccountId& account_id,
bool is_ephemeral);
// Gets encoded wallpaper from cache. Returns true if success. // Gets encoded wallpaper from cache. Returns true if success.
bool GetWallpaperFromCache(const AccountId& account_id, bool GetWallpaperFromCache(const AccountId& account_id,
gfx::ImageSkia* image); gfx::ImageSkia* image);
...@@ -272,15 +193,18 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -272,15 +193,18 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
// Gets path of encoded wallpaper from cache. Returns true if success. // Gets path of encoded wallpaper from cache. Returns true if success.
bool GetPathFromCache(const AccountId& account_id, base::FilePath* path); bool GetPathFromCache(const AccountId& account_id, base::FilePath* path);
// Returns true if device wallpaper policy is in effect and we are at the
// login screen right now.
bool ShouldSetDevicePolicyWallpaper() const;
// Runs |callback| upon the completion of the first wallpaper animation that's // Runs |callback| upon the completion of the first wallpaper animation that's
// shown on |window|'s root window. // shown on |window|'s root window.
void AddFirstWallpaperAnimationEndCallback(base::OnceClosure callback, void AddFirstWallpaperAnimationEndCallback(base::OnceClosure callback,
aura::Window* window); aura::Window* window);
// A wrapper of |ReadAndDecodeWallpaper| used in |SetWallpaperFromPath|.
void StartDecodeFromPath(const AccountId& account_id,
const user_manager::UserType& user_type,
const base::FilePath& wallpaper_path,
const WallpaperInfo& info,
bool show_wallpaper);
// mojom::WallpaperController: // mojom::WallpaperController:
void Init(mojom::WallpaperControllerClientPtr client, void Init(mojom::WallpaperControllerClientPtr client,
const base::FilePath& user_data_path, const base::FilePath& user_data_path,
...@@ -350,12 +274,25 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -350,12 +274,25 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
void ShouldShowWallpaperSetting( void ShouldShowWallpaperSetting(
ShouldShowWallpaperSettingCallback callback) override; ShouldShowWallpaperSettingCallback callback) override;
// WindowTreeHostManager::Observer:
void OnDisplayConfigurationChanged() override;
// ShellObserver:
void OnRootWindowAdded(aura::Window* root_window) override;
void OnLocalStatePrefServiceInitialized(PrefService* pref_service) override;
// WallpaperResizerObserver: // WallpaperResizerObserver:
void OnWallpaperResized() override; void OnWallpaperResized() override;
// WallpaperColorCalculatorObserver: // WallpaperColorCalculatorObserver:
void OnColorCalculationComplete() override; void OnColorCalculationComplete() override;
// SessionObserver:
void OnSessionStateChanged(session_manager::SessionState state) override;
// CompositorLockClient:
void CompositorLockTimedOut() override;
// Sets dummy values for wallpaper directories. // Sets dummy values for wallpaper directories.
void InitializePathsForTesting( void InitializePathsForTesting(
const base::FilePath& user_data_path, const base::FilePath& user_data_path,
...@@ -379,6 +316,10 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -379,6 +316,10 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
// Flushes the mojo message pipe to chrome. // Flushes the mojo message pipe to chrome.
void FlushForTesting(); void FlushForTesting();
void set_wallpaper_reload_no_delay_for_test() {
wallpaper_reload_delay_ = base::TimeDelta::FromMilliseconds(0);
}
private: private:
FRIEND_TEST_ALL_PREFIXES(WallpaperControllerTest, BasicReparenting); FRIEND_TEST_ALL_PREFIXES(WallpaperControllerTest, BasicReparenting);
FRIEND_TEST_ALL_PREFIXES(WallpaperControllerTest, FRIEND_TEST_ALL_PREFIXES(WallpaperControllerTest,
...@@ -386,6 +327,8 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -386,6 +327,8 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
friend class WallpaperControllerTest; friend class WallpaperControllerTest;
friend class WallpaperControllerTestApi; friend class WallpaperControllerTestApi;
enum WallpaperMode { WALLPAPER_NONE, WALLPAPER_IMAGE };
// Cached default wallpaper image and file path. The file path can be used to // Cached default wallpaper image and file path. The file path can be used to
// check if the image is outdated (i.e. when there's a new default wallpaper). // check if the image is outdated (i.e. when there's a new default wallpaper).
struct CachedDefaultWallpaper { struct CachedDefaultWallpaper {
...@@ -422,6 +365,37 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -422,6 +365,37 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
void RemoveUserWallpaperImpl(const AccountId& account_id, void RemoveUserWallpaperImpl(const AccountId& account_id,
const std::string& wallpaper_files_id); const std::string& wallpaper_files_id);
// Implementation of |SetDefaultWallpaper|. Sets wallpaper to default if
// |show_wallpaper| is true. Otherwise just save the defaut wallpaper to
// cache. |user_type| is the type of the user initiating the wallpaper
// request; may be different from the active user.
void SetDefaultWallpaperImpl(const AccountId& account_id,
const user_manager::UserType& user_type,
bool show_wallpaper);
// When kiosk app is running or policy is enforced, setting a user wallpaper
// is not allowed.
bool CanSetUserWallpaper(const AccountId& account_id,
bool is_ephemeral) const;
// Returns true if the specified wallpaper is already stored in
// |current_wallpaper_|. If |compare_layouts| is false, layout is ignored.
bool WallpaperIsAlreadyLoaded(const gfx::ImageSkia& image,
bool compare_layouts,
WallpaperLayout layout) const;
// Reads image from |file_path| on disk, and calls |OnWallpaperDataRead|
// with the result of |ReadFileToString|.
void ReadAndDecodeWallpaper(
LoadedCallback callback,
scoped_refptr<base::SequencedTaskRunner> task_runner,
const base::FilePath& file_path);
// Initializes wallpaper info for the user to default and saves it to local
// state if |is_ephemeral| is false. Returns false if initialization fails.
bool InitializeUserWallpaperInfo(const AccountId& account_id,
bool is_ephemeral);
// Used as the callback of checking ONLINE wallpaper existence in // Used as the callback of checking ONLINE wallpaper existence in
// |SetOnlineWallpaperIfExists|. Initiates reading and decoding the wallpaper // |SetOnlineWallpaperIfExists|. Initiates reading and decoding the wallpaper
// if |file_path| is not empty. // if |file_path| is not empty.
...@@ -470,13 +444,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -470,13 +444,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
bool show_wallpaper, bool show_wallpaper,
const gfx::ImageSkia& image); const gfx::ImageSkia& image);
// A wrapper of |ReadAndDecodeWallpaper| used in |SetWallpaperFromPath|.
void StartDecodeFromPath(const AccountId& account_id,
const user_manager::UserType& user_type,
const base::FilePath& wallpaper_path,
const WallpaperInfo& info,
bool show_wallpaper);
// Used as the callback of wallpaper decoding. (Wallpapers of type ONLINE, // Used as the callback of wallpaper decoding. (Wallpapers of type ONLINE,
// DEFAULT and DEVICE should use their corresponding |*Decoded|, and all other // DEFAULT and DEVICE should use their corresponding |*Decoded|, and all other
// types should use this.) Shows the wallpaper immediately if |show_wallpaper| // types should use this.) Shows the wallpaper immediately if |show_wallpaper|
...@@ -535,6 +502,10 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -535,6 +502,10 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
// Returns whether the current wallpaper is set by device policy. // Returns whether the current wallpaper is set by device policy.
bool IsDevicePolicyWallpaper() const; bool IsDevicePolicyWallpaper() const;
// Returns true if device wallpaper policy is in effect and we are at the
// login screen right now.
bool ShouldSetDevicePolicyWallpaper() const;
// Reads the device wallpaper file and sets it as the current wallpaper. Note // Reads the device wallpaper file and sets it as the current wallpaper. Note
// when it's called, it's guaranteed that ShouldSetDevicePolicyWallpaper() // when it's called, it's guaranteed that ShouldSetDevicePolicyWallpaper()
// should be true. // should be true.
...@@ -556,9 +527,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -556,9 +527,6 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
// simplicity, we only lock the compositor for the internal display. // simplicity, we only lock the compositor for the internal display.
void GetInternalDisplayCompositorLock(); void GetInternalDisplayCompositorLock();
// CompositorLockClient:
void CompositorLockTimedOut() override;
bool locked_; bool locked_;
WallpaperMode wallpaper_mode_; WallpaperMode wallpaper_mode_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment