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

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: Nikita's review. 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 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" 10 #include "ash/desktop_background/desktop_background_resources.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/time.h"
12 #include "base/timer.h" 13 #include "base/timer.h"
13 #include "chrome/browser/chromeos/login/user.h" 14 #include "chrome/browser/chromeos/login/user.h"
14 #include "chrome/browser/chromeos/login/user_image.h" 15 #include "chrome/browser/chromeos/login/user_image.h"
15 #include "chrome/browser/chromeos/login/user_image_loader.h" 16 #include "chrome/browser/chromeos/login/user_image_loader.h"
16 #include "chrome/browser/chromeos/power/resume_observer.h"
17 #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 "chromeos/dbus/power_manager_client.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
22 #include "ui/gfx/image/image_skia.h"
18 #include "unicode/timezone.h" 23 #include "unicode/timezone.h"
19 24
20 class PrefService; 25 class PrefService;
21 26
22 namespace chromeos { 27 namespace chromeos {
23 28
29 class UserImage;
30
24 // This class maintains wallpapers for users who have logged into this Chrome 31 // This class maintains wallpapers for users who have logged into this Chrome
25 // OS device. 32 // OS device.
26 class WallpaperManager: public system::TimezoneSettings::Observer, 33 class WallpaperManager: public system::TimezoneSettings::Observer,
27 public chromeos::ResumeObserver { 34 public chromeos::PowerManagerClient::Observer,
35 public content::NotificationObserver {
28 public: 36 public:
29 static WallpaperManager* Get(); 37 static WallpaperManager* Get();
30 38
31 WallpaperManager(); 39 WallpaperManager();
32 40
33 // Registers wallpaper manager preferences. 41 // Registers wallpaper manager preferences.
34 static void RegisterPrefs(PrefService* local_state); 42 static void RegisterPrefs(PrefService* local_state);
35 43
36 // Adds PowerManagerClient observer. It needs to be added after 44 // Adds PowerManagerClient and TimeZoneSettings observers. It needs to be
37 // PowerManagerClient initialized. 45 // added after PowerManagerClient initialized.
38 void AddPowerManagerClientObserver(); 46 void AddObservers();
47
48 // Caches |email|'s wallpaper to memory if it is custom wallpaper.
49 void CacheIfCustomWallpaper(const std::string& email);
50
51 // Loads wallpaper asynchronously if the current wallpaper is not the
52 // wallpaper of logged in user.
53 void EnsureLoggedInUserWallpaperLoaded();
54
55 // Fetches |email|'s wallpaper from local disk.
56 void FetchCustomWallpaper(const std::string& email);
57
58 // Gets encoded custom wallpaper from cache. Returns true if success.
59 bool GetCustomWallpaperFromCache(const std::string& email,
60 gfx::ImageSkia* wallpaper);
61
62 // Returns wallpaper/thumbnail filepath for the given user.
63 FilePath GetWallpaperPathForUser(const std::string& username,
64 bool is_thumbnail);
65
66 // Gets the thumbnail of custom wallpaper from cache.
67 gfx::ImageSkia GetCustomWallpaperThumbnail(const std::string& email);
68
69 // Sets |type| and |index| to the value saved in local state for logged in
70 // user.
71 void GetLoggedInUserWallpaperProperties(User::WallpaperType* type,
72 int* index,
73 base::Time* last_modification_date);
74
75 // Initializes wallpaper. If logged in, loads user's wallpaper. If not logged
76 // in, uses a solid color wallpaper. If logged in as a stub user, uses an
77 // empty wallpaper.
78 void InitializeWallpaper();
79
80 // NotificationObserver overrides:
81 virtual void Observe(int type,
82 const content::NotificationSource& source,
83 const content::NotificationDetails& details) OVERRIDE;
39 84
40 // Starts a one shot timer which calls BatchUpdateWallpaper at next midnight. 85 // Starts a one shot timer which calls BatchUpdateWallpaper at next midnight.
41 // Cancel any previous timer if any. 86 // Cancel any previous timer if any.
42 void RestartTimer(); 87 void RestartTimer();
43 88
89 // Tries to load user image from disk; if successful, sets it for the user,
90 // and updates Local State.
91 void SetUserWallpaperFromFile(const std::string& username,
92 const FilePath& path,
93 ash::WallpaperLayout layout,
94 base::WeakPtr<WallpaperDelegate> delegate);
95
96 // Set |email|'s wallpaper |type|, |index| and local date to local state.
97 void SaveUserWallpaperProperties(const std::string& email,
98 User::WallpaperType type,
99 int index);
100
101 // Sets one of the default wallpapers for the specified user and saves this
102 // settings in local state.
103 void SetInitialUserWallpaper(const std::string& username);
104
44 // Saves |username| selected wallpaper information to local state. 105 // Saves |username| selected wallpaper information to local state.
45 void SaveUserWallpaperInfo(const std::string& username, 106 void SaveUserWallpaperInfo(const std::string& username,
46 const std::string& file_name, 107 const std::string& file_name,
47 ash::WallpaperLayout layout, 108 ash::WallpaperLayout layout,
48 User::WallpaperType type); 109 User::WallpaperType type);
49 110
50 // Sets last selected user on user pod row. 111 // Sets last selected user on user pod row.
51 void SetLastSelectedUser(const std::string& last_selected_user); 112 void SetLastSelectedUser(const std::string& last_selected_user);
52 113
114 // Sets |email|'s wallpaper.
115 void SetUserWallpaper(const std::string& email);
116
53 // Sets wallpaper to the image file |path| points to. 117 // Sets wallpaper to the image file |path| points to.
54 void SetWallpaperFromFilePath(const std::string& path, 118 void SetWallpaperFromFilePath(const std::string& path,
55 ash::WallpaperLayout layout); 119 ash::WallpaperLayout layout);
56 120
57 // Sets wallpaper to |wallpaper|. 121 // Sets wallpaper to |wallpaper|.
58 void SetWallpaperFromImageSkia(const gfx::ImageSkia& wallpaper, 122 void SetWallpaperFromImageSkia(const gfx::ImageSkia& wallpaper,
59 ash::WallpaperLayout layout); 123 ash::WallpaperLayout layout);
60 124
61 // User was deselected at login screen, reset wallpaper if needed. 125 // User was deselected at login screen, reset wallpaper if needed.
62 void UserDeselected(); 126 void OnUserDeselected();
127
128 // User |email| was selected at login screen, load wallpaper.
129 void OnUserSelected(const std::string& email);
63 130
64 private: 131 private:
132 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap;
133
65 virtual ~WallpaperManager(); 134 virtual ~WallpaperManager();
66 135
67 void OnCustomWallpaperLoaded(const std::string& email, 136 void OnCustomWallpaperLoaded(const std::string& email,
68 ash::WallpaperLayout layout, 137 ash::WallpaperLayout layout,
69 const UserImage& user_image); 138 const UserImage& user_image);
70 139
71 // Change the wallpapers for users who choose DAILY wallpaper type. Updates 140 // Change the wallpapers for users who choose DAILY wallpaper type. Updates
72 // current wallpaper if it changed. This function should be called at exactly 141 // current wallpaper if it changed. This function should be called at exactly
73 // at 0am if chromeos device is on. 142 // at 0am if chromeos device is on.
74 void BatchUpdateWallpaper(); 143 void BatchUpdateWallpaper();
75 144
145 // Caches the decoded wallpaper to memory.
146 void CacheWallpaper(const std::string& email, const UserImage& wallpaper);
147
148 // Generates a 128x80 thumbnail and caches it.
149 void CacheThumbnail(const std::string& email,
150 const gfx::ImageSkia& wallpaper);
151
152 // Sets wallpaper to the decoded wallpaper.
153 void FetchWallpaper(const std::string& email,
154 ash::WallpaperLayout layout,
155 const UserImage& wallpaper);
156
157 // Generates a 128x80 thumbnail and notifies delegate when ready.
158 void GenerateUserWallpaperThumbnail(const std::string& email,
159 User::WallpaperType type,
160 base::WeakPtr<WallpaperDelegate> delegate,
161 const gfx::ImageSkia& wallpaper);
162
163 // Get wallpaper |type|, |index| and |last_modification_date| of |email|
164 // from local state.
165 void GetUserWallpaperProperties(const std::string& email,
166 User::WallpaperType* type,
167 int* index,
168 base::Time* last_modification_date);
169
170 // Updates the custom wallpaper thumbnail in wallpaper picker UI.
171 void OnThumbnailUpdated(base::WeakPtr<WallpaperDelegate> delegate);
172
173 // Saves wallpaper to |path|.
174 void SaveWallpaper(const std::string& path, const UserImage& wallpaper);
175
176 // Saves wallpaper to file, post task to generate thumbnail and updates local
177 // state preferences.
178 void SetWallpaper(const std::string& username,
179 ash::WallpaperLayout layout,
180 User::WallpaperType type,
181 base::WeakPtr<WallpaperDelegate> delegate,
182 const UserImage& wallpaper);
183
76 // Sets wallpaper to image in |user_image| with |layout|. 184 // Sets wallpaper to image in |user_image| with |layout|.
77 void OnWallpaperLoaded(ash::WallpaperLayout layout, 185 void OnWallpaperLoaded(ash::WallpaperLayout layout,
78 const UserImage& user_image); 186 const UserImage& user_image);
79 187
80 // Loads user image from its file. 188 // Loads user image from its file.
81 scoped_refptr<UserImageLoader> image_loader_; 189 scoped_refptr<UserImageLoader> image_loader_;
82 190
83 // Overridden from chromeos::ResumeObserver 191 // Overridden from chromeos::ResumeObserver
84 virtual void SystemResumed() OVERRIDE; 192 virtual void SystemResumed() OVERRIDE;
85 193
86 // Overridden from system::TimezoneSettings::Observer. 194 // Overridden from system::TimezoneSettings::Observer.
87 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE; 195 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE;
88 196
197 // Loads user wallpaper from its file.
198 scoped_refptr<UserImageLoader> wallpaper_loader_;
199
200 // Logged-in user wallpaper type.
201 User::WallpaperType current_user_wallpaper_type_;
202
203 // Logged-in user wallpaper index.
204 int current_user_wallpaper_index_;
205
206 // Caches custom wallpapers of users. Accessed only on UI thread.
207 CustomWallpaperMap custom_wallpaper_cache_;
208
209 CustomWallpaperMap custom_wallpaper_thumbnail_cache_;
210
89 // The last selected user on user pod row. 211 // The last selected user on user pod row.
90 std::string last_selected_user_; 212 std::string last_selected_user_;
91 213
214 base::WeakPtrFactory<WallpaperManager> weak_factory_;
215
216 content::NotificationRegistrar registrar_;
217
92 base::OneShotTimer<WallpaperManager> timer_; 218 base::OneShotTimer<WallpaperManager> timer_;
93 219
94 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); 220 DISALLOW_COPY_AND_ASSIGN(WallpaperManager);
95 }; 221 };
96 222
97 } // namespace chromeos 223 } // namespace chromeos
98 224
99 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ 225 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698