| 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/file_path.h" |
| 11 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 13 #include "base/time.h" | 14 #include "base/time.h" |
| 14 #include "base/timer.h" | 15 #include "base/timer.h" |
| 15 #include "chrome/browser/chromeos/login/user.h" | 16 #include "chrome/browser/chromeos/login/user.h" |
| 16 #include "chrome/browser/chromeos/login/user_image.h" | 17 #include "chrome/browser/chromeos/login/user_image.h" |
| 17 #include "chrome/browser/chromeos/login/user_image_loader.h" | 18 #include "chrome/browser/chromeos/login/user_image_loader.h" |
| 18 #include "chrome/browser/chromeos/system/timezone_settings.h" | 19 #include "chrome/browser/chromeos/system/timezone_settings.h" |
| 19 #include "chrome/browser/ui/webui/options/chromeos/set_wallpaper_options_handler
.h" | |
| 20 #include "chromeos/dbus/power_manager_client.h" | 20 #include "chromeos/dbus/power_manager_client.h" |
| 21 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
| 22 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
| 23 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
| 24 #include "unicode/timezone.h" | 24 #include "unicode/timezone.h" |
| 25 | 25 |
| 26 class PrefService; | 26 class PrefService; |
| 27 | 27 |
| 28 namespace chromeos { | 28 namespace chromeos { |
| 29 | 29 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 56 | 56 |
| 57 WallpaperManager(); | 57 WallpaperManager(); |
| 58 | 58 |
| 59 // Registers wallpaper manager preferences. | 59 // Registers wallpaper manager preferences. |
| 60 static void RegisterPrefs(PrefService* local_state); | 60 static void RegisterPrefs(PrefService* local_state); |
| 61 | 61 |
| 62 // Adds PowerManagerClient and TimeZoneSettings observers. It needs to be | 62 // Adds PowerManagerClient and TimeZoneSettings observers. It needs to be |
| 63 // added after PowerManagerClient initialized. | 63 // added after PowerManagerClient initialized. |
| 64 void AddObservers(); | 64 void AddObservers(); |
| 65 | 65 |
| 66 // Migrate the old wallpaper index to a new wallpaper structure for all users | |
| 67 // in |users|. | |
| 68 // The new wallpaper structure is: | |
| 69 // { WallpaperType: DAILY|CUSTOMIZED|DEFAULT, | |
| 70 // index: index of the default wallpapers } | |
| 71 void MigrateWallpaperData(const UserList& users); | |
| 72 | |
| 73 // Loads wallpaper asynchronously if the current wallpaper is not the | 66 // Loads wallpaper asynchronously if the current wallpaper is not the |
| 74 // wallpaper of logged in user. | 67 // wallpaper of logged in user. |
| 75 void EnsureLoggedInUserWallpaperLoaded(); | 68 void EnsureLoggedInUserWallpaperLoaded(); |
| 76 | 69 |
| 77 // Clears ONLINE and CUSTOM wallpaper cache. | 70 // Clears ONLINE and CUSTOM wallpaper cache. |
| 78 void ClearWallpaperCache(); | 71 void ClearWallpaperCache(); |
| 79 | 72 |
| 80 // Gets encoded wallpaper from cache. Returns true if success. | 73 // Gets encoded wallpaper from cache. Returns true if success. |
| 81 bool GetWallpaperFromCache(const std::string& email, | 74 bool GetWallpaperFromCache(const std::string& email, |
| 82 gfx::ImageSkia* wallpaper); | 75 gfx::ImageSkia* wallpaper); |
| 83 | 76 |
| 84 // Returns filepath to save original custom wallpaper for the given user. | 77 // Returns filepath to save original custom wallpaper for the given user. |
| 85 FilePath GetOriginalWallpaperPathForUser(const std::string& username); | 78 FilePath GetOriginalWallpaperPathForUser(const std::string& username); |
| 86 | 79 |
| 87 // Returns small resolution custom wallpaper filepath for the given user when | 80 // Returns small resolution custom wallpaper filepath for the given user when |
| 88 // |is_small| is ture. Otherwise, returns large resolution custom wallpaper | 81 // |is_small| is ture. Otherwise, returns large resolution custom wallpaper |
| 89 // path. | 82 // path. |
| 90 FilePath GetWallpaperPathForUser(const std::string& username, | 83 FilePath GetWallpaperPathForUser(const std::string& username, |
| 91 bool is_small); | 84 bool is_small); |
| 92 | 85 |
| 93 // Gets the thumbnail of custom wallpaper from cache. | 86 // Gets the thumbnail of custom wallpaper from cache. |
| 94 gfx::ImageSkia GetCustomWallpaperThumbnail(const std::string& email); | 87 gfx::ImageSkia GetCustomWallpaperThumbnail(const std::string& email); |
| 95 | 88 |
| 96 // Gets wallpaper properties of logged in user. | |
| 97 void GetLoggedInUserWallpaperProperties(User::WallpaperType* type, | |
| 98 int* index, | |
| 99 base::Time* last_modification_date); | |
| 100 | |
| 101 // Gets wallpaper information of logged in user. | 89 // Gets wallpaper information of logged in user. |
| 102 bool GetLoggedInUserWallpaperInfo(WallpaperInfo* info); | 90 bool GetLoggedInUserWallpaperInfo(WallpaperInfo* info); |
| 103 | 91 |
| 104 // Initializes wallpaper. If logged in, loads user's wallpaper. If not logged | 92 // Initializes wallpaper. If logged in, loads user's wallpaper. If not logged |
| 105 // in, uses a solid color wallpaper. If logged in as a stub user, uses an | 93 // in, uses a solid color wallpaper. If logged in as a stub user, uses an |
| 106 // empty wallpaper. | 94 // empty wallpaper. |
| 107 void InitializeWallpaper(); | 95 void InitializeWallpaper(); |
| 108 | 96 |
| 109 // NotificationObserver overrides: | 97 // NotificationObserver overrides: |
| 110 virtual void Observe(int type, | 98 virtual void Observe(int type, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 125 | 113 |
| 126 // Starts a one shot timer which calls BatchUpdateWallpaper at next midnight. | 114 // Starts a one shot timer which calls BatchUpdateWallpaper at next midnight. |
| 127 // Cancel any previous timer if any. | 115 // Cancel any previous timer if any. |
| 128 void RestartTimer(); | 116 void RestartTimer(); |
| 129 | 117 |
| 130 // Saves custom wallpaper to file, post task to generate thumbnail and updates | 118 // Saves custom wallpaper to file, post task to generate thumbnail and updates |
| 131 // local state preferences. | 119 // local state preferences. |
| 132 void SetCustomWallpaper(const std::string& username, | 120 void SetCustomWallpaper(const std::string& username, |
| 133 ash::WallpaperLayout layout, | 121 ash::WallpaperLayout layout, |
| 134 User::WallpaperType type, | 122 User::WallpaperType type, |
| 135 base::WeakPtr<WallpaperDelegate> delegate, | |
| 136 const UserImage& wallpaper); | 123 const UserImage& wallpaper); |
| 137 | 124 |
| 138 // Tries to load user image from disk; if successful, sets it for the user, | |
| 139 // and updates Local State. | |
| 140 void SetUserWallpaperFromFile(const std::string& username, | |
| 141 const FilePath& path, | |
| 142 ash::WallpaperLayout layout, | |
| 143 base::WeakPtr<WallpaperDelegate> delegate); | |
| 144 | |
| 145 // Sets selected wallpaper properties for |username| and saves it to Local | |
| 146 // State if |is_persistent| is true. | |
| 147 void SetUserWallpaperProperties(const std::string& email, | |
| 148 User::WallpaperType type, | |
| 149 int index, | |
| 150 bool is_persistent); | |
| 151 | |
| 152 // Sets wallpaper to default wallpaper at |index|. | 125 // Sets wallpaper to default wallpaper at |index|. |
| 153 void SetDefaultWallpaper(int index); | 126 void SetDefaultWallpaper(int index); |
| 154 | 127 |
| 155 // Sets one of the default wallpapers for the specified user and saves this | 128 // Sets one of the default wallpapers for the specified user and saves this |
| 156 // settings in local state. | 129 // settings in local state. |
| 157 void SetInitialUserWallpaper(const std::string& username, bool is_persistent); | 130 void SetInitialUserWallpaper(const std::string& username, bool is_persistent); |
| 158 | 131 |
| 159 // Sets selected wallpaper information for |username| and saves it to Local | 132 // Sets selected wallpaper information for |username| and saves it to Local |
| 160 // State if |is_persistent| is true. | 133 // State if |is_persistent| is true. |
| 161 void SetUserWallpaperInfo(const std::string& username, | 134 void SetUserWallpaperInfo(const std::string& username, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 // should be only executed once. | 178 // should be only executed once. |
| 206 void CacheAllUsersWallpapers(); | 179 void CacheAllUsersWallpapers(); |
| 207 | 180 |
| 208 // Caches |email|'s wallpaper to memory. | 181 // Caches |email|'s wallpaper to memory. |
| 209 void CacheUserWallpaper(const std::string& email); | 182 void CacheUserWallpaper(const std::string& email); |
| 210 | 183 |
| 211 // Generates a 128x80 thumbnail and caches it. | 184 // Generates a 128x80 thumbnail and caches it. |
| 212 void CacheThumbnail(const std::string& email, | 185 void CacheThumbnail(const std::string& email, |
| 213 scoped_ptr<gfx::ImageSkia> wallpaper); | 186 scoped_ptr<gfx::ImageSkia> wallpaper); |
| 214 | 187 |
| 188 // Clears all obsolete wallpaper prefs from old version wallpaper pickers. |
| 189 void ClearObsoleteWallpaperPrefs(); |
| 190 |
| 215 // Deletes a list of wallpaper files in |file_list|. | 191 // Deletes a list of wallpaper files in |file_list|. |
| 216 void DeleteWallpaperInList(const std::vector<FilePath>& file_list); | 192 void DeleteWallpaperInList(const std::vector<FilePath>& file_list); |
| 217 | 193 |
| 218 // Deletes all |email| related custom or converted wallpapers. | 194 // Deletes all |email| related custom or converted wallpapers. |
| 219 void DeleteUserWallpapers(const std::string& email); | 195 void DeleteUserWallpapers(const std::string& email); |
| 220 | 196 |
| 221 // Loads |email|'s wallpaper. When |update_wallpaper| is true, sets wallpaper | 197 // Loads |email|'s wallpaper. When |update_wallpaper| is true, sets wallpaper |
| 222 // to the loaded wallpaper. | 198 // to the loaded wallpaper. |
| 223 void LoadWallpaper(const std::string& email, | 199 void LoadWallpaper(const std::string& email, |
| 224 const WallpaperInfo& info, | 200 const WallpaperInfo& info, |
| 225 bool update_wallpaper); | 201 bool update_wallpaper); |
| 226 | 202 |
| 227 // Generates a 128x80 thumbnail and notifies delegate when ready. | 203 // Generates a 128x80 thumbnail. |
| 228 void GenerateUserWallpaperThumbnail(const std::string& email, | 204 void GenerateUserWallpaperThumbnail(const std::string& email, |
| 229 User::WallpaperType type, | 205 User::WallpaperType type, |
| 230 base::WeakPtr<WallpaperDelegate> delegate, | |
| 231 const gfx::ImageSkia& wallpaper); | 206 const gfx::ImageSkia& wallpaper); |
| 232 | 207 |
| 233 // Gets |email|'s custom wallpaper at |wallpaper_path|. Falls back on original | 208 // Gets |email|'s custom wallpaper at |wallpaper_path|. Falls back on original |
| 234 // custom wallpaper. When |update_wallpaper| is true, sets wallpaper to the | 209 // custom wallpaper. When |update_wallpaper| is true, sets wallpaper to the |
| 235 // loaded wallpaper. Must run on FILE thread. | 210 // loaded wallpaper. Must run on FILE thread. |
| 236 void GetCustomWallpaperInternal(const std::string& email, | 211 void GetCustomWallpaperInternal(const std::string& email, |
| 237 const WallpaperInfo& info, | 212 const WallpaperInfo& info, |
| 238 const FilePath& wallpaper_path, | 213 const FilePath& wallpaper_path, |
| 239 bool update_wallpaper); | 214 bool update_wallpaper); |
| 240 | 215 |
| 241 // Gets wallpaper information of |email| from Local State or memory. Returns | 216 // Gets wallpaper information of |email| from Local State or memory. Returns |
| 242 // false if wallpaper information is not found. | 217 // false if wallpaper information is not found. |
| 243 bool GetUserWallpaperInfo(const std::string& email, WallpaperInfo* info); | 218 bool GetUserWallpaperInfo(const std::string& email, WallpaperInfo* info); |
| 244 | 219 |
| 245 // Gets wallpaper |type|, |index| and |last_modification_date| of |email| | |
| 246 // from local state. | |
| 247 void GetUserWallpaperProperties(const std::string& email, | |
| 248 User::WallpaperType* type, | |
| 249 int* index, | |
| 250 base::Time* last_modification_date); | |
| 251 | |
| 252 // Copy |email| selected built-in wallpapers (high and low resolution) in | |
| 253 // ChromeOS image binary to local files on disk. Also converts the wallpaper | |
| 254 // properties correspond to the built-in wallpapers to the new wallpaper info. | |
| 255 void MigrateBuiltInWallpaper(const std::string& email); | |
| 256 | |
| 257 // Updates the custom wallpaper thumbnail in wallpaper picker UI. | |
| 258 void OnThumbnailUpdated(base::WeakPtr<WallpaperDelegate> delegate); | |
| 259 | |
| 260 // Sets wallpaper to the decoded wallpaper if |update_wallpaper| is true. | 220 // Sets wallpaper to the decoded wallpaper if |update_wallpaper| is true. |
| 261 // Otherwise, cache wallpaper to memory if not logged in. | 221 // Otherwise, cache wallpaper to memory if not logged in. |
| 262 void OnWallpaperDecoded(const std::string& email, | 222 void OnWallpaperDecoded(const std::string& email, |
| 263 ash::WallpaperLayout layout, | 223 ash::WallpaperLayout layout, |
| 264 bool update_wallpaper, | 224 bool update_wallpaper, |
| 265 const UserImage& wallpaper); | 225 const UserImage& wallpaper); |
| 266 | 226 |
| 267 // Saves encoded wallpaper to |path|. This callback is called after encoding | 227 // Saves encoded wallpaper to |path|. This callback is called after encoding |
| 268 // to PNG completes. | 228 // to PNG completes. |
| 269 void OnWallpaperEncoded(const FilePath& path, | 229 void OnWallpaperEncoded(const FilePath& path, |
| 270 scoped_refptr<base::RefCountedBytes> data); | 230 scoped_refptr<base::RefCountedBytes> data); |
| 271 | 231 |
| 272 // Generates thumbnail of custom wallpaper on FILE thread. If |persistent| is | 232 // Generates thumbnail of custom wallpaper on FILE thread. If |persistent| is |
| 273 // true, saves original custom image and resized images to disk. | 233 // true, saves original custom image and resized images to disk. |
| 274 void ProcessCustomWallpaper(const std::string& email, | 234 void ProcessCustomWallpaper(const std::string& email, |
| 275 bool persistent, | 235 bool persistent, |
| 276 const WallpaperInfo& info, | 236 const WallpaperInfo& info, |
| 277 base::WeakPtr<WallpaperDelegate> delegate, | |
| 278 scoped_ptr<gfx::ImageSkia> image, | 237 scoped_ptr<gfx::ImageSkia> image, |
| 279 const UserImage::RawImage& raw_image); | 238 const UserImage::RawImage& raw_image); |
| 280 | 239 |
| 281 // Record data for User Metrics Analysis. | 240 // Record data for User Metrics Analysis. |
| 282 void RecordUma(User::WallpaperType type, int index); | 241 void RecordUma(User::WallpaperType type, int index); |
| 283 | 242 |
| 284 // Saves original custom wallpaper to |path| (absolute path) on filesystem | 243 // Saves original custom wallpaper to |path| (absolute path) on filesystem |
| 285 // and starts resizing operation of the custom wallpaper if necessary. | 244 // and starts resizing operation of the custom wallpaper if necessary. |
| 286 void SaveCustomWallpaper(const std::string& email, | 245 void SaveCustomWallpaper(const std::string& email, |
| 287 const FilePath& path, | 246 const FilePath& path, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 285 |
| 327 // The file path of current loaded/loading custom/online wallpaper. | 286 // The file path of current loaded/loading custom/online wallpaper. |
| 328 FilePath current_wallpaper_path_; | 287 FilePath current_wallpaper_path_; |
| 329 | 288 |
| 330 // The index of current loaded/loading default wallpaper. | 289 // The index of current loaded/loading default wallpaper. |
| 331 int current_default_wallpaper_index_; | 290 int current_default_wallpaper_index_; |
| 332 | 291 |
| 333 // Loads user wallpaper from its file. | 292 // Loads user wallpaper from its file. |
| 334 scoped_refptr<UserImageLoader> wallpaper_loader_; | 293 scoped_refptr<UserImageLoader> wallpaper_loader_; |
| 335 | 294 |
| 336 // Logged-in user wallpaper type. | |
| 337 User::WallpaperType current_user_wallpaper_type_; | |
| 338 | |
| 339 // Logged-in user wallpaper index. | |
| 340 int current_user_wallpaper_index_; | |
| 341 | |
| 342 // Logged-in user wallpaper information. | 295 // Logged-in user wallpaper information. |
| 343 WallpaperInfo current_user_wallpaper_info_; | 296 WallpaperInfo current_user_wallpaper_info_; |
| 344 | 297 |
| 345 // Caches wallpapers of users. Accessed only on UI thread. | 298 // Caches wallpapers of users. Accessed only on UI thread. |
| 346 CustomWallpaperMap wallpaper_cache_; | 299 CustomWallpaperMap wallpaper_cache_; |
| 347 | 300 |
| 348 CustomWallpaperMap custom_wallpaper_thumbnail_cache_; | 301 CustomWallpaperMap custom_wallpaper_thumbnail_cache_; |
| 349 | 302 |
| 350 // The last selected user on user pod row. | 303 // The last selected user on user pod row. |
| 351 std::string last_selected_user_; | 304 std::string last_selected_user_; |
| 352 | 305 |
| 353 bool should_cache_wallpaper_; | 306 bool should_cache_wallpaper_; |
| 354 | 307 |
| 355 base::WeakPtrFactory<WallpaperManager> weak_factory_; | 308 base::WeakPtrFactory<WallpaperManager> weak_factory_; |
| 356 | 309 |
| 357 content::NotificationRegistrar registrar_; | 310 content::NotificationRegistrar registrar_; |
| 358 | 311 |
| 359 base::OneShotTimer<WallpaperManager> timer_; | 312 base::OneShotTimer<WallpaperManager> timer_; |
| 360 | 313 |
| 361 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); | 314 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); |
| 362 }; | 315 }; |
| 363 | 316 |
| 364 } // namespace chromeos | 317 } // namespace chromeos |
| 365 | 318 |
| 366 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ | 319 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ |
| OLD | NEW |