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

Unified 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: Use DCHECK replace if cause. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/login/wallpaper_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/login/wallpaper_manager.cc
diff --git a/chrome/browser/chromeos/login/wallpaper_manager.cc b/chrome/browser/chromeos/login/wallpaper_manager.cc
index b0e59a88a19350c7b4fb479062761fb4b76eed06..6e051c62843045f9b840bfe130a17a96dcb63aa5 100644
--- a/chrome/browser/chromeos/login/wallpaper_manager.cc
+++ b/chrome/browser/chromeos/login/wallpaper_manager.cc
@@ -17,6 +17,7 @@
#include "base/time.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/login/user.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
@@ -47,6 +48,8 @@ const char kWallpaperDateNodeName[] = "date";
const int kThumbnailWidth = 128;
const int kThumbnailHeight = 80;
+const int kCacheWallpaperDelayMs = 500;
+
// Default wallpaper index used in OOBE (first boot).
// Defined here because Chromium default index differs.
// Also see ash::WallpaperInfo kDefaultWallpapers in
@@ -83,11 +86,18 @@ WallpaperManager::WallpaperManager()
current_user_wallpaper_type_(User::UNKNOWN),
ALLOW_THIS_IN_INITIALIZER_LIST(current_user_wallpaper_index_(
ash::GetInvalidWallpaperIndex())),
+ should_cache_wallpaper_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
RestartTimer();
registrar_.Add(this,
chrome::NOTIFICATION_LOGIN_USER_CHANGED,
content::NotificationService::AllSources());
+ registrar_.Add(this,
+ chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE,
+ content::NotificationService::AllSources());
+ registrar_.Add(this,
+ chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED,
+ content::NotificationService::AllSources());
}
// static
@@ -102,21 +112,6 @@ void WallpaperManager::AddObservers() {
system::TimezoneSettings::GetInstance()->AddObserver(this);
}
-void WallpaperManager::CacheIfCustomWallpaper(const std::string& email) {
- User::WallpaperType type;
- int index;
- base::Time date;
- GetUserWallpaperProperties(email, &type, &index, &date);
- if (type == User::CUSTOMIZED) {
- std::string wallpaper_path = GetWallpaperPathForUser(email, false).value();
-
- // Uses WeakPtr here to make the request cancelable.
- wallpaper_loader_->Start(wallpaper_path, 0,
- base::Bind(&WallpaperManager::CacheWallpaper,
- weak_factory_.GetWeakPtr(), email));
- }
-}
-
void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() {
User::WallpaperType type;
int index;
@@ -245,10 +240,39 @@ void WallpaperManager::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) {
- // Cancel callback for previous cache requests.
- weak_factory_.InvalidateWeakPtrs();
- custom_wallpaper_cache_.clear();
+ switch (type) {
+ case chrome::NOTIFICATION_LOGIN_USER_CHANGED: {
+ // Cancel callback for previous cache requests.
+ weak_factory_.InvalidateWeakPtrs();
+ custom_wallpaper_cache_.clear();
+ break;
+ }
+ case chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE: {
+ if (!CommandLine::ForCurrentProcess()->
+ HasSwitch(switches::kDisableBootAnimation)) {
+ BrowserThread::PostDelayedTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&WallpaperManager::CacheAllUsersWallpapers,
+ weak_factory_.GetWeakPtr()),
+ base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs));
+ } else {
+ should_cache_wallpaper_ = true;
+ }
+ break;
+ }
+ case chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED: {
+ if (should_cache_wallpaper_) {
+ BrowserThread::PostDelayedTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&WallpaperManager::CacheAllUsersWallpapers,
+ weak_factory_.GetWeakPtr()),
+ base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs));
+ should_cache_wallpaper_ = false;
+ }
+ break;
+ }
+ default:
+ NOTREACHED() << "Unexpected notification " << type;
}
}
@@ -448,6 +472,37 @@ void WallpaperManager::BatchUpdateWallpaper() {
RestartTimer();
}
+void WallpaperManager::CacheAllUsersWallpapers() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ UserList users = UserManager::Get()->GetUsers();
+
+ UserList::const_iterator it = users.begin();
+ // Skip the wallpaper of first user in the list. It should have been cached.
+ it++;
+ for (; it != users.end(); ++it) {
+ std::string user_email = (*it)->email();
+ CacheUserWallpaper(user_email);
+ }
+}
+
+void WallpaperManager::CacheUserWallpaper(const std::string& email) {
+ User::WallpaperType type;
+ int index;
+ base::Time date;
+ GetUserWallpaperProperties(email, &type, &index, &date);
+ if (type == User::CUSTOMIZED) {
+ std::string wallpaper_path = GetWallpaperPathForUser(email, false).value();
+
+ // Uses WeakPtr here to make the request cancelable.
+ wallpaper_loader_->Start(wallpaper_path, 0,
+ base::Bind(&WallpaperManager::CacheWallpaper,
+ weak_factory_.GetWeakPtr(), email));
+ } else {
+ ash::Shell::GetInstance()->desktop_background_controller()->
+ CacheDefaultWallpaper(index);
+ }
+}
+
void WallpaperManager::CacheWallpaper(const std::string& email,
const UserImage& wallpaper) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -483,6 +538,7 @@ void WallpaperManager::FetchWallpaper(const std::string& email,
base::Bind(&WallpaperManager::CacheThumbnail,
base::Unretained(this), email, wallpaper.image()));
+ custom_wallpaper_cache_.insert(std::make_pair(email, wallpaper.image()));
ash::Shell::GetInstance()->desktop_background_controller()->
SetCustomWallpaper(wallpaper.image(), layout);
}
« no previous file with comments | « chrome/browser/chromeos/login/wallpaper_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698