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

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: Fix compile 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
53 // Sets wallpaper to the image file |path| points to. 114 // Sets |email|'s wallpaper.
54 void SetWallpaperFromFilePath(const std::string& path, 115 void SetUserWallpaper(const std::string& email);
55 ash::WallpaperLayout layout);
56 116
57 // Sets wallpaper to |wallpaper|. 117 // Sets wallpaper to |wallpaper|.
58 void SetWallpaperFromImageSkia(const gfx::ImageSkia& wallpaper, 118 void SetWallpaperFromImageSkia(const gfx::ImageSkia& wallpaper,
59 ash::WallpaperLayout layout); 119 ash::WallpaperLayout layout);
60 120
61 // User was deselected at login screen, reset wallpaper if needed. 121 // User was deselected at login screen, reset wallpaper if needed.
62 void UserDeselected(); 122 void OnUserDeselected();
123
124 // User |email| was selected at login screen, load wallpaper.
125 void OnUserSelected(const std::string& email);
63 126
64 private: 127 private:
128 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap;
129
65 virtual ~WallpaperManager(); 130 virtual ~WallpaperManager();
66 131
67 void OnCustomWallpaperLoaded(const std::string& email,
68 ash::WallpaperLayout layout,
69 const UserImage& user_image);
70
71 // Change the wallpapers for users who choose DAILY wallpaper type. Updates 132 // Change the wallpapers for users who choose DAILY wallpaper type. Updates
72 // current wallpaper if it changed. This function should be called at exactly 133 // current wallpaper if it changed. This function should be called at exactly
73 // at 0am if chromeos device is on. 134 // at 0am if chromeos device is on.
74 void BatchUpdateWallpaper(); 135 void BatchUpdateWallpaper();
75 136
137 // Caches the decoded wallpaper to memory.
138 void CacheWallpaper(const std::string& email, const UserImage& wallpaper);
139
140 // Generates a 128x80 thumbnail and caches it.
141 void CacheThumbnail(const std::string& email,
142 const gfx::ImageSkia& wallpaper);
143
144 // Sets wallpaper to the decoded wallpaper.
145 void FetchWallpaper(const std::string& email,
146 ash::WallpaperLayout layout,
147 const UserImage& wallpaper);
148
149 // Generates a 128x80 thumbnail and notifies delegate when ready.
150 void GenerateUserWallpaperThumbnail(const std::string& email,
151 User::WallpaperType type,
152 base::WeakPtr<WallpaperDelegate> delegate,
153 const gfx::ImageSkia& wallpaper);
154
155 // Get wallpaper |type|, |index| and |last_modification_date| of |email|
156 // from local state.
157 void GetUserWallpaperProperties(const std::string& email,
158 User::WallpaperType* type,
159 int* index,
160 base::Time* last_modification_date);
161
162 // Updates the custom wallpaper thumbnail in wallpaper picker UI.
163 void OnThumbnailUpdated(base::WeakPtr<WallpaperDelegate> delegate);
164
165 // Saves wallpaper to |path|.
166 void SaveWallpaper(const std::string& path, const UserImage& wallpaper);
167
168 // Saves wallpaper to file, post task to generate thumbnail and updates local
169 // state preferences.
170 void SetWallpaper(const std::string& username,
171 ash::WallpaperLayout layout,
172 User::WallpaperType type,
173 base::WeakPtr<WallpaperDelegate> delegate,
174 const UserImage& wallpaper);
175
76 // Sets wallpaper to image in |user_image| with |layout|. 176 // Sets wallpaper to image in |user_image| with |layout|.
77 void OnWallpaperLoaded(ash::WallpaperLayout layout, 177 void OnWallpaperLoaded(ash::WallpaperLayout layout,
78 const UserImage& user_image); 178 const UserImage& user_image);
79 179
80 // Loads user image from its file.
81 scoped_refptr<UserImageLoader> image_loader_;
82
83 // Overridden from chromeos::ResumeObserver 180 // Overridden from chromeos::ResumeObserver
84 virtual void SystemResumed() OVERRIDE; 181 virtual void SystemResumed() OVERRIDE;
85 182
86 // Overridden from system::TimezoneSettings::Observer. 183 // Overridden from system::TimezoneSettings::Observer.
87 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE; 184 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE;
88 185
186 // Loads user wallpaper from its file.
187 scoped_refptr<UserImageLoader> wallpaper_loader_;
188
189 // Logged-in user wallpaper type.
190 User::WallpaperType current_user_wallpaper_type_;
191
192 // Logged-in user wallpaper index.
193 int current_user_wallpaper_index_;
194
195 // Caches custom wallpapers of users. Accessed only on UI thread.
196 CustomWallpaperMap custom_wallpaper_cache_;
197
198 CustomWallpaperMap custom_wallpaper_thumbnail_cache_;
199
89 // The last selected user on user pod row. 200 // The last selected user on user pod row.
90 std::string last_selected_user_; 201 std::string last_selected_user_;
91 202
203 base::WeakPtrFactory<WallpaperManager> weak_factory_;
204
205 content::NotificationRegistrar registrar_;
206
92 base::OneShotTimer<WallpaperManager> timer_; 207 base::OneShotTimer<WallpaperManager> timer_;
93 208
94 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); 209 DISALLOW_COPY_AND_ASSIGN(WallpaperManager);
95 }; 210 };
96 211
97 } // namespace chromeos 212 } // namespace chromeos
98 213
99 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ 214 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/user_manager_impl.cc ('k') | chrome/browser/chromeos/login/wallpaper_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698