Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: chrome/browser/chromeos/login/wallpaper_manager.cc

Issue 11968044: Fix login visual hitch on chromebook (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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);
123 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
124 system::TimezoneSettings::GetInstance()->AddObserver(this);
125 CrosSettings::Get()->AddSettingsObserver(kAccountsPrefShowUserNamesOnSignIn,
126 this);
127 }
128
129 WallpaperManager::~WallpaperManager() {
130 DCHECK(called_shutdown_);
131 ClearObsoleteWallpaperPrefs();
132 weak_factory_.InvalidateWeakPtrs();
133 }
134
135 void WallpaperManager::Shutdown() {
136 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
137 system::TimezoneSettings::GetInstance()->RemoveObserver(this);
138 CrosSettings::Get()->RemoveSettingsObserver(
139 kAccountsPrefShowUserNamesOnSignIn, this);
140 called_shutdown_ = true;
122 } 141 }
123 142
124 // static 143 // static
125 void WallpaperManager::RegisterPrefs(PrefServiceSimple* local_state) { 144 void WallpaperManager::RegisterPrefs(PrefServiceSimple* local_state) {
126 local_state->RegisterDictionaryPref(prefs::kUsersWallpaperInfo); 145 local_state->RegisterDictionaryPref(prefs::kUsersWallpaperInfo);
127 local_state->RegisterDictionaryPref(kUserWallpapers); 146 local_state->RegisterDictionaryPref(kUserWallpapers);
128 local_state->RegisterDictionaryPref(kUserWallpapersProperties); 147 local_state->RegisterDictionaryPref(kUserWallpapersProperties);
129 } 148 }
130 149
131 void WallpaperManager::AddObservers() {
132 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
133 system::TimezoneSettings::GetInstance()->AddObserver(this);
134 }
135
136 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { 150 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() {
137 // Some browser tests do not have a shell instance. As no wallpaper is needed 151 // 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 152 // in these tests anyway, avoid loading one, preventing crashes and speeding
139 // up the tests. 153 // up the tests.
140 if (!ash::Shell::HasInstance()) 154 if (!ash::Shell::HasInstance())
141 return; 155 return;
142 156
143 WallpaperInfo info; 157 WallpaperInfo info;
144 if (GetLoggedInUserWallpaperInfo(&info)) { 158 if (GetLoggedInUserWallpaperInfo(&info)) {
145 // TODO(sschmitz): We need an index for default wallpapers for the new UI. 159 // 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
260 if (should_cache_wallpaper_) { 274 if (should_cache_wallpaper_) {
261 BrowserThread::PostDelayedTask( 275 BrowserThread::PostDelayedTask(
262 BrowserThread::UI, FROM_HERE, 276 BrowserThread::UI, FROM_HERE,
263 base::Bind(&WallpaperManager::CacheUsersWallpapers, 277 base::Bind(&WallpaperManager::CacheUsersWallpapers,
264 weak_factory_.GetWeakPtr()), 278 weak_factory_.GetWeakPtr()),
265 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); 279 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs));
266 should_cache_wallpaper_ = false; 280 should_cache_wallpaper_ = false;
267 } 281 }
268 break; 282 break;
269 } 283 }
284 case chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED: {
285 if (*content::Details<const std::string>(details).ptr() ==
286 kAccountsPrefShowUserNamesOnSignIn) {
287 InitializeRegisteredDeviceWallpaper();
288 }
289 break;
290 }
270 default: 291 default:
271 NOTREACHED() << "Unexpected notification " << type; 292 NOTREACHED() << "Unexpected notification " << type;
272 } 293 }
273 } 294 }
274 295
275 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& email) { 296 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& email) {
276 PrefService* prefs = g_browser_process->local_state(); 297 PrefService* prefs = g_browser_process->local_state();
277 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs, 298 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs,
278 prefs::kUsersWallpaperInfo); 299 prefs::kUsersWallpaperInfo);
279 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(email, NULL); 300 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(email, NULL);
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 } 567 }
547 568
548 void WallpaperManager::UpdateWallpaper() { 569 void WallpaperManager::UpdateWallpaper() {
549 ClearWallpaperCache(); 570 ClearWallpaperCache();
550 current_wallpaper_path_.clear(); 571 current_wallpaper_path_.clear();
551 SetUserWallpaper(last_selected_user_); 572 SetUserWallpaper(last_selected_user_);
552 } 573 }
553 574
554 // WallpaperManager, private: -------------------------------------------------- 575 // WallpaperManager, private: --------------------------------------------------
555 576
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() { 577 void WallpaperManager::BatchUpdateWallpaper() {
564 NOTIMPLEMENTED(); 578 NOTIMPLEMENTED();
565 } 579 }
566 580
567 void WallpaperManager::CacheUsersWallpapers() { 581 void WallpaperManager::CacheUsersWallpapers() {
568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 582 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
569 UserList users = UserManager::Get()->GetUsers(); 583 UserList users = UserManager::Get()->GetUsers();
570 584
571 if (!users.empty()) { 585 if (!users.empty()) {
572 UserList::const_iterator it = users.begin(); 586 UserList::const_iterator it = users.begin();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 657
644 base::WorkerPool::PostTask( 658 base::WorkerPool::PostTask(
645 FROM_HERE, 659 FROM_HERE,
646 base::Bind(&WallpaperManager::DeleteWallpaperInList, 660 base::Bind(&WallpaperManager::DeleteWallpaperInList,
647 base::Unretained(this), 661 base::Unretained(this),
648 file_to_remove), 662 file_to_remove),
649 false); 663 false);
650 } 664 }
651 665
652 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { 666 void WallpaperManager::InitializeRegisteredDeviceWallpaper() {
653 if (CrosSettingsProvider::TEMPORARILY_UNTRUSTED == 667 if (UserManager::Get()->IsUserLoggedIn())
654 CrosSettings::Get()->PrepareTrustedValues(
655 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper,
656 base::Unretained(this)))) {
657 return; 668 return;
658 } 669
659 bool disable_boot_animation = CommandLine::ForCurrentProcess()-> 670 bool disable_boot_animation = CommandLine::ForCurrentProcess()->
660 HasSwitch(switches::kDisableBootAnimation); 671 HasSwitch(switches::kDisableBootAnimation);
661 bool show_users = true; 672 bool show_users = true;
662 bool result = CrosSettings::Get()->GetBoolean( 673 bool result = CrosSettings::Get()->GetBoolean(
663 kAccountsPrefShowUserNamesOnSignIn, &show_users); 674 kAccountsPrefShowUserNamesOnSignIn, &show_users);
664 DCHECK(result) << "Unable to fetch setting " 675 DCHECK(result) << "Unable to fetch setting "
665 << kAccountsPrefShowUserNamesOnSignIn; 676 << kAccountsPrefShowUserNamesOnSignIn;
666 const chromeos::UserList& users = UserManager::Get()->GetUsers(); 677 const chromeos::UserList& users = UserManager::Get()->GetUsers();
667 if (!show_users || users.empty()) { 678 if (!show_users || users.empty()) {
668 // Boot into sign in form, preload default wallpaper. 679 // Boot into sign in form, preload default wallpaper.
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 FROM_HERE, 924 FROM_HERE,
914 base::Bind(&WallpaperManager::StartLoad, 925 base::Bind(&WallpaperManager::StartLoad,
915 base::Unretained(this), 926 base::Unretained(this),
916 email, 927 email,
917 info, 928 info,
918 update_wallpaper, 929 update_wallpaper,
919 valid_path)); 930 valid_path));
920 } 931 }
921 932
922 } // chromeos 933 } // chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698