Commit 02428591 authored by xdai's avatar xdai Committed by Commit Bot

wallpaper refactoring: update |current_user_wallpaper_info_| when setting wallpaper.

Bug: 794780
Change-Id: I1696b84bb4987ab5ccf5c91525a195b110befa70
Reviewed-on: https://chromium-review.googlesource.com/829881
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Reviewed-by: default avatarWenzhao (Colin) Zang <wzang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#525098}
parent c93669df
...@@ -506,6 +506,7 @@ void WallpaperController::SetCustomizedDefaultWallpaperImpl( ...@@ -506,6 +506,7 @@ void WallpaperController::SetCustomizedDefaultWallpaperImpl(
void WallpaperController::SetWallpaperImage(const gfx::ImageSkia& image, void WallpaperController::SetWallpaperImage(const gfx::ImageSkia& image,
const WallpaperInfo& info) { const WallpaperInfo& info) {
current_user_wallpaper_info_ = info;
wallpaper::WallpaperLayout layout = info.layout; wallpaper::WallpaperLayout layout = info.layout;
VLOG(1) << "SetWallpaper: image_id=" VLOG(1) << "SetWallpaper: image_id="
<< wallpaper::WallpaperResizer::GetImageId(image) << wallpaper::WallpaperResizer::GetImageId(image)
...@@ -516,7 +517,6 @@ void WallpaperController::SetWallpaperImage(const gfx::ImageSkia& image, ...@@ -516,7 +517,6 @@ void WallpaperController::SetWallpaperImage(const gfx::ImageSkia& image,
return; return;
} }
current_location_ = info.location;
// Cancel any in-flight color calculation because we have a new wallpaper. // Cancel any in-flight color calculation because we have a new wallpaper.
if (color_calculator_) { if (color_calculator_) {
color_calculator_->RemoveObserver(this); color_calculator_->RemoveObserver(this);
...@@ -664,6 +664,9 @@ bool WallpaperController::IsBlurEnabled() const { ...@@ -664,6 +664,9 @@ bool WallpaperController::IsBlurEnabled() const {
void WallpaperController::SetUserWallpaperInfo(const AccountId& account_id, void WallpaperController::SetUserWallpaperInfo(const AccountId& account_id,
const WallpaperInfo& info, const WallpaperInfo& info,
bool is_persistent) { 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; current_user_wallpaper_info_ = info;
if (!is_persistent) if (!is_persistent)
return; return;
...@@ -906,8 +909,8 @@ void WallpaperController::OnColorCalculationComplete() { ...@@ -906,8 +909,8 @@ void WallpaperController::OnColorCalculationComplete() {
color_calculator_.reset(); color_calculator_.reset();
// TODO(crbug.com/787134): The prominent colors of wallpapers with empty // TODO(crbug.com/787134): The prominent colors of wallpapers with empty
// location should be cached as well. // location should be cached as well.
if (!current_location_.empty()) if (!current_user_wallpaper_info_.location.empty())
CacheProminentColors(colors, current_location_); CacheProminentColors(colors, current_user_wallpaper_info_.location);
SetProminentColors(colors); SetProminentColors(colors);
} }
...@@ -1117,9 +1120,9 @@ void WallpaperController::CalculateWallpaperColors() { ...@@ -1117,9 +1120,9 @@ void WallpaperController::CalculateWallpaperColors() {
color_calculator_.reset(); color_calculator_.reset();
} }
if (!current_location_.empty()) { if (!current_user_wallpaper_info_.location.empty()) {
base::Optional<std::vector<SkColor>> cached_colors = base::Optional<std::vector<SkColor>> cached_colors =
GetCachedColors(current_location_); GetCachedColors(current_user_wallpaper_info_.location);
if (cached_colors.has_value()) { if (cached_colors.has_value()) {
SetProminentColors(cached_colors.value()); SetProminentColors(cached_colors.value());
return; return;
......
...@@ -460,7 +460,9 @@ class ASH_EXPORT WallpaperController ...@@ -460,7 +460,9 @@ class ASH_EXPORT WallpaperController
// Caches the color profiles that need to do wallpaper color extracting. // Caches the color profiles that need to do wallpaper color extracting.
const std::vector<color_utils::ColorProfile> color_profiles_; 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_; wallpaper::WallpaperInfo current_user_wallpaper_info_;
// Cached wallpapers of users. // Cached wallpapers of users.
...@@ -473,11 +475,6 @@ class ASH_EXPORT WallpaperController ...@@ -473,11 +475,6 @@ class ASH_EXPORT WallpaperController
base::FilePath customized_default_wallpaper_small_; base::FilePath customized_default_wallpaper_small_;
base::FilePath customized_default_wallpaper_large_; 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_; gfx::Size current_max_display_size_;
base::OneShotTimer timer_; base::OneShotTimer timer_;
......
...@@ -790,7 +790,6 @@ void WallpaperManager::ShowUserWallpaper(const AccountId& account_id) { ...@@ -790,7 +790,6 @@ void WallpaperManager::ShowUserWallpaper(const AccountId& account_id) {
} }
gfx::ImageSkia user_wallpaper; gfx::ImageSkia user_wallpaper;
*GetCachedWallpaperInfo() = info;
if (GetWallpaperFromCache(account_id, &user_wallpaper)) { if (GetWallpaperFromCache(account_id, &user_wallpaper)) {
GetPendingWallpaper()->SetWallpaperFromImage(account_id, user_wallpaper, GetPendingWallpaper()->SetWallpaperFromImage(account_id, user_wallpaper,
info); info);
......
...@@ -489,8 +489,10 @@ IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, DevicePolicyTest) { ...@@ -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 // Log in a test user and set the user wallpaper policy. The user policy
// controlled wallpaper shows up in the user session. // controlled wallpaper shows up in the user session.
LoginUser(testUsers_[0]); LoginUser(testUsers_[0]);
InjectPolicy(0, kGreenImageFileName);
RunUntilWallpaperChangeCount(3); RunUntilWallpaperChangeCount(3);
InjectPolicy(0, kGreenImageFileName);
RunUntilWallpaperChangeCount(4);
EXPECT_EQ(kGreenImageColor, GetAverageWallpaperColor()); EXPECT_EQ(kGreenImageColor, GetAverageWallpaperColor());
// Set the device wallpaper policy inside the user session. That that the // Set the device wallpaper policy inside the user session. That that the
......
...@@ -57,10 +57,14 @@ chrome.test.getConfig(function(config) { ...@@ -57,10 +57,14 @@ chrome.test.getConfig(function(config) {
true, true,
'123', '123',
pass(function(thumbnail) { pass(function(thumbnail) {
chrome.wallpaperPrivate.setCustomWallpaperLayout('CENTER', // The current wallpaper might have not changed when |thumbnail| data is
pass(function() { // passed back. Allow the async setWallpaper task to finish.
chrome.wallpaperPrivate.setCustomWallpaperLayout('STRETCH', pass()); setTimeout(function() {
})); chrome.wallpaperPrivate.setCustomWallpaperLayout(
'CENTER', pass(function() {
chrome.wallpaperPrivate.setCustomWallpaperLayout('STRETCH', pass());
}));
}, 500);
})); }));
}, },
function setCustomPngWallpaper() { function setCustomPngWallpaper() {
...@@ -75,11 +79,15 @@ chrome.test.getConfig(function(config) { ...@@ -75,11 +79,15 @@ chrome.test.getConfig(function(config) {
true, true,
'123', '123',
pass(function(thumbnail) { pass(function(thumbnail) {
chrome.wallpaperPrivate.setCustomWallpaperLayout('CENTER', // The current wallpaper might have not changed when |thumbnail|
pass(function() { // data is passed back. Allow the async setWallpaper task to finish.
chrome.wallpaperPrivate.setCustomWallpaperLayout('STRETCH', setTimeout(function() {
pass()); chrome.wallpaperPrivate.setCustomWallpaperLayout(
})); 'CENTER', pass(function() {
chrome.wallpaperPrivate.setCustomWallpaperLayout(
'STRETCH', pass());
}));
}, 500);
})); }));
} else { } else {
chrome.test.fail('Failed to load test.png from local server.'); chrome.test.fail('Failed to load test.png from local server.');
......
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