Commit d07204a6 authored by bshe@chromium.org's avatar bshe@chromium.org

Speed up custom wallpaper loading and wallpaper manager code refactor


BUG=138588, 131203, 139887
TEST=

Review URL: https://chromiumcodereview.appspot.com/10832019

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149796 0039d316-1c4b-4281-b951-d872f2087c98
parent 47ff9ff0
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h" #include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h"
#include "chrome/browser/chromeos/login/user_manager.h" #include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/login/wallpaper_manager.h"
#include "chrome/browser/chromeos/login/wizard_controller.h" #include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
...@@ -49,7 +50,7 @@ class UserWallpaperDelegate: public ash::UserWallpaperDelegate { ...@@ -49,7 +50,7 @@ class UserWallpaperDelegate: public ash::UserWallpaperDelegate {
} }
virtual void InitializeWallpaper() OVERRIDE { virtual void InitializeWallpaper() OVERRIDE {
chromeos::UserManager::Get()->InitializeWallpaper(); chromeos::WallpaperManager::Get()->InitializeWallpaper();
} }
virtual void OpenSetWallpaperPage() OVERRIDE { virtual void OpenSetWallpaperPage() OVERRIDE {
......
...@@ -284,9 +284,9 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopStart() { ...@@ -284,9 +284,9 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopStart() {
// Initialize DBusThreadManager for the browser. This must be done after // Initialize DBusThreadManager for the browser. This must be done after
// the main message loop is started, as it uses the message loop. // the main message loop is started, as it uses the message loop.
chromeos::DBusThreadManager::Initialize(); chromeos::DBusThreadManager::Initialize();
// Add PowerManagerClient observer for WallpaperManager. WallpaperManager // Add observers for WallpaperManager. WallpaperManager is initialized before
// is initialized before DBusThreadManager. // DBusThreadManager.
chromeos::WallpaperManager::Get()->AddPowerManagerClientObserver(); chromeos::WallpaperManager::Get()->AddObservers();
chromeos::CrosDBusService::Initialize(); chromeos::CrosDBusService::Initialize();
......
...@@ -136,8 +136,6 @@ class ExistingUserControllerTest : public CrosInProcessBrowserTest { ...@@ -136,8 +136,6 @@ class ExistingUserControllerTest : public CrosInProcessBrowserTest {
mock_login_display_host_.reset(new MockLoginDisplayHost()); mock_login_display_host_.reset(new MockLoginDisplayHost());
EXPECT_CALL(*mock_user_manager_.user_manager(), InitializeWallpaper())
.Times(1);
EXPECT_CALL(*mock_user_manager_.user_manager(), IsKnownUser(kUsername)) EXPECT_CALL(*mock_user_manager_.user_manager(), IsKnownUser(kUsername))
.Times(AnyNumber()) .Times(AnyNumber())
.WillRepeatedly(Return(true)); .WillRepeatedly(Return(true));
......
...@@ -25,8 +25,6 @@ class MockUserManager : public UserManager { ...@@ -25,8 +25,6 @@ class MockUserManager : public UserManager {
MOCK_METHOD0(DemoUserLoggedIn, void(void)); MOCK_METHOD0(DemoUserLoggedIn, void(void));
MOCK_METHOD0(GuestUserLoggedIn, void(void)); MOCK_METHOD0(GuestUserLoggedIn, void(void));
MOCK_METHOD1(EphemeralUserLoggedIn, void(const std::string&)); MOCK_METHOD1(EphemeralUserLoggedIn, void(const std::string&));
MOCK_METHOD0(InitializeWallpaper, void(void));
MOCK_METHOD1(UserSelected, void(const std::string&));
MOCK_METHOD0(SessionStarted, void(void)); MOCK_METHOD0(SessionStarted, void(void));
MOCK_METHOD2(RemoveUser, void(const std::string&, RemoveUserDelegate*)); MOCK_METHOD2(RemoveUser, void(const std::string&, RemoveUserDelegate*));
MOCK_METHOD1(RemoveUserFromList, void(const std::string&)); MOCK_METHOD1(RemoveUserFromList, void(const std::string&));
...@@ -39,9 +37,6 @@ class MockUserManager : public UserManager { ...@@ -39,9 +37,6 @@ class MockUserManager : public UserManager {
MOCK_CONST_METHOD1(GetUserDisplayName, string16(const std::string&)); MOCK_CONST_METHOD1(GetUserDisplayName, string16(const std::string&));
MOCK_METHOD2(SaveUserDisplayEmail, void(const std::string&, MOCK_METHOD2(SaveUserDisplayEmail, void(const std::string&,
const std::string&)); const std::string&));
MOCK_METHOD3(GetLoggedInUserWallpaperProperties, void(User::WallpaperType*,
int*,
base::Time*));
MOCK_METHOD2(SaveLoggedInUserWallpaperProperties, void(User::WallpaperType, MOCK_METHOD2(SaveLoggedInUserWallpaperProperties, void(User::WallpaperType,
int)); int));
MOCK_CONST_METHOD1(GetUserDisplayEmail, std::string(const std::string&)); MOCK_CONST_METHOD1(GetUserDisplayEmail, std::string(const std::string&));
...@@ -51,11 +46,6 @@ class MockUserManager : public UserManager { ...@@ -51,11 +46,6 @@ class MockUserManager : public UserManager {
ash::WallpaperLayout)); ash::WallpaperLayout));
MOCK_METHOD2(SaveUserImageFromFile, void(const std::string&, MOCK_METHOD2(SaveUserImageFromFile, void(const std::string&,
const FilePath&)); const FilePath&));
MOCK_METHOD4(SaveUserWallpaperFromFile, void(
const std::string&,
const FilePath&,
ash::WallpaperLayout,
base::WeakPtr<WallpaperDelegate>));
MOCK_METHOD1(SaveUserImageFromProfileImage, void(const std::string&)); MOCK_METHOD1(SaveUserImageFromProfileImage, void(const std::string&));
MOCK_METHOD1(DownloadProfileImage, void(const std::string&)); MOCK_METHOD1(DownloadProfileImage, void(const std::string&));
MOCK_CONST_METHOD0(IsCurrentUserOwner, bool(void)); MOCK_CONST_METHOD0(IsCurrentUserOwner, bool(void));
......
...@@ -60,10 +60,6 @@ void User::SetStubImage(int image_index) { ...@@ -60,10 +60,6 @@ void User::SetStubImage(int image_index) {
image_is_stub_ = true; image_is_stub_ = true;
} }
void User::SetWallpaperThumbnail(const SkBitmap& wallpaper_thumbnail) {
wallpaper_thumbnail_ = wallpaper_thumbnail;
}
std::string User::GetAccountName(bool use_display_email) const { std::string User::GetAccountName(bool use_display_email) const {
if (use_display_email && !display_email_.empty()) if (use_display_email && !display_email_.empty())
return GetUserName(display_email_); return GetUserName(display_email_);
......
...@@ -85,9 +85,6 @@ class User { ...@@ -85,9 +85,6 @@ class User {
// image has a URL, for other images empty URL is returned. // image has a URL, for other images empty URL is returned.
GURL image_url() const { return user_image_.url(); } GURL image_url() const { return user_image_.url(); }
// The thumbnail of user custom wallpaper.
const SkBitmap& wallpaper_thumbnail() const { return wallpaper_thumbnail_; }
// True if user image is a stub (while real image is being loaded from file). // True if user image is a stub (while real image is being loaded from file).
bool image_is_stub() const { return image_is_stub_; } bool image_is_stub() const { return image_is_stub_; }
...@@ -142,7 +139,6 @@ class User { ...@@ -142,7 +139,6 @@ class User {
std::string display_email_; std::string display_email_;
UserImage user_image_; UserImage user_image_;
OAuthTokenStatus oauth_token_status_; OAuthTokenStatus oauth_token_status_;
SkBitmap wallpaper_thumbnail_;
// Either index of a default image for the user, |kExternalImageIndex| or // Either index of a default image for the user, |kExternalImageIndex| or
// |kProfileImageIndex|. // |kProfileImageIndex|.
......
...@@ -110,14 +110,6 @@ class UserManager { ...@@ -110,14 +110,6 @@ class UserManager {
// Indicates that a user just logged in as ephemeral. // Indicates that a user just logged in as ephemeral.
virtual void EphemeralUserLoggedIn(const std::string& email) = 0; virtual void EphemeralUserLoggedIn(const std::string& email) = 0;
// Initializes wallpaper. If logged in, loads user's wallpaper. If not logged
// in, uses a solid color wallpaper. If logged in as a stub user, uses an
// empty wallpaper.
virtual void InitializeWallpaper() = 0;
// Called when user pod with |email| is selected.
virtual void UserSelected(const std::string& email) = 0;
// Called when browser session is started i.e. after // Called when browser session is started i.e. after
// browser_creator.LaunchBrowser(...) was called after user sign in. // browser_creator.LaunchBrowser(...) was called after user sign in.
// When user is at the image screen IsUserLoggedIn() will return true // When user is at the image screen IsUserLoggedIn() will return true
...@@ -174,12 +166,6 @@ class UserManager { ...@@ -174,12 +166,6 @@ class UserManager {
virtual std::string GetUserDisplayEmail( virtual std::string GetUserDisplayEmail(
const std::string& username) const = 0; const std::string& username) const = 0;
// Sets |type| and |index| to the value saved in local state for logged in
// user.
virtual void GetLoggedInUserWallpaperProperties(User::WallpaperType* type,
int* index,
base::Time* last_modification_date) = 0;
// Saves |type| and |index| chose by logged in user to Local State. // Saves |type| and |index| chose by logged in user to Local State.
virtual void SaveLoggedInUserWallpaperProperties(User::WallpaperType type, virtual void SaveLoggedInUserWallpaperProperties(User::WallpaperType type,
int index) = 0; int index) = 0;
...@@ -204,14 +190,6 @@ class UserManager { ...@@ -204,14 +190,6 @@ class UserManager {
virtual void SaveUserImageFromFile(const std::string& username, virtual void SaveUserImageFromFile(const std::string& username,
const FilePath& path) = 0; const FilePath& path) = 0;
// Tries to load user image from disk; if successful, sets it for the user,
// and updates Local State.
virtual void SaveUserWallpaperFromFile(
const std::string& username,
const FilePath& path,
ash::WallpaperLayout layout,
base::WeakPtr<WallpaperDelegate> delegate) = 0;
// Sets profile image as user image for |username|, sends // Sets profile image as user image for |username|, sends
// LOGIN_USER_IMAGE_CHANGED notification and updates Local State. If the user // LOGIN_USER_IMAGE_CHANGED notification and updates Local State. If the user
// is not logged-in or the last |DownloadProfileImage| call has failed, a // is not logged-in or the last |DownloadProfileImage| call has failed, a
......
...@@ -51,8 +51,6 @@ class UserManagerImpl : public UserManager, ...@@ -51,8 +51,6 @@ class UserManagerImpl : public UserManager,
virtual void DemoUserLoggedIn() OVERRIDE; virtual void DemoUserLoggedIn() OVERRIDE;
virtual void GuestUserLoggedIn() OVERRIDE; virtual void GuestUserLoggedIn() OVERRIDE;
virtual void EphemeralUserLoggedIn(const std::string& email) OVERRIDE; virtual void EphemeralUserLoggedIn(const std::string& email) OVERRIDE;
virtual void InitializeWallpaper() OVERRIDE;
virtual void UserSelected(const std::string& email) OVERRIDE;
virtual void SessionStarted() OVERRIDE; virtual void SessionStarted() OVERRIDE;
virtual void RemoveUser(const std::string& email, virtual void RemoveUser(const std::string& email,
RemoveUserDelegate* delegate) OVERRIDE; RemoveUserDelegate* delegate) OVERRIDE;
...@@ -72,9 +70,6 @@ class UserManagerImpl : public UserManager, ...@@ -72,9 +70,6 @@ class UserManagerImpl : public UserManager,
const std::string& display_email) OVERRIDE; const std::string& display_email) OVERRIDE;
virtual std::string GetUserDisplayEmail( virtual std::string GetUserDisplayEmail(
const std::string& username) const OVERRIDE; const std::string& username) const OVERRIDE;
virtual void GetLoggedInUserWallpaperProperties(User::WallpaperType* type,
int* index,
base::Time* last_modification_date) OVERRIDE;
virtual void SaveLoggedInUserWallpaperProperties(User::WallpaperType type, virtual void SaveLoggedInUserWallpaperProperties(User::WallpaperType type,
int index) OVERRIDE; int index) OVERRIDE;
virtual void SaveUserDefaultImageIndex(const std::string& username, virtual void SaveUserDefaultImageIndex(const std::string& username,
...@@ -85,11 +80,6 @@ class UserManagerImpl : public UserManager, ...@@ -85,11 +80,6 @@ class UserManagerImpl : public UserManager,
ash::WallpaperLayout layout) OVERRIDE; ash::WallpaperLayout layout) OVERRIDE;
virtual void SaveUserImageFromFile(const std::string& username, virtual void SaveUserImageFromFile(const std::string& username,
const FilePath& path) OVERRIDE; const FilePath& path) OVERRIDE;
virtual void SaveUserWallpaperFromFile(
const std::string& username,
const FilePath& path,
ash::WallpaperLayout layout,
base::WeakPtr<WallpaperDelegate> delegate) OVERRIDE;
virtual void SaveUserImageFromProfileImage( virtual void SaveUserImageFromProfileImage(
const std::string& username) OVERRIDE; const std::string& username) OVERRIDE;
virtual void DownloadProfileImage(const std::string& reason) OVERRIDE; virtual void DownloadProfileImage(const std::string& reason) OVERRIDE;
...@@ -120,10 +110,6 @@ class UserManagerImpl : public UserManager, ...@@ -120,10 +110,6 @@ class UserManagerImpl : public UserManager,
// Returns image filepath for the given user. // Returns image filepath for the given user.
FilePath GetImagePathForUser(const std::string& username); FilePath GetImagePathForUser(const std::string& username);
// Returns wallpaper/thumbnail filepath for the given user.
FilePath GetWallpaperPathForUser(const std::string& username,
bool is_thumbnail);
private: private:
friend class UserManagerImplWrapper; friend class UserManagerImplWrapper;
friend class UserManagerTest; friend class UserManagerTest;
...@@ -133,10 +119,6 @@ class UserManagerImpl : public UserManager, ...@@ -133,10 +119,6 @@ class UserManagerImpl : public UserManager,
// Subsequent calls have no effect. Must be called on the UI thread. // Subsequent calls have no effect. Must be called on the UI thread.
void EnsureUsersLoaded(); void EnsureUsersLoaded();
// Loads wallpaper asynchronously if the current wallpaper is not the
// wallpaper of logged in user.
void EnsureLoggedInUserWallpaperLoaded();
// Retrieves trusted device policies and removes users from the persistent // Retrieves trusted device policies and removes users from the persistent
// list if ephemeral users are enabled. Schedules a callback to itself if // list if ephemeral users are enabled. Schedules a callback to itself if
// trusted device policies are not yet available. // trusted device policies are not yet available.
...@@ -167,10 +149,6 @@ class UserManagerImpl : public UserManager, ...@@ -167,10 +149,6 @@ class UserManagerImpl : public UserManager,
// Does not send LOGIN_USER_IMAGE_CHANGED notification. // Does not send LOGIN_USER_IMAGE_CHANGED notification.
void SetInitialUserImage(const std::string& username); void SetInitialUserImage(const std::string& username);
// Sets one of the default wallpapers for the specified user and saves this
// settings in local state.
void SetInitialUserWallpaper(const std::string& username);
// Migrate the old wallpaper index to a new wallpaper structure. // Migrate the old wallpaper index to a new wallpaper structure.
// The new wallpaper structure is: // The new wallpaper structure is:
// { WallpaperType: DAILY|CUSTOMIZED|DEFAULT, // { WallpaperType: DAILY|CUSTOMIZED|DEFAULT,
...@@ -185,18 +163,6 @@ class UserManagerImpl : public UserManager, ...@@ -185,18 +163,6 @@ class UserManagerImpl : public UserManager,
const GURL& image_url, const GURL& image_url,
const UserImage& user_image); const UserImage& user_image);
// Get wallpaper |type|, |index| and |last_modification_date| of |username|
// from local state.
void GetUserWallpaperProperties(const std::string& username,
User::WallpaperType* type,
int* index,
base::Time* last_modification_date);
// Set |username|'s wallpaper |type|, |index| and local date to local state.
void SaveUserWallpaperProperties(const std::string& username,
User::WallpaperType type,
int index);
// Saves image to file, updates local state preferences to given image index // Saves image to file, updates local state preferences to given image index
// and sends LOGIN_USER_IMAGE_CHANGED notification. // and sends LOGIN_USER_IMAGE_CHANGED notification.
void SaveUserImageInternal(const std::string& username, void SaveUserImageInternal(const std::string& username,
...@@ -204,33 +170,6 @@ class UserManagerImpl : public UserManager, ...@@ -204,33 +170,6 @@ class UserManagerImpl : public UserManager,
const GURL& image_url, const GURL& image_url,
const UserImage& user_image); const UserImage& user_image);
// Saves wallpaper to file, post task to generate thumbnail and updates local
// state preferences.
void SaveUserWallpaperInternal(const std::string& username,
ash::WallpaperLayout layout,
User::WallpaperType type,
base::WeakPtr<WallpaperDelegate> delegate,
const UserImage& user_image);
// Sets desktop background to custom wallpaper and loads wallpaper thumbnail
// asynchronously.
void OnCustomWallpaperLoaded(const std::string& email,
ash::WallpaperLayout layout,
const UserImage& wallpaper);
// Caches the loaded wallpaper for the given user.
void OnCustomWallpaperThumbnailLoaded(const std::string& email,
const UserImage& user_image);
// Updates the custom wallpaper thumbnail in wallpaper picker UI.
void OnThumbnailUpdated(base::WeakPtr<WallpaperDelegate> delegate);
// Generates a 128x80 thumbnail and saves it to local file system.
void GenerateUserWallpaperThumbnail(const std::string& username,
User::WallpaperType type,
base::WeakPtr<WallpaperDelegate> delegate,
const SkBitmap& wallpaper);
// Saves image to file with specified path and sends LOGIN_USER_IMAGE_CHANGED // Saves image to file with specified path and sends LOGIN_USER_IMAGE_CHANGED
// notification. Runs on FILE thread. Posts task for saving image info to // notification. Runs on FILE thread. Posts task for saving image info to
// Local State on UI thread. // Local State on UI thread.
...@@ -240,14 +179,6 @@ class UserManagerImpl : public UserManager, ...@@ -240,14 +179,6 @@ class UserManagerImpl : public UserManager,
int image_index, int image_index,
const GURL& image_url); const GURL& image_url);
// Saves wallpaper to file with specified path. Runs on FILE thread. Posts
// task for saving wallpaper info to Local State on UI thread.
void SaveWallpaperToFile(const std::string& username,
const SkBitmap& wallpaper,
const FilePath& wallpaper_path,
ash::WallpaperLayout layout,
User::WallpaperType type);
// Stores path to the image and its index in local state. Runs on UI thread. // Stores path to the image and its index in local state. Runs on UI thread.
// If |is_async| is true, it has been posted from the FILE thread after // If |is_async| is true, it has been posted from the FILE thread after
// saving the image. // saving the image.
...@@ -334,10 +265,6 @@ class UserManagerImpl : public UserManager, ...@@ -334,10 +265,6 @@ class UserManagerImpl : public UserManager,
// mounting their cryptohomes using tmpfs. // mounting their cryptohomes using tmpfs.
bool is_current_user_ephemeral_; bool is_current_user_ephemeral_;
User::WallpaperType current_user_wallpaper_type_;
int current_user_wallpaper_index_;
// Cached flag indicating whether ephemeral users are enabled. Defaults to // Cached flag indicating whether ephemeral users are enabled. Defaults to
// |false| if the value has not been read from trusted device policy yet. // |false| if the value has not been read from trusted device policy yet.
bool ephemeral_users_enabled_; bool ephemeral_users_enabled_;
......
...@@ -8,23 +8,31 @@ ...@@ -8,23 +8,31 @@
#include <string> #include <string>
#include "ash/desktop_background/desktop_background_resources.h" #include "ash/desktop_background/desktop_background_resources.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/time.h"
#include "base/timer.h" #include "base/timer.h"
#include "chrome/browser/chromeos/login/user.h" #include "chrome/browser/chromeos/login/user.h"
#include "chrome/browser/chromeos/login/user_image.h" #include "chrome/browser/chromeos/login/user_image.h"
#include "chrome/browser/chromeos/login/user_image_loader.h" #include "chrome/browser/chromeos/login/user_image_loader.h"
#include "chrome/browser/chromeos/power/resume_observer.h"
#include "chrome/browser/chromeos/system/timezone_settings.h" #include "chrome/browser/chromeos/system/timezone_settings.h"
#include "chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler.h"
#include "chromeos/dbus/power_manager_client.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/gfx/image/image_skia.h"
#include "unicode/timezone.h" #include "unicode/timezone.h"
class PrefService; class PrefService;
namespace chromeos { namespace chromeos {
class UserImage;
// This class maintains wallpapers for users who have logged into this Chrome // This class maintains wallpapers for users who have logged into this Chrome
// OS device. // OS device.
class WallpaperManager: public system::TimezoneSettings::Observer, class WallpaperManager: public system::TimezoneSettings::Observer,
public chromeos::ResumeObserver { public chromeos::PowerManagerClient::Observer,
public content::NotificationObserver {
public: public:
static WallpaperManager* Get(); static WallpaperManager* Get();
...@@ -33,14 +41,67 @@ class WallpaperManager: public system::TimezoneSettings::Observer, ...@@ -33,14 +41,67 @@ class WallpaperManager: public system::TimezoneSettings::Observer,
// Registers wallpaper manager preferences. // Registers wallpaper manager preferences.
static void RegisterPrefs(PrefService* local_state); static void RegisterPrefs(PrefService* local_state);
// Adds PowerManagerClient observer. It needs to be added after // Adds PowerManagerClient and TimeZoneSettings observers. It needs to be
// PowerManagerClient initialized. // added after PowerManagerClient initialized.
void AddPowerManagerClientObserver(); void AddObservers();
// Caches |email|'s wallpaper to memory if it is custom wallpaper.
void CacheIfCustomWallpaper(const std::string& email);
// Loads wallpaper asynchronously if the current wallpaper is not the
// wallpaper of logged in user.
void EnsureLoggedInUserWallpaperLoaded();
// Fetches |email|'s wallpaper from local disk.
void FetchCustomWallpaper(const std::string& email);
// Gets encoded custom wallpaper from cache. Returns true if success.
bool GetCustomWallpaperFromCache(const std::string& email,
gfx::ImageSkia* wallpaper);
// Returns wallpaper/thumbnail filepath for the given user.
FilePath GetWallpaperPathForUser(const std::string& username,
bool is_thumbnail);
// Gets the thumbnail of custom wallpaper from cache.
gfx::ImageSkia GetCustomWallpaperThumbnail(const std::string& email);
// Sets |type| and |index| to the value saved in local state for logged in
// user.
void GetLoggedInUserWallpaperProperties(User::WallpaperType* type,
int* index,
base::Time* last_modification_date);
// Initializes wallpaper. If logged in, loads user's wallpaper. If not logged
// in, uses a solid color wallpaper. If logged in as a stub user, uses an
// empty wallpaper.
void InitializeWallpaper();
// NotificationObserver overrides:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// Starts a one shot timer which calls BatchUpdateWallpaper at next midnight. // Starts a one shot timer which calls BatchUpdateWallpaper at next midnight.
// Cancel any previous timer if any. // Cancel any previous timer if any.
void RestartTimer(); void RestartTimer();
// Tries to load user image from disk; if successful, sets it for the user,
// and updates Local State.
void SetUserWallpaperFromFile(const std::string& username,
const FilePath& path,
ash::WallpaperLayout layout,
base::WeakPtr<WallpaperDelegate> delegate);
// Set |email|'s wallpaper |type|, |index| and local date to local state.
void SaveUserWallpaperProperties(const std::string& email,
User::WallpaperType type,
int index);
// Sets one of the default wallpapers for the specified user and saves this
// settings in local state.
void SetInitialUserWallpaper(const std::string& username);
// Saves |username| selected wallpaper information to local state. // Saves |username| selected wallpaper information to local state.
void SaveUserWallpaperInfo(const std::string& username, void SaveUserWallpaperInfo(const std::string& username,
const std::string& file_name, const std::string& file_name,
...@@ -50,45 +111,99 @@ class WallpaperManager: public system::TimezoneSettings::Observer, ...@@ -50,45 +111,99 @@ class WallpaperManager: public system::TimezoneSettings::Observer,
// Sets last selected user on user pod row. // Sets last selected user on user pod row.
void SetLastSelectedUser(const std::string& last_selected_user); void SetLastSelectedUser(const std::string& last_selected_user);
// Sets wallpaper to the image file |path| points to. // Sets |email|'s wallpaper.
void SetWallpaperFromFilePath(const std::string& path, void SetUserWallpaper(const std::string& email);
ash::WallpaperLayout layout);
// Sets wallpaper to |wallpaper|. // Sets wallpaper to |wallpaper|.
void SetWallpaperFromImageSkia(const gfx::ImageSkia& wallpaper, void SetWallpaperFromImageSkia(const gfx::ImageSkia& wallpaper,
ash::WallpaperLayout layout); ash::WallpaperLayout layout);
// User was deselected at login screen, reset wallpaper if needed. // User was deselected at login screen, reset wallpaper if needed.
void UserDeselected(); void OnUserDeselected();
// User |email| was selected at login screen, load wallpaper.
void OnUserSelected(const std::string& email);
private: private:
virtual ~WallpaperManager(); typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap;
void OnCustomWallpaperLoaded(const std::string& email, virtual ~WallpaperManager();
ash::WallpaperLayout layout,
const UserImage& user_image);
// Change the wallpapers for users who choose DAILY wallpaper type. Updates // Change the wallpapers for users who choose DAILY wallpaper type. Updates
// current wallpaper if it changed. This function should be called at exactly // current wallpaper if it changed. This function should be called at exactly
// at 0am if chromeos device is on. // at 0am if chromeos device is on.
void BatchUpdateWallpaper(); void BatchUpdateWallpaper();
// Caches the decoded wallpaper to memory.
void CacheWallpaper(const std::string& email, const UserImage& wallpaper);
// Generates a 128x80 thumbnail and caches it.
void CacheThumbnail(const std::string& email,
const gfx::ImageSkia& wallpaper);
// Sets wallpaper to the decoded wallpaper.
void FetchWallpaper(const std::string& email,
ash::WallpaperLayout layout,
const UserImage& wallpaper);
// Generates a 128x80 thumbnail and notifies delegate when ready.
void GenerateUserWallpaperThumbnail(const std::string& email,
User::WallpaperType type,
base::WeakPtr<WallpaperDelegate> delegate,
const gfx::ImageSkia& wallpaper);
// Get wallpaper |type|, |index| and |last_modification_date| of |email|
// from local state.
void GetUserWallpaperProperties(const std::string& email,
User::WallpaperType* type,
int* index,
base::Time* last_modification_date);
// Updates the custom wallpaper thumbnail in wallpaper picker UI.
void OnThumbnailUpdated(base::WeakPtr<WallpaperDelegate> delegate);
// Saves wallpaper to |path|.
void SaveWallpaper(const std::string& path, const UserImage& wallpaper);
// Saves wallpaper to file, post task to generate thumbnail and updates local
// state preferences.
void SetWallpaper(const std::string& username,
ash::WallpaperLayout layout,
User::WallpaperType type,
base::WeakPtr<WallpaperDelegate> delegate,
const UserImage& wallpaper);
// Sets wallpaper to image in |user_image| with |layout|. // Sets wallpaper to image in |user_image| with |layout|.
void OnWallpaperLoaded(ash::WallpaperLayout layout, void OnWallpaperLoaded(ash::WallpaperLayout layout,
const UserImage& user_image); const UserImage& user_image);
// Loads user image from its file.
scoped_refptr<UserImageLoader> image_loader_;
// Overridden from chromeos::ResumeObserver // Overridden from chromeos::ResumeObserver
virtual void SystemResumed() OVERRIDE; virtual void SystemResumed() OVERRIDE;
// Overridden from system::TimezoneSettings::Observer. // Overridden from system::TimezoneSettings::Observer.
virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE; virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE;
// Loads user wallpaper from its file.
scoped_refptr<UserImageLoader> wallpaper_loader_;
// Logged-in user wallpaper type.
User::WallpaperType current_user_wallpaper_type_;
// Logged-in user wallpaper index.
int current_user_wallpaper_index_;
// Caches custom wallpapers of users. Accessed only on UI thread.
CustomWallpaperMap custom_wallpaper_cache_;
CustomWallpaperMap custom_wallpaper_thumbnail_cache_;
// The last selected user on user pod row. // The last selected user on user pod row.
std::string last_selected_user_; std::string last_selected_user_;
base::WeakPtrFactory<WallpaperManager> weak_factory_;
content::NotificationRegistrar registrar_;
base::OneShotTimer<WallpaperManager> timer_; base::OneShotTimer<WallpaperManager> timer_;
DISALLOW_COPY_AND_ASSIGN(WallpaperManager); DISALLOW_COPY_AND_ASSIGN(WallpaperManager);
......
...@@ -195,12 +195,12 @@ void WebUILoginDisplay::CreateAccount() { ...@@ -195,12 +195,12 @@ void WebUILoginDisplay::CreateAccount() {
delegate_->CreateAccount(); delegate_->CreateAccount();
} }
void WebUILoginDisplay::UserDeselected() { void WebUILoginDisplay::OnUserDeselected() {
WallpaperManager::Get()->UserDeselected(); WallpaperManager::Get()->OnUserDeselected();
} }
void WebUILoginDisplay::UserSelected(const std::string& username) { void WebUILoginDisplay::OnUserSelected(const std::string& username) {
UserManager::Get()->UserSelected(username); WallpaperManager::Get()->OnUserSelected(username);
} }
void WebUILoginDisplay::RemoveUser(const std::string& username) { void WebUILoginDisplay::RemoveUser(const std::string& username) {
......
...@@ -50,8 +50,8 @@ class WebUILoginDisplay : public LoginDisplay, ...@@ -50,8 +50,8 @@ class WebUILoginDisplay : public LoginDisplay,
virtual void LoginAsGuest() OVERRIDE; virtual void LoginAsGuest() OVERRIDE;
virtual void Signout() OVERRIDE; virtual void Signout() OVERRIDE;
virtual void CreateAccount() OVERRIDE; virtual void CreateAccount() OVERRIDE;
virtual void UserDeselected() OVERRIDE; virtual void OnUserDeselected() OVERRIDE;
virtual void UserSelected(const std::string& username) OVERRIDE; virtual void OnUserSelected(const std::string& username) OVERRIDE;
virtual void RemoveUser(const std::string& username) OVERRIDE; virtual void RemoveUser(const std::string& username) OVERRIDE;
virtual void ShowEnterpriseEnrollmentScreen() OVERRIDE; virtual void ShowEnterpriseEnrollmentScreen() OVERRIDE;
virtual void SetWebUIHandler( virtual void SetWebUIHandler(
......
...@@ -88,6 +88,9 @@ class WizardController : public ScreenObserver { ...@@ -88,6 +88,9 @@ class WizardController : public ScreenObserver {
// Returns initial locale from local settings. // Returns initial locale from local settings.
static std::string GetInitialLocale(); static std::string GetInitialLocale();
// Sets delays to zero. MUST be used only for browser tests.
static void SetZeroDelays();
// If true zero delays have been enabled (for browser tests). // If true zero delays have been enabled (for browser tests).
static bool IsZeroDelayEnabled(); static bool IsZeroDelayEnabled();
...@@ -214,9 +217,6 @@ class WizardController : public ScreenObserver { ...@@ -214,9 +217,6 @@ class WizardController : public ScreenObserver {
// Logs in the specified user via default login screen. // Logs in the specified user via default login screen.
void Login(const std::string& username, const std::string& password); void Login(const std::string& username, const std::string& password);
// Sets delays to zero. MUST be used only for browser tests.
static void SetZeroDelays();
static bool skip_user_image_selection_; static bool skip_user_image_selection_;
static bool zero_delay_enabled_; static bool zero_delay_enabled_;
......
...@@ -804,7 +804,7 @@ void SigninScreenHandler::HandleShutdownSystem(const base::ListValue* args) { ...@@ -804,7 +804,7 @@ void SigninScreenHandler::HandleShutdownSystem(const base::ListValue* args) {
void SigninScreenHandler::HandleUserDeselected(const base::ListValue* args) { void SigninScreenHandler::HandleUserDeselected(const base::ListValue* args) {
if (delegate_) if (delegate_)
delegate_->UserDeselected(); delegate_->OnUserDeselected();
} }
void SigninScreenHandler::HandleUserSelected(const base::ListValue* args) { void SigninScreenHandler::HandleUserSelected(const base::ListValue* args) {
...@@ -817,7 +817,7 @@ void SigninScreenHandler::HandleUserSelected(const base::ListValue* args) { ...@@ -817,7 +817,7 @@ void SigninScreenHandler::HandleUserSelected(const base::ListValue* args) {
return; return;
} }
delegate_->UserSelected(email); delegate_->OnUserSelected(email);
} }
void SigninScreenHandler::HandleRemoveUser(const base::ListValue* args) { void SigninScreenHandler::HandleRemoveUser(const base::ListValue* args) {
......
...@@ -81,11 +81,11 @@ class SigninScreenHandlerDelegate { ...@@ -81,11 +81,11 @@ class SigninScreenHandlerDelegate {
virtual void CreateAccount() = 0; virtual void CreateAccount() = 0;
// Called user pod selection is canceled. // Called user pod selection is canceled.
virtual void UserDeselected() = 0; virtual void OnUserDeselected() = 0;
// Called when user pod with |username| is selected at login screen. // Called when user pod with |username| is selected at login screen.
// |username| is the email address of the selected user. // |username| is the email address of the selected user.
virtual void UserSelected(const std::string& username) = 0; virtual void OnUserSelected(const std::string& username) = 0;
// Attempts to remove given user. // Attempts to remove given user.
virtual void RemoveUser(const std::string& username) = 0; virtual void RemoveUser(const std::string& username) = 0;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/string_util.h" #include "base/string_util.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chromeos/login/user_manager.h" #include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/login/wallpaper_manager.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_select_file_policy.h" #include "chrome/browser/ui/chrome_select_file_policy.h"
...@@ -106,7 +107,7 @@ void SetWallpaperOptionsHandler::FileSelected(const FilePath& path, ...@@ -106,7 +107,7 @@ void SetWallpaperOptionsHandler::FileSelected(const FilePath& path,
UserManager* user_manager = UserManager::Get(); UserManager* user_manager = UserManager::Get();
// Default wallpaper layout is CENTER_CROPPED. // Default wallpaper layout is CENTER_CROPPED.
user_manager->SaveUserWallpaperFromFile( WallpaperManager::Get()->SetUserWallpaperFromFile(
user_manager->GetLoggedInUser().email(), path, ash::CENTER_CROPPED, user_manager->GetLoggedInUser().email(), path, ash::CENTER_CROPPED,
weak_factory_.GetWeakPtr()); weak_factory_.GetWeakPtr());
web_ui()->CallJavascriptFunction("SetWallpaperOptions.didSelectFile"); web_ui()->CallJavascriptFunction("SetWallpaperOptions.didSelectFile");
...@@ -166,7 +167,8 @@ void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) { ...@@ -166,7 +167,8 @@ void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) {
User::WallpaperType type; User::WallpaperType type;
int index; int index;
base::Time date; base::Time date;
UserManager::Get()->GetLoggedInUserWallpaperProperties(&type, &index, &date); WallpaperManager::Get()->GetLoggedInUserWallpaperProperties(
&type, &index, &date);
if (type == User::DAILY && date != base::Time::Now().LocalMidnight()) { if (type == User::DAILY && date != base::Time::Now().LocalMidnight()) {
index = ash::GetNextWallpaperIndex(index); index = ash::GetNextWallpaperIndex(index);
UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DAILY, UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DAILY,
...@@ -240,7 +242,8 @@ void SetWallpaperOptionsHandler::HandleDailyWallpaper(const ListValue* args) { ...@@ -240,7 +242,8 @@ void SetWallpaperOptionsHandler::HandleDailyWallpaper(const ListValue* args) {
User::WallpaperType type; User::WallpaperType type;
int index; int index;
base::Time date; base::Time date;
UserManager::Get()->GetLoggedInUserWallpaperProperties(&type, &index, &date); WallpaperManager::Get()->GetLoggedInUserWallpaperProperties(
&type, &index, &date);
if (date != base::Time::Now().LocalMidnight()) if (date != base::Time::Now().LocalMidnight())
index = ash::GetNextWallpaperIndex(index); index = ash::GetNextWallpaperIndex(index);
UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DAILY, index); UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DAILY, index);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "base/threading/worker_pool.h" #include "base/threading/worker_pool.h"
#include "chrome/browser/chromeos/login/user_manager.h" #include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/login/wallpaper_manager.h"
#include "chrome/browser/io_thread.h" #include "chrome/browser/io_thread.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager.h" #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
...@@ -51,8 +52,9 @@ class WallpaperThumbnailSource::ThumbnailEncodingOperation ...@@ -51,8 +52,9 @@ class WallpaperThumbnailSource::ThumbnailEncodingOperation
void EncodeThumbnail() { void EncodeThumbnail() {
if (cancel_flag_.IsSet()) if (cancel_flag_.IsSet())
return; return;
gfx::PNGCodec::EncodeBGRASkBitmap(user_->wallpaper_thumbnail(), gfx::PNGCodec::EncodeBGRASkBitmap(
false, &data_->data()); WallpaperManager::Get()->GetCustomWallpaperThumbnail(user_->email()),
false, &data_->data());
} }
void Cancel() { void Cancel() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment