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

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

Powered by Google App Engine
This is Rietveld 408576698