From e7ace3c7a13eecee1e757d22a70dd0ce4eb5b672 Mon Sep 17 00:00:00 2001 From: "bshe@chromium.org" Date: Mon, 17 Mar 2014 16:18:51 +0000 Subject: Invalidate all wallpaper cache if display configuration changed BUG=350406 Review URL: https://codereview.chromium.org/190993003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257440 0039d316-1c4b-4281-b951-d872f2087c98 --- ash/default_user_wallpaper_delegate.cc | 2 +- ash/default_user_wallpaper_delegate.h | 2 +- .../desktop_background_controller.cc | 2 +- ash/desktop_background/user_wallpaper_delegate.h | 9 +++- ash/test/test_user_wallpaper_delegate.cc | 4 +- ash/test/test_user_wallpaper_delegate.h | 2 +- .../background/ash_user_wallpaper_delegate.cc | 4 +- .../chromeos/extensions/wallpaper_private_api.cc | 2 +- chrome/browser/chromeos/login/wallpaper_manager.cc | 13 +++--- chrome/browser/chromeos/login/wallpaper_manager.h | 9 ++-- .../login/wallpaper_manager_browsertest.cc | 53 +++++++++++++++------- .../chromeos/login/wallpaper_manager_unittest.cc | 2 +- .../browser/ui/ash/user_wallpaper_delegate_win.cc | 4 +- 13 files changed, 67 insertions(+), 41 deletions(-) diff --git a/ash/default_user_wallpaper_delegate.cc b/ash/default_user_wallpaper_delegate.cc index 99c1d58..c6a5587e 100644 --- a/ash/default_user_wallpaper_delegate.cc +++ b/ash/default_user_wallpaper_delegate.cc @@ -26,7 +26,7 @@ bool DefaultUserWallpaperDelegate::ShouldShowInitialAnimation() { return false; } -void DefaultUserWallpaperDelegate::UpdateWallpaper() { +void DefaultUserWallpaperDelegate::UpdateWallpaper(bool clear_cache) { } void DefaultUserWallpaperDelegate::InitializeWallpaper() { diff --git a/ash/default_user_wallpaper_delegate.h b/ash/default_user_wallpaper_delegate.h index 9978738..ad7da6c 100644 --- a/ash/default_user_wallpaper_delegate.h +++ b/ash/default_user_wallpaper_delegate.h @@ -23,7 +23,7 @@ class ASH_EXPORT DefaultUserWallpaperDelegate : public UserWallpaperDelegate { virtual void SetAnimationDurationOverride( int animation_duration_in_ms) OVERRIDE; virtual bool ShouldShowInitialAnimation() OVERRIDE; - virtual void UpdateWallpaper() OVERRIDE; + virtual void UpdateWallpaper(bool clear_cache) OVERRIDE; virtual void InitializeWallpaper() OVERRIDE; virtual void OpenSetWallpaperPage() OVERRIDE; virtual bool CanOpenSetWallpaperPage() OVERRIDE; diff --git a/ash/desktop_background/desktop_background_controller.cc b/ash/desktop_background/desktop_background_controller.cc index daf104e..7673f29 100644 --- a/ash/desktop_background/desktop_background_controller.cc +++ b/ash/desktop_background/desktop_background_controller.cc @@ -448,7 +448,7 @@ void DesktopBackgroundController::UpdateWallpaper() { current_default_wallpaper_path_ = base::FilePath(); current_default_wallpaper_resource_id_ = -1; ash::Shell::GetInstance()->user_wallpaper_delegate()-> - UpdateWallpaper(); + UpdateWallpaper(true /* clear cache */); } // static diff --git a/ash/desktop_background/user_wallpaper_delegate.h b/ash/desktop_background/user_wallpaper_delegate.h index 16f2cf7..5e47ec0 100644 --- a/ash/desktop_background/user_wallpaper_delegate.h +++ b/ash/desktop_background/user_wallpaper_delegate.h @@ -30,8 +30,13 @@ class ASH_EXPORT UserWallpaperDelegate { virtual bool ShouldShowInitialAnimation() = 0; // Updates current wallpaper. It may switch the size of wallpaper based on the - // current display's resolution. - virtual void UpdateWallpaper() = 0; + // 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. virtual void InitializeWallpaper() = 0; diff --git a/ash/test/test_user_wallpaper_delegate.cc b/ash/test/test_user_wallpaper_delegate.cc index cbf1e9a..24ab287e 100644 --- a/ash/test/test_user_wallpaper_delegate.cc +++ b/ash/test/test_user_wallpaper_delegate.cc @@ -15,8 +15,8 @@ TestUserWallpaperDelegate::TestUserWallpaperDelegate() TestUserWallpaperDelegate::~TestUserWallpaperDelegate() {} -void TestUserWallpaperDelegate::UpdateWallpaper() { - DefaultUserWallpaperDelegate::UpdateWallpaper(); +void TestUserWallpaperDelegate::UpdateWallpaper(bool clear_cache) { + DefaultUserWallpaperDelegate::UpdateWallpaper(clear_cache); if (!custom_wallpaper_.isNull()) { Shell::GetInstance()->desktop_background_controller()->SetCustomWallpaper( custom_wallpaper_, WALLPAPER_LAYOUT_STRETCH); diff --git a/ash/test/test_user_wallpaper_delegate.h b/ash/test/test_user_wallpaper_delegate.h index 83c2583..aa92861 100644 --- a/ash/test/test_user_wallpaper_delegate.h +++ b/ash/test/test_user_wallpaper_delegate.h @@ -22,7 +22,7 @@ class TestUserWallpaperDelegate : public DefaultUserWallpaperDelegate { } // DefaultUserWallpaperDelegate overrides: - virtual void UpdateWallpaper() OVERRIDE; + virtual void UpdateWallpaper(bool clear_cache) OVERRIDE; // Returns and clears |update_wallpaper_count_|. int GetUpdateWallpaperCountAndReset(); diff --git a/chrome/browser/chromeos/background/ash_user_wallpaper_delegate.cc b/chrome/browser/chromeos/background/ash_user_wallpaper_delegate.cc index fd35a40..e86e223 100644 --- a/chrome/browser/chromeos/background/ash_user_wallpaper_delegate.cc +++ b/chrome/browser/chromeos/background/ash_user_wallpaper_delegate.cc @@ -77,8 +77,8 @@ class UserWallpaperDelegate : public ash::UserWallpaperDelegate { return true; } - virtual void UpdateWallpaper() OVERRIDE { - chromeos::WallpaperManager::Get()->UpdateWallpaper(); + virtual void UpdateWallpaper(bool clear_cache) OVERRIDE { + chromeos::WallpaperManager::Get()->UpdateWallpaper(clear_cache); } virtual void InitializeWallpaper() OVERRIDE { diff --git a/chrome/browser/chromeos/extensions/wallpaper_private_api.cc b/chrome/browser/chromeos/extensions/wallpaper_private_api.cc index 2b98284..fa4c567 100644 --- a/chrome/browser/chromeos/extensions/wallpaper_private_api.cc +++ b/chrome/browser/chromeos/extensions/wallpaper_private_api.cc @@ -631,7 +631,7 @@ bool WallpaperPrivateSetCustomWallpaperLayoutFunction::RunImpl() { bool is_persistent = !chromeos::UserManager::Get()->IsCurrentUserNonCryptohomeDataEphemeral(); wallpaper_manager->SetUserWallpaperInfo(email, info, is_persistent); - wallpaper_manager->UpdateWallpaper(); + wallpaper_manager->UpdateWallpaper(false /* clear_cache */); SendResponse(true); // Gets email address while at UI thread. diff --git a/chrome/browser/chromeos/login/wallpaper_manager.cc b/chrome/browser/chromeos/login/wallpaper_manager.cc index 84870fc..899f9c0 100644 --- a/chrome/browser/chromeos/login/wallpaper_manager.cc +++ b/chrome/browser/chromeos/login/wallpaper_manager.cc @@ -289,8 +289,8 @@ void WallpaperManager::TestApi::SetWallpaperCache(const std::string& user_id, wallpaper_manager_->wallpaper_cache_[user_id] = image; } -void WallpaperManager::TestApi::ClearWallpaperCache() { - wallpaper_manager_->ClearWallpaperCache(); +void WallpaperManager::TestApi::ClearDisposableWallpaperCache() { + wallpaper_manager_->ClearDisposableWallpaperCache(); } // static @@ -370,7 +370,7 @@ void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { SetUserWallpaperNow(UserManager::Get()->GetLoggedInUser()->email()); } -void WallpaperManager::ClearWallpaperCache() { +void WallpaperManager::ClearDisposableWallpaperCache() { // Cancel callback for previous cache requests. weak_factory_.InvalidateWeakPtrs(); if (!UserManager::IsMultipleProfilesAllowed()) { @@ -467,7 +467,7 @@ void WallpaperManager::Observe(int type, DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); switch (type) { case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { - ClearWallpaperCache(); + ClearDisposableWallpaperCache(); BrowserThread::PostDelayedTask( BrowserThread::UI, FROM_HERE, @@ -887,8 +887,9 @@ void WallpaperManager::SetWallpaperFromImageSkia( } } -void WallpaperManager::UpdateWallpaper() { - ClearWallpaperCache(); +void WallpaperManager::UpdateWallpaper(bool clear_cache) { + if (clear_cache) + wallpaper_cache_.clear(); current_wallpaper_path_.clear(); // For GAIA login flow, the last_selected_user_ may not be set before user // login. If UpdateWallpaper is called at GAIA login screen, no wallpaper will diff --git a/chrome/browser/chromeos/login/wallpaper_manager.h b/chrome/browser/chromeos/login/wallpaper_manager.h index ff6b90a..56b5433 100644 --- a/chrome/browser/chromeos/login/wallpaper_manager.h +++ b/chrome/browser/chromeos/login/wallpaper_manager.h @@ -86,7 +86,7 @@ class WallpaperManager: public content::NotificationObserver { void SetWallpaperCache(const std::string& user_id, const gfx::ImageSkia& image); - void ClearWallpaperCache(); + void ClearDisposableWallpaperCache(); private: WallpaperManager* wallpaper_manager_; // not owned @@ -189,8 +189,9 @@ class WallpaperManager: public content::NotificationObserver { // wallpaper of logged in user. void EnsureLoggedInUserWallpaperLoaded(); - // Clears ONLINE and CUSTOM wallpaper cache. - void ClearWallpaperCache(); + // Clears disposable ONLINE and CUSTOM wallpaper cache. At multi profile + // world, logged in users' wallpaper cache is not disposable. + void ClearDisposableWallpaperCache(); // Returns custom wallpaper path. Append |sub_dir|, |user_id_hash| and |file| // to custom wallpaper directory. @@ -280,7 +281,7 @@ class WallpaperManager: public content::NotificationObserver { // Updates current wallpaper. It may switch the size of wallpaper based on the // current display's resolution. (asynchronously with zero delay) - void UpdateWallpaper(); + void UpdateWallpaper(bool clear_cache); // Adds given observer to the list. void AddObserver(Observer* observer); diff --git a/chrome/browser/chromeos/login/wallpaper_manager_browsertest.cc b/chrome/browser/chromeos/login/wallpaper_manager_browsertest.cc index 22e6a63..4647619 100644 --- a/chrome/browser/chromeos/login/wallpaper_manager_browsertest.cc +++ b/chrome/browser/chromeos/login/wallpaper_manager_browsertest.cc @@ -53,7 +53,8 @@ const char kTestUser2Hash[] = "test2@domain.com-hash"; } // namespace class WallpaperManagerBrowserTest : public InProcessBrowserTest, - public DesktopBackgroundControllerObserver { + public DesktopBackgroundControllerObserver, + public testing::WithParamInterface { public: WallpaperManagerBrowserTest () : controller_(NULL), local_state_(NULL) { @@ -71,6 +72,8 @@ class WallpaperManagerBrowserTest : public InProcessBrowserTest, virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { command_line->AppendSwitch(switches::kLoginManager); command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); + if (GetParam()) + command_line->AppendSwitch(::switches::kMultiProfiles); } virtual void CleanUpOnMainThread() OVERRIDE { @@ -150,7 +153,7 @@ class WallpaperManagerBrowserTest : public InProcessBrowserTest, // Tests that the appropriate custom wallpaper (large vs. small) is loaded // depending on the desktop resolution. -IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, +IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, LoadCustomLargeWallpaperForLargeExternalScreen) { WallpaperManager* wallpaper_manager = WallpaperManager::Get(); LogIn(kTestUser1, kTestUser1Hash); @@ -226,7 +229,7 @@ IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, // If chrome tries to reload the same wallpaper twice, the latter request should // be prevented. Otherwise, there are some strange animation issues as // described in crbug.com/158383. -IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, +IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, PreventReloadingSameWallpaper) { WallpaperManager* wallpaper_manager = WallpaperManager::Get(); // New user log in, a default wallpaper is loaded. @@ -242,7 +245,7 @@ IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, wallpaper_manager->SetUserWallpaperNow(kTestUser1); WaitAsyncWallpaperLoadFinished(); EXPECT_EQ(1, LoadedWallpapers()); - wallpaper_manager->ClearWallpaperCache(); + wallpaper_manager->ClearDisposableWallpaperCache(); // Change wallpaper to a custom wallpaper. std::string id = base::Int64ToString(base::Time::Now().ToInternalValue()); @@ -280,7 +283,7 @@ IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, // lagacy wallpapers should migrate to new wallpaper picker version seamlessly. // This tests make sure we compatible with migrated old wallpapers. // crosbug.com/38429 -IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, +IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, PRE_UseMigratedWallpaperInfo) { // New user log in, a default wallpaper is loaded. LogIn(kTestUser1, kTestUser1Hash); @@ -300,7 +303,7 @@ IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, WallpaperManager::Get()->SetUserWallpaperInfo(kTestUser1, info, true); } -IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, +IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, UseMigratedWallpaperInfo) { LogIn(kTestUser1, kTestUser1Hash); WaitAsyncWallpaperLoadFinished(); @@ -311,7 +314,7 @@ IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, // Some users have old user profiles which may never get a chance to migrate. // This tests make sure we compatible with these profiles. -IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, +IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, PRE_UsePreMigrationWallpaperInfo) { // New user log in, a default wallpaper is loaded. LogIn(kTestUser1, kTestUser1Hash); @@ -321,7 +324,7 @@ IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, WallpaperManager::Get()->RemoveUserWallpaperInfo(kTestUser1); } -IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, +IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, UsePreMigrationWallpaperInfo) { LogIn(kTestUser1, kTestUser1Hash); WaitAsyncWallpaperLoadFinished(); @@ -331,7 +334,7 @@ IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, // Test for http://crbug.com/265689. When hooked up a large external monitor, // the default large resolution wallpaper should load. -IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, +IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, HotPlugInScreenAtGAIALoginScreen) { UpdateDisplay("800x600"); // Set initial wallpaper to the default wallpaper. @@ -357,7 +360,7 @@ class WallpaperManagerBrowserTestNoAnimation // Same test as WallpaperManagerBrowserTest.UseMigratedWallpaperInfo. But // disabled boot and login animation. -IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation, +IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestNoAnimation, PRE_UseMigratedWallpaperInfo) { // New user log in, a default wallpaper is loaded. LogIn(kTestUser1, kTestUser1Hash); @@ -377,7 +380,7 @@ IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation, WallpaperManager::Get()->SetUserWallpaperInfo(kTestUser1, info, true); } -IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation, +IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestNoAnimation, UseMigratedWallpaperInfo) { LogIn(kTestUser1, kTestUser1Hash); WaitAsyncWallpaperLoadFinished(); @@ -388,7 +391,7 @@ IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation, // Same test as WallpaperManagerBrowserTest.UsePreMigrationWallpaperInfo. But // disabled boot and login animation. -IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation, +IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestNoAnimation, PRE_UsePreMigrationWallpaperInfo) { // New user log in, a default wallpaper is loaded. LogIn(kTestUser1, kTestUser1Hash); @@ -399,7 +402,7 @@ IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation, WallpaperManager::Get()->RemoveUserWallpaperInfo(kTestUser1); } -IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation, +IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestNoAnimation, UsePreMigrationWallpaperInfo) { LogIn(kTestUser1, kTestUser1Hash); WaitAsyncWallpaperLoadFinished(); @@ -420,7 +423,7 @@ class WallpaperManagerBrowserTestCrashRestore } }; -IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCrashRestore, +IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestCrashRestore, PRE_RestoreWallpaper) { LogIn(kTestUser1, kTestUser1Hash); WaitAsyncWallpaperLoadFinished(); @@ -428,7 +431,7 @@ IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCrashRestore, // Test for crbug.com/270278. It simulates a browser crash and verifies if user // wallpaper is loaded. -IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCrashRestore, +IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestCrashRestore, RestoreWallpaper) { EXPECT_EQ(1, LoadedWallpapers()); } @@ -454,7 +457,7 @@ class WallpaperManagerBrowserTestCacheUpdate }; // Sets kTestUser1's wallpaper to a custom wallpaper. -IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCacheUpdate, +IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestCacheUpdate, PRE_VerifyWallpaperCache) { // Add kTestUser1 to user list. kTestUser1 is the default login profile. LogIn(kTestUser1, kTestUser1Hash); @@ -504,7 +507,7 @@ IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCacheUpdate, // 3. reverts to a default wallpaper. // Also, when user login at multi-profile mode, previous logged in users' // wallpaper cache should not be deleted. -IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCacheUpdate, +IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestCacheUpdate, VerifyWallpaperCache) { WaitAsyncWallpaperLoadFinished(); WallpaperManager* wallpaper_manager = WallpaperManager::Get(); @@ -552,4 +555,20 @@ IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCacheUpdate, EXPECT_FALSE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); } +INSTANTIATE_TEST_CASE_P(WallpaperManagerBrowserTestInstantiation, + WallpaperManagerBrowserTest, + testing::Bool()); + +INSTANTIATE_TEST_CASE_P(WallpaperManagerBrowserTestNoAnimationInstantiation, + WallpaperManagerBrowserTestNoAnimation, + testing::Bool()); + +INSTANTIATE_TEST_CASE_P(WallpaperManagerBrowserTestCrashRestoreInstantiation, + WallpaperManagerBrowserTestCrashRestore, + testing::Bool()); + +INSTANTIATE_TEST_CASE_P(WallpaperManagerBrowserTestCacheUpdateInstantiation, + WallpaperManagerBrowserTestCacheUpdate, + testing::Bool()); + } // namespace chromeos diff --git a/chrome/browser/chromeos/login/wallpaper_manager_unittest.cc b/chrome/browser/chromeos/login/wallpaper_manager_unittest.cc index 3fd40e4..c477456 100644 --- a/chrome/browser/chromeos/login/wallpaper_manager_unittest.cc +++ b/chrome/browser/chromeos/login/wallpaper_manager_unittest.cc @@ -186,7 +186,7 @@ TEST_F(WallpaperManagerCacheTest, VerifyWallpaperCache) { test_api->SetWallpaperCache(test_user_2, test_user_2_wallpaper); test_api->SetWallpaperCache(test_user_3, test_user_3_wallpaper); - test_api->ClearWallpaperCache(); + test_api->ClearDisposableWallpaperCache(); gfx::ImageSkia cached_wallpaper; EXPECT_TRUE(test_api->GetWallpaperFromCache(test_user_1, &cached_wallpaper)); diff --git a/chrome/browser/ui/ash/user_wallpaper_delegate_win.cc b/chrome/browser/ui/ash/user_wallpaper_delegate_win.cc index 2c040bd..c058b59 100644 --- a/chrome/browser/ui/ash/user_wallpaper_delegate_win.cc +++ b/chrome/browser/ui/ash/user_wallpaper_delegate_win.cc @@ -44,7 +44,7 @@ class UserWallpaperDelegate : public ash::UserWallpaperDelegate { NOTIMPLEMENTED(); } - virtual void UpdateWallpaper() OVERRIDE { + virtual void UpdateWallpaper(bool clear_cache) OVERRIDE { SkBitmap bitmap; bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); bitmap.allocPixels(); @@ -63,7 +63,7 @@ class UserWallpaperDelegate : public ash::UserWallpaperDelegate { } virtual void InitializeWallpaper() OVERRIDE { - UpdateWallpaper(); + UpdateWallpaper(false); } virtual void OpenSetWallpaperPage() OVERRIDE { -- cgit v1.1