Index: chrome/browser/chromeos/login/wallpaper_manager.h |
diff --git a/chrome/browser/chromeos/login/wallpaper_manager.h b/chrome/browser/chromeos/login/wallpaper_manager.h |
index 50fce515f4a9f4d17deefd2a4e56983c1861dbce..d9ae6fe66d962027ec113c8fba4bfe5e8e34fb9b 100644 |
--- a/chrome/browser/chromeos/login/wallpaper_manager.h |
+++ b/chrome/browser/chromeos/login/wallpaper_manager.h |
@@ -8,20 +8,27 @@ |
#include <string> |
#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 "chrome/browser/chromeos/login/user_image.h" |
-#include "chrome/browser/chromeos/login/user_image_loader.h" |
+#include "chrome/browser/chromeos/login/user.h" |
+#include "chrome/browser/chromeos/login/wallpaper_loader.h" |
#include "chrome/browser/chromeos/power/resume_observer.h" |
#include "chrome/browser/chromeos/system/timezone_settings.h" |
+#include "chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler.h" |
+#include "content/public/browser/notification_observer.h" |
+#include "content/public/browser/notification_registrar.h" |
#include "unicode/timezone.h" |
namespace chromeos { |
+class UserImage; |
+ |
// This class maintains wallpapers for users who have logged into this Chrome |
// OS device. |
class WallpaperManager: public system::TimezoneSettings::Observer, |
- public chromeos::ResumeObserver { |
+ public chromeos::ResumeObserver, |
+ public content::NotificationObserver { |
public: |
static WallpaperManager* Get(); |
@@ -31,22 +38,78 @@ class WallpaperManager: public system::TimezoneSettings::Observer, |
// PowerManagerClient initialized. |
void AddPowerManagerClientObserver(); |
+ // 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, |
+ SkBitmap* 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. |
+ SkBitmap 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. |
// Cancel any previous timer if any. |
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); |
+ |
// Sets last selected user on user pod row. |
void SetLastSelectedUser(const std::string& last_selected_user); |
- // Sets wallpaper to the image file |path| points to. |
- void SetWallpaperFromFile(std::string email, |
- const std::string& path, |
- ash::WallpaperLayout layout); |
+ // Sets |email|'s wallpaper. |
+ void SetUserWallpaper(const std::string& email); |
// 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: |
+ typedef std::map<std::string, SkBitmap> CustomWallpaperMap; |
+ |
virtual ~WallpaperManager(); |
void OnCustomWallpaperLoaded(const std::string& email, |
@@ -58,8 +121,44 @@ class WallpaperManager: public system::TimezoneSettings::Observer, |
// at 0am if chromeos device is on. |
void BatchUpdateWallpaper(); |
- // Loads user image from its file. |
- scoped_refptr<UserImageLoader> image_loader_; |
+ // Caches the decoded wallpaper to memory. |
+ void CacheWallpaper(const std::string& email, const SkBitmap& wallpaper); |
+ |
+ // Generates a 128x80 thumbnail and caches it. |
+ void CacheThumbnail(const std::string& email, const SkBitmap& wallpaper); |
+ |
+ // Sets wallpaper to the decoded wallpaper. |
+ void FetchWallpaper(const std::string& email, |
+ ash::WallpaperLayout layout, |
+ const SkBitmap& wallpaper); |
+ |
+ // Generates a 128x80 thumbnail and notifies delegate when ready. |
+ void GenerateUserWallpaperThumbnail(const std::string& email, |
+ User::WallpaperType type, |
+ base::WeakPtr<WallpaperDelegate> delegate, |
+ const SkBitmap& 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); |
+ |
+ // Loads the custom wallpaper of user |email|. |
+ void LoadCustomWallpaperFromFile(const std::string& email, |
+ const LoadedCallback& loaded_cb); |
+ |
+ // Updates the custom wallpaper thumbnail in wallpaper picker UI. |
+ void OnThumbnailUpdated(base::WeakPtr<WallpaperDelegate> delegate); |
+ |
+ // Saves wallpaper to file, post task to generate thumbnail and updates local |
+ // state preferences. |
+ void SetCallback(const std::string& username, |
+ ash::WallpaperLayout layout, |
+ User::WallpaperType type, |
+ base::WeakPtr<WallpaperDelegate> delegate, |
+ const SkBitmap& wallpaper); |
// Overridden from chromeos::ResumeObserver |
virtual void SystemResumed() OVERRIDE; |
@@ -67,9 +166,27 @@ class WallpaperManager: public system::TimezoneSettings::Observer, |
// Overridden from system::TimezoneSettings::Observer. |
virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE; |
+ // Loads user wallpaper from its file. |
+ scoped_refptr<WallpaperLoader> 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. |
std::string last_selected_user_; |
+ base::WeakPtrFactory<WallpaperManager> weak_factory_; |
+ |
+ content::NotificationRegistrar registrar_; |
+ |
base::OneShotTimer<WallpaperManager> timer_; |
DISALLOW_COPY_AND_ASSIGN(WallpaperManager); |