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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 using content::BrowserThread; | 57 using content::BrowserThread; |
58 using wallpaper::WallpaperManagerBase; | 58 using wallpaper::WallpaperManagerBase; |
59 using wallpaper::WallpaperInfo; | 59 using wallpaper::WallpaperInfo; |
60 using wallpaper::MovableOnDestroyCallback; | 60 using wallpaper::MovableOnDestroyCallback; |
61 using wallpaper::MovableOnDestroyCallbackHolder; | 61 using wallpaper::MovableOnDestroyCallbackHolder; |
62 | 62 |
63 namespace chromeos { | 63 namespace chromeos { |
64 | 64 |
65 namespace { | 65 namespace { |
66 | 66 |
| 67 WallpaperManager* wallpaper_manager = nullptr; |
| 68 |
67 // The amount of delay before starts to move custom wallpapers to the new place. | 69 // The amount of delay before starts to move custom wallpapers to the new place. |
68 const int kMoveCustomWallpaperDelaySeconds = 30; | 70 const int kMoveCustomWallpaperDelaySeconds = 30; |
69 | 71 |
70 const int kCacheWallpaperDelayMs = 500; | 72 const int kCacheWallpaperDelayMs = 500; |
71 | 73 |
72 // Names of nodes with info about wallpaper in |kUserWallpapersProperties| | 74 // Names of nodes with info about wallpaper in |kUserWallpapersProperties| |
73 // dictionary. | 75 // dictionary. |
74 const char kNewWallpaperDateNodeName[] = "date"; | 76 const char kNewWallpaperDateNodeName[] = "date"; |
75 const char kNewWallpaperLayoutNodeName[] = "layout"; | 77 const char kNewWallpaperLayoutNodeName[] = "layout"; |
76 const char kNewWallpaperLocationNodeName[] = "file"; | 78 const char kNewWallpaperLocationNodeName[] = "file"; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 // image will be loaded. | 266 // image will be loaded. |
265 wallpaper::MovableOnDestroyCallbackHolder on_finish_; | 267 wallpaper::MovableOnDestroyCallbackHolder on_finish_; |
266 base::OneShotTimer<WallpaperManager::PendingWallpaper> timer; | 268 base::OneShotTimer<WallpaperManager::PendingWallpaper> timer; |
267 | 269 |
268 // Load start time to calculate duration. | 270 // Load start time to calculate duration. |
269 base::Time started_load_at_; | 271 base::Time started_load_at_; |
270 | 272 |
271 DISALLOW_COPY_AND_ASSIGN(PendingWallpaper); | 273 DISALLOW_COPY_AND_ASSIGN(PendingWallpaper); |
272 }; | 274 }; |
273 | 275 |
274 static WallpaperManager* g_wallpaper_manager = NULL; | |
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_); | |
318 | |
319 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); | 280 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); |
320 | |
321 ClearObsoleteWallpaperPrefs(); | 281 ClearObsoleteWallpaperPrefs(); |
322 weak_factory_.InvalidateWeakPtrs(); | 282 weak_factory_.InvalidateWeakPtrs(); |
323 } | 283 } |
324 | 284 |
| 285 // static |
| 286 void WallpaperManager::Initialize() { |
| 287 CHECK(!wallpaper_manager); |
| 288 wallpaper_manager = new WallpaperManager(); |
| 289 } |
| 290 |
| 291 // static |
| 292 WallpaperManager* WallpaperManager::Get() { |
| 293 DCHECK(wallpaper_manager); |
| 294 return wallpaper_manager; |
| 295 } |
| 296 |
| 297 // static |
| 298 void WallpaperManager::Shutdown() { |
| 299 CHECK(wallpaper_manager); |
| 300 delete wallpaper_manager; |
| 301 wallpaper_manager = nullptr; |
| 302 } |
| 303 |
325 WallpaperManager::WallpaperResolution | 304 WallpaperManager::WallpaperResolution |
326 WallpaperManager::GetAppropriateResolution() { | 305 WallpaperManager::GetAppropriateResolution() { |
327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
328 gfx::Size size = | 307 gfx::Size size = |
329 ash::DesktopBackgroundController::GetMaxDisplaySizeInNative(); | 308 ash::DesktopBackgroundController::GetMaxDisplaySizeInNative(); |
330 return (size.width() > wallpaper::kSmallWallpaperMaxWidth || | 309 return (size.width() > wallpaper::kSmallWallpaperMaxWidth || |
331 size.height() > wallpaper::kSmallWallpaperMaxHeight) | 310 size.height() > wallpaper::kSmallWallpaperMaxHeight) |
332 ? WALLPAPER_RESOLUTION_LARGE | 311 ? WALLPAPER_RESOLUTION_LARGE |
333 : WALLPAPER_RESOLUTION_SMALL; | 312 : WALLPAPER_RESOLUTION_SMALL; |
334 } | 313 } |
335 | 314 |
336 void WallpaperManager::Shutdown() { | |
337 show_user_name_on_signin_subscription_.reset(); | |
338 } | |
339 | |
340 void WallpaperManager::AddObservers() { | 315 void WallpaperManager::AddObservers() { |
341 show_user_name_on_signin_subscription_ = | 316 show_user_name_on_signin_subscription_ = |
342 CrosSettings::Get()->AddSettingsObserver( | 317 CrosSettings::Get()->AddSettingsObserver( |
343 kAccountsPrefShowUserNamesOnSignIn, | 318 kAccountsPrefShowUserNamesOnSignIn, |
344 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper, | 319 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper, |
345 weak_factory_.GetWeakPtr())); | 320 weak_factory_.GetWeakPtr())); |
346 } | 321 } |
347 | 322 |
348 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { | 323 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { |
349 // Some browser tests do not have a shell instance. As no wallpaper is needed | 324 // 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 | 714 |
740 if (update_wallpaper) { | 715 if (update_wallpaper) { |
741 GetPendingWallpaper(last_selected_user_, false /* Not delayed */) | 716 GetPendingWallpaper(last_selected_user_, false /* Not delayed */) |
742 ->ResetSetWallpaperImage(image, info); | 717 ->ResetSetWallpaperImage(image, info); |
743 } | 718 } |
744 } | 719 } |
745 | 720 |
746 | 721 |
747 // WallpaperManager, private: -------------------------------------------------- | 722 // WallpaperManager, private: -------------------------------------------------- |
748 | 723 |
| 724 WallpaperManager::WallpaperManager() |
| 725 : pending_inactive_(NULL), weak_factory_(this) { |
| 726 wallpaper::WallpaperManagerBase::SetPathIds( |
| 727 chrome::DIR_USER_DATA, chrome::DIR_CHROMEOS_WALLPAPERS, |
| 728 chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS); |
| 729 SetDefaultWallpaperPathsFromCommandLine( |
| 730 base::CommandLine::ForCurrentProcess()); |
| 731 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 732 content::NotificationService::AllSources()); |
| 733 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 734 content::NotificationService::AllSources()); |
| 735 registrar_.Add(this, chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, |
| 736 content::NotificationService::AllSources()); |
| 737 sequence_token_ = BrowserThread::GetBlockingPool()->GetNamedSequenceToken( |
| 738 wallpaper::kWallpaperSequenceTokenName); |
| 739 task_runner_ = |
| 740 BrowserThread::GetBlockingPool() |
| 741 ->GetSequencedTaskRunnerWithShutdownBehavior( |
| 742 sequence_token_, base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| 743 wallpaper_loader_ = |
| 744 new UserImageLoader(ImageDecoder::ROBUST_JPEG_CODEC, task_runner_); |
| 745 |
| 746 user_manager::UserManager::Get()->AddSessionStateObserver(this); |
| 747 } |
| 748 |
749 WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper( | 749 WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper( |
750 const std::string& user_id, | 750 const std::string& user_id, |
751 bool delayed) { | 751 bool delayed) { |
752 if (!pending_inactive_) { | 752 if (!pending_inactive_) { |
753 loading_.push_back(new WallpaperManager::PendingWallpaper( | 753 loading_.push_back(new WallpaperManager::PendingWallpaper( |
754 (delayed ? GetWallpaperLoadDelay() | 754 (delayed ? GetWallpaperLoadDelay() |
755 : base::TimeDelta::FromMilliseconds(0)), | 755 : base::TimeDelta::FromMilliseconds(0)), |
756 user_id)); | 756 user_id)); |
757 pending_inactive_ = loading_.back().get(); | 757 pending_inactive_ = loading_.back().get(); |
758 } | 758 } |
(...skipping 11 matching lines...) Expand all Loading... |
770 break; | 770 break; |
771 } | 771 } |
772 } | 772 } |
773 | 773 |
774 if (loading_.empty()) | 774 if (loading_.empty()) |
775 FOR_EACH_OBSERVER(Observer, observers_, OnPendingListEmptyForTesting()); | 775 FOR_EACH_OBSERVER(Observer, observers_, OnPendingListEmptyForTesting()); |
776 } | 776 } |
777 | 777 |
778 void WallpaperManager::ClearObsoleteWallpaperPrefs() { | 778 void WallpaperManager::ClearObsoleteWallpaperPrefs() { |
779 PrefService* prefs = g_browser_process->local_state(); | 779 PrefService* prefs = g_browser_process->local_state(); |
780 DictionaryPrefUpdate wallpaper_properties_pref(prefs, | 780 // LocalState can be NULL in tests. Skip for tests. |
781 wallpaper::kUserWallpapersProperties); | 781 if (prefs) { |
782 wallpaper_properties_pref->Clear(); | 782 DictionaryPrefUpdate wallpaper_properties_pref(prefs, |
783 DictionaryPrefUpdate wallpapers_pref(prefs, wallpaper::kUserWallpapers); | 783 wallpaper::kUserWallpapersProperties); |
784 wallpapers_pref->Clear(); | 784 wallpaper_properties_pref->Clear(); |
| 785 DictionaryPrefUpdate wallpapers_pref(prefs, wallpaper::kUserWallpapers); |
| 786 wallpapers_pref->Clear(); |
| 787 } |
785 } | 788 } |
786 | 789 |
787 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { | 790 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { |
788 if (user_manager::UserManager::Get()->IsUserLoggedIn()) | 791 if (user_manager::UserManager::Get()->IsUserLoggedIn()) |
789 return; | 792 return; |
790 | 793 |
791 bool disable_boot_animation = | 794 bool disable_boot_animation = |
792 GetCommandLine()->HasSwitch(switches::kDisableBootAnimation); | 795 GetCommandLine()->HasSwitch(switches::kDisableBootAnimation); |
793 bool show_users = true; | 796 bool show_users = true; |
794 bool result = CrosSettings::Get()->GetBoolean( | 797 bool result = CrosSettings::Get()->GetBoolean( |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 } | 1043 } |
1041 } | 1044 } |
1042 | 1045 |
1043 if (need_update_screen) { | 1046 if (need_update_screen) { |
1044 DoSetDefaultWallpaper(std::string(), | 1047 DoSetDefaultWallpaper(std::string(), |
1045 MovableOnDestroyCallbackHolder().Pass()); | 1048 MovableOnDestroyCallbackHolder().Pass()); |
1046 } | 1049 } |
1047 } | 1050 } |
1048 | 1051 |
1049 } // namespace chromeos | 1052 } // namespace chromeos |
OLD | NEW |