Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 content::NotificationService::AllSources()); | 112 content::NotificationService::AllSources()); |
| 113 registrar_.Add(this, | 113 registrar_.Add(this, |
| 114 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, | 114 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, |
| 115 content::NotificationService::AllSources()); | 115 content::NotificationService::AllSources()); |
| 116 sequence_token_ = BrowserThread::GetBlockingPool()-> | 116 sequence_token_ = BrowserThread::GetBlockingPool()-> |
| 117 GetNamedSequenceToken(kWallpaperSequenceTokenName); | 117 GetNamedSequenceToken(kWallpaperSequenceTokenName); |
| 118 task_runner_ = BrowserThread::GetBlockingPool()-> | 118 task_runner_ = BrowserThread::GetBlockingPool()-> |
| 119 GetSequencedTaskRunnerWithShutdownBehavior( | 119 GetSequencedTaskRunnerWithShutdownBehavior( |
| 120 sequence_token_, | 120 sequence_token_, |
| 121 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 121 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| 122 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | |
| 123 system::TimezoneSettings::GetInstance()->AddObserver(this); | |
| 124 CrosSettings::Get()->AddSettingsObserver(kAccountsPrefShowUserNamesOnSignIn, | |
| 125 this); | |
| 126 } | |
| 127 | |
| 128 WallpaperManager::~WallpaperManager() { | |
| 129 ClearObsoleteWallpaperPrefs(); | |
|
Nikita (slow)
2013/01/22 11:30:54
DCHECK that shutdown has been called.
bshe
2013/01/22 15:36:26
Done.
| |
| 130 weak_factory_.InvalidateWeakPtrs(); | |
| 131 } | |
| 132 | |
| 133 void WallpaperManager::Shutdown() { | |
| 134 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | |
| 135 system::TimezoneSettings::GetInstance()->RemoveObserver(this); | |
| 136 CrosSettings::Get()->RemoveSettingsObserver( | |
| 137 kAccountsPrefShowUserNamesOnSignIn, this); | |
| 122 } | 138 } |
| 123 | 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() { | |
| 132 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | |
| 133 system::TimezoneSettings::GetInstance()->AddObserver(this); | |
| 134 } | |
| 135 | |
| 136 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { | 147 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { |
| 137 // Some browser tests do not have a shell instance. As no wallpaper is needed | 148 // 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 | 149 // in these tests anyway, avoid loading one, preventing crashes and speeding |
| 139 // up the tests. | 150 // up the tests. |
| 140 if (!ash::Shell::HasInstance()) | 151 if (!ash::Shell::HasInstance()) |
| 141 return; | 152 return; |
| 142 | 153 |
| 143 WallpaperInfo info; | 154 WallpaperInfo info; |
| 144 if (GetLoggedInUserWallpaperInfo(&info)) { | 155 if (GetLoggedInUserWallpaperInfo(&info)) { |
| 145 // TODO(sschmitz): We need an index for default wallpapers for the new UI. | 156 // TODO(sschmitz): We need an index for default wallpapers for the new UI. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 if (should_cache_wallpaper_) { | 271 if (should_cache_wallpaper_) { |
| 261 BrowserThread::PostDelayedTask( | 272 BrowserThread::PostDelayedTask( |
| 262 BrowserThread::UI, FROM_HERE, | 273 BrowserThread::UI, FROM_HERE, |
| 263 base::Bind(&WallpaperManager::CacheUsersWallpapers, | 274 base::Bind(&WallpaperManager::CacheUsersWallpapers, |
| 264 weak_factory_.GetWeakPtr()), | 275 weak_factory_.GetWeakPtr()), |
| 265 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); | 276 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); |
| 266 should_cache_wallpaper_ = false; | 277 should_cache_wallpaper_ = false; |
| 267 } | 278 } |
| 268 break; | 279 break; |
| 269 } | 280 } |
| 281 case chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED: { | |
| 282 if (*content::Details<const std::string>(details).ptr() == | |
| 283 kAccountsPrefShowUserNamesOnSignIn) { | |
| 284 InitializeRegisteredDeviceWallpaper(); | |
| 285 } | |
| 286 break; | |
| 287 } | |
| 270 default: | 288 default: |
| 271 NOTREACHED() << "Unexpected notification " << type; | 289 NOTREACHED() << "Unexpected notification " << type; |
| 272 } | 290 } |
| 273 } | 291 } |
| 274 | 292 |
| 275 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& email) { | 293 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& email) { |
| 276 PrefService* prefs = g_browser_process->local_state(); | 294 PrefService* prefs = g_browser_process->local_state(); |
| 277 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs, | 295 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs, |
| 278 prefs::kUsersWallpaperInfo); | 296 prefs::kUsersWallpaperInfo); |
| 279 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(email, NULL); | 297 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(email, NULL); |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 } | 564 } |
| 547 | 565 |
| 548 void WallpaperManager::UpdateWallpaper() { | 566 void WallpaperManager::UpdateWallpaper() { |
| 549 ClearWallpaperCache(); | 567 ClearWallpaperCache(); |
| 550 current_wallpaper_path_.clear(); | 568 current_wallpaper_path_.clear(); |
| 551 SetUserWallpaper(last_selected_user_); | 569 SetUserWallpaper(last_selected_user_); |
| 552 } | 570 } |
| 553 | 571 |
| 554 // WallpaperManager, private: -------------------------------------------------- | 572 // WallpaperManager, private: -------------------------------------------------- |
| 555 | 573 |
| 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() { | 574 void WallpaperManager::BatchUpdateWallpaper() { |
| 564 NOTIMPLEMENTED(); | 575 NOTIMPLEMENTED(); |
| 565 } | 576 } |
| 566 | 577 |
| 567 void WallpaperManager::CacheUsersWallpapers() { | 578 void WallpaperManager::CacheUsersWallpapers() { |
| 568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 579 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 569 UserList users = UserManager::Get()->GetUsers(); | 580 UserList users = UserManager::Get()->GetUsers(); |
| 570 | 581 |
| 571 if (!users.empty()) { | 582 if (!users.empty()) { |
| 572 UserList::const_iterator it = users.begin(); | 583 UserList::const_iterator it = users.begin(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 643 | 654 |
| 644 base::WorkerPool::PostTask( | 655 base::WorkerPool::PostTask( |
| 645 FROM_HERE, | 656 FROM_HERE, |
| 646 base::Bind(&WallpaperManager::DeleteWallpaperInList, | 657 base::Bind(&WallpaperManager::DeleteWallpaperInList, |
| 647 base::Unretained(this), | 658 base::Unretained(this), |
| 648 file_to_remove), | 659 file_to_remove), |
| 649 false); | 660 false); |
| 650 } | 661 } |
| 651 | 662 |
| 652 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { | 663 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { |
| 653 if (CrosSettingsProvider::TEMPORARILY_UNTRUSTED == | 664 if (UserManager::Get()->IsUserLoggedIn()) |
| 654 CrosSettings::Get()->PrepareTrustedValues( | |
| 655 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper, | |
| 656 base::Unretained(this)))) { | |
| 657 return; | 665 return; |
| 658 } | 666 |
| 659 bool disable_boot_animation = CommandLine::ForCurrentProcess()-> | 667 bool disable_boot_animation = CommandLine::ForCurrentProcess()-> |
| 660 HasSwitch(switches::kDisableBootAnimation); | 668 HasSwitch(switches::kDisableBootAnimation); |
| 661 bool show_users = true; | 669 bool show_users = true; |
| 662 bool result = CrosSettings::Get()->GetBoolean( | 670 bool result = CrosSettings::Get()->GetBoolean( |
| 663 kAccountsPrefShowUserNamesOnSignIn, &show_users); | 671 kAccountsPrefShowUserNamesOnSignIn, &show_users); |
| 664 DCHECK(result) << "Unable to fetch setting " | 672 DCHECK(result) << "Unable to fetch setting " |
| 665 << kAccountsPrefShowUserNamesOnSignIn; | 673 << kAccountsPrefShowUserNamesOnSignIn; |
| 666 const chromeos::UserList& users = UserManager::Get()->GetUsers(); | 674 const chromeos::UserList& users = UserManager::Get()->GetUsers(); |
| 667 if (!show_users || users.empty()) { | 675 if (!show_users || users.empty()) { |
| 668 // Boot into sign in form, preload default wallpaper. | 676 // Boot into sign in form, preload default wallpaper. |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 FROM_HERE, | 921 FROM_HERE, |
| 914 base::Bind(&WallpaperManager::StartLoad, | 922 base::Bind(&WallpaperManager::StartLoad, |
| 915 base::Unretained(this), | 923 base::Unretained(this), |
| 916 email, | 924 email, |
| 917 info, | 925 info, |
| 918 update_wallpaper, | 926 update_wallpaper, |
| 919 valid_path)); | 927 valid_path)); |
| 920 } | 928 } |
| 921 | 929 |
| 922 } // chromeos | 930 } // chromeos |
| OLD | NEW |