Skip to content

Commit

Permalink
Reland: wallpaper refactoring: update |current_user_wallpaper_info_| …
Browse files Browse the repository at this point in the history
…when setting wallpaper.

Bug: 794780
Change-Id: Id481b2f3bdb2fba9557ac9a1fab75b57434bcba5
Reviewed-on: https://chromium-review.googlesource.com/829881
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Reviewed-by: Wenzhao (Colin) Zang <wzang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#525098}

TBR=wzang@chromium.org

Change-Id: Id481b2f3bdb2fba9557ac9a1fab75b57434bcba5
Reviewed-on: https://chromium-review.googlesource.com/838364
Reviewed-by: Xiaoqian Dai <xdai@chromium.org>
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#525588}
  • Loading branch information
xdai authored and Commit Bot committed Dec 21, 2017
1 parent be456d0 commit a12772b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
13 changes: 8 additions & 5 deletions ash/wallpaper/wallpaper_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ void WallpaperController::SetCustomizedDefaultWallpaperImpl(

void WallpaperController::SetWallpaperImage(const gfx::ImageSkia& image,
const WallpaperInfo& info) {
current_user_wallpaper_info_ = info;
wallpaper::WallpaperLayout layout = info.layout;
VLOG(1) << "SetWallpaper: image_id="
<< wallpaper::WallpaperResizer::GetImageId(image)
Expand All @@ -719,7 +720,6 @@ void WallpaperController::SetWallpaperImage(const gfx::ImageSkia& image,
return;
}

current_location_ = info.location;
// Cancel any in-flight color calculation because we have a new wallpaper.
if (color_calculator_) {
color_calculator_->RemoveObserver(this);
Expand Down Expand Up @@ -881,6 +881,9 @@ bool WallpaperController::IsBlurEnabled() const {
void WallpaperController::SetUserWallpaperInfo(const AccountId& account_id,
const WallpaperInfo& info,
bool is_persistent) {
// TODO(xdai): Remove this line after wallpaper refactoring is done.
// |current_user_wallpaper_info_| will be later updated in SetWallpaperImage()
// so theoretically it should be safe to remove the udpate here.
current_user_wallpaper_info_ = info;
if (!is_persistent)
return;
Expand Down Expand Up @@ -1170,8 +1173,8 @@ void WallpaperController::OnColorCalculationComplete() {
color_calculator_.reset();
// TODO(crbug.com/787134): The prominent colors of wallpapers with empty
// location should be cached as well.
if (!current_location_.empty())
CacheProminentColors(colors, current_location_);
if (!current_user_wallpaper_info_.location.empty())
CacheProminentColors(colors, current_user_wallpaper_info_.location);
SetProminentColors(colors);
}

Expand Down Expand Up @@ -1443,9 +1446,9 @@ void WallpaperController::CalculateWallpaperColors() {
color_calculator_.reset();
}

if (!current_location_.empty()) {
if (!current_user_wallpaper_info_.location.empty()) {
base::Optional<std::vector<SkColor>> cached_colors =
GetCachedColors(current_location_);
GetCachedColors(current_user_wallpaper_info_.location);
if (cached_colors.has_value()) {
SetProminentColors(cached_colors.value());
return;
Expand Down
9 changes: 3 additions & 6 deletions ash/wallpaper/wallpaper_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,9 @@ class ASH_EXPORT WallpaperController
// Caches the color profiles that need to do wallpaper color extracting.
const std::vector<color_utils::ColorProfile> color_profiles_;

// Cached logged-in user wallpaper info.
// Cached current user wallpaper info. Note its location is used as a key for
// storing |prominent_colors_| in the wallpaper::kWallpaperColors pref. An
// empty string disables color caching.
wallpaper::WallpaperInfo current_user_wallpaper_info_;

// Cached wallpapers of users.
Expand All @@ -558,11 +560,6 @@ class ASH_EXPORT WallpaperController
base::FilePath customized_default_wallpaper_small_;
base::FilePath customized_default_wallpaper_large_;

// Location (see WallpaperInfo::location) used by the current wallpaper.
// Used as a key for storing |prominent_colors_| in the
// wallpaper::kWallpaperColors pref. An empty string disables color caching.
std::string current_location_;

gfx::Size current_max_display_size_;

base::OneShotTimer timer_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ void WallpaperManager::ShowUserWallpaper(const AccountId& account_id) {
}

gfx::ImageSkia user_wallpaper;
*GetCachedWallpaperInfo() = info;
if (GetWallpaperFromCache(account_id, &user_wallpaper)) {
GetPendingWallpaper()->SetWallpaperFromImage(account_id, user_wallpaper,
info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,10 @@ IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, DevicePolicyTest) {
// Log in a test user and set the user wallpaper policy. The user policy
// controlled wallpaper shows up in the user session.
LoginUser(testUsers_[0]);
InjectPolicy(0, kGreenImageFileName);
RunUntilWallpaperChangeCount(3);

InjectPolicy(0, kGreenImageFileName);
RunUntilWallpaperChangeCount(4);
EXPECT_EQ(kGreenImageColor, GetAverageWallpaperColor());

// Set the device wallpaper policy inside the user session. That that the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ chrome.test.getConfig(function(config) {
'123',
pass(function(thumbnail) {
chrome.wallpaperPrivate.setCustomWallpaperLayout('CENTER',
pass(function() {
chrome.wallpaperPrivate.setCustomWallpaperLayout('STRETCH', pass());
}));
pass(function() {}));
}));
},
function setCustomPngWallpaper() {
Expand All @@ -77,8 +75,6 @@ chrome.test.getConfig(function(config) {
pass(function(thumbnail) {
chrome.wallpaperPrivate.setCustomWallpaperLayout('CENTER',
pass(function() {
chrome.wallpaperPrivate.setCustomWallpaperLayout('STRETCH',
pass());
}));
}));
} else {
Expand Down

0 comments on commit a12772b

Please sign in to comment.