| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // Directory names of custom wallpapers. | 65 // Directory names of custom wallpapers. |
| 66 extern const char kSmallWallpaperSubDir[]; | 66 extern const char kSmallWallpaperSubDir[]; |
| 67 extern const char kLargeWallpaperSubDir[]; | 67 extern const char kLargeWallpaperSubDir[]; |
| 68 extern const char kOriginalWallpaperSubDir[]; | 68 extern const char kOriginalWallpaperSubDir[]; |
| 69 extern const char kThumbnailWallpaperSubDir[]; | 69 extern const char kThumbnailWallpaperSubDir[]; |
| 70 | 70 |
| 71 // This class maintains wallpapers for users who have logged into this Chrome | 71 // This class maintains wallpapers for users who have logged into this Chrome |
| 72 // OS device. | 72 // OS device. |
| 73 class WallpaperManager: public content::NotificationObserver { | 73 class WallpaperManager: public content::NotificationObserver { |
| 74 public: | 74 public: |
| 75 class CustomizedWallpaperRescaledFiles; |
| 76 class CustomizedWallpaperFilesExist; |
| 77 |
| 75 // For testing. | 78 // For testing. |
| 76 class TestApi { | 79 class TestApi { |
| 77 public: | 80 public: |
| 78 explicit TestApi(WallpaperManager* wallpaper_manager); | 81 explicit TestApi(WallpaperManager* wallpaper_manager); |
| 79 virtual ~TestApi(); | 82 virtual ~TestApi(); |
| 80 | 83 |
| 81 base::FilePath current_wallpaper_path(); | 84 base::FilePath current_wallpaper_path(); |
| 82 | 85 |
| 83 bool GetWallpaperFromCache(const std::string& user_id, | 86 bool GetWallpaperFromCache(const std::string& user_id, |
| 84 gfx::ImageSkia* image); | 87 gfx::ImageSkia* image); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 // and |preferred_height| while maintaining aspect ratio. | 225 // and |preferred_height| while maintaining aspect ratio. |
| 223 bool ResizeWallpaper(const UserImage& wallpaper, | 226 bool ResizeWallpaper(const UserImage& wallpaper, |
| 224 ash::WallpaperLayout layout, | 227 ash::WallpaperLayout layout, |
| 225 int preferred_width, | 228 int preferred_width, |
| 226 int preferred_height, | 229 int preferred_height, |
| 227 scoped_refptr<base::RefCountedBytes>* output) const; | 230 scoped_refptr<base::RefCountedBytes>* output) const; |
| 228 | 231 |
| 229 // Resizes |wallpaper| to a resolution which is nearest to |preferred_width| | 232 // Resizes |wallpaper| to a resolution which is nearest to |preferred_width| |
| 230 // and |preferred_height| while maintaining aspect ratio. And saves the | 233 // and |preferred_height| while maintaining aspect ratio. And saves the |
| 231 // resized wallpaper to |path|. | 234 // resized wallpaper to |path|. |
| 232 void ResizeAndSaveWallpaper(const UserImage& wallpaper, | 235 // Result is true on success. |
| 236 bool ResizeAndSaveWallpaper(const UserImage& wallpaper, |
| 233 const base::FilePath& path, | 237 const base::FilePath& path, |
| 234 ash::WallpaperLayout layout, | 238 ash::WallpaperLayout layout, |
| 235 int preferred_width, | 239 int preferred_width, |
| 236 int preferred_height) const; | 240 int preferred_height) const; |
| 237 | 241 |
| 238 // Saves custom wallpaper to file, post task to generate thumbnail and updates | 242 // Saves custom wallpaper to file, post task to generate thumbnail and updates |
| 239 // local state preferences. If |update_wallpaper| is false, don't change | 243 // local state preferences. If |update_wallpaper| is false, don't change |
| 240 // wallpaper but only update cache. | 244 // wallpaper but only update cache. |
| 241 void SetCustomWallpaper(const std::string& user_id, | 245 void SetCustomWallpaper(const std::string& user_id, |
| 242 const std::string& user_id_hash, | 246 const std::string& user_id_hash, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 302 |
| 299 // Called when the wallpaper policy has been cleared for |user_id|. | 303 // Called when the wallpaper policy has been cleared for |user_id|. |
| 300 void OnPolicyCleared(const std::string& policy, const std::string& user_id); | 304 void OnPolicyCleared(const std::string& policy, const std::string& user_id); |
| 301 | 305 |
| 302 // Called when the policy-set wallpaper has been fetched. Initiates decoding | 306 // Called when the policy-set wallpaper has been fetched. Initiates decoding |
| 303 // of the JPEG |data| with a callback to SetPolicyControlledWallpaper(). | 307 // of the JPEG |data| with a callback to SetPolicyControlledWallpaper(). |
| 304 void OnPolicyFetched(const std::string& policy, | 308 void OnPolicyFetched(const std::string& policy, |
| 305 const std::string& user_id, | 309 const std::string& user_id, |
| 306 scoped_ptr<std::string> data); | 310 scoped_ptr<std::string> data); |
| 307 | 311 |
| 312 // This is called from CustomizationDocument. |
| 313 // scaled_directory - directory where resized versions are stored |
| 314 // (must be writable) |
| 315 void SetCustomizedDefaultWallpaper(const GURL& wallpaper_url, |
| 316 const base::FilePath& downloaded_file, |
| 317 const base::FilePath& resized_directory); |
| 318 |
| 319 // These global default values are used to init customized default |
| 320 // wallpaper in Desktop Background Controller before first wallpaper was |
| 321 // shown. |
| 322 static base::FilePath GetCustomizedWallpaperDefaultRescaledSmallFileName(); |
| 323 static base::FilePath GetCustomizedWallpaperDefaultRescaledLargeFileName(); |
| 324 |
| 325 // If DesktopBackgroundController should start with customized default |
| 326 // wallpaper. |
| 327 static bool ShouldUseCustomizedDefaultWallpaper(); |
| 328 |
| 308 private: | 329 private: |
| 309 friend class TestApi; | 330 friend class TestApi; |
| 310 friend class WallpaperManagerBrowserTest; | 331 friend class WallpaperManagerBrowserTest; |
| 311 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap; | 332 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap; |
| 312 | 333 |
| 313 // Set |wallpaper| controlled by policy. | 334 // Set |wallpaper| controlled by policy. |
| 314 void SetPolicyControlledWallpaper(const std::string& user_id, | 335 void SetPolicyControlledWallpaper(const std::string& user_id, |
| 315 const UserImage& wallpaper); | 336 const UserImage& wallpaper); |
| 316 | 337 |
| 317 // Gets encoded wallpaper from cache. Returns true if success. | 338 // Gets encoded wallpaper from cache. Returns true if success. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 void RecordUma(User::WallpaperType type, int index) const; | 439 void RecordUma(User::WallpaperType type, int index) const; |
| 419 | 440 |
| 420 // Saves original custom wallpaper to |path| (absolute path) on filesystem | 441 // Saves original custom wallpaper to |path| (absolute path) on filesystem |
| 421 // and starts resizing operation of the custom wallpaper if necessary. | 442 // and starts resizing operation of the custom wallpaper if necessary. |
| 422 void SaveCustomWallpaper(const std::string& user_id_hash, | 443 void SaveCustomWallpaper(const std::string& user_id_hash, |
| 423 const base::FilePath& path, | 444 const base::FilePath& path, |
| 424 ash::WallpaperLayout layout, | 445 ash::WallpaperLayout layout, |
| 425 const UserImage& wallpaper); | 446 const UserImage& wallpaper); |
| 426 | 447 |
| 427 // Saves wallpaper image raw |data| to |path| (absolute path) in file system. | 448 // Saves wallpaper image raw |data| to |path| (absolute path) in file system. |
| 428 void SaveWallpaperInternal(const base::FilePath& path, const char* data, | 449 // True on success. |
| 450 bool SaveWallpaperInternal(const base::FilePath& path, |
| 451 const char* data, |
| 429 int size) const; | 452 int size) const; |
| 430 | 453 |
| 431 // Creates new PendingWallpaper request (or updates currently pending). | 454 // Creates new PendingWallpaper request (or updates currently pending). |
| 432 void ScheduleSetUserWallpaper(const std::string& user_id, bool delayed); | 455 void ScheduleSetUserWallpaper(const std::string& user_id, bool delayed); |
| 433 | 456 |
| 434 // Sets wallpaper to default. | 457 // Sets wallpaper to default. |
| 435 void DoSetDefaultWallpaper( | 458 void DoSetDefaultWallpaper( |
| 436 const std::string& user_id, | 459 const std::string& user_id, |
| 437 MovableOnDestroyCallbackHolder on_finish); | 460 MovableOnDestroyCallbackHolder on_finish); |
| 438 | 461 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 455 PendingWallpaper* GetPendingWallpaper(const std::string& user_id, | 478 PendingWallpaper* GetPendingWallpaper(const std::string& user_id, |
| 456 bool delayed); | 479 bool delayed); |
| 457 | 480 |
| 458 // Calculate delay for next wallpaper load. | 481 // Calculate delay for next wallpaper load. |
| 459 // It is usually average wallpaper load time. | 482 // It is usually average wallpaper load time. |
| 460 // If last wallpaper load happened long ago, timeout should be reduced by | 483 // If last wallpaper load happened long ago, timeout should be reduced by |
| 461 // the time passed after last wallpaper load. So usual user experience results | 484 // the time passed after last wallpaper load. So usual user experience results |
| 462 // in zero delay. | 485 // in zero delay. |
| 463 base::TimeDelta GetWallpaperLoadDelay() const; | 486 base::TimeDelta GetWallpaperLoadDelay() const; |
| 464 | 487 |
| 488 // This is called after we check that supplied default wallpaper files exist. |
| 489 void SetCustomizedDefaultWallpaperAfterCheck( |
| 490 const GURL& wallpaper_url, |
| 491 const base::FilePath& downloaded_file, |
| 492 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, |
| 493 scoped_ptr<CustomizedWallpaperFilesExist> exist); |
| 494 |
| 495 // Starts rescaling of customized wallpaper. |
| 496 void OnCustomizedDefaultWallpaperDecoded( |
| 497 const GURL& wallpaper_url, |
| 498 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, |
| 499 const UserImage& user_image); |
| 500 |
| 501 // Resize and save customized default wallpaper. |
| 502 void ResizeCustomizedDefaultWallpaper( |
| 503 scoped_ptr<gfx::ImageSkia> image, |
| 504 const UserImage::RawImage& raw_image, |
| 505 const CustomizedWallpaperRescaledFiles* rescaled_files, |
| 506 bool* success); |
| 507 |
| 508 // Check the result of ResizeCustomizedDefaultWallpaper and finally |
| 509 // apply Customized Default Wallpaper. |
| 510 void OnCustomizedDefaultWallpaperResized( |
| 511 const GURL& wallpaper_url, |
| 512 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, |
| 513 scoped_ptr<bool> success); |
| 514 |
| 465 // The number of loaded wallpapers. | 515 // The number of loaded wallpapers. |
| 466 int loaded_wallpapers_; | 516 int loaded_wallpapers_; |
| 467 | 517 |
| 468 // Sequence token associated with wallpaper operations. | 518 // Sequence token associated with wallpaper operations. |
| 469 base::SequencedWorkerPool::SequenceToken sequence_token_; | 519 base::SequencedWorkerPool::SequenceToken sequence_token_; |
| 470 | 520 |
| 471 // Wallpaper sequenced task runner. | 521 // Wallpaper sequenced task runner. |
| 472 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 522 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 473 | 523 |
| 474 // The file path of current loaded/loading custom/online wallpaper. | 524 // The file path of current loaded/loading custom/online wallpaper. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 // All pending will be finally deleted on destroy. | 567 // All pending will be finally deleted on destroy. |
| 518 typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList; | 568 typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList; |
| 519 PendingList loading_; | 569 PendingList loading_; |
| 520 | 570 |
| 521 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); | 571 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); |
| 522 }; | 572 }; |
| 523 | 573 |
| 524 } // namespace chromeos | 574 } // namespace chromeos |
| 525 | 575 |
| 526 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ | 576 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ |
| OLD | NEW |