Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 // WallpaperManager, public: --------------------------------------------------- | 91 // WallpaperManager, public: --------------------------------------------------- |
| 92 | 92 |
| 93 // static | 93 // static |
| 94 WallpaperManager* WallpaperManager::Get() { | 94 WallpaperManager* WallpaperManager::Get() { |
| 95 if (!g_wallpaper_manager) | 95 if (!g_wallpaper_manager) |
| 96 g_wallpaper_manager = new WallpaperManager(); | 96 g_wallpaper_manager = new WallpaperManager(); |
| 97 return g_wallpaper_manager; | 97 return g_wallpaper_manager; |
| 98 } | 98 } |
| 99 | 99 |
| 100 WallpaperManager::WallpaperManager() | 100 WallpaperManager::WallpaperManager() |
| 101 : loaded_wallpapers_(0), | 101 : called_shutdown_(false), |
| 102 loaded_wallpapers_(0), | |
| 102 ALLOW_THIS_IN_INITIALIZER_LIST(wallpaper_loader_( | 103 ALLOW_THIS_IN_INITIALIZER_LIST(wallpaper_loader_( |
| 103 new UserImageLoader(ImageDecoder::ROBUST_JPEG_CODEC))), | 104 new UserImageLoader(ImageDecoder::ROBUST_JPEG_CODEC))), |
| 104 should_cache_wallpaper_(false), | 105 should_cache_wallpaper_(false), |
| 105 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 106 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 106 RestartTimer(); | 107 RestartTimer(); |
| 107 registrar_.Add(this, | 108 registrar_.Add(this, |
| 108 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 109 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 109 content::NotificationService::AllSources()); | 110 content::NotificationService::AllSources()); |
| 110 registrar_.Add(this, | 111 registrar_.Add(this, |
| 111 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, | 112 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, |
| 112 content::NotificationService::AllSources()); | 113 content::NotificationService::AllSources()); |
| 113 registrar_.Add(this, | 114 registrar_.Add(this, |
| 114 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, | 115 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, |
| 115 content::NotificationService::AllSources()); | 116 content::NotificationService::AllSources()); |
| 116 sequence_token_ = BrowserThread::GetBlockingPool()-> | 117 sequence_token_ = BrowserThread::GetBlockingPool()-> |
| 117 GetNamedSequenceToken(kWallpaperSequenceTokenName); | 118 GetNamedSequenceToken(kWallpaperSequenceTokenName); |
| 118 task_runner_ = BrowserThread::GetBlockingPool()-> | 119 task_runner_ = BrowserThread::GetBlockingPool()-> |
| 119 GetSequencedTaskRunnerWithShutdownBehavior( | 120 GetSequencedTaskRunnerWithShutdownBehavior( |
| 120 sequence_token_, | 121 sequence_token_, |
| 121 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 122 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| 122 } | 123 } |
| 123 | 124 |
| 125 WallpaperManager::~WallpaperManager() { | |
| 126 // TODO(bshe): Lifetime of WallpaperManager needs more consideration. | |
|
Nikita (slow)
2013/01/23 16:28:17
Issue #?
bshe
2013/01/23 17:11:45
Done.
| |
| 127 DCHECK(called_shutdown_); | |
| 128 ClearObsoleteWallpaperPrefs(); | |
| 129 weak_factory_.InvalidateWeakPtrs(); | |
| 130 } | |
| 131 | |
| 132 void WallpaperManager::Shutdown() { | |
| 133 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | |
| 134 system::TimezoneSettings::GetInstance()->RemoveObserver(this); | |
| 135 CrosSettings::Get()->RemoveSettingsObserver( | |
| 136 kAccountsPrefShowUserNamesOnSignIn, this); | |
| 137 called_shutdown_ = true; | |
| 138 } | |
| 139 | |
| 124 // static | 140 // static |
| 125 void WallpaperManager::RegisterPrefs(PrefServiceSimple* local_state) { | 141 void WallpaperManager::RegisterPrefs(PrefServiceSimple* local_state) { |
| 126 local_state->RegisterDictionaryPref(prefs::kUsersWallpaperInfo); | 142 local_state->RegisterDictionaryPref(prefs::kUsersWallpaperInfo); |
| 127 local_state->RegisterDictionaryPref(kUserWallpapers); | 143 local_state->RegisterDictionaryPref(kUserWallpapers); |
| 128 local_state->RegisterDictionaryPref(kUserWallpapersProperties); | 144 local_state->RegisterDictionaryPref(kUserWallpapersProperties); |
| 129 } | 145 } |
| 130 | 146 |
| 131 void WallpaperManager::AddObservers() { | 147 void WallpaperManager::AddObservers() { |
| 132 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 148 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
| 133 system::TimezoneSettings::GetInstance()->AddObserver(this); | 149 system::TimezoneSettings::GetInstance()->AddObserver(this); |
| 150 CrosSettings::Get()->AddSettingsObserver(kAccountsPrefShowUserNamesOnSignIn, | |
| 151 this); | |
| 134 } | 152 } |
| 135 | 153 |
| 136 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { | 154 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { |
| 137 // Some browser tests do not have a shell instance. As no wallpaper is needed | 155 // Some browser tests do not have a shell instance. As no wallpaper is needed |
| 138 // in these tests anyway, avoid loading one, preventing crashes and speeding | 156 // in these tests anyway, avoid loading one, preventing crashes and speeding |
| 139 // up the tests. | 157 // up the tests. |
| 140 if (!ash::Shell::HasInstance()) | 158 if (!ash::Shell::HasInstance()) |
| 141 return; | 159 return; |
| 142 | 160 |
| 143 WallpaperInfo info; | 161 WallpaperInfo info; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 if (should_cache_wallpaper_) { | 278 if (should_cache_wallpaper_) { |
| 261 BrowserThread::PostDelayedTask( | 279 BrowserThread::PostDelayedTask( |
| 262 BrowserThread::UI, FROM_HERE, | 280 BrowserThread::UI, FROM_HERE, |
| 263 base::Bind(&WallpaperManager::CacheUsersWallpapers, | 281 base::Bind(&WallpaperManager::CacheUsersWallpapers, |
| 264 weak_factory_.GetWeakPtr()), | 282 weak_factory_.GetWeakPtr()), |
| 265 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); | 283 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); |
| 266 should_cache_wallpaper_ = false; | 284 should_cache_wallpaper_ = false; |
| 267 } | 285 } |
| 268 break; | 286 break; |
| 269 } | 287 } |
| 288 case chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED: { | |
| 289 if (*content::Details<const std::string>(details).ptr() == | |
| 290 kAccountsPrefShowUserNamesOnSignIn) { | |
| 291 InitializeRegisteredDeviceWallpaper(); | |
| 292 } | |
| 293 break; | |
| 294 } | |
| 270 default: | 295 default: |
| 271 NOTREACHED() << "Unexpected notification " << type; | 296 NOTREACHED() << "Unexpected notification " << type; |
| 272 } | 297 } |
| 273 } | 298 } |
| 274 | 299 |
| 275 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& email) { | 300 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& email) { |
| 276 PrefService* prefs = g_browser_process->local_state(); | 301 PrefService* prefs = g_browser_process->local_state(); |
| 277 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs, | 302 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs, |
| 278 prefs::kUsersWallpaperInfo); | 303 prefs::kUsersWallpaperInfo); |
| 279 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(email, NULL); | 304 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(email, NULL); |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 } | 571 } |
| 547 | 572 |
| 548 void WallpaperManager::UpdateWallpaper() { | 573 void WallpaperManager::UpdateWallpaper() { |
| 549 ClearWallpaperCache(); | 574 ClearWallpaperCache(); |
| 550 current_wallpaper_path_.clear(); | 575 current_wallpaper_path_.clear(); |
| 551 SetUserWallpaper(last_selected_user_); | 576 SetUserWallpaper(last_selected_user_); |
| 552 } | 577 } |
| 553 | 578 |
| 554 // WallpaperManager, private: -------------------------------------------------- | 579 // WallpaperManager, private: -------------------------------------------------- |
| 555 | 580 |
| 556 WallpaperManager::~WallpaperManager() { | |
| 557 ClearObsoleteWallpaperPrefs(); | |
| 558 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | |
| 559 system::TimezoneSettings::GetInstance()->RemoveObserver(this); | |
| 560 weak_factory_.InvalidateWeakPtrs(); | |
| 561 } | |
| 562 | |
| 563 void WallpaperManager::BatchUpdateWallpaper() { | 581 void WallpaperManager::BatchUpdateWallpaper() { |
| 564 NOTIMPLEMENTED(); | 582 NOTIMPLEMENTED(); |
| 565 } | 583 } |
| 566 | 584 |
| 567 void WallpaperManager::CacheUsersWallpapers() { | 585 void WallpaperManager::CacheUsersWallpapers() { |
| 568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 586 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 569 UserList users = UserManager::Get()->GetUsers(); | 587 UserList users = UserManager::Get()->GetUsers(); |
| 570 | 588 |
| 571 if (!users.empty()) { | 589 if (!users.empty()) { |
| 572 UserList::const_iterator it = users.begin(); | 590 UserList::const_iterator it = users.begin(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 643 | 661 |
| 644 base::WorkerPool::PostTask( | 662 base::WorkerPool::PostTask( |
| 645 FROM_HERE, | 663 FROM_HERE, |
| 646 base::Bind(&WallpaperManager::DeleteWallpaperInList, | 664 base::Bind(&WallpaperManager::DeleteWallpaperInList, |
| 647 base::Unretained(this), | 665 base::Unretained(this), |
| 648 file_to_remove), | 666 file_to_remove), |
| 649 false); | 667 false); |
| 650 } | 668 } |
| 651 | 669 |
| 652 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { | 670 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { |
| 653 if (CrosSettingsProvider::TEMPORARILY_UNTRUSTED == | 671 if (UserManager::Get()->IsUserLoggedIn()) |
| 654 CrosSettings::Get()->PrepareTrustedValues( | |
| 655 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper, | |
| 656 base::Unretained(this)))) { | |
| 657 return; | 672 return; |
| 658 } | 673 |
| 659 bool disable_boot_animation = CommandLine::ForCurrentProcess()-> | 674 bool disable_boot_animation = CommandLine::ForCurrentProcess()-> |
| 660 HasSwitch(switches::kDisableBootAnimation); | 675 HasSwitch(switches::kDisableBootAnimation); |
| 661 bool show_users = true; | 676 bool show_users = true; |
| 662 bool result = CrosSettings::Get()->GetBoolean( | 677 bool result = CrosSettings::Get()->GetBoolean( |
| 663 kAccountsPrefShowUserNamesOnSignIn, &show_users); | 678 kAccountsPrefShowUserNamesOnSignIn, &show_users); |
| 664 DCHECK(result) << "Unable to fetch setting " | 679 DCHECK(result) << "Unable to fetch setting " |
| 665 << kAccountsPrefShowUserNamesOnSignIn; | 680 << kAccountsPrefShowUserNamesOnSignIn; |
| 666 const chromeos::UserList& users = UserManager::Get()->GetUsers(); | 681 const chromeos::UserList& users = UserManager::Get()->GetUsers(); |
| 667 if (!show_users || users.empty()) { | 682 if (!show_users || users.empty()) { |
| 668 // Boot into sign in form, preload default wallpaper. | 683 // Boot into sign in form, preload default wallpaper. |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 FROM_HERE, | 928 FROM_HERE, |
| 914 base::Bind(&WallpaperManager::StartLoad, | 929 base::Bind(&WallpaperManager::StartLoad, |
| 915 base::Unretained(this), | 930 base::Unretained(this), |
| 916 email, | 931 email, |
| 917 info, | 932 info, |
| 918 update_wallpaper, | 933 update_wallpaper, |
| 919 valid_path)); | 934 valid_path)); |
| 920 } | 935 } |
| 921 | 936 |
| 922 } // chromeos | 937 } // chromeos |
| OLD | NEW |