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

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

Issue 10827154: Preload default wallpaper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nikita's reivew Created 8 years, 4 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) 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 "ash/desktop_background/desktop_background_controller.h" 7 #include "ash/desktop_background/desktop_background_controller.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 29 matching lines...) Expand all
40 40
41 const int kWallpaperUpdateIntervalSec = 24 * 60 * 60; 41 const int kWallpaperUpdateIntervalSec = 24 * 60 * 60;
42 42
43 const char kWallpaperTypeNodeName[] = "type"; 43 const char kWallpaperTypeNodeName[] = "type";
44 const char kWallpaperIndexNodeName[] = "index"; 44 const char kWallpaperIndexNodeName[] = "index";
45 const char kWallpaperDateNodeName[] = "date"; 45 const char kWallpaperDateNodeName[] = "date";
46 46
47 const int kThumbnailWidth = 128; 47 const int kThumbnailWidth = 128;
48 const int kThumbnailHeight = 80; 48 const int kThumbnailHeight = 80;
49 49
50 const int kCacheWallpaperDelayMs = 500;
51
50 // Default wallpaper index used in OOBE (first boot). 52 // Default wallpaper index used in OOBE (first boot).
51 // Defined here because Chromium default index differs. 53 // Defined here because Chromium default index differs.
52 // Also see ash::WallpaperInfo kDefaultWallpapers in 54 // Also see ash::WallpaperInfo kDefaultWallpapers in
53 // desktop_background_resources.cc 55 // desktop_background_resources.cc
54 #if defined(GOOGLE_CHROME_BUILD) 56 #if defined(GOOGLE_CHROME_BUILD)
55 const int kDefaultOOBEWallpaperIndex = 16; // IDR_AURA_WALLPAPERS_3_URBAN0 57 const int kDefaultOOBEWallpaperIndex = 16; // IDR_AURA_WALLPAPERS_3_URBAN0
56 #else 58 #else
57 const int kDefaultOOBEWallpaperIndex = 0; // IDR_AURA_WALLPAPERS_ROMAINGUY_0 59 const int kDefaultOOBEWallpaperIndex = 0; // IDR_AURA_WALLPAPERS_ROMAINGUY_0
58 #endif 60 #endif
59 61
(...skipping 16 matching lines...) Expand all
76 if (!g_wallpaper_manager) 78 if (!g_wallpaper_manager)
77 g_wallpaper_manager = new WallpaperManager(); 79 g_wallpaper_manager = new WallpaperManager();
78 return g_wallpaper_manager; 80 return g_wallpaper_manager;
79 } 81 }
80 82
81 WallpaperManager::WallpaperManager() 83 WallpaperManager::WallpaperManager()
82 : ALLOW_THIS_IN_INITIALIZER_LIST(wallpaper_loader_(new UserImageLoader)), 84 : ALLOW_THIS_IN_INITIALIZER_LIST(wallpaper_loader_(new UserImageLoader)),
83 current_user_wallpaper_type_(User::UNKNOWN), 85 current_user_wallpaper_type_(User::UNKNOWN),
84 ALLOW_THIS_IN_INITIALIZER_LIST(current_user_wallpaper_index_( 86 ALLOW_THIS_IN_INITIALIZER_LIST(current_user_wallpaper_index_(
85 ash::GetInvalidWallpaperIndex())), 87 ash::GetInvalidWallpaperIndex())),
88 should_cache_wallpaper_(false),
86 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 89 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
87 RestartTimer(); 90 RestartTimer();
88 registrar_.Add(this, 91 registrar_.Add(this,
89 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 92 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
90 content::NotificationService::AllSources()); 93 content::NotificationService::AllSources());
94 registrar_.Add(this,
95 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE,
96 content::NotificationService::AllSources());
91 } 97 }
92 98
93 // static 99 // static
94 void WallpaperManager::RegisterPrefs(PrefService* local_state) { 100 void WallpaperManager::RegisterPrefs(PrefService* local_state) {
95 local_state->RegisterDictionaryPref(prefs::kUsersWallpaperInfo, 101 local_state->RegisterDictionaryPref(prefs::kUsersWallpaperInfo,
96 PrefService::UNSYNCABLE_PREF); 102 PrefService::UNSYNCABLE_PREF);
97 } 103 }
98 104
99 void WallpaperManager::AddObservers() { 105 void WallpaperManager::AddObservers() {
100 if (!DBusThreadManager::Get()->GetPowerManagerClient()->HasObserver(this)) 106 if (!DBusThreadManager::Get()->GetPowerManagerClient()->HasObserver(this))
101 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); 107 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
102 system::TimezoneSettings::GetInstance()->AddObserver(this); 108 system::TimezoneSettings::GetInstance()->AddObserver(this);
103 } 109 }
104 110
105 void WallpaperManager::CacheIfCustomWallpaper(const std::string& email) {
106 User::WallpaperType type;
107 int index;
108 base::Time date;
109 GetUserWallpaperProperties(email, &type, &index, &date);
110 if (type == User::CUSTOMIZED) {
111 std::string wallpaper_path = GetWallpaperPathForUser(email, false).value();
112
113 // Uses WeakPtr here to make the request cancelable.
114 wallpaper_loader_->Start(wallpaper_path, 0,
115 base::Bind(&WallpaperManager::CacheWallpaper,
116 weak_factory_.GetWeakPtr(), email));
117 }
118 }
119
120 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { 111 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() {
121 User::WallpaperType type; 112 User::WallpaperType type;
122 int index; 113 int index;
123 base::Time last_modification_date; 114 base::Time last_modification_date;
124 GetLoggedInUserWallpaperProperties(&type, &index, &last_modification_date); 115 GetLoggedInUserWallpaperProperties(&type, &index, &last_modification_date);
125 116
126 if (type != current_user_wallpaper_type_ || 117 if (type != current_user_wallpaper_type_ ||
127 index != current_user_wallpaper_index_) { 118 index != current_user_wallpaper_index_) {
128 SetUserWallpaper(UserManager::Get()->GetLoggedInUser().email()); 119 SetUserWallpaper(UserManager::Get()->GetLoggedInUser().email());
129 } 120 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 212 }
222 return; 213 return;
223 } 214 }
224 SetUserWallpaper(user_manager->GetLoggedInUser().email()); 215 SetUserWallpaper(user_manager->GetLoggedInUser().email());
225 } 216 }
226 217
227 void WallpaperManager::Observe(int type, 218 void WallpaperManager::Observe(int type,
228 const content::NotificationSource& source, 219 const content::NotificationSource& source,
229 const content::NotificationDetails& details) { 220 const content::NotificationDetails& details) {
230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
231 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { 222 switch (type) {
232 // Cancel callback for previous cache requests. 223 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: {
233 weak_factory_.InvalidateWeakPtrs(); 224 // Cancel callback for previous cache requests.
234 custom_wallpaper_cache_.clear(); 225 weak_factory_.InvalidateWeakPtrs();
226 custom_wallpaper_cache_.clear();
227 break;
228 }
229 case chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE: {
230 if (!CommandLine::ForCurrentProcess()->
231 HasSwitch(switches::kDisableBootAnimation)) {
232 BrowserThread::PostDelayedTask(
233 BrowserThread::UI, FROM_HERE,
234 base::Bind(&WallpaperManager::CacheAllUsersWallpapers,
235 weak_factory_.GetWeakPtr()),
236 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs));
237 } else {
238 should_cache_wallpaper_ = true;
239 }
240 break;
241 }
242 default:
243 NOTREACHED() << "Unexpected notification " << type;
235 } 244 }
236 } 245 }
237 246
238 void WallpaperManager::RestartTimer() { 247 void WallpaperManager::RestartTimer() {
239 timer_.Stop(); 248 timer_.Stop();
240 base::Time midnight = base::Time::Now().LocalMidnight(); 249 base::Time midnight = base::Time::Now().LocalMidnight();
241 base::TimeDelta interval = base::Time::Now() - midnight; 250 base::TimeDelta interval = base::Time::Now() - midnight;
242 int64 remaining_seconds = kWallpaperUpdateIntervalSec - interval.InSeconds(); 251 int64 remaining_seconds = kWallpaperUpdateIntervalSec - interval.InSeconds();
243 if (remaining_seconds <= 0) { 252 if (remaining_seconds <= 0) {
244 BatchUpdateWallpaper(); 253 BatchUpdateWallpaper();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 void WallpaperManager::OnUserDeselected() { 389 void WallpaperManager::OnUserDeselected() {
381 if (!UserManager::Get()->IsUserLoggedIn()) { 390 if (!UserManager::Get()->IsUserLoggedIn()) {
382 // This will set default login wallpaper (#fefefe). 391 // This will set default login wallpaper (#fefefe).
383 ash::Shell::GetInstance()->desktop_background_controller()-> 392 ash::Shell::GetInstance()->desktop_background_controller()->
384 SetDefaultWallpaper(ash::GetSolidColorIndex()); 393 SetDefaultWallpaper(ash::GetSolidColorIndex());
385 } 394 }
386 } 395 }
387 396
388 void WallpaperManager::OnUserSelected(const std::string& email) { 397 void WallpaperManager::OnUserSelected(const std::string& email) {
389 SetUserWallpaper(email); 398 SetUserWallpaper(email);
399 if (should_cache_wallpaper_) {
400 BrowserThread::PostDelayedTask(
401 BrowserThread::UI, FROM_HERE,
402 base::Bind(&WallpaperManager::CacheAllUsersWallpapers,
Nikita (slow) 2012/08/06 16:36:01 We should no cache all users wallpapers when singl
bshe 2012/08/07 15:18:57 It should be a single time operation. The only tim
403 weak_factory_.GetWeakPtr()),
404 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs));
405 should_cache_wallpaper_ = false;
406 }
390 } 407 }
391 408
392 // WallpaperManager, private: -------------------------------------------------- 409 // WallpaperManager, private: --------------------------------------------------
393 410
394 WallpaperManager::~WallpaperManager() { 411 WallpaperManager::~WallpaperManager() {
395 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); 412 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
396 system::TimezoneSettings::GetInstance()->RemoveObserver(this); 413 system::TimezoneSettings::GetInstance()->RemoveObserver(this);
397 } 414 }
398 415
399 void WallpaperManager::BatchUpdateWallpaper() { 416 void WallpaperManager::BatchUpdateWallpaper() {
(...skipping 24 matching lines...) Expand all
424 SetUserWallpaper(email); 441 SetUserWallpaper(email);
425 } else if (show_users && 442 } else if (show_users &&
426 email == last_selected_user_) { 443 email == last_selected_user_) {
427 SetUserWallpaper(email); 444 SetUserWallpaper(email);
428 } 445 }
429 } 446 }
430 } 447 }
431 RestartTimer(); 448 RestartTimer();
432 } 449 }
433 450
451 void CacheAllUsersWallpapers() {
452 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
453 if (!users_.empty())
454 return;
455 if (!g_browser_process)
456 return;
457
458 PrefService* local_state = g_browser_process->local_state();
Nikita (slow) 2012/08/06 16:36:01 Use user_manager->GetUsers() instead.
bshe 2012/08/07 15:18:57 Done.
459
460 const ListValue* prefs_users =
461 local_state->GetList(UserManager::kLoggedInUsers);
462
463 if (prefs_users) {
464 ListValue::const_iterator it = prefs_users->begin();
465 it++;
466 for (; it != prefs_users->end(); ++it) {
467 CacheUserWallpaper(email);
468 }
469 }
470 }
471
472 void WallpaperManager::CacheUserWallpaper(const std::string& email) {
473 User::WallpaperType type;
474 int index;
475 base::Time date;
476 GetUserWallpaperProperties(email, &type, &index, &date);
477 if (type == User::CUSTOMIZED) {
478 std::string wallpaper_path = GetWallpaperPathForUser(email, false).value();
479
480 // Uses WeakPtr here to make the request cancelable.
481 wallpaper_loader_->Start(wallpaper_path, 0,
482 base::Bind(&WallpaperManager::CacheWallpaper,
483 weak_factory_.GetWeakPtr(), email));
484 } else {
485 ash::Shell::GetInstance()->desktop_background_controller()->
486 TriggerCacheDefaultWallpaper(index);
487 }
488 }
489
434 void WallpaperManager::CacheWallpaper(const std::string& email, 490 void WallpaperManager::CacheWallpaper(const std::string& email,
435 const UserImage& wallpaper) { 491 const UserImage& wallpaper) {
436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 492 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
437 DCHECK(custom_wallpaper_cache_.find(email) == custom_wallpaper_cache_.end()); 493 DCHECK(custom_wallpaper_cache_.find(email) == custom_wallpaper_cache_.end());
438 494
439 BrowserThread::PostTask( 495 BrowserThread::PostTask(
440 BrowserThread::FILE, 496 BrowserThread::FILE,
441 FROM_HERE, 497 FROM_HERE,
442 base::Bind(&WallpaperManager::CacheThumbnail, 498 base::Bind(&WallpaperManager::CacheThumbnail,
443 base::Unretained(this), email, wallpaper.image())); 499 base::Unretained(this), email, wallpaper.image()));
(...skipping 15 matching lines...) Expand all
459 ash::WallpaperLayout layout, 515 ash::WallpaperLayout layout,
460 const UserImage& wallpaper) { 516 const UserImage& wallpaper) {
461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 517 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
462 518
463 BrowserThread::PostTask( 519 BrowserThread::PostTask(
464 BrowserThread::FILE, 520 BrowserThread::FILE,
465 FROM_HERE, 521 FROM_HERE,
466 base::Bind(&WallpaperManager::CacheThumbnail, 522 base::Bind(&WallpaperManager::CacheThumbnail,
467 base::Unretained(this), email, wallpaper.image())); 523 base::Unretained(this), email, wallpaper.image()));
468 524
525 custom_wallpaper_cache_.insert(std::make_pair(email, wallpaper.image()));
469 ash::Shell::GetInstance()->desktop_background_controller()-> 526 ash::Shell::GetInstance()->desktop_background_controller()->
470 SetCustomWallpaper(wallpaper.image(), layout); 527 SetCustomWallpaper(wallpaper.image(), layout);
471 } 528 }
472 529
473 void WallpaperManager::GetUserWallpaperProperties(const std::string& email, 530 void WallpaperManager::GetUserWallpaperProperties(const std::string& email,
474 User::WallpaperType* type, 531 User::WallpaperType* type,
475 int* index, 532 int* index,
476 base::Time* last_modification_date) { 533 base::Time* last_modification_date) {
477 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
478 535
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 635
579 void WallpaperManager::SystemResumed() { 636 void WallpaperManager::SystemResumed() {
580 BatchUpdateWallpaper(); 637 BatchUpdateWallpaper();
581 } 638 }
582 639
583 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { 640 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) {
584 RestartTimer(); 641 RestartTimer();
585 } 642 }
586 643
587 } // chromeos 644 } // chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698