Commit 57b0df8d authored by Wenzhao Zang's avatar Wenzhao Zang Committed by Commit Bot

wallpaper refactoring: Delete UpdateWallpaper in WallpaperDelegate

Previously, UpdateWallpaper() is needed in the WallpaperDelegate
interface because it relies on Chrome to set the correct image. After
everything is migrated, it no longer needs to call into Chrome.
(Eventually WallpaperDelegate will be deleted as well.)

All the tests in |wallpaper_manager_browsertest.cc| have been migrated
(some of them are deleted because they have been disabled for a long
time). But there is some untested code path in wallpaper_manager and
we'll add more tests in follow-up CLs.

TBR=oshima@chromium.org

Bug: 779221, 794725
Change-Id: I81b0a0b6b2a96423a1191054e154761b10304382
Reviewed-on: https://chromium-review.googlesource.com/826325Reviewed-by: default avatarWenzhao (Colin) Zang <wzang@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Commit-Queue: Wenzhao (Colin) Zang <wzang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#526654}
parent 5ac59e66
...@@ -25,8 +25,6 @@ bool DefaultWallpaperDelegate::ShouldShowInitialAnimation() { ...@@ -25,8 +25,6 @@ bool DefaultWallpaperDelegate::ShouldShowInitialAnimation() {
return false; return false;
} }
void DefaultWallpaperDelegate::UpdateWallpaper(bool clear_cache) {}
void DefaultWallpaperDelegate::InitializeWallpaper() { void DefaultWallpaperDelegate::InitializeWallpaper() {
Shell::Get()->wallpaper_controller()->CreateEmptyWallpaper(); Shell::Get()->wallpaper_controller()->CreateEmptyWallpaper();
} }
......
...@@ -21,7 +21,6 @@ class ASH_EXPORT DefaultWallpaperDelegate : public WallpaperDelegate { ...@@ -21,7 +21,6 @@ class ASH_EXPORT DefaultWallpaperDelegate : public WallpaperDelegate {
int GetAnimationDurationOverride() override; int GetAnimationDurationOverride() override;
void SetAnimationDurationOverride(int animation_duration_in_ms) override; void SetAnimationDurationOverride(int animation_duration_in_ms) override;
bool ShouldShowInitialAnimation() override; bool ShouldShowInitialAnimation() override;
void UpdateWallpaper(bool clear_cache) override;
void InitializeWallpaper() override; void InitializeWallpaper() override;
bool CanOpenSetWallpaperPage() override; bool CanOpenSetWallpaperPage() override;
void OnWallpaperAnimationFinished() override; void OnWallpaperAnimationFinished() override;
......
...@@ -4,35 +4,14 @@ ...@@ -4,35 +4,14 @@
#include "ash/wallpaper/test_wallpaper_delegate.h" #include "ash/wallpaper/test_wallpaper_delegate.h"
#include "ash/shell.h"
#include "ash/wallpaper/wallpaper_controller.h"
namespace ash { namespace ash {
TestWallpaperDelegate::TestWallpaperDelegate() : update_wallpaper_count_(0) {} TestWallpaperDelegate::TestWallpaperDelegate() {}
TestWallpaperDelegate::~TestWallpaperDelegate() = default; TestWallpaperDelegate::~TestWallpaperDelegate() = default;
void TestWallpaperDelegate::UpdateWallpaper(bool clear_cache) {
DefaultWallpaperDelegate::UpdateWallpaper(clear_cache);
if (!custom_wallpaper_.isNull()) {
wallpaper::WallpaperInfo info("", wallpaper::WALLPAPER_LAYOUT_STRETCH,
wallpaper::DEFAULT,
base::Time::Now().LocalMidnight());
Shell::Get()->wallpaper_controller()->SetWallpaperImage(custom_wallpaper_,
info);
}
update_wallpaper_count_++;
}
bool TestWallpaperDelegate::CanOpenSetWallpaperPage() { bool TestWallpaperDelegate::CanOpenSetWallpaperPage() {
return true; return true;
} }
int TestWallpaperDelegate::GetUpdateWallpaperCountAndReset() {
int count = update_wallpaper_count_;
update_wallpaper_count_ = 0;
return count;
}
} // namespace ash } // namespace ash
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "ash/default_wallpaper_delegate.h" #include "ash/default_wallpaper_delegate.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/gfx/image/image_skia.h"
namespace ash { namespace ash {
...@@ -16,24 +15,10 @@ class TestWallpaperDelegate : public DefaultWallpaperDelegate { ...@@ -16,24 +15,10 @@ class TestWallpaperDelegate : public DefaultWallpaperDelegate {
TestWallpaperDelegate(); TestWallpaperDelegate();
~TestWallpaperDelegate() override; ~TestWallpaperDelegate() override;
void set_custom_wallpaper(const gfx::ImageSkia& wallpaper) {
custom_wallpaper_ = wallpaper;
}
// DefaultWallpaperDelegate overrides: // DefaultWallpaperDelegate overrides:
void UpdateWallpaper(bool clear_cache) override;
bool CanOpenSetWallpaperPage() override; bool CanOpenSetWallpaperPage() override;
// Returns and clears |update_wallpaper_count_|.
int GetUpdateWallpaperCountAndReset();
private: private:
// Number of times that UpdateWallpaper() has been called.
int update_wallpaper_count_;
// If non-null, used as custom wallpaper by UpdateWallpaper().
gfx::ImageSkia custom_wallpaper_;
DISALLOW_COPY_AND_ASSIGN(TestWallpaperDelegate); DISALLOW_COPY_AND_ASSIGN(TestWallpaperDelegate);
}; };
......
...@@ -632,6 +632,12 @@ wallpaper::WallpaperLayout WallpaperController::GetWallpaperLayout() const { ...@@ -632,6 +632,12 @@ wallpaper::WallpaperLayout WallpaperController::GetWallpaperLayout() const {
return wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED; return wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED;
} }
wallpaper::WallpaperType WallpaperController::GetWallpaperType() const {
if (current_wallpaper_)
return current_wallpaper_->wallpaper_info().type;
return wallpaper::DEFAULT;
}
void WallpaperController::SetDefaultWallpaperImpl( void WallpaperController::SetDefaultWallpaperImpl(
const AccountId& account_id, const AccountId& account_id,
const user_manager::UserType& user_type, const user_manager::UserType& user_type,
...@@ -824,8 +830,8 @@ void WallpaperController::OnDisplayConfigurationChanged() { ...@@ -824,8 +830,8 @@ void WallpaperController::OnDisplayConfigurationChanged() {
GetInternalDisplayCompositorLock(); GetInternalDisplayCompositorLock();
timer_.Start(FROM_HERE, timer_.Start(FROM_HERE,
base::TimeDelta::FromMilliseconds(wallpaper_reload_delay_), base::TimeDelta::FromMilliseconds(wallpaper_reload_delay_),
base::Bind(&WallpaperController::UpdateWallpaper, base::Bind(&WallpaperController::ReloadWallpaper,
base::Unretained(this), false /* clear cache */)); base::Unretained(this), false /*clear_cache=*/));
} }
} }
} }
...@@ -840,7 +846,7 @@ void WallpaperController::OnRootWindowAdded(aura::Window* root_window) { ...@@ -840,7 +846,7 @@ void WallpaperController::OnRootWindowAdded(aura::Window* root_window) {
if (current_max_display_size_ != max_display_size) { if (current_max_display_size_ != max_display_size) {
current_max_display_size_ = max_display_size; current_max_display_size_ = max_display_size;
if (wallpaper_mode_ == WALLPAPER_IMAGE && current_wallpaper_) if (wallpaper_mode_ == WALLPAPER_IMAGE && current_wallpaper_)
UpdateWallpaper(true /* clear cache */); ReloadWallpaper(true /*clear_cache=*/);
} }
InstallDesktopController(root_window); InstallDesktopController(root_window);
...@@ -1177,22 +1183,22 @@ void WallpaperController::SetDeviceWallpaperPolicyEnforced(bool enforced) { ...@@ -1177,22 +1183,22 @@ void WallpaperController::SetDeviceWallpaperPolicyEnforced(bool enforced) {
void WallpaperController::ShowUserWallpaper( void WallpaperController::ShowUserWallpaper(
mojom::WallpaperUserInfoPtr user_info) { mojom::WallpaperUserInfoPtr user_info) {
current_user_ = std::move(user_info);
const AccountId account_id = current_user_->account_id;
const bool is_persistent = !current_user_->is_ephemeral;
// Guest user or regular user in ephemeral mode. // Guest user or regular user in ephemeral mode.
// TODO(wzang/xdai): Check if the wallpaper info for ephemeral users should // TODO(wzang/xdai): Check if the wallpaper info for ephemeral users should
// be saved to local state. // be saved to local state.
if ((user_info->is_ephemeral && user_info->has_gaia_account) || if ((!is_persistent && current_user_->has_gaia_account) ||
user_info->type == user_manager::USER_TYPE_GUEST) { current_user_->type == user_manager::USER_TYPE_GUEST) {
InitializeUserWallpaperInfo(user_info->account_id, InitializeUserWallpaperInfo(account_id, is_persistent);
!user_info->is_ephemeral); SetDefaultWallpaperImpl(account_id, current_user_->type,
SetDefaultWallpaperImpl(user_info->account_id, user_info->type,
true /*show_wallpaper=*/); true /*show_wallpaper=*/);
LOG(ERROR) << "User is ephemeral or guest! Fallback to default wallpaper."; LOG(ERROR) << "User is ephemeral or guest! Fallback to default wallpaper.";
return; return;
} }
current_user_ = std::move(user_info);
const AccountId account_id = current_user_->account_id;
const bool is_persistent = !current_user_->is_ephemeral;
WallpaperInfo info; WallpaperInfo info;
if (!GetUserWallpaperInfo(account_id, &info, is_persistent)) { if (!GetUserWallpaperInfo(account_id, &info, is_persistent)) {
InitializeUserWallpaperInfo(account_id, is_persistent); InitializeUserWallpaperInfo(account_id, is_persistent);
...@@ -1257,6 +1263,7 @@ void WallpaperController::ShowUserWallpaper( ...@@ -1257,6 +1263,7 @@ void WallpaperController::ShowUserWallpaper(
} }
void WallpaperController::ShowSigninWallpaper() { void WallpaperController::ShowSigninWallpaper() {
current_user_.reset();
// TODO(crbug.com/791654): Call |SetDeviceWallpaperIfApplicable| from here. // TODO(crbug.com/791654): Call |SetDeviceWallpaperIfApplicable| from here.
SetDefaultWallpaperImpl(EmptyAccountId(), user_manager::USER_TYPE_REGULAR, SetDefaultWallpaperImpl(EmptyAccountId(), user_manager::USER_TYPE_REGULAR,
true /*show_wallpaper=*/); true /*show_wallpaper=*/);
...@@ -1412,11 +1419,6 @@ int WallpaperController::GetWallpaperContainerId(bool locked) { ...@@ -1412,11 +1419,6 @@ int WallpaperController::GetWallpaperContainerId(bool locked) {
: kShellWindowId_WallpaperContainer; : kShellWindowId_WallpaperContainer;
} }
void WallpaperController::UpdateWallpaper(bool clear_cache) {
current_wallpaper_.reset();
Shell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache);
}
void WallpaperController::RemoveUserWallpaperInfo(const AccountId& account_id, void WallpaperController::RemoveUserWallpaperInfo(const AccountId& account_id,
bool is_persistent) { bool is_persistent) {
if (wallpaper_cache_map_.find(account_id) != wallpaper_cache_map_.end()) if (wallpaper_cache_map_.find(account_id) != wallpaper_cache_map_.end())
...@@ -1643,7 +1645,7 @@ void WallpaperController::OnWallpaperDecoded( ...@@ -1643,7 +1645,7 @@ void WallpaperController::OnWallpaperDecoded(
// Empty image indicates decode failure. Use default wallpaper in this case. // Empty image indicates decode failure. Use default wallpaper in this case.
if (user_image->image().isNull()) { if (user_image->image().isNull()) {
LOG(ERROR) << "Failed to decode user wallpaper at " << path.value() LOG(ERROR) << "Failed to decode user wallpaper at " << path.value()
<< "Falls back to default wallpaper. "; << " Falls back to default wallpaper. ";
SetDefaultWallpaperImpl(account_id, user_type, show_wallpaper); SetDefaultWallpaperImpl(account_id, user_type, show_wallpaper);
return; return;
} }
...@@ -1654,6 +1656,17 @@ void WallpaperController::OnWallpaperDecoded( ...@@ -1654,6 +1656,17 @@ void WallpaperController::OnWallpaperDecoded(
SetWallpaperImage(user_image->image(), info); SetWallpaperImage(user_image->image(), info);
} }
void WallpaperController::ReloadWallpaper(bool clear_cache) {
current_wallpaper_.reset();
if (clear_cache)
wallpaper_cache_map_.clear();
if (current_user_)
ShowUserWallpaper(std::move(current_user_));
else
ShowSigninWallpaper();
}
void WallpaperController::SetProminentColors( void WallpaperController::SetProminentColors(
const std::vector<SkColor>& colors) { const std::vector<SkColor>& colors) {
if (prominent_colors_ == colors) if (prominent_colors_ == colors)
......
...@@ -237,6 +237,8 @@ class ASH_EXPORT WallpaperController ...@@ -237,6 +237,8 @@ class ASH_EXPORT WallpaperController
wallpaper::WallpaperLayout GetWallpaperLayout() const; wallpaper::WallpaperLayout GetWallpaperLayout() const;
wallpaper::WallpaperType GetWallpaperType() const;
// Sets the wallpaper and alerts observers of changes. // Sets the wallpaper and alerts observers of changes.
void SetWallpaperImage(const gfx::ImageSkia& image, void SetWallpaperImage(const gfx::ImageSkia& image,
const wallpaper::WallpaperInfo& info); const wallpaper::WallpaperInfo& info);
...@@ -451,10 +453,6 @@ class ASH_EXPORT WallpaperController ...@@ -451,10 +453,6 @@ class ASH_EXPORT WallpaperController
// Returns the wallpaper container id for unlocked and locked states. // Returns the wallpaper container id for unlocked and locked states.
int GetWallpaperContainerId(bool locked); int GetWallpaperContainerId(bool locked);
// Reload the wallpaper. |clear_cache| specifies whether to clear the
// wallpaper cache or not.
void UpdateWallpaper(bool clear_cache);
// Removes |account_id|'s wallpaper info and color cache if it exists. // Removes |account_id|'s wallpaper info and color cache if it exists.
void RemoveUserWallpaperInfo(const AccountId& account_id, bool is_persistent); void RemoveUserWallpaperInfo(const AccountId& account_id, bool is_persistent);
...@@ -509,6 +507,15 @@ class ASH_EXPORT WallpaperController ...@@ -509,6 +507,15 @@ class ASH_EXPORT WallpaperController
bool show_wallpaper, bool show_wallpaper,
std::unique_ptr<user_manager::UserImage> user_image); std::unique_ptr<user_manager::UserImage> user_image);
// Reloads the current wallpaper. It may change the wallpaper size based on
// the current display's resolution. If |clear_cache| is true, all wallpaper
// cache should be cleared. This is required when the display's native
// resolution changes to a larger resolution (e.g. when hooked up a large
// external display) and we need to load a larger resolution wallpaper for the
// display. All the previous small resolution wallpaper cache should be
// cleared.
void ReloadWallpaper(bool clear_cache);
// Sets |prominent_colors_| and notifies the observers if there is a change. // Sets |prominent_colors_| and notifies the observers if there is a change.
void SetProminentColors(const std::vector<SkColor>& prominent_colors); void SetProminentColors(const std::vector<SkColor>& prominent_colors);
......
...@@ -29,15 +29,6 @@ class ASH_EXPORT WallpaperDelegate { ...@@ -29,15 +29,6 @@ class ASH_EXPORT WallpaperDelegate {
// another's on the login screen)? // another's on the login screen)?
virtual bool ShouldShowInitialAnimation() = 0; virtual bool ShouldShowInitialAnimation() = 0;
// Updates current wallpaper. It may switch the size of wallpaper based on the
// current display's resolution. If |clear_cache| is true, all wallpaper
// cache should be cleared. This is required when the display's native
// resolution changes to a larger resolution (e.g. when hooked up a large
// external display) and we need to load a larger resolution wallpaper for the
// large display. All the previous small resolution wallpaper cache should be
// cleared.
virtual void UpdateWallpaper(bool clear_cache) = 0;
// Initialize wallpaper. // Initialize wallpaper.
virtual void InitializeWallpaper() = 0; virtual void InitializeWallpaper() = 0;
......
...@@ -28,10 +28,6 @@ bool WallpaperDelegateMus::ShouldShowInitialAnimation() { ...@@ -28,10 +28,6 @@ bool WallpaperDelegateMus::ShouldShowInitialAnimation() {
return false; return false;
} }
void WallpaperDelegateMus::UpdateWallpaper(bool clear_cache) {
NOTIMPLEMENTED_LOG_ONCE();
}
void WallpaperDelegateMus::InitializeWallpaper() { void WallpaperDelegateMus::InitializeWallpaper() {
// No action required; ChromeBrowserMainPartsChromeos inits WallpaperManager. // No action required; ChromeBrowserMainPartsChromeos inits WallpaperManager.
} }
......
...@@ -21,7 +21,6 @@ class WallpaperDelegateMus : public WallpaperDelegate { ...@@ -21,7 +21,6 @@ class WallpaperDelegateMus : public WallpaperDelegate {
int GetAnimationDurationOverride() override; int GetAnimationDurationOverride() override;
void SetAnimationDurationOverride(int animation_duration_in_ms) override; void SetAnimationDurationOverride(int animation_duration_in_ms) override;
bool ShouldShowInitialAnimation() override; bool ShouldShowInitialAnimation() override;
void UpdateWallpaper(bool clear_cache) override;
void InitializeWallpaper() override; void InitializeWallpaper() override;
bool CanOpenSetWallpaperPage() override; bool CanOpenSetWallpaperPage() override;
void OnWallpaperAnimationFinished() override; void OnWallpaperAnimationFinished() override;
......
...@@ -78,10 +78,6 @@ class WallpaperDelegate : public ash::WallpaperDelegate { ...@@ -78,10 +78,6 @@ class WallpaperDelegate : public ash::WallpaperDelegate {
return true; return true;
} }
void UpdateWallpaper(bool clear_cache) override {
chromeos::WallpaperManager::Get()->UpdateWallpaper(clear_cache);
}
void InitializeWallpaper() override { void InitializeWallpaper() override {
chromeos::WallpaperManager::Get()->InitializeWallpaper(); chromeos::WallpaperManager::Get()->InitializeWallpaper();
} }
......
...@@ -4696,7 +4696,6 @@ if (is_android) { ...@@ -4696,7 +4696,6 @@ if (is_android) {
"../browser/chromeos/login/test/https_forwarder.h", "../browser/chromeos/login/test/https_forwarder.h",
"../browser/chromeos/login/test/oobe_base_test.cc", "../browser/chromeos/login/test/oobe_base_test.cc",
"../browser/chromeos/login/test/oobe_base_test.h", "../browser/chromeos/login/test/oobe_base_test.h",
"../browser/chromeos/login/users/wallpaper/wallpaper_manager_browsertest.cc",
"../browser/chromeos/login/users/wallpaper/wallpaper_manager_test_utils.cc", "../browser/chromeos/login/users/wallpaper/wallpaper_manager_test_utils.cc",
"../browser/chromeos/login/users/wallpaper/wallpaper_manager_test_utils.h", "../browser/chromeos/login/users/wallpaper/wallpaper_manager_test_utils.h",
"../browser/notifications/login_state_notification_blocker_chromeos_browsertest.cc", "../browser/notifications/login_state_notification_blocker_chromeos_browsertest.cc",
......
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