| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 83 |
| 84 // This class maintains wallpapers for users who have logged into this Chrome | 84 // This class maintains wallpapers for users who have logged into this Chrome |
| 85 // OS device. | 85 // OS device. |
| 86 class WallpaperManager: public content::NotificationObserver { | 86 class WallpaperManager: public content::NotificationObserver { |
| 87 public: | 87 public: |
| 88 enum WallpaperResolution { | 88 enum WallpaperResolution { |
| 89 WALLPAPER_RESOLUTION_LARGE, | 89 WALLPAPER_RESOLUTION_LARGE, |
| 90 WALLPAPER_RESOLUTION_SMALL | 90 WALLPAPER_RESOLUTION_SMALL |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 struct CustomizedWallpaperRescaledFiles { |
| 94 CustomizedWallpaperRescaledFiles(const base::FilePath& path_rescaled_small, |
| 95 const base::FilePath& path_rescaled_large); |
| 96 |
| 97 base::FilePath path_rescaled_small; |
| 98 base::FilePath path_rescaled_large; |
| 99 }; |
| 100 |
| 101 struct CustomizedWallpaperFilesExist { |
| 102 CustomizedWallpaperFilesExist(); |
| 103 |
| 104 bool AllRescaledExist() const; |
| 105 |
| 106 bool downloaded; |
| 107 bool rescaled_small; |
| 108 bool rescaled_large; |
| 109 }; |
| 110 |
| 93 // For testing. | 111 // For testing. |
| 94 class TestApi { | 112 class TestApi { |
| 95 public: | 113 public: |
| 96 explicit TestApi(WallpaperManager* wallpaper_manager); | 114 explicit TestApi(WallpaperManager* wallpaper_manager); |
| 97 virtual ~TestApi(); | 115 virtual ~TestApi(); |
| 98 | 116 |
| 99 base::FilePath current_wallpaper_path(); | 117 base::FilePath current_wallpaper_path(); |
| 100 | 118 |
| 101 bool GetWallpaperFromCache(const std::string& user_id, | 119 bool GetWallpaperFromCache(const std::string& user_id, |
| 102 gfx::ImageSkia* image); | 120 gfx::ImageSkia* image); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 // local state preferences. If |update_wallpaper| is false, don't change | 277 // local state preferences. If |update_wallpaper| is false, don't change |
| 260 // wallpaper but only update cache. | 278 // wallpaper but only update cache. |
| 261 void SetCustomWallpaper(const std::string& user_id, | 279 void SetCustomWallpaper(const std::string& user_id, |
| 262 const std::string& user_id_hash, | 280 const std::string& user_id_hash, |
| 263 const std::string& file, | 281 const std::string& file, |
| 264 ash::WallpaperLayout layout, | 282 ash::WallpaperLayout layout, |
| 265 User::WallpaperType type, | 283 User::WallpaperType type, |
| 266 const UserImage& wallpaper, | 284 const UserImage& wallpaper, |
| 267 bool update_wallpaper); | 285 bool update_wallpaper); |
| 268 | 286 |
| 287 // Use given files as new default wallpaper. |
| 288 // Reloads current wallpaper, if old default was loaded. |
| 289 // Current value of default_wallpaper_image_ is destroyed. |
| 290 // Sets default_wallpaper_image_ either to |small_wallpaper_image| or |
| 291 // |large_wallpaper_image| depending on GetAppropriateResolution(). |
| 292 void SetDefaultWallpaperPath( |
| 293 const base::FilePath& customized_default_wallpaper_file_small, |
| 294 scoped_ptr<gfx::ImageSkia> small_wallpaper_image, |
| 295 const base::FilePath& customized_default_wallpaper_file_large, |
| 296 scoped_ptr<gfx::ImageSkia> large_wallpaper_image); |
| 297 |
| 269 // Sets wallpaper to default wallpaper (asynchronously with zero delay). | 298 // Sets wallpaper to default wallpaper (asynchronously with zero delay). |
| 270 void SetDefaultWallpaperNow(const std::string& user_id); | 299 void SetDefaultWallpaperNow(const std::string& user_id); |
| 271 | 300 |
| 272 // Sets wallpaper to default wallpaper (asynchronously with default delay). | 301 // Sets wallpaper to default wallpaper (asynchronously with default delay). |
| 273 void SetDefaultWallpaperDelayed(const std::string& user_id); | 302 void SetDefaultWallpaperDelayed(const std::string& user_id); |
| 274 | 303 |
| 275 // Initialize wallpaper for the specified user to default and saves this | 304 // Initialize wallpaper for the specified user to default and saves this |
| 276 // settings in local state. | 305 // settings in local state. |
| 277 void InitInitialUserWallpaper(const std::string& user_id, | 306 void InitInitialUserWallpaper(const std::string& user_id, |
| 278 bool is_persistent); | 307 bool is_persistent); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 350 |
| 322 // Called when the policy-set wallpaper has been fetched. Initiates decoding | 351 // Called when the policy-set wallpaper has been fetched. Initiates decoding |
| 323 // of the JPEG |data| with a callback to SetPolicyControlledWallpaper(). | 352 // of the JPEG |data| with a callback to SetPolicyControlledWallpaper(). |
| 324 void OnPolicyFetched(const std::string& policy, | 353 void OnPolicyFetched(const std::string& policy, |
| 325 const std::string& user_id, | 354 const std::string& user_id, |
| 326 scoped_ptr<std::string> data); | 355 scoped_ptr<std::string> data); |
| 327 | 356 |
| 328 // Returns the appropriate wallpaper resolution for all root windows. | 357 // Returns the appropriate wallpaper resolution for all root windows. |
| 329 static WallpaperResolution GetAppropriateResolution(); | 358 static WallpaperResolution GetAppropriateResolution(); |
| 330 | 359 |
| 360 // This is called from CustomizationDocument. |
| 361 // resized_directory - directory where resized versions are stored |
| 362 // (must be writable) |
| 363 void SetCustomizedDefaultWallpaper(const GURL& wallpaper_url, |
| 364 const base::FilePath& downloaded_file, |
| 365 const base::FilePath& resized_directory); |
| 366 |
| 331 private: | 367 private: |
| 332 friend class TestApi; | 368 friend class TestApi; |
| 333 friend class WallpaperManagerBrowserTest; | 369 friend class WallpaperManagerBrowserTest; |
| 334 friend class WallpaperManagerBrowserTestDefaultWallpaper; | 370 friend class WallpaperManagerBrowserTestDefaultWallpaper; |
| 335 friend class WallpaperManagerPolicyTest; | 371 friend class WallpaperManagerPolicyTest; |
| 336 | 372 |
| 337 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap; | 373 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap; |
| 338 | 374 |
| 339 // Set |wallpaper| controlled by policy. | 375 // Set |wallpaper| controlled by policy. |
| 340 void SetPolicyControlledWallpaper(const std::string& user_id, | 376 void SetPolicyControlledWallpaper(const std::string& user_id, |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 PendingWallpaper* GetPendingWallpaper(const std::string& user_id, | 519 PendingWallpaper* GetPendingWallpaper(const std::string& user_id, |
| 484 bool delayed); | 520 bool delayed); |
| 485 | 521 |
| 486 // Calculate delay for next wallpaper load. | 522 // Calculate delay for next wallpaper load. |
| 487 // It is usually average wallpaper load time. | 523 // It is usually average wallpaper load time. |
| 488 // If last wallpaper load happened long ago, timeout should be reduced by | 524 // If last wallpaper load happened long ago, timeout should be reduced by |
| 489 // the time passed after last wallpaper load. So usual user experience results | 525 // the time passed after last wallpaper load. So usual user experience results |
| 490 // in zero delay. | 526 // in zero delay. |
| 491 base::TimeDelta GetWallpaperLoadDelay() const; | 527 base::TimeDelta GetWallpaperLoadDelay() const; |
| 492 | 528 |
| 529 // This is called after we check that supplied default wallpaper files exist. |
| 530 void SetCustomizedDefaultWallpaperAfterCheck( |
| 531 const GURL& wallpaper_url, |
| 532 const base::FilePath& downloaded_file, |
| 533 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, |
| 534 scoped_ptr<CustomizedWallpaperFilesExist> exist); |
| 535 |
| 536 // Starts rescaling of customized wallpaper. |
| 537 void OnCustomizedDefaultWallpaperDecoded( |
| 538 const GURL& wallpaper_url, |
| 539 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, |
| 540 const UserImage& user_image); |
| 541 |
| 542 // Resize and save customized default wallpaper. |
| 543 void ResizeCustomizedDefaultWallpaper( |
| 544 scoped_ptr<gfx::ImageSkia> image, |
| 545 const UserImage::RawImage& raw_image, |
| 546 const CustomizedWallpaperRescaledFiles* rescaled_files, |
| 547 bool* success, |
| 548 gfx::ImageSkia* small_wallpaper_image, |
| 549 gfx::ImageSkia* large_wallpaper_image); |
| 550 |
| 551 // Check the result of ResizeCustomizedDefaultWallpaper and finally |
| 552 // apply Customized Default Wallpaper. |
| 553 void OnCustomizedDefaultWallpaperResized( |
| 554 const GURL& wallpaper_url, |
| 555 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, |
| 556 scoped_ptr<bool> success, |
| 557 scoped_ptr<gfx::ImageSkia> small_wallpaper_image, |
| 558 scoped_ptr<gfx::ImageSkia> large_wallpaper_image); |
| 559 |
| 560 // These global default values are used to set customized default |
| 561 // wallpaper path in InitializeWallpaper(). |
| 562 static base::FilePath GetCustomizedWallpaperDefaultRescaledFileName( |
| 563 const char* suffix); |
| 564 |
| 565 // If DesktopBackgroundController should start with customized default |
| 566 // wallpaper in InitializeWallpaper(). |
| 567 static bool ShouldUseCustomizedDefaultWallpaper(); |
| 568 |
| 493 // Init |*default_*_wallpaper_file_| from given command line and | 569 // Init |*default_*_wallpaper_file_| from given command line and |
| 494 // clear |default_wallpaper_image_|. | 570 // clear |default_wallpaper_image_|. |
| 495 void SetDefaultWallpaperPathsFromCommandLine(base::CommandLine* command_line); | 571 void SetDefaultWallpaperPathsFromCommandLine(base::CommandLine* command_line); |
| 496 | 572 |
| 497 // Sets wallpaper to decoded default. | 573 // Sets wallpaper to decoded default. |
| 498 void OnDefaultWallpaperDecoded(const base::FilePath& path, | 574 void OnDefaultWallpaperDecoded(const base::FilePath& path, |
| 499 const ash::WallpaperLayout layout, | 575 const ash::WallpaperLayout layout, |
| 500 scoped_ptr<UserImage>* result, | 576 scoped_ptr<UserImage>* result, |
| 501 MovableOnDestroyCallbackHolder on_finish, | 577 MovableOnDestroyCallbackHolder on_finish, |
| 502 const UserImage& wallpaper); | 578 const UserImage& wallpaper); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 | 650 |
| 575 // Current decoded default image is stored in cache. | 651 // Current decoded default image is stored in cache. |
| 576 scoped_ptr<UserImage> default_wallpaper_image_; | 652 scoped_ptr<UserImage> default_wallpaper_image_; |
| 577 | 653 |
| 578 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); | 654 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); |
| 579 }; | 655 }; |
| 580 | 656 |
| 581 } // namespace chromeos | 657 } // namespace chromeos |
| 582 | 658 |
| 583 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ | 659 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ |
| OLD | NEW |