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

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: rebase Created 7 years, 10 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
« no previous file with comments | « chrome/browser/chromeos/login/wallpaper_manager.h ('k') | chrome/browser/image_decoder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 : no_observers_(true),
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.
127 // http://crbug.com/171694
128 DCHECK(no_observers_);
129 ClearObsoleteWallpaperPrefs();
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);
138 no_observers_ = true;
139 }
140
124 // static 141 // static
125 void WallpaperManager::RegisterPrefs(PrefServiceSimple* local_state) { 142 void WallpaperManager::RegisterPrefs(PrefServiceSimple* local_state) {
126 local_state->RegisterDictionaryPref(prefs::kUsersWallpaperInfo); 143 local_state->RegisterDictionaryPref(prefs::kUsersWallpaperInfo);
127 local_state->RegisterDictionaryPref(kUserWallpapers); 144 local_state->RegisterDictionaryPref(kUserWallpapers);
128 local_state->RegisterDictionaryPref(kUserWallpapersProperties); 145 local_state->RegisterDictionaryPref(kUserWallpapersProperties);
129 } 146 }
130 147
131 void WallpaperManager::AddObservers() { 148 void WallpaperManager::AddObservers() {
132 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); 149 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
133 system::TimezoneSettings::GetInstance()->AddObserver(this); 150 system::TimezoneSettings::GetInstance()->AddObserver(this);
151 CrosSettings::Get()->AddSettingsObserver(kAccountsPrefShowUserNamesOnSignIn,
152 this);
153 no_observers_ = false;
134 } 154 }
135 155
136 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { 156 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() {
137 // Some browser tests do not have a shell instance. As no wallpaper is needed 157 // 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 158 // in these tests anyway, avoid loading one, preventing crashes and speeding
139 // up the tests. 159 // up the tests.
140 if (!ash::Shell::HasInstance()) 160 if (!ash::Shell::HasInstance())
141 return; 161 return;
142 162
143 WallpaperInfo info; 163 WallpaperInfo info;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 if (should_cache_wallpaper_) { 280 if (should_cache_wallpaper_) {
261 BrowserThread::PostDelayedTask( 281 BrowserThread::PostDelayedTask(
262 BrowserThread::UI, FROM_HERE, 282 BrowserThread::UI, FROM_HERE,
263 base::Bind(&WallpaperManager::CacheUsersWallpapers, 283 base::Bind(&WallpaperManager::CacheUsersWallpapers,
264 weak_factory_.GetWeakPtr()), 284 weak_factory_.GetWeakPtr()),
265 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); 285 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs));
266 should_cache_wallpaper_ = false; 286 should_cache_wallpaper_ = false;
267 } 287 }
268 break; 288 break;
269 } 289 }
290 case chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED: {
291 if (*content::Details<const std::string>(details).ptr() ==
292 kAccountsPrefShowUserNamesOnSignIn) {
293 InitializeRegisteredDeviceWallpaper();
294 }
295 break;
296 }
270 default: 297 default:
271 NOTREACHED() << "Unexpected notification " << type; 298 NOTREACHED() << "Unexpected notification " << type;
272 } 299 }
273 } 300 }
274 301
275 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& email) { 302 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& email) {
276 PrefService* prefs = g_browser_process->local_state(); 303 PrefService* prefs = g_browser_process->local_state();
277 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs, 304 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs,
278 prefs::kUsersWallpaperInfo); 305 prefs::kUsersWallpaperInfo);
279 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(email, NULL); 306 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(email, NULL);
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 } 573 }
547 574
548 void WallpaperManager::UpdateWallpaper() { 575 void WallpaperManager::UpdateWallpaper() {
549 ClearWallpaperCache(); 576 ClearWallpaperCache();
550 current_wallpaper_path_.clear(); 577 current_wallpaper_path_.clear();
551 SetUserWallpaper(last_selected_user_); 578 SetUserWallpaper(last_selected_user_);
552 } 579 }
553 580
554 // WallpaperManager, private: -------------------------------------------------- 581 // WallpaperManager, private: --------------------------------------------------
555 582
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() { 583 void WallpaperManager::BatchUpdateWallpaper() {
564 NOTIMPLEMENTED(); 584 NOTIMPLEMENTED();
565 } 585 }
566 586
567 void WallpaperManager::CacheUsersWallpapers() { 587 void WallpaperManager::CacheUsersWallpapers() {
568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
569 UserList users = UserManager::Get()->GetUsers(); 589 UserList users = UserManager::Get()->GetUsers();
570 590
571 if (!users.empty()) { 591 if (!users.empty()) {
572 UserList::const_iterator it = users.begin(); 592 UserList::const_iterator it = users.begin();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 663
644 base::WorkerPool::PostTask( 664 base::WorkerPool::PostTask(
645 FROM_HERE, 665 FROM_HERE,
646 base::Bind(&WallpaperManager::DeleteWallpaperInList, 666 base::Bind(&WallpaperManager::DeleteWallpaperInList,
647 base::Unretained(this), 667 base::Unretained(this),
648 file_to_remove), 668 file_to_remove),
649 false); 669 false);
650 } 670 }
651 671
652 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { 672 void WallpaperManager::InitializeRegisteredDeviceWallpaper() {
653 if (CrosSettingsProvider::TEMPORARILY_UNTRUSTED == 673 if (UserManager::Get()->IsUserLoggedIn())
654 CrosSettings::Get()->PrepareTrustedValues(
655 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper,
656 base::Unretained(this)))) {
657 return; 674 return;
658 } 675
659 bool disable_boot_animation = CommandLine::ForCurrentProcess()-> 676 bool disable_boot_animation = CommandLine::ForCurrentProcess()->
660 HasSwitch(switches::kDisableBootAnimation); 677 HasSwitch(switches::kDisableBootAnimation);
661 bool show_users = true; 678 bool show_users = true;
662 bool result = CrosSettings::Get()->GetBoolean( 679 bool result = CrosSettings::Get()->GetBoolean(
663 kAccountsPrefShowUserNamesOnSignIn, &show_users); 680 kAccountsPrefShowUserNamesOnSignIn, &show_users);
664 DCHECK(result) << "Unable to fetch setting " 681 DCHECK(result) << "Unable to fetch setting "
665 << kAccountsPrefShowUserNamesOnSignIn; 682 << kAccountsPrefShowUserNamesOnSignIn;
666 const chromeos::UserList& users = UserManager::Get()->GetUsers(); 683 const chromeos::UserList& users = UserManager::Get()->GetUsers();
667 if (!show_users || users.empty()) { 684 if (!show_users || users.empty()) {
668 // Boot into sign in form, preload default wallpaper. 685 // Boot into sign in form, preload default wallpaper.
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 FROM_HERE, 930 FROM_HERE,
914 base::Bind(&WallpaperManager::StartLoad, 931 base::Bind(&WallpaperManager::StartLoad,
915 base::Unretained(this), 932 base::Unretained(this),
916 email, 933 email,
917 info, 934 info,
918 update_wallpaper, 935 update_wallpaper,
919 valid_path)); 936 valid_path));
920 } 937 }
921 938
922 } // chromeos 939 } // chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/wallpaper_manager.h ('k') | chrome/browser/image_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698