Commit f5402766 authored by Wenzhao Zang's avatar Wenzhao Zang Committed by Commit Bot

cros: Ephemeral user's wallpaper should be kept within the session

When ephemeral user selects a new wallpaper, it's not saved to disk.
But we should still be able to keep this wallpaper before user logout.
The wallpaper is already cached in memory, but we ignored the cache for
ephemeral users: so when lock screen or wallpaper app calls
ShowUserWallpaper, it always thinks that ephemeral users never set a
wallpaper and then display the default wallpaper.

Bug: 825237, 902327
Change-Id: Id9a811c91243b04c7459f3ee20569ec4fdff14b0
Reviewed-on: https://chromium-review.googlesource.com/c/1343105
Commit-Queue: Wenzhao (Colin) Zang <wzang@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609844}
parent 1fdbc832
...@@ -1139,17 +1139,6 @@ void WallpaperController::ShowUserWallpaper( ...@@ -1139,17 +1139,6 @@ void WallpaperController::ShowUserWallpaper(
const AccountId account_id = current_user_->account_id; const AccountId account_id = current_user_->account_id;
const bool is_ephemeral = current_user_->is_ephemeral; const bool is_ephemeral = current_user_->is_ephemeral;
// Guest user or regular user in ephemeral mode.
if ((is_ephemeral && current_user_->has_gaia_account) ||
current_user_->type == user_manager::USER_TYPE_GUEST) {
if (!InitializeUserWallpaperInfo(account_id, is_ephemeral))
return;
SetDefaultWallpaperImpl(account_id, current_user_->type,
/*show_wallpaper=*/true);
VLOG(1) << "User is ephemeral. Fallback to default wallpaper.";
return;
}
WallpaperInfo info; WallpaperInfo info;
if (!GetUserWallpaperInfo(account_id, &info, is_ephemeral)) { if (!GetUserWallpaperInfo(account_id, &info, is_ephemeral)) {
if (!InitializeUserWallpaperInfo(account_id, is_ephemeral)) if (!InitializeUserWallpaperInfo(account_id, is_ephemeral))
...@@ -1157,14 +1146,20 @@ void WallpaperController::ShowUserWallpaper( ...@@ -1157,14 +1146,20 @@ void WallpaperController::ShowUserWallpaper(
GetUserWallpaperInfo(account_id, &info, is_ephemeral); GetUserWallpaperInfo(account_id, &info, is_ephemeral);
} }
// For ephemeral users, the cache is the only place to access their wallpaper
// because it is not saved to disk. If the image doesn't exist in cache, it
// means the user's wallpaper type is default (i.e. the user never sets their
// own wallpaper), and it's a bug if it's not.
//
// For regular users, the image will be read from disk if the cache is not
// hit (e.g. when the first time the wallpaper is shown on login screen).
gfx::ImageSkia user_wallpaper; gfx::ImageSkia user_wallpaper;
if (GetWallpaperFromCache(account_id, &user_wallpaper)) { if (GetWallpaperFromCache(account_id, &user_wallpaper)) {
ShowWallpaperImage(user_wallpaper, info, /*preview_mode=*/false); ShowWallpaperImage(user_wallpaper, info, /*preview_mode=*/false);
return; return;
} }
if (info.location.empty()) { if (info.type == DEFAULT) {
// Uses default wallpaper when file is empty.
SetDefaultWallpaperImpl(account_id, current_user_->type, SetDefaultWallpaperImpl(account_id, current_user_->type,
/*show_wallpaper=*/true); /*show_wallpaper=*/true);
return; return;
......
...@@ -2425,6 +2425,50 @@ TEST_F(WallpaperControllerTest, OnFirstWallpaperShown) { ...@@ -2425,6 +2425,50 @@ TEST_F(WallpaperControllerTest, OnFirstWallpaperShown) {
controller_->RemoveObserver(&observer); controller_->RemoveObserver(&observer);
} }
// Although ephemeral users' custom wallpapers are not saved to disk, they
// should be kept within the user session. Test for https://crbug.com/825237.
TEST_F(WallpaperControllerTest, ShowWallpaperForEphemeralUser) {
auto initialize_ephemeral_user = [&](const AccountId& account_id) {
mojom::WallpaperUserInfoPtr wallpaper_user_info =
InitializeUser(account_id);
wallpaper_user_info->is_ephemeral = true;
return wallpaper_user_info;
};
SimulateUserLogin(kUser1);
// The user doesn't have wallpaper cache in the beginning.
gfx::ImageSkia cached_wallpaper;
EXPECT_FALSE(
controller_->GetWallpaperFromCache(account_id_1, &cached_wallpaper));
base::FilePath path;
EXPECT_FALSE(controller_->GetPathFromCache(account_id_1, &path));
controller_->SetCustomWallpaper(
initialize_ephemeral_user(account_id_1), wallpaper_files_id_1,
file_name_1, WALLPAPER_LAYOUT_CENTER,
CreateImage(640, 480, kWallpaperColor), /*preview_mode=*/false);
RunAllTasksUntilIdle();
EXPECT_EQ(1, GetWallpaperCount());
EXPECT_EQ(CUSTOMIZED, controller_->GetWallpaperType());
EXPECT_EQ(kWallpaperColor, GetWallpaperColor());
// The custom wallpaper is cached.
EXPECT_TRUE(
controller_->GetWallpaperFromCache(account_id_1, &cached_wallpaper));
EXPECT_EQ(
kWallpaperColor,
cached_wallpaper.GetRepresentation(1.0f).GetBitmap().getColor(0, 0));
EXPECT_TRUE(controller_->GetPathFromCache(account_id_1, &path));
// Calling |ShowUserWallpaper| will continue showing the custom wallpaper
// instead of reverting to the default.
controller_->ShowUserWallpaper(initialize_ephemeral_user(account_id_1));
RunAllTasksUntilIdle();
EXPECT_EQ(0, GetWallpaperCount());
EXPECT_EQ(CUSTOMIZED, controller_->GetWallpaperType());
EXPECT_EQ(kWallpaperColor, GetWallpaperColor());
}
// A test wallpaper controller client class. // A test wallpaper controller client class.
class TestWallpaperControllerClient : public mojom::WallpaperControllerClient { class TestWallpaperControllerClient : public mojom::WallpaperControllerClient {
public: public:
......
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