| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <deque> | 8 #include <deque> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 // Registers wallpaper manager preferences. | 182 // Registers wallpaper manager preferences. |
| 183 static void RegisterPrefs(PrefRegistrySimple* registry); | 183 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 184 | 184 |
| 185 // Adds PowerManagerClient, TimeZoneSettings and CrosSettings observers. | 185 // Adds PowerManagerClient, TimeZoneSettings and CrosSettings observers. |
| 186 void AddObservers(); | 186 void AddObservers(); |
| 187 | 187 |
| 188 // Loads wallpaper asynchronously if the current wallpaper is not the | 188 // Loads wallpaper asynchronously if the current wallpaper is not the |
| 189 // wallpaper of logged in user. | 189 // wallpaper of logged in user. |
| 190 void EnsureLoggedInUserWallpaperLoaded(); | 190 void EnsureLoggedInUserWallpaperLoaded(); |
| 191 | 191 |
| 192 // Clears disposable ONLINE and CUSTOM wallpaper cache. At multi profile | |
| 193 // world, logged in users' wallpaper cache is not disposable. | |
| 194 void ClearDisposableWallpaperCache(); | |
| 195 | |
| 196 // Returns custom wallpaper path. Append |sub_dir|, |user_id_hash| and |file| | 192 // Returns custom wallpaper path. Append |sub_dir|, |user_id_hash| and |file| |
| 197 // to custom wallpaper directory. | 193 // to custom wallpaper directory. |
| 198 base::FilePath GetCustomWallpaperPath(const char* sub_dir, | 194 base::FilePath GetCustomWallpaperPath(const char* sub_dir, |
| 199 const std::string& user_id_hash, | 195 const std::string& user_id_hash, |
| 200 const std::string& file) const; | 196 const std::string& file) const; |
| 201 | 197 |
| 202 // Returns filepath to save original custom wallpaper for the given user. | |
| 203 base::FilePath GetOriginalWallpaperPathForUser(const std::string& user_id); | |
| 204 | |
| 205 // Gets wallpaper information of logged in user. | 198 // Gets wallpaper information of logged in user. |
| 206 bool GetLoggedInUserWallpaperInfo(WallpaperInfo* info); | 199 bool GetLoggedInUserWallpaperInfo(WallpaperInfo* info); |
| 207 | 200 |
| 208 // Initializes wallpaper. If logged in, loads user's wallpaper. If not logged | 201 // Initializes wallpaper. If logged in, loads user's wallpaper. If not logged |
| 209 // in, uses a solid color wallpaper. If logged in as a stub user, uses an | 202 // in, uses a solid color wallpaper. If logged in as a stub user, uses an |
| 210 // empty wallpaper. | 203 // empty wallpaper. |
| 211 void InitializeWallpaper(); | 204 void InitializeWallpaper(); |
| 212 | 205 |
| 213 // NotificationObserver overrides: | 206 // NotificationObserver overrides: |
| 214 virtual void Observe(int type, | 207 virtual void Observe(int type, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 245 User::WallpaperType type, | 238 User::WallpaperType type, |
| 246 const UserImage& wallpaper, | 239 const UserImage& wallpaper, |
| 247 bool update_wallpaper); | 240 bool update_wallpaper); |
| 248 | 241 |
| 249 // Sets wallpaper to default wallpaper (asynchronously with zero delay). | 242 // Sets wallpaper to default wallpaper (asynchronously with zero delay). |
| 250 void SetDefaultWallpaperNow(const std::string& user_id); | 243 void SetDefaultWallpaperNow(const std::string& user_id); |
| 251 | 244 |
| 252 // Sets wallpaper to default wallpaper (asynchronously with default delay). | 245 // Sets wallpaper to default wallpaper (asynchronously with default delay). |
| 253 void SetDefaultWallpaperDelayed(const std::string& user_id); | 246 void SetDefaultWallpaperDelayed(const std::string& user_id); |
| 254 | 247 |
| 255 // Initialize wallpaper for the specified user to default and saves this | |
| 256 // settings in local state. | |
| 257 void InitInitialUserWallpaper(const std::string& user_id, | |
| 258 bool is_persistent); | |
| 259 | |
| 260 // Sets selected wallpaper information for |user_id| and saves it to Local | 248 // Sets selected wallpaper information for |user_id| and saves it to Local |
| 261 // State if |is_persistent| is true. | 249 // State if |is_persistent| is true. |
| 262 void SetUserWallpaperInfo(const std::string& user_id, | 250 void SetUserWallpaperInfo(const std::string& user_id, |
| 263 const WallpaperInfo& info, | 251 const WallpaperInfo& info, |
| 264 bool is_persistent); | 252 bool is_persistent); |
| 265 | 253 |
| 266 // Sets last selected user on user pod row. | |
| 267 void SetLastSelectedUser(const std::string& last_selected_user); | |
| 268 | |
| 269 // Sets |user_id|'s wallpaper (asynchronously with zero delay). | 254 // Sets |user_id|'s wallpaper (asynchronously with zero delay). |
| 270 void SetUserWallpaperNow(const std::string& user_id); | 255 void SetUserWallpaperNow(const std::string& user_id); |
| 271 | 256 |
| 272 // Sets |user_id|'s wallpaper (asynchronously with default delay). | 257 // Sets |user_id|'s wallpaper (asynchronously with default delay). |
| 273 void SetUserWallpaperDelayed(const std::string& user_id); | 258 void SetUserWallpaperDelayed(const std::string& user_id); |
| 274 | 259 |
| 275 // Sets wallpaper to |wallpaper| (asynchronously with zero delay). If | 260 // Sets wallpaper to |wallpaper| (asynchronously with zero delay). If |
| 276 // |update_wallpaper| is false, skip change wallpaper but only update cache. | 261 // |update_wallpaper| is false, skip change wallpaper but only update cache. |
| 277 void SetWallpaperFromImageSkia(const std::string& user_id, | 262 void SetWallpaperFromImageSkia(const std::string& user_id, |
| 278 const gfx::ImageSkia& wallpaper, | 263 const gfx::ImageSkia& wallpaper, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 305 const std::string& user_id, | 290 const std::string& user_id, |
| 306 scoped_ptr<std::string> data); | 291 scoped_ptr<std::string> data); |
| 307 | 292 |
| 308 private: | 293 private: |
| 309 friend class TestApi; | 294 friend class TestApi; |
| 310 friend class WallpaperManagerBrowserTest; | 295 friend class WallpaperManagerBrowserTest; |
| 311 friend class WallpaperManagerPolicyTest; | 296 friend class WallpaperManagerPolicyTest; |
| 312 | 297 |
| 313 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap; | 298 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap; |
| 314 | 299 |
| 300 // Initialize wallpaper for the specified user to default and saves this |
| 301 // settings in local state. |
| 302 void InitInitialUserWallpaper(const std::string& user_id, |
| 303 bool is_persistent); |
| 304 |
| 315 // Set |wallpaper| controlled by policy. | 305 // Set |wallpaper| controlled by policy. |
| 316 void SetPolicyControlledWallpaper(const std::string& user_id, | 306 void SetPolicyControlledWallpaper(const std::string& user_id, |
| 317 const UserImage& wallpaper); | 307 const UserImage& wallpaper); |
| 318 | 308 |
| 319 // Gets encoded wallpaper from cache. Returns true if success. | 309 // Gets encoded wallpaper from cache. Returns true if success. |
| 320 bool GetWallpaperFromCache(const std::string& user_id, | 310 bool GetWallpaperFromCache(const std::string& user_id, |
| 321 gfx::ImageSkia* wallpaper); | 311 gfx::ImageSkia* wallpaper); |
| 322 | 312 |
| 323 // The number of wallpapers have loaded. For test only. | 313 // The number of wallpapers have loaded. For test only. |
| 324 int loaded_wallpapers() const { return loaded_wallpapers_; } | 314 int loaded_wallpapers() const { return loaded_wallpapers_; } |
| 325 | 315 |
| 326 // Cache some (or all) logged in users' wallpapers to memory at login | 316 // Cache some (or all) logged in users' wallpapers to memory at login |
| 327 // screen. It should not compete with first wallpaper loading when boot | 317 // screen. It should not compete with first wallpaper loading when boot |
| 328 // up/initialize login WebUI page. | 318 // up/initialize login WebUI page. |
| 329 // There are two ways the first wallpaper might be loaded: | 319 // There are two ways the first wallpaper might be loaded: |
| 330 // 1. Loaded on boot. Login WebUI waits for it. | 320 // 1. Loaded on boot. Login WebUI waits for it. |
| 331 // 2. When flag --disable-boot-animation is passed. Login WebUI is loaded | 321 // 2. When flag --disable-boot-animation is passed. Login WebUI is loaded |
| 332 // right away and in 500ms after. Wallpaper started to load. | 322 // right away and in 500ms after. Wallpaper started to load. |
| 333 // For case 2, should_cache_wallpaper_ is used to indicate if we need to | 323 // For case 2, should_cache_wallpaper_ is used to indicate if we need to |
| 334 // cache wallpapers on wallpaper animation finished. The cache operation | 324 // cache wallpapers on wallpaper animation finished. The cache operation |
| 335 // should be only executed once. | 325 // should be only executed once. |
| 336 void CacheUsersWallpapers(); | 326 void CacheUsersWallpapers(); |
| 337 | 327 |
| 338 // Caches |user_id|'s wallpaper to memory. | 328 // Caches |user_id|'s wallpaper to memory. |
| 339 void CacheUserWallpaper(const std::string& user_id); | 329 void CacheUserWallpaper(const std::string& user_id); |
| 340 | 330 |
| 331 // Clears disposable ONLINE and CUSTOM wallpaper cache. At multi profile |
| 332 // world, logged in users' wallpaper cache is not disposable. |
| 333 void ClearDisposableWallpaperCache(); |
| 334 |
| 341 // Clears all obsolete wallpaper prefs from old version wallpaper pickers. | 335 // Clears all obsolete wallpaper prefs from old version wallpaper pickers. |
| 342 void ClearObsoleteWallpaperPrefs(); | 336 void ClearObsoleteWallpaperPrefs(); |
| 343 | 337 |
| 344 // Deletes everything else except |path| in the same directory. | 338 // Deletes everything else except |path| in the same directory. |
| 345 void DeleteAllExcept(const base::FilePath& path); | 339 static void DeleteAllExcept(const base::FilePath& path); |
| 346 | 340 |
| 347 // Deletes a list of wallpaper files in |file_list|. | 341 // Deletes a list of wallpaper files in |file_list|. |
| 348 void DeleteWallpaperInList(const std::vector<base::FilePath>& file_list); | 342 static void DeleteWallpaperInList( |
| 343 const std::vector<base::FilePath>& file_list); |
| 349 | 344 |
| 350 // Deletes all |user_id| related custom wallpapers and directories. | 345 // Deletes all |user_id| related custom wallpapers and directories. |
| 351 void DeleteUserWallpapers(const std::string& user_id, | 346 void DeleteUserWallpapers(const std::string& user_id, |
| 352 const std::string& path_to_file); | 347 const std::string& path_to_file); |
| 353 | 348 |
| 354 // Creates all new custom wallpaper directories for |user_id_hash| if not | 349 // Creates all new custom wallpaper directories for |user_id_hash| if not |
| 355 // exist. | 350 // exist. |
| 356 void EnsureCustomWallpaperDirectories(const std::string& user_id_hash); | 351 static void EnsureCustomWallpaperDirectories(const std::string& user_id_hash); |
| 357 | 352 |
| 358 // Gets the CommandLine representing the current process's command line. | 353 // Gets the CommandLine representing the current process's command line. |
| 359 base::CommandLine* GetComandLine(); | 354 base::CommandLine* GetComandLine(); |
| 360 | 355 |
| 361 // Initialize wallpaper of registered device after device policy is trusted. | 356 // Initialize wallpaper of registered device after device policy is trusted. |
| 362 // Note that before device is enrolled, it proceeds with untrusted setting. | 357 // Note that before device is enrolled, it proceeds with untrusted setting. |
| 363 void InitializeRegisteredDeviceWallpaper(); | 358 void InitializeRegisteredDeviceWallpaper(); |
| 364 | 359 |
| 365 // Loads |user_id|'s wallpaper. When |update_wallpaper| is true, sets | 360 // Loads |user_id|'s wallpaper. When |update_wallpaper| is true, sets |
| 366 // wallpaper to the loaded wallpaper. | 361 // wallpaper to the loaded wallpaper. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 WallpaperInfo* info) const; | 395 WallpaperInfo* info) const; |
| 401 | 396 |
| 402 // Sets wallpaper to the decoded wallpaper if |update_wallpaper| is true. | 397 // Sets wallpaper to the decoded wallpaper if |update_wallpaper| is true. |
| 403 // Otherwise, cache wallpaper to memory if not logged in. | 398 // Otherwise, cache wallpaper to memory if not logged in. |
| 404 void OnWallpaperDecoded(const std::string& user_id, | 399 void OnWallpaperDecoded(const std::string& user_id, |
| 405 ash::WallpaperLayout layout, | 400 ash::WallpaperLayout layout, |
| 406 bool update_wallpaper, | 401 bool update_wallpaper, |
| 407 MovableOnDestroyCallbackHolder on_finish, | 402 MovableOnDestroyCallbackHolder on_finish, |
| 408 const UserImage& wallpaper); | 403 const UserImage& wallpaper); |
| 409 | 404 |
| 410 // Generates thumbnail of custom wallpaper on wallpaper sequenced worker | |
| 411 // thread. If |persistent| is true, saves original custom image and resized | |
| 412 // images to disk. | |
| 413 void ProcessCustomWallpaper(const std::string& user_id_hash, | |
| 414 bool persistent, | |
| 415 const WallpaperInfo& info, | |
| 416 scoped_ptr<gfx::ImageSkia> image, | |
| 417 const UserImage::RawImage& raw_image); | |
| 418 | |
| 419 // Record data for User Metrics Analysis. | 405 // Record data for User Metrics Analysis. |
| 420 void RecordUma(User::WallpaperType type, int index) const; | 406 void RecordUma(User::WallpaperType type, int index) const; |
| 421 | 407 |
| 422 // Saves original custom wallpaper to |path| (absolute path) on filesystem | 408 // Saves original custom wallpaper to |path| (absolute path) on filesystem |
| 423 // and starts resizing operation of the custom wallpaper if necessary. | 409 // and starts resizing operation of the custom wallpaper if necessary. |
| 424 void SaveCustomWallpaper(const std::string& user_id_hash, | 410 void SaveCustomWallpaper(const std::string& user_id_hash, |
| 425 const base::FilePath& path, | 411 const base::FilePath& path, |
| 426 ash::WallpaperLayout layout, | 412 ash::WallpaperLayout layout, |
| 427 const UserImage& wallpaper); | 413 const UserImage& wallpaper) const; |
| 428 | 414 |
| 429 // Saves wallpaper image raw |data| to |path| (absolute path) in file system. | 415 // Saves wallpaper image raw |data| to |path| (absolute path) in file system. |
| 430 void SaveWallpaperInternal(const base::FilePath& path, const char* data, | 416 void SaveWallpaperInternal(const base::FilePath& path, const char* data, |
| 431 int size) const; | 417 int size) const; |
| 432 | 418 |
| 433 // Creates new PendingWallpaper request (or updates currently pending). | 419 // Creates new PendingWallpaper request (or updates currently pending). |
| 434 void ScheduleSetUserWallpaper(const std::string& user_id, bool delayed); | 420 void ScheduleSetUserWallpaper(const std::string& user_id, bool delayed); |
| 435 | 421 |
| 436 // Sets wallpaper to default. | 422 // Sets wallpaper to default. |
| 437 void DoSetDefaultWallpaper( | 423 void DoSetDefaultWallpaper( |
| 438 const std::string& user_id, | 424 const std::string& user_id, |
| 439 MovableOnDestroyCallbackHolder on_finish); | 425 MovableOnDestroyCallbackHolder on_finish); |
| 440 | 426 |
| 441 // Starts to load wallpaper at |wallpaper_path|. If |wallpaper_path| is the | 427 // Starts to load wallpaper at |wallpaper_path|. If |wallpaper_path| is the |
| 442 // same as |current_wallpaper_path_|, do nothing. Must be called on UI thread. | 428 // same as |current_wallpaper_path_|, do nothing. Must be called on UI thread. |
| 443 void StartLoad(const std::string& user_id, | 429 void StartLoad(const std::string& user_id, |
| 444 const WallpaperInfo& info, | 430 const WallpaperInfo& info, |
| 445 bool update_wallpaper, | 431 bool update_wallpaper, |
| 446 const base::FilePath& wallpaper_path, | 432 const base::FilePath& wallpaper_path, |
| 447 MovableOnDestroyCallbackHolder on_finish); | 433 MovableOnDestroyCallbackHolder on_finish); |
| 448 | 434 |
| 449 // After completed load operation, update average load time. | 435 // After completed load operation, update average load time. |
| 450 void SaveLastLoadTime(const base::TimeDelta elapsed); | 436 void SaveLastLoadTime(const base::TimeDelta elapsed); |
| 451 | 437 |
| 452 // Notify all registed observers. | 438 // Notify all registered observers. |
| 453 void NotifyAnimationFinished(); | 439 void NotifyAnimationFinished(); |
| 454 | 440 |
| 455 // Returns modifiable PendingWallpaper. | 441 // Returns modifiable PendingWallpaper. |
| 456 // Returns pending_inactive_ or creates new PendingWallpaper if necessary. | 442 // Returns pending_inactive_ or creates new PendingWallpaper if necessary. |
| 457 PendingWallpaper* GetPendingWallpaper(const std::string& user_id, | 443 PendingWallpaper* GetPendingWallpaper(const std::string& user_id, |
| 458 bool delayed); | 444 bool delayed); |
| 459 | 445 |
| 460 // Calculate delay for next wallpaper load. | 446 // Calculate delay for next wallpaper load. |
| 461 // It is usually average wallpaper load time. | 447 // It is usually average wallpaper load time. |
| 462 // If last wallpaper load happened long ago, timeout should be reduced by | 448 // If last wallpaper load happened long ago, timeout should be reduced by |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 // All pending will be finally deleted on destroy. | 505 // All pending will be finally deleted on destroy. |
| 520 typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList; | 506 typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList; |
| 521 PendingList loading_; | 507 PendingList loading_; |
| 522 | 508 |
| 523 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); | 509 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); |
| 524 }; | 510 }; |
| 525 | 511 |
| 526 } // namespace chromeos | 512 } // namespace chromeos |
| 527 | 513 |
| 528 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ | 514 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ |
| OLD | NEW |