| 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 "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" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/chromeos/login/user.h" |
| 20 #include "chrome/browser/chromeos/login/user_manager.h" | 21 #include "chrome/browser/chromeos/login/user_manager.h" |
| 21 #include "chrome/browser/chromeos/login/wizard_controller.h" | 22 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 22 #include "chrome/browser/chromeos/settings/cros_settings.h" | 23 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 23 #include "chrome/browser/prefs/pref_service.h" | 24 #include "chrome/browser/prefs/pref_service.h" |
| 24 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 25 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 25 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
| 26 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
| 27 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 29 #include "chromeos/dbus/dbus_thread_manager.h" | 30 #include "chromeos/dbus/dbus_thread_manager.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 40 | 41 |
| 41 const int kWallpaperUpdateIntervalSec = 24 * 60 * 60; | 42 const int kWallpaperUpdateIntervalSec = 24 * 60 * 60; |
| 42 | 43 |
| 43 const char kWallpaperTypeNodeName[] = "type"; | 44 const char kWallpaperTypeNodeName[] = "type"; |
| 44 const char kWallpaperIndexNodeName[] = "index"; | 45 const char kWallpaperIndexNodeName[] = "index"; |
| 45 const char kWallpaperDateNodeName[] = "date"; | 46 const char kWallpaperDateNodeName[] = "date"; |
| 46 | 47 |
| 47 const int kThumbnailWidth = 128; | 48 const int kThumbnailWidth = 128; |
| 48 const int kThumbnailHeight = 80; | 49 const int kThumbnailHeight = 80; |
| 49 | 50 |
| 51 const int kCacheWallpaperDelayMs = 500; |
| 52 |
| 50 // Default wallpaper index used in OOBE (first boot). | 53 // Default wallpaper index used in OOBE (first boot). |
| 51 // Defined here because Chromium default index differs. | 54 // Defined here because Chromium default index differs. |
| 52 // Also see ash::WallpaperInfo kDefaultWallpapers in | 55 // Also see ash::WallpaperInfo kDefaultWallpapers in |
| 53 // desktop_background_resources.cc | 56 // desktop_background_resources.cc |
| 54 #if defined(GOOGLE_CHROME_BUILD) | 57 #if defined(GOOGLE_CHROME_BUILD) |
| 55 const int kDefaultOOBEWallpaperIndex = 16; // IDR_AURA_WALLPAPERS_3_URBAN0 | 58 const int kDefaultOOBEWallpaperIndex = 16; // IDR_AURA_WALLPAPERS_3_URBAN0 |
| 56 #else | 59 #else |
| 57 const int kDefaultOOBEWallpaperIndex = 0; // IDR_AURA_WALLPAPERS_ROMAINGUY_0 | 60 const int kDefaultOOBEWallpaperIndex = 0; // IDR_AURA_WALLPAPERS_ROMAINGUY_0 |
| 58 #endif | 61 #endif |
| 59 | 62 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 76 if (!g_wallpaper_manager) | 79 if (!g_wallpaper_manager) |
| 77 g_wallpaper_manager = new WallpaperManager(); | 80 g_wallpaper_manager = new WallpaperManager(); |
| 78 return g_wallpaper_manager; | 81 return g_wallpaper_manager; |
| 79 } | 82 } |
| 80 | 83 |
| 81 WallpaperManager::WallpaperManager() | 84 WallpaperManager::WallpaperManager() |
| 82 : ALLOW_THIS_IN_INITIALIZER_LIST(wallpaper_loader_(new UserImageLoader)), | 85 : ALLOW_THIS_IN_INITIALIZER_LIST(wallpaper_loader_(new UserImageLoader)), |
| 83 current_user_wallpaper_type_(User::UNKNOWN), | 86 current_user_wallpaper_type_(User::UNKNOWN), |
| 84 ALLOW_THIS_IN_INITIALIZER_LIST(current_user_wallpaper_index_( | 87 ALLOW_THIS_IN_INITIALIZER_LIST(current_user_wallpaper_index_( |
| 85 ash::GetInvalidWallpaperIndex())), | 88 ash::GetInvalidWallpaperIndex())), |
| 89 should_cache_wallpaper_(false), |
| 86 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 90 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 87 RestartTimer(); | 91 RestartTimer(); |
| 88 registrar_.Add(this, | 92 registrar_.Add(this, |
| 89 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 93 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 90 content::NotificationService::AllSources()); | 94 content::NotificationService::AllSources()); |
| 95 registrar_.Add(this, |
| 96 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, |
| 97 content::NotificationService::AllSources()); |
| 98 registrar_.Add(this, |
| 99 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, |
| 100 content::NotificationService::AllSources()); |
| 91 } | 101 } |
| 92 | 102 |
| 93 // static | 103 // static |
| 94 void WallpaperManager::RegisterPrefs(PrefService* local_state) { | 104 void WallpaperManager::RegisterPrefs(PrefService* local_state) { |
| 95 local_state->RegisterDictionaryPref(prefs::kUsersWallpaperInfo, | 105 local_state->RegisterDictionaryPref(prefs::kUsersWallpaperInfo, |
| 96 PrefService::UNSYNCABLE_PREF); | 106 PrefService::UNSYNCABLE_PREF); |
| 97 } | 107 } |
| 98 | 108 |
| 99 void WallpaperManager::AddObservers() { | 109 void WallpaperManager::AddObservers() { |
| 100 if (!DBusThreadManager::Get()->GetPowerManagerClient()->HasObserver(this)) | 110 if (!DBusThreadManager::Get()->GetPowerManagerClient()->HasObserver(this)) |
| 101 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 111 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
| 102 system::TimezoneSettings::GetInstance()->AddObserver(this); | 112 system::TimezoneSettings::GetInstance()->AddObserver(this); |
| 103 } | 113 } |
| 104 | 114 |
| 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() { | 115 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { |
| 121 User::WallpaperType type; | 116 User::WallpaperType type; |
| 122 int index; | 117 int index; |
| 123 base::Time last_modification_date; | 118 base::Time last_modification_date; |
| 124 GetLoggedInUserWallpaperProperties(&type, &index, &last_modification_date); | 119 GetLoggedInUserWallpaperProperties(&type, &index, &last_modification_date); |
| 125 | 120 |
| 126 if (type != current_user_wallpaper_type_ || | 121 if (type != current_user_wallpaper_type_ || |
| 127 index != current_user_wallpaper_index_) { | 122 index != current_user_wallpaper_index_) { |
| 128 SetUserWallpaper(UserManager::Get()->GetLoggedInUser().email()); | 123 SetUserWallpaper(UserManager::Get()->GetLoggedInUser().email()); |
| 129 } | 124 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 } | 233 } |
| 239 return; | 234 return; |
| 240 } | 235 } |
| 241 SetUserWallpaper(user_manager->GetLoggedInUser().email()); | 236 SetUserWallpaper(user_manager->GetLoggedInUser().email()); |
| 242 } | 237 } |
| 243 | 238 |
| 244 void WallpaperManager::Observe(int type, | 239 void WallpaperManager::Observe(int type, |
| 245 const content::NotificationSource& source, | 240 const content::NotificationSource& source, |
| 246 const content::NotificationDetails& details) { | 241 const content::NotificationDetails& details) { |
| 247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 248 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { | 243 switch (type) { |
| 249 // Cancel callback for previous cache requests. | 244 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { |
| 250 weak_factory_.InvalidateWeakPtrs(); | 245 // Cancel callback for previous cache requests. |
| 251 custom_wallpaper_cache_.clear(); | 246 weak_factory_.InvalidateWeakPtrs(); |
| 247 custom_wallpaper_cache_.clear(); |
| 248 break; |
| 249 } |
| 250 case chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE: { |
| 251 if (!CommandLine::ForCurrentProcess()-> |
| 252 HasSwitch(switches::kDisableBootAnimation)) { |
| 253 BrowserThread::PostDelayedTask( |
| 254 BrowserThread::UI, FROM_HERE, |
| 255 base::Bind(&WallpaperManager::CacheAllUsersWallpapers, |
| 256 weak_factory_.GetWeakPtr()), |
| 257 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); |
| 258 } else { |
| 259 should_cache_wallpaper_ = true; |
| 260 } |
| 261 break; |
| 262 } |
| 263 case chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED: { |
| 264 if (should_cache_wallpaper_) { |
| 265 BrowserThread::PostDelayedTask( |
| 266 BrowserThread::UI, FROM_HERE, |
| 267 base::Bind(&WallpaperManager::CacheAllUsersWallpapers, |
| 268 weak_factory_.GetWeakPtr()), |
| 269 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); |
| 270 should_cache_wallpaper_ = false; |
| 271 } |
| 272 break; |
| 273 } |
| 274 default: |
| 275 NOTREACHED() << "Unexpected notification " << type; |
| 252 } | 276 } |
| 253 } | 277 } |
| 254 | 278 |
| 255 void WallpaperManager::RestartTimer() { | 279 void WallpaperManager::RestartTimer() { |
| 256 timer_.Stop(); | 280 timer_.Stop(); |
| 257 base::Time midnight = base::Time::Now().LocalMidnight(); | 281 base::Time midnight = base::Time::Now().LocalMidnight(); |
| 258 base::TimeDelta interval = base::Time::Now() - midnight; | 282 base::TimeDelta interval = base::Time::Now() - midnight; |
| 259 int64 remaining_seconds = kWallpaperUpdateIntervalSec - interval.InSeconds(); | 283 int64 remaining_seconds = kWallpaperUpdateIntervalSec - interval.InSeconds(); |
| 260 if (remaining_seconds <= 0) { | 284 if (remaining_seconds <= 0) { |
| 261 BatchUpdateWallpaper(); | 285 BatchUpdateWallpaper(); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 SetUserWallpaper(email); | 465 SetUserWallpaper(email); |
| 442 } else if (show_users && | 466 } else if (show_users && |
| 443 email == last_selected_user_) { | 467 email == last_selected_user_) { |
| 444 SetUserWallpaper(email); | 468 SetUserWallpaper(email); |
| 445 } | 469 } |
| 446 } | 470 } |
| 447 } | 471 } |
| 448 RestartTimer(); | 472 RestartTimer(); |
| 449 } | 473 } |
| 450 | 474 |
| 475 void WallpaperManager::CacheAllUsersWallpapers() { |
| 476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 477 UserList users = UserManager::Get()->GetUsers(); |
| 478 |
| 479 UserList::const_iterator it = users.begin(); |
| 480 // Skip the wallpaper of first user in the list. It should have been cached. |
| 481 it++; |
| 482 for (; it != users.end(); ++it) { |
| 483 std::string user_email = (*it)->email(); |
| 484 CacheUserWallpaper(user_email); |
| 485 } |
| 486 } |
| 487 |
| 488 void WallpaperManager::CacheUserWallpaper(const std::string& email) { |
| 489 User::WallpaperType type; |
| 490 int index; |
| 491 base::Time date; |
| 492 GetUserWallpaperProperties(email, &type, &index, &date); |
| 493 if (type == User::CUSTOMIZED) { |
| 494 std::string wallpaper_path = GetWallpaperPathForUser(email, false).value(); |
| 495 |
| 496 // Uses WeakPtr here to make the request cancelable. |
| 497 wallpaper_loader_->Start(wallpaper_path, 0, |
| 498 base::Bind(&WallpaperManager::CacheWallpaper, |
| 499 weak_factory_.GetWeakPtr(), email)); |
| 500 } else { |
| 501 ash::Shell::GetInstance()->desktop_background_controller()-> |
| 502 CacheDefaultWallpaper(index); |
| 503 } |
| 504 } |
| 505 |
| 451 void WallpaperManager::CacheWallpaper(const std::string& email, | 506 void WallpaperManager::CacheWallpaper(const std::string& email, |
| 452 const UserImage& wallpaper) { | 507 const UserImage& wallpaper) { |
| 453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 508 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 454 DCHECK(custom_wallpaper_cache_.find(email) == custom_wallpaper_cache_.end()); | 509 DCHECK(custom_wallpaper_cache_.find(email) == custom_wallpaper_cache_.end()); |
| 455 | 510 |
| 456 BrowserThread::PostTask( | 511 BrowserThread::PostTask( |
| 457 BrowserThread::FILE, | 512 BrowserThread::FILE, |
| 458 FROM_HERE, | 513 FROM_HERE, |
| 459 base::Bind(&WallpaperManager::CacheThumbnail, | 514 base::Bind(&WallpaperManager::CacheThumbnail, |
| 460 base::Unretained(this), email, wallpaper.image())); | 515 base::Unretained(this), email, wallpaper.image())); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 476 ash::WallpaperLayout layout, | 531 ash::WallpaperLayout layout, |
| 477 const UserImage& wallpaper) { | 532 const UserImage& wallpaper) { |
| 478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 533 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 479 | 534 |
| 480 BrowserThread::PostTask( | 535 BrowserThread::PostTask( |
| 481 BrowserThread::FILE, | 536 BrowserThread::FILE, |
| 482 FROM_HERE, | 537 FROM_HERE, |
| 483 base::Bind(&WallpaperManager::CacheThumbnail, | 538 base::Bind(&WallpaperManager::CacheThumbnail, |
| 484 base::Unretained(this), email, wallpaper.image())); | 539 base::Unretained(this), email, wallpaper.image())); |
| 485 | 540 |
| 541 custom_wallpaper_cache_.insert(std::make_pair(email, wallpaper.image())); |
| 486 ash::Shell::GetInstance()->desktop_background_controller()-> | 542 ash::Shell::GetInstance()->desktop_background_controller()-> |
| 487 SetCustomWallpaper(wallpaper.image(), layout); | 543 SetCustomWallpaper(wallpaper.image(), layout); |
| 488 } | 544 } |
| 489 | 545 |
| 490 void WallpaperManager::GetUserWallpaperProperties(const std::string& email, | 546 void WallpaperManager::GetUserWallpaperProperties(const std::string& email, |
| 491 User::WallpaperType* type, | 547 User::WallpaperType* type, |
| 492 int* index, | 548 int* index, |
| 493 base::Time* last_modification_date) { | 549 base::Time* last_modification_date) { |
| 494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 550 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 495 | 551 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 | 651 |
| 596 void WallpaperManager::SystemResumed() { | 652 void WallpaperManager::SystemResumed() { |
| 597 BatchUpdateWallpaper(); | 653 BatchUpdateWallpaper(); |
| 598 } | 654 } |
| 599 | 655 |
| 600 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { | 656 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { |
| 601 RestartTimer(); | 657 RestartTimer(); |
| 602 } | 658 } |
| 603 | 659 |
| 604 } // chromeos | 660 } // chromeos |
| OLD | NEW |