Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/users/wallpaper/wallpaper_manager.h" | 5 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 6 | 6 |
| 7 #include <numeric> | 7 #include <numeric> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/ash_constants.h" | 10 #include "ash/ash_constants.h" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 // image will be loaded. | 264 // image will be loaded. |
| 265 wallpaper::MovableOnDestroyCallbackHolder on_finish_; | 265 wallpaper::MovableOnDestroyCallbackHolder on_finish_; |
| 266 base::OneShotTimer<WallpaperManager::PendingWallpaper> timer; | 266 base::OneShotTimer<WallpaperManager::PendingWallpaper> timer; |
| 267 | 267 |
| 268 // Load start time to calculate duration. | 268 // Load start time to calculate duration. |
| 269 base::Time started_load_at_; | 269 base::Time started_load_at_; |
| 270 | 270 |
| 271 DISALLOW_COPY_AND_ASSIGN(PendingWallpaper); | 271 DISALLOW_COPY_AND_ASSIGN(PendingWallpaper); |
| 272 }; | 272 }; |
| 273 | 273 |
| 274 static WallpaperManager* g_wallpaper_manager = NULL; | 274 static WallpaperManager* g_wallpaper_manager = NULL; |
|
oshima
2015/03/13 22:16:41
move this to anonymous namespace, remove static, r
| |
| 275 | 275 |
| 276 // WallpaperManager, public: --------------------------------------------------- | 276 // WallpaperManager, public: --------------------------------------------------- |
| 277 | 277 |
| 278 // static | |
| 279 WallpaperManager* WallpaperManager::Get() { | |
| 280 if (!g_wallpaper_manager) | |
| 281 g_wallpaper_manager = new WallpaperManager(); | |
| 282 return g_wallpaper_manager; | |
| 283 } | |
| 284 | |
| 285 WallpaperManager::WallpaperManager() | |
| 286 : pending_inactive_(NULL), weak_factory_(this) { | |
| 287 wallpaper::WallpaperManagerBase::SetPathIds( | |
| 288 chrome::DIR_USER_DATA, | |
| 289 chrome::DIR_CHROMEOS_WALLPAPERS, | |
| 290 chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS); | |
| 291 SetDefaultWallpaperPathsFromCommandLine( | |
| 292 base::CommandLine::ForCurrentProcess()); | |
| 293 registrar_.Add(this, | |
| 294 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | |
| 295 content::NotificationService::AllSources()); | |
| 296 registrar_.Add(this, | |
| 297 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | |
| 298 content::NotificationService::AllSources()); | |
| 299 registrar_.Add(this, | |
| 300 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, | |
| 301 content::NotificationService::AllSources()); | |
| 302 sequence_token_ = BrowserThread::GetBlockingPool()->GetNamedSequenceToken( | |
| 303 wallpaper::kWallpaperSequenceTokenName); | |
| 304 task_runner_ = BrowserThread::GetBlockingPool()-> | |
| 305 GetSequencedTaskRunnerWithShutdownBehavior( | |
| 306 sequence_token_, | |
| 307 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | |
| 308 wallpaper_loader_ = new UserImageLoader(ImageDecoder::ROBUST_JPEG_CODEC, | |
| 309 task_runner_); | |
| 310 | |
| 311 user_manager::UserManager::Get()->AddSessionStateObserver(this); | |
| 312 } | |
| 313 | |
| 314 WallpaperManager::~WallpaperManager() { | 278 WallpaperManager::~WallpaperManager() { |
| 315 // TODO(bshe): Lifetime of WallpaperManager needs more consideration. | 279 show_user_name_on_signin_subscription_.reset(); |
| 316 // http://crbug.com/171694 | |
| 317 DCHECK(!show_user_name_on_signin_subscription_); | 280 DCHECK(!show_user_name_on_signin_subscription_); |
| 318 | 281 |
| 319 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); | 282 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); |
| 320 | 283 |
| 321 ClearObsoleteWallpaperPrefs(); | 284 ClearObsoleteWallpaperPrefs(); |
| 322 weak_factory_.InvalidateWeakPtrs(); | 285 weak_factory_.InvalidateWeakPtrs(); |
| 323 } | 286 } |
| 324 | 287 |
| 288 // static | |
| 289 WallpaperManager* WallpaperManager::Get() { | |
|
oshima
2015/03/13 22:16:41
is it possible to have explicit Init(ialize) metho
| |
| 290 if (!g_wallpaper_manager) | |
| 291 g_wallpaper_manager = new WallpaperManager(); | |
| 292 return g_wallpaper_manager; | |
| 293 } | |
| 294 | |
| 295 // static | |
| 296 void WallpaperManager::Shutdown() { | |
| 297 CHECK(g_wallpaper_manager); | |
| 298 delete g_wallpaper_manager; | |
| 299 g_wallpaper_manager = NULL; | |
| 300 } | |
| 301 | |
| 325 WallpaperManager::WallpaperResolution | 302 WallpaperManager::WallpaperResolution |
| 326 WallpaperManager::GetAppropriateResolution() { | 303 WallpaperManager::GetAppropriateResolution() { |
| 327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 328 gfx::Size size = | 305 gfx::Size size = |
| 329 ash::DesktopBackgroundController::GetMaxDisplaySizeInNative(); | 306 ash::DesktopBackgroundController::GetMaxDisplaySizeInNative(); |
| 330 return (size.width() > wallpaper::kSmallWallpaperMaxWidth || | 307 return (size.width() > wallpaper::kSmallWallpaperMaxWidth || |
| 331 size.height() > wallpaper::kSmallWallpaperMaxHeight) | 308 size.height() > wallpaper::kSmallWallpaperMaxHeight) |
| 332 ? WALLPAPER_RESOLUTION_LARGE | 309 ? WALLPAPER_RESOLUTION_LARGE |
| 333 : WALLPAPER_RESOLUTION_SMALL; | 310 : WALLPAPER_RESOLUTION_SMALL; |
| 334 } | 311 } |
| 335 | 312 |
| 336 void WallpaperManager::Shutdown() { | |
| 337 show_user_name_on_signin_subscription_.reset(); | |
| 338 } | |
| 339 | |
| 340 void WallpaperManager::AddObservers() { | 313 void WallpaperManager::AddObservers() { |
| 341 show_user_name_on_signin_subscription_ = | 314 show_user_name_on_signin_subscription_ = |
| 342 CrosSettings::Get()->AddSettingsObserver( | 315 CrosSettings::Get()->AddSettingsObserver( |
| 343 kAccountsPrefShowUserNamesOnSignIn, | 316 kAccountsPrefShowUserNamesOnSignIn, |
| 344 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper, | 317 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper, |
| 345 weak_factory_.GetWeakPtr())); | 318 weak_factory_.GetWeakPtr())); |
| 346 } | 319 } |
| 347 | 320 |
| 348 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { | 321 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { |
| 349 // Some browser tests do not have a shell instance. As no wallpaper is needed | 322 // Some browser tests do not have a shell instance. As no wallpaper is needed |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 | 712 |
| 740 if (update_wallpaper) { | 713 if (update_wallpaper) { |
| 741 GetPendingWallpaper(last_selected_user_, false /* Not delayed */) | 714 GetPendingWallpaper(last_selected_user_, false /* Not delayed */) |
| 742 ->ResetSetWallpaperImage(image, info); | 715 ->ResetSetWallpaperImage(image, info); |
| 743 } | 716 } |
| 744 } | 717 } |
| 745 | 718 |
| 746 | 719 |
| 747 // WallpaperManager, private: -------------------------------------------------- | 720 // WallpaperManager, private: -------------------------------------------------- |
| 748 | 721 |
| 722 WallpaperManager::WallpaperManager() | |
| 723 : pending_inactive_(NULL), weak_factory_(this) { | |
| 724 wallpaper::WallpaperManagerBase::SetPathIds( | |
| 725 chrome::DIR_USER_DATA, chrome::DIR_CHROMEOS_WALLPAPERS, | |
| 726 chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS); | |
| 727 SetDefaultWallpaperPathsFromCommandLine( | |
| 728 base::CommandLine::ForCurrentProcess()); | |
| 729 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, | |
| 730 content::NotificationService::AllSources()); | |
| 731 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | |
| 732 content::NotificationService::AllSources()); | |
| 733 registrar_.Add(this, chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, | |
| 734 content::NotificationService::AllSources()); | |
| 735 sequence_token_ = BrowserThread::GetBlockingPool()->GetNamedSequenceToken( | |
| 736 wallpaper::kWallpaperSequenceTokenName); | |
| 737 task_runner_ = | |
| 738 BrowserThread::GetBlockingPool() | |
| 739 ->GetSequencedTaskRunnerWithShutdownBehavior( | |
| 740 sequence_token_, base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | |
| 741 wallpaper_loader_ = | |
| 742 new UserImageLoader(ImageDecoder::ROBUST_JPEG_CODEC, task_runner_); | |
| 743 | |
| 744 user_manager::UserManager::Get()->AddSessionStateObserver(this); | |
| 745 } | |
| 746 | |
| 749 WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper( | 747 WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper( |
| 750 const std::string& user_id, | 748 const std::string& user_id, |
| 751 bool delayed) { | 749 bool delayed) { |
| 752 if (!pending_inactive_) { | 750 if (!pending_inactive_) { |
| 753 loading_.push_back(new WallpaperManager::PendingWallpaper( | 751 loading_.push_back(new WallpaperManager::PendingWallpaper( |
| 754 (delayed ? GetWallpaperLoadDelay() | 752 (delayed ? GetWallpaperLoadDelay() |
| 755 : base::TimeDelta::FromMilliseconds(0)), | 753 : base::TimeDelta::FromMilliseconds(0)), |
| 756 user_id)); | 754 user_id)); |
| 757 pending_inactive_ = loading_.back().get(); | 755 pending_inactive_ = loading_.back().get(); |
| 758 } | 756 } |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1040 } | 1038 } |
| 1041 } | 1039 } |
| 1042 | 1040 |
| 1043 if (need_update_screen) { | 1041 if (need_update_screen) { |
| 1044 DoSetDefaultWallpaper(std::string(), | 1042 DoSetDefaultWallpaper(std::string(), |
| 1045 MovableOnDestroyCallbackHolder().Pass()); | 1043 MovableOnDestroyCallbackHolder().Pass()); |
| 1046 } | 1044 } |
| 1047 } | 1045 } |
| 1048 | 1046 |
| 1049 } // namespace chromeos | 1047 } // namespace chromeos |
| OLD | NEW |