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

Unified Diff: chrome/browser/chromeos/login/wallpaper_manager.h

Issue 10832019: Speed up custom wallpaper switching time and wallpaper manager code refactor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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
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 8aea9ba6074052a24cadd6c80c0324dced90649a..63c9c2e8fce0c8d2f0d94d7b4963d7ec6132c0e3 100644
--- a/chrome/browser/chromeos/login/wallpaper_manager.h
+++ b/chrome/browser/chromeos/login/wallpaper_manager.h
@@ -7,17 +7,28 @@
#include <string>
+#include "ash/desktop_background/desktop_background_resources.h"
+#include "base/memory/weak_ptr.h"
+#include "base/time.h"
#include "base/timer.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();
@@ -27,16 +38,68 @@ 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);
+
+ // 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);
// User was deselected at login screen, reset wallpaper if needed.
void UserDeselected();
+ // User |email| was selected at login screen, load wallpaper.
+ void UserSelected(const std::string& email);
+
private:
virtual ~WallpaperManager();
@@ -45,15 +108,74 @@ class WallpaperManager: public system::TimezoneSettings::Observer,
// at 0am if chromeos device is on.
void BatchUpdateWallpaper();
+ // Caches the decoded wallpaper to memory.
+ void CacheCallback(const std::string& email, const SkBitmap& wallpaper);
Ivan Korotkov 2012/07/27 23:02:02 Please remove 'Callback' sufffix from names. Somet
bshe 2012/07/31 14:27:54 Done.
+
+ // Generates a 128x80 thumbnail and caches it.
+ void CacheThumbnail(const std::string& email, const SkBitmap& wallpaper);
+
+ // Sets wallpaper to the decoded wallpaper.
+ void FetchCallback(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;
// Overridden from system::TimezoneSettings::Observer.
virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE;
+ // Loads user wallpaper from its file.
+ scoped_refptr<WallpaperLoader> wallpaper_loader_;
+
+ // Stores logged in user wallpaper type.
+ User::WallpaperType current_user_wallpaper_type_;
+
+ // Stores logged in user wallpaper index.
Ivan Korotkov 2012/07/27 23:02:02 Please remove word 'stores' from field description
bshe 2012/07/31 14:27:54 On 2012/07/27 23:02:02, Ivan Korotkov wrote: > Ple
+ int current_user_wallpaper_index_;
+
+ typedef std::map<std::string, SkBitmap> CustomWallpaperMap;
Ivan Korotkov 2012/07/27 23:02:02 typedefs go before methods and fields.
bshe 2012/07/31 14:27:54 Done.
+
+ // 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);

Powered by Google App Engine
This is Rietveld 408576698