| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/login/wallpaper_manager.h" | 5 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 123 } |
| 124 | 124 |
| 125 // static | 125 // static |
| 126 WallpaperManager* WallpaperManager::Get() { | 126 WallpaperManager* WallpaperManager::Get() { |
| 127 if (!g_wallpaper_manager) | 127 if (!g_wallpaper_manager) |
| 128 g_wallpaper_manager = new WallpaperManager(); | 128 g_wallpaper_manager = new WallpaperManager(); |
| 129 return g_wallpaper_manager; | 129 return g_wallpaper_manager; |
| 130 } | 130 } |
| 131 | 131 |
| 132 WallpaperManager::WallpaperManager() | 132 WallpaperManager::WallpaperManager() |
| 133 : no_observers_(true), | 133 : loaded_wallpapers_(0), |
| 134 loaded_wallpapers_(0), | |
| 135 wallpaper_loader_(new UserImageLoader(ImageDecoder::ROBUST_JPEG_CODEC)), | 134 wallpaper_loader_(new UserImageLoader(ImageDecoder::ROBUST_JPEG_CODEC)), |
| 136 command_line_for_testing_(NULL), | 135 command_line_for_testing_(NULL), |
| 137 should_cache_wallpaper_(false), | 136 should_cache_wallpaper_(false), |
| 138 weak_factory_(this) { | 137 weak_factory_(this) { |
| 139 registrar_.Add(this, | 138 registrar_.Add(this, |
| 140 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 139 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 141 content::NotificationService::AllSources()); | 140 content::NotificationService::AllSources()); |
| 142 registrar_.Add(this, | 141 registrar_.Add(this, |
| 143 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 142 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 144 content::NotificationService::AllSources()); | 143 content::NotificationService::AllSources()); |
| 145 registrar_.Add(this, | 144 registrar_.Add(this, |
| 146 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, | 145 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, |
| 147 content::NotificationService::AllSources()); | 146 content::NotificationService::AllSources()); |
| 148 sequence_token_ = BrowserThread::GetBlockingPool()-> | 147 sequence_token_ = BrowserThread::GetBlockingPool()-> |
| 149 GetNamedSequenceToken(kWallpaperSequenceTokenName); | 148 GetNamedSequenceToken(kWallpaperSequenceTokenName); |
| 150 task_runner_ = BrowserThread::GetBlockingPool()-> | 149 task_runner_ = BrowserThread::GetBlockingPool()-> |
| 151 GetSequencedTaskRunnerWithShutdownBehavior( | 150 GetSequencedTaskRunnerWithShutdownBehavior( |
| 152 sequence_token_, | 151 sequence_token_, |
| 153 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 152 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| 154 } | 153 } |
| 155 | 154 |
| 156 WallpaperManager::~WallpaperManager() { | 155 WallpaperManager::~WallpaperManager() { |
| 157 // TODO(bshe): Lifetime of WallpaperManager needs more consideration. | 156 // TODO(bshe): Lifetime of WallpaperManager needs more consideration. |
| 158 // http://crbug.com/171694 | 157 // http://crbug.com/171694 |
| 159 DCHECK(no_observers_); | 158 DCHECK(!show_user_name_on_signin_subscription_); |
| 160 ClearObsoleteWallpaperPrefs(); | 159 ClearObsoleteWallpaperPrefs(); |
| 161 weak_factory_.InvalidateWeakPtrs(); | 160 weak_factory_.InvalidateWeakPtrs(); |
| 162 } | 161 } |
| 163 | 162 |
| 164 void WallpaperManager::Shutdown() { | 163 void WallpaperManager::Shutdown() { |
| 165 CrosSettings::Get()->RemoveSettingsObserver( | 164 show_user_name_on_signin_subscription_.reset(); |
| 166 kAccountsPrefShowUserNamesOnSignIn, this); | |
| 167 no_observers_ = true; | |
| 168 } | 165 } |
| 169 | 166 |
| 170 // static | 167 // static |
| 171 void WallpaperManager::RegisterPrefs(PrefRegistrySimple* registry) { | 168 void WallpaperManager::RegisterPrefs(PrefRegistrySimple* registry) { |
| 172 registry->RegisterDictionaryPref(prefs::kUsersWallpaperInfo); | 169 registry->RegisterDictionaryPref(prefs::kUsersWallpaperInfo); |
| 173 registry->RegisterDictionaryPref(kUserWallpapers); | 170 registry->RegisterDictionaryPref(kUserWallpapers); |
| 174 registry->RegisterDictionaryPref(kUserWallpapersProperties); | 171 registry->RegisterDictionaryPref(kUserWallpapersProperties); |
| 175 } | 172 } |
| 176 | 173 |
| 177 void WallpaperManager::AddObservers() { | 174 void WallpaperManager::AddObservers() { |
| 178 CrosSettings::Get()->AddSettingsObserver(kAccountsPrefShowUserNamesOnSignIn, | 175 show_user_name_on_signin_subscription_ = |
| 179 this); | 176 CrosSettings::Get()->AddSettingsObserver( |
| 180 no_observers_ = false; | 177 kAccountsPrefShowUserNamesOnSignIn, |
| 178 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper, |
| 179 base::Unretained(this))); |
| 181 } | 180 } |
| 182 | 181 |
| 183 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { | 182 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { |
| 184 // Some browser tests do not have a shell instance. As no wallpaper is needed | 183 // Some browser tests do not have a shell instance. As no wallpaper is needed |
| 185 // in these tests anyway, avoid loading one, preventing crashes and speeding | 184 // in these tests anyway, avoid loading one, preventing crashes and speeding |
| 186 // up the tests. | 185 // up the tests. |
| 187 if (!ash::Shell::HasInstance()) | 186 if (!ash::Shell::HasInstance()) |
| 188 return; | 187 return; |
| 189 | 188 |
| 190 WallpaperInfo info; | 189 WallpaperInfo info; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 if (should_cache_wallpaper_) { | 302 if (should_cache_wallpaper_) { |
| 304 BrowserThread::PostDelayedTask( | 303 BrowserThread::PostDelayedTask( |
| 305 BrowserThread::UI, FROM_HERE, | 304 BrowserThread::UI, FROM_HERE, |
| 306 base::Bind(&WallpaperManager::CacheUsersWallpapers, | 305 base::Bind(&WallpaperManager::CacheUsersWallpapers, |
| 307 weak_factory_.GetWeakPtr()), | 306 weak_factory_.GetWeakPtr()), |
| 308 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); | 307 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); |
| 309 should_cache_wallpaper_ = false; | 308 should_cache_wallpaper_ = false; |
| 310 } | 309 } |
| 311 break; | 310 break; |
| 312 } | 311 } |
| 313 case chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED: { | |
| 314 if (*content::Details<const std::string>(details).ptr() == | |
| 315 kAccountsPrefShowUserNamesOnSignIn) { | |
| 316 InitializeRegisteredDeviceWallpaper(); | |
| 317 } | |
| 318 break; | |
| 319 } | |
| 320 default: | 312 default: |
| 321 NOTREACHED() << "Unexpected notification " << type; | 313 NOTREACHED() << "Unexpected notification " << type; |
| 322 } | 314 } |
| 323 } | 315 } |
| 324 | 316 |
| 325 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& email) { | 317 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& email) { |
| 326 PrefService* prefs = g_browser_process->local_state(); | 318 PrefService* prefs = g_browser_process->local_state(); |
| 327 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs, | 319 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs, |
| 328 prefs::kUsersWallpaperInfo); | 320 prefs::kUsersWallpaperInfo); |
| 329 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(email, NULL); | 321 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(email, NULL); |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 // |sequence_token_| here. | 967 // |sequence_token_| here. |
| 976 wallpaper_loader_->Start(wallpaper_path.value(), 0, sequence_token_, | 968 wallpaper_loader_->Start(wallpaper_path.value(), 0, sequence_token_, |
| 977 base::Bind(&WallpaperManager::OnWallpaperDecoded, | 969 base::Bind(&WallpaperManager::OnWallpaperDecoded, |
| 978 base::Unretained(this), | 970 base::Unretained(this), |
| 979 email, | 971 email, |
| 980 info.layout, | 972 info.layout, |
| 981 update_wallpaper)); | 973 update_wallpaper)); |
| 982 } | 974 } |
| 983 | 975 |
| 984 } // namespace chromeos | 976 } // namespace chromeos |
| OLD | NEW |