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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "ash/desktop_background/desktop_background_resources.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/time.h"
10 #include "base/timer.h" 13 #include "base/timer.h"
14 #include "chrome/browser/chromeos/login/user.h"
15 #include "chrome/browser/chromeos/login/wallpaper_loader.h"
11 #include "chrome/browser/chromeos/power/resume_observer.h" 16 #include "chrome/browser/chromeos/power/resume_observer.h"
12 #include "chrome/browser/chromeos/system/timezone_settings.h" 17 #include "chrome/browser/chromeos/system/timezone_settings.h"
18 #include "chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handle r.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
13 #include "unicode/timezone.h" 21 #include "unicode/timezone.h"
14 22
15 namespace chromeos { 23 namespace chromeos {
16 24
25 class UserImage;
26
17 // This class maintains wallpapers for users who have logged into this Chrome 27 // This class maintains wallpapers for users who have logged into this Chrome
18 // OS device. 28 // OS device.
19 class WallpaperManager: public system::TimezoneSettings::Observer, 29 class WallpaperManager: public system::TimezoneSettings::Observer,
20 public chromeos::ResumeObserver { 30 public chromeos::ResumeObserver,
31 public content::NotificationObserver {
21 public: 32 public:
22 static WallpaperManager* Get(); 33 static WallpaperManager* Get();
23 34
24 WallpaperManager(); 35 WallpaperManager();
25 36
26 // Adds PowerManagerClient observer. It needs to be added after 37 // Adds PowerManagerClient observer. It needs to be added after
27 // PowerManagerClient initialized. 38 // PowerManagerClient initialized.
28 void AddPowerManagerClientObserver(); 39 void AddPowerManagerClientObserver();
29 40
41 // Caches |email|'s wallpaper to memory if it is custom wallpaper.
42 void CacheIfCustomWallpaper(const std::string& email);
43
44 // Loads wallpaper asynchronously if the current wallpaper is not the
45 // wallpaper of logged in user.
46 void EnsureLoggedInUserWallpaperLoaded();
47
48 // Fetches |email|'s wallpaper from local disk.
49 void FetchCustomWallpaper(const std::string& email);
50
51 // Gets encoded custom wallpaper from cache. Returns true if success.
52 bool GetCustomWallpaperFromCache(const std::string& email,
53 SkBitmap* wallpaper);
54
55 // Gets the thumbnail of custom wallpaper from cache.
56 SkBitmap GetCustomWallpaperThumbnail(const std::string& email);
57
58 // Sets |type| and |index| to the value saved in local state for logged in
59 // user.
60 void GetLoggedInUserWallpaperProperties(User::WallpaperType* type,
61 int* index,
62 base::Time* last_modification_date);
63
64 // Initializes wallpaper. If logged in, loads user's wallpaper. If not logged
65 // in, uses a solid color wallpaper. If logged in as a stub user, uses an
66 // empty wallpaper.
67 void InitializeWallpaper();
68
69 // NotificationObserver overrides:
70 virtual void Observe(int type,
71 const content::NotificationSource& source,
72 const content::NotificationDetails& details) OVERRIDE;
73
30 // Starts a one shot timer which calls BatchUpdateWallpaper at next midnight. 74 // Starts a one shot timer which calls BatchUpdateWallpaper at next midnight.
31 // Cancel any previous timer if any. 75 // Cancel any previous timer if any.
32 void RestartTimer(); 76 void RestartTimer();
33 77
78 // Tries to load user image from disk; if successful, sets it for the user,
79 // and updates Local State.
80 void SetUserWallpaperFromFile(const std::string& username,
81 const FilePath& path,
82 ash::WallpaperLayout layout,
83 base::WeakPtr<WallpaperDelegate> delegate);
84
85 // Set |email|'s wallpaper |type|, |index| and local date to local state.
86 void SaveUserWallpaperProperties(const std::string& email,
87 User::WallpaperType type,
88 int index);
89
90 // Sets one of the default wallpapers for the specified user and saves this
91 // settings in local state.
92 void SetInitialUserWallpaper(const std::string& username);
93
34 // Sets last selected user on user pod row. 94 // Sets last selected user on user pod row.
35 void SetLastSelectedUser(const std::string& last_selected_user); 95 void SetLastSelectedUser(const std::string& last_selected_user);
36 96
37 // User was deselected at login screen, reset wallpaper if needed. 97 // User was deselected at login screen, reset wallpaper if needed.
38 void UserDeselected(); 98 void UserDeselected();
39 99
100 // User |email| was selected at login screen, load wallpaper.
101 void UserSelected(const std::string& email);
102
40 private: 103 private:
41 virtual ~WallpaperManager(); 104 virtual ~WallpaperManager();
42 105
43 // Change the wallpapers for users who choose DAILY wallpaper type. Updates 106 // Change the wallpapers for users who choose DAILY wallpaper type. Updates
44 // current wallpaper if it changed. This function should be called at exactly 107 // current wallpaper if it changed. This function should be called at exactly
45 // at 0am if chromeos device is on. 108 // at 0am if chromeos device is on.
46 void BatchUpdateWallpaper(); 109 void BatchUpdateWallpaper();
47 110
111 // Caches the decoded wallpaper to memory.
112 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.
113
114 // Generates a 128x80 thumbnail and caches it.
115 void CacheThumbnail(const std::string& email, const SkBitmap& wallpaper);
116
117 // Sets wallpaper to the decoded wallpaper.
118 void FetchCallback(const std::string& email,
119 ash::WallpaperLayout layout,
120 const SkBitmap& wallpaper);
121
122 // Generates a 128x80 thumbnail and notifies delegate when ready.
123 void GenerateUserWallpaperThumbnail(const std::string& email,
124 User::WallpaperType type,
125 base::WeakPtr<WallpaperDelegate> delegate,
126 const SkBitmap& wallpaper);
127
128 // Get wallpaper |type|, |index| and |last_modification_date| of |email|
129 // from local state.
130 void GetUserWallpaperProperties(const std::string& email,
131 User::WallpaperType* type,
132 int* index,
133 base::Time* last_modification_date);
134
135 // Loads the custom wallpaper of user |email|.
136 void LoadCustomWallpaperFromFile(const std::string& email,
137 const LoadedCallback& loaded_cb);
138
139 // Updates the custom wallpaper thumbnail in wallpaper picker UI.
140 void OnThumbnailUpdated(base::WeakPtr<WallpaperDelegate> delegate);
141
142 // Saves wallpaper to file, post task to generate thumbnail and updates local
143 // state preferences.
144 void SetCallback(const std::string& username,
145 ash::WallpaperLayout layout,
146 User::WallpaperType type,
147 base::WeakPtr<WallpaperDelegate> delegate,
148 const SkBitmap& wallpaper);
149
48 // Overridden from chromeos::ResumeObserver 150 // Overridden from chromeos::ResumeObserver
49 virtual void SystemResumed() OVERRIDE; 151 virtual void SystemResumed() OVERRIDE;
50 152
51 // Overridden from system::TimezoneSettings::Observer. 153 // Overridden from system::TimezoneSettings::Observer.
52 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE; 154 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE;
53 155
156 // Loads user wallpaper from its file.
157 scoped_refptr<WallpaperLoader> wallpaper_loader_;
158
159 // Stores logged in user wallpaper type.
160 User::WallpaperType current_user_wallpaper_type_;
161
162 // 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
163 int current_user_wallpaper_index_;
164
165 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.
166
167 // Caches custom wallpapers of users. Accessed only on UI thread.
168 CustomWallpaperMap custom_wallpaper_cache_;
169
170 CustomWallpaperMap custom_wallpaper_thumbnail_cache_;
171
54 // The last selected user on user pod row. 172 // The last selected user on user pod row.
55 std::string last_selected_user_; 173 std::string last_selected_user_;
56 174
175 base::WeakPtrFactory<WallpaperManager> weak_factory_;
176
177 content::NotificationRegistrar registrar_;
178
57 base::OneShotTimer<WallpaperManager> timer_; 179 base::OneShotTimer<WallpaperManager> timer_;
58 180
59 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); 181 DISALLOW_COPY_AND_ASSIGN(WallpaperManager);
60 }; 182 };
61 183
62 } // namespace chromeos 184 } // namespace chromeos
63 185
64 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ 186 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698