Chromium Code Reviews| Index: chrome/browser/chromeos/login/wallpaper_manager.cc |
| diff --git a/chrome/browser/chromeos/login/wallpaper_manager.cc b/chrome/browser/chromeos/login/wallpaper_manager.cc |
| index 1543c1e06c49f1ac87500d5e1bb3bb7c1851281f..6d97aff56cdb09bfc8f9c632eb1d8000bc02034a 100644 |
| --- a/chrome/browser/chromeos/login/wallpaper_manager.cc |
| +++ b/chrome/browser/chromeos/login/wallpaper_manager.cc |
| @@ -47,6 +47,8 @@ const char kWallpaperDateNodeName[] = "date"; |
| const int kThumbnailWidth = 128; |
| const int kThumbnailHeight = 80; |
| +const int kCacheWallpaperDelayMs = 500; |
| + |
| // Default wallpaper index used in OOBE (first boot). |
| // Defined here because Chromium default index differs. |
| // Also see ash::WallpaperInfo kDefaultWallpapers in |
| @@ -83,11 +85,15 @@ WallpaperManager::WallpaperManager() |
| current_user_wallpaper_type_(User::UNKNOWN), |
| ALLOW_THIS_IN_INITIALIZER_LIST(current_user_wallpaper_index_( |
| ash::GetInvalidWallpaperIndex())), |
| + should_cache_wallpaper_(false), |
| ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| RestartTimer(); |
| registrar_.Add(this, |
| chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| content::NotificationService::AllSources()); |
| + registrar_.Add(this, |
| + chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, |
| + content::NotificationService::AllSources()); |
| } |
| // static |
| @@ -102,21 +108,6 @@ void WallpaperManager::AddObservers() { |
| system::TimezoneSettings::GetInstance()->AddObserver(this); |
| } |
| -void WallpaperManager::CacheIfCustomWallpaper(const std::string& email) { |
| - User::WallpaperType type; |
| - int index; |
| - base::Time date; |
| - GetUserWallpaperProperties(email, &type, &index, &date); |
| - if (type == User::CUSTOMIZED) { |
| - std::string wallpaper_path = GetWallpaperPathForUser(email, false).value(); |
| - |
| - // Uses WeakPtr here to make the request cancelable. |
| - wallpaper_loader_->Start(wallpaper_path, 0, |
| - base::Bind(&WallpaperManager::CacheWallpaper, |
| - weak_factory_.GetWeakPtr(), email)); |
| - } |
| -} |
| - |
| void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { |
| User::WallpaperType type; |
| int index; |
| @@ -228,10 +219,28 @@ void WallpaperManager::Observe(int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { |
| - // Cancel callback for previous cache requests. |
| - weak_factory_.InvalidateWeakPtrs(); |
| - custom_wallpaper_cache_.clear(); |
| + switch (type) { |
| + case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { |
| + // Cancel callback for previous cache requests. |
| + weak_factory_.InvalidateWeakPtrs(); |
| + custom_wallpaper_cache_.clear(); |
| + break; |
| + } |
| + case chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE: { |
| + if (!CommandLine::ForCurrentProcess()-> |
| + HasSwitch(switches::kDisableBootAnimation)) { |
| + BrowserThread::PostDelayedTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind(&WallpaperManager::CacheAllUsersWallpapers, |
| + weak_factory_.GetWeakPtr()), |
| + base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); |
| + } else { |
| + should_cache_wallpaper_ = true; |
| + } |
| + break; |
| + } |
| + default: |
| + NOTREACHED() << "Unexpected notification " << type; |
| } |
| } |
| @@ -387,6 +396,14 @@ void WallpaperManager::OnUserDeselected() { |
| void WallpaperManager::OnUserSelected(const std::string& email) { |
| SetUserWallpaper(email); |
| + if (should_cache_wallpaper_) { |
| + BrowserThread::PostDelayedTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind(&WallpaperManager::CacheAllUsersWallpapers, |
|
Nikita (slow)
2012/08/06 16:36:01
We should no cache all users wallpapers when singl
bshe
2012/08/07 15:18:57
It should be a single time operation. The only tim
|
| + weak_factory_.GetWeakPtr()), |
| + base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); |
| + should_cache_wallpaper_ = false; |
| + } |
| } |
| // WallpaperManager, private: -------------------------------------------------- |
| @@ -431,6 +448,45 @@ void WallpaperManager::BatchUpdateWallpaper() { |
| RestartTimer(); |
| } |
| +void CacheAllUsersWallpapers() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + if (!users_.empty()) |
| + return; |
| + if (!g_browser_process) |
| + return; |
| + |
| + PrefService* local_state = g_browser_process->local_state(); |
|
Nikita (slow)
2012/08/06 16:36:01
Use user_manager->GetUsers() instead.
bshe
2012/08/07 15:18:57
Done.
|
| + |
| + const ListValue* prefs_users = |
| + local_state->GetList(UserManager::kLoggedInUsers); |
| + |
| + if (prefs_users) { |
| + ListValue::const_iterator it = prefs_users->begin(); |
| + it++; |
| + for (; it != prefs_users->end(); ++it) { |
| + CacheUserWallpaper(email); |
| + } |
| + } |
| +} |
| + |
| +void WallpaperManager::CacheUserWallpaper(const std::string& email) { |
| + User::WallpaperType type; |
| + int index; |
| + base::Time date; |
| + GetUserWallpaperProperties(email, &type, &index, &date); |
| + if (type == User::CUSTOMIZED) { |
| + std::string wallpaper_path = GetWallpaperPathForUser(email, false).value(); |
| + |
| + // Uses WeakPtr here to make the request cancelable. |
| + wallpaper_loader_->Start(wallpaper_path, 0, |
| + base::Bind(&WallpaperManager::CacheWallpaper, |
| + weak_factory_.GetWeakPtr(), email)); |
| + } else { |
| + ash::Shell::GetInstance()->desktop_background_controller()-> |
| + TriggerCacheDefaultWallpaper(index); |
| + } |
| +} |
| + |
| void WallpaperManager::CacheWallpaper(const std::string& email, |
| const UserImage& wallpaper) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| @@ -466,6 +522,7 @@ void WallpaperManager::FetchWallpaper(const std::string& email, |
| base::Bind(&WallpaperManager::CacheThumbnail, |
| base::Unretained(this), email, wallpaper.image())); |
| + custom_wallpaper_cache_.insert(std::make_pair(email, wallpaper.image())); |
| ash::Shell::GetInstance()->desktop_background_controller()-> |
| SetCustomWallpaper(wallpaper.image(), layout); |
| } |