| OLD | NEW |
| 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/ref_counted_memory.h" |
| 11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 12 #include "base/time.h" | 13 #include "base/time.h" |
| 13 #include "base/timer.h" | 14 #include "base/timer.h" |
| 14 #include "chrome/browser/chromeos/login/user.h" | 15 #include "chrome/browser/chromeos/login/user.h" |
| 15 #include "chrome/browser/chromeos/login/user_image.h" | 16 #include "chrome/browser/chromeos/login/user_image.h" |
| 16 #include "chrome/browser/chromeos/login/user_image_loader.h" | 17 #include "chrome/browser/chromeos/login/user_image_loader.h" |
| 17 #include "chrome/browser/chromeos/system/timezone_settings.h" | 18 #include "chrome/browser/chromeos/system/timezone_settings.h" |
| 18 #include "chrome/browser/ui/webui/options/chromeos/set_wallpaper_options_handler
.h" | 19 #include "chrome/browser/ui/webui/options/chromeos/set_wallpaper_options_handler
.h" |
| 19 #include "chromeos/dbus/power_manager_client.h" | 20 #include "chromeos/dbus/power_manager_client.h" |
| 20 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 static void RegisterPrefs(PrefService* local_state); | 54 static void RegisterPrefs(PrefService* local_state); |
| 54 | 55 |
| 55 // Adds PowerManagerClient and TimeZoneSettings observers. It needs to be | 56 // Adds PowerManagerClient and TimeZoneSettings observers. It needs to be |
| 56 // added after PowerManagerClient initialized. | 57 // added after PowerManagerClient initialized. |
| 57 void AddObservers(); | 58 void AddObservers(); |
| 58 | 59 |
| 59 // Loads wallpaper asynchronously if the current wallpaper is not the | 60 // Loads wallpaper asynchronously if the current wallpaper is not the |
| 60 // wallpaper of logged in user. | 61 // wallpaper of logged in user. |
| 61 void EnsureLoggedInUserWallpaperLoaded(); | 62 void EnsureLoggedInUserWallpaperLoaded(); |
| 62 | 63 |
| 63 // Fetches |email|'s wallpaper from local disk. | 64 // Gets |email|'s wallpaper from local disk. |
| 64 void FetchCustomWallpaper(const std::string& email); | 65 void GetCustomWallpaper(const std::string& email); |
| 65 | 66 |
| 66 // Gets encoded custom wallpaper from cache. Returns true if success. | 67 // Gets encoded custom wallpaper from cache. Returns true if success. |
| 67 bool GetCustomWallpaperFromCache(const std::string& email, | 68 bool GetCustomWallpaperFromCache(const std::string& email, |
| 68 gfx::ImageSkia* wallpaper); | 69 gfx::ImageSkia* wallpaper); |
| 69 | 70 |
| 70 // Returns wallpaper/thumbnail filepath for the given user. | 71 // Returns filepath to save original custom wallpaper for the given user. |
| 72 FilePath GetOriginalWallpaperPathForUser(const std::string& username); |
| 73 |
| 74 // Returns small resolution custom wallpaper filepath for the given user when |
| 75 // |is_small| is ture. Otherwise, returns large resolution custom wallpaper |
| 76 // path. |
| 71 FilePath GetWallpaperPathForUser(const std::string& username, | 77 FilePath GetWallpaperPathForUser(const std::string& username, |
| 72 bool is_thumbnail); | 78 bool is_small); |
| 73 | 79 |
| 74 // Gets the thumbnail of custom wallpaper from cache. | 80 // Gets the thumbnail of custom wallpaper from cache. |
| 75 gfx::ImageSkia GetCustomWallpaperThumbnail(const std::string& email); | 81 gfx::ImageSkia GetCustomWallpaperThumbnail(const std::string& email); |
| 76 | 82 |
| 77 // Gets wallpaper properties of logged in user. | 83 // Gets wallpaper properties of logged in user. |
| 78 void GetLoggedInUserWallpaperProperties(User::WallpaperType* type, | 84 void GetLoggedInUserWallpaperProperties(User::WallpaperType* type, |
| 79 int* index, | 85 int* index, |
| 80 base::Time* last_modification_date); | 86 base::Time* last_modification_date); |
| 81 | 87 |
| 82 // Gets wallpaper information of logged in user. | 88 // Gets wallpaper information of logged in user. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 void FetchWallpaper(const std::string& email, | 182 void FetchWallpaper(const std::string& email, |
| 177 ash::WallpaperLayout layout, | 183 ash::WallpaperLayout layout, |
| 178 const UserImage& wallpaper); | 184 const UserImage& wallpaper); |
| 179 | 185 |
| 180 // Generates a 128x80 thumbnail and notifies delegate when ready. | 186 // Generates a 128x80 thumbnail and notifies delegate when ready. |
| 181 void GenerateUserWallpaperThumbnail(const std::string& email, | 187 void GenerateUserWallpaperThumbnail(const std::string& email, |
| 182 User::WallpaperType type, | 188 User::WallpaperType type, |
| 183 base::WeakPtr<WallpaperDelegate> delegate, | 189 base::WeakPtr<WallpaperDelegate> delegate, |
| 184 const gfx::ImageSkia& wallpaper); | 190 const gfx::ImageSkia& wallpaper); |
| 185 | 191 |
| 192 // Gets |email|'s custom wallpaper in appropriate resolution. Falls back on |
| 193 // original custom wallpaper. Must run on FILE thread. |
| 194 void GetCustomWallpaperInternal(const std::string& email, |
| 195 const WallpaperInfo& info); |
| 196 |
| 186 // Gets wallpaper information of |email| from Local State or memory. Returns | 197 // Gets wallpaper information of |email| from Local State or memory. Returns |
| 187 // false if wallpaper information is not found. | 198 // false if wallpaper information is not found. |
| 188 bool GetUserWallpaperInfo(const std::string& email, WallpaperInfo* info); | 199 bool GetUserWallpaperInfo(const std::string& email, WallpaperInfo* info); |
| 189 | 200 |
| 190 // Gets wallpaper |type|, |index| and |last_modification_date| of |email| | 201 // Gets wallpaper |type|, |index| and |last_modification_date| of |email| |
| 191 // from local state. | 202 // from local state. |
| 192 void GetUserWallpaperProperties(const std::string& email, | 203 void GetUserWallpaperProperties(const std::string& email, |
| 193 User::WallpaperType* type, | 204 User::WallpaperType* type, |
| 194 int* index, | 205 int* index, |
| 195 base::Time* last_modification_date); | 206 base::Time* last_modification_date); |
| 196 | 207 |
| 197 // Copy |email| selected built-in wallpapers (high and low resolution) in | 208 // Copy |email| selected built-in wallpapers (high and low resolution) in |
| 198 // ChromeOS image binary to local files on disk. Also converts the wallpaper | 209 // ChromeOS image binary to local files on disk. Also converts the wallpaper |
| 199 // properties correspond to the built-in wallpapers to the new wallpaper info. | 210 // properties correspond to the built-in wallpapers to the new wallpaper info. |
| 200 void MigrateBuiltInWallpaper(const std::string& email); | 211 void MigrateBuiltInWallpaper(const std::string& email); |
| 201 | 212 |
| 202 // Updates the custom wallpaper thumbnail in wallpaper picker UI. | 213 // Updates the custom wallpaper thumbnail in wallpaper picker UI. |
| 203 void OnThumbnailUpdated(base::WeakPtr<WallpaperDelegate> delegate); | 214 void OnThumbnailUpdated(base::WeakPtr<WallpaperDelegate> delegate); |
| 204 | 215 |
| 205 // Saves wallpaper to |path| (absolute path) in file system. | 216 // Saves encoded wallpaper to |path|. This callback is called after encoding |
| 206 void SaveWallpaper(const FilePath& path, const UserImage& wallpaper); | 217 // to PNG completes. |
| 218 void OnWallpaperEncoded(const FilePath& path, |
| 219 scoped_refptr<base::RefCountedBytes> data); |
| 220 |
| 221 // Resizes |wallpaper| to a resolution which is nearest to |preferred_width| |
| 222 // and |preferred_height| while maintaining aspect ratio. And saves the |
| 223 // resized wallpaper to |path|. |
| 224 void ResizeAndSaveCustomWallpaper(const UserImage& wallpaper, |
| 225 const FilePath& path, |
| 226 ash::WallpaperLayout layout, |
| 227 int preferred_width, |
| 228 int preferred_height); |
| 229 |
| 230 // Saves original custom wallpaper to |path| (absolute path) on filesystem |
| 231 // and starts resizing operation of the custom wallpaper if necessary. |
| 232 void SaveCustomWallpaper(const std::string& email, |
| 233 const FilePath& path, |
| 234 ash::WallpaperLayout layout, |
| 235 const UserImage& wallpaper); |
| 207 | 236 |
| 208 // Saves wallpaper image raw |data| to |path| (absolute path) in file system. | 237 // Saves wallpaper image raw |data| to |path| (absolute path) in file system. |
| 209 void SaveWallpaperInternal(const FilePath& path, const char* data, int size); | 238 void SaveWallpaperInternal(const FilePath& path, const char* data, int size); |
| 210 | 239 |
| 211 // Saves wallpaper to file, post task to generate thumbnail and updates local | 240 // Saves custom wallpaper to file, post task to generate thumbnail and updates |
| 212 // state preferences. | 241 // local state preferences. |
| 213 void SetWallpaper(const std::string& username, | 242 void SetCustomWallpaper(const std::string& username, |
| 214 ash::WallpaperLayout layout, | 243 ash::WallpaperLayout layout, |
| 215 User::WallpaperType type, | 244 User::WallpaperType type, |
| 216 base::WeakPtr<WallpaperDelegate> delegate, | 245 base::WeakPtr<WallpaperDelegate> delegate, |
| 217 const UserImage& wallpaper); | 246 const UserImage& wallpaper); |
| 218 | 247 |
| 219 // Whether wallpaper data should be persisted for user |email|. | 248 // Whether wallpaper data should be persisted for user |email|. |
| 220 // Note: this function can not be called in SetUserWallpaperProperties. It | 249 // Note: this function can not be called in SetUserWallpaperProperties. It |
| 221 // will create a deadlock. (issue 142440) | 250 // will create a deadlock. (issue 142440) |
| 222 bool ShouldPersistDataForUser(const std::string& email); | 251 bool ShouldPersistDataForUser(const std::string& email); |
| 223 | 252 |
| 224 // Sets wallpaper to image in |user_image| with |layout|. | 253 // Sets wallpaper to image in |user_image| with |layout|. |
| 225 void OnWallpaperLoaded(ash::WallpaperLayout layout, | 254 void OnWallpaperLoaded(ash::WallpaperLayout layout, |
| 226 const UserImage& user_image); | 255 const UserImage& user_image); |
| 227 | 256 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 258 content::NotificationRegistrar registrar_; | 287 content::NotificationRegistrar registrar_; |
| 259 | 288 |
| 260 base::OneShotTimer<WallpaperManager> timer_; | 289 base::OneShotTimer<WallpaperManager> timer_; |
| 261 | 290 |
| 262 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); | 291 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); |
| 263 }; | 292 }; |
| 264 | 293 |
| 265 } // namespace chromeos | 294 } // namespace chromeos |
| 266 | 295 |
| 267 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ | 296 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ |
| OLD | NEW |