OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "ash/desktop_background/desktop_background_controller.h" | 12 #include "ash/desktop_background/desktop_background_controller.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
18 #include "base/threading/sequenced_worker_pool.h" | 18 #include "base/threading/sequenced_worker_pool.h" |
19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
20 #include "chrome/browser/chromeos/login/users/avatar/user_image.h" | |
21 #include "chrome/browser/chromeos/login/users/avatar/user_image_loader.h" | 20 #include "chrome/browser/chromeos/login/users/avatar/user_image_loader.h" |
22 #include "chrome/browser/chromeos/login/users/user.h" | 21 #include "chrome/browser/chromeos/login/users/user.h" |
23 #include "chrome/browser/chromeos/settings/cros_settings.h" | 22 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 23 #include "components/user_manager/user_image/user_image.h" |
24 #include "content/public/browser/notification_observer.h" | 24 #include "content/public/browser/notification_observer.h" |
25 #include "content/public/browser/notification_registrar.h" | 25 #include "content/public/browser/notification_registrar.h" |
26 #include "third_party/icu/source/i18n/unicode/timezone.h" | 26 #include "third_party/icu/source/i18n/unicode/timezone.h" |
27 #include "ui/gfx/image/image_skia.h" | 27 #include "ui/gfx/image/image_skia.h" |
28 | 28 |
29 class PrefRegistrySimple; | 29 class PrefRegistrySimple; |
30 | 30 |
31 namespace base { | 31 namespace base { |
32 class CommandLine; | 32 class CommandLine; |
33 class SequencedTaskRunner; | 33 class SequencedTaskRunner; |
34 } | 34 } |
35 | 35 |
| 36 namespace user_manager { |
| 37 class UserImage; |
| 38 } |
| 39 |
36 namespace chromeos { | 40 namespace chromeos { |
37 | 41 |
38 struct WallpaperInfo { | 42 struct WallpaperInfo { |
39 // Online wallpaper URL or file name of migrated wallpaper. | 43 // Online wallpaper URL or file name of migrated wallpaper. |
40 std::string file; | 44 std::string file; |
41 ash::WallpaperLayout layout; | 45 ash::WallpaperLayout layout; |
42 User::WallpaperType type; | 46 User::WallpaperType type; |
43 base::Time date; | 47 base::Time date; |
44 bool operator==(const WallpaperInfo& other) { | 48 bool operator==(const WallpaperInfo& other) { |
45 return (file == other.file) && (layout == other.layout) && | 49 return (file == other.file) && (layout == other.layout) && |
46 (type == other.type); | 50 (type == other.type); |
47 } | 51 } |
48 }; | 52 }; |
49 | 53 |
50 class MovableOnDestroyCallback; | 54 class MovableOnDestroyCallback; |
51 typedef scoped_ptr<MovableOnDestroyCallback> MovableOnDestroyCallbackHolder; | 55 typedef scoped_ptr<MovableOnDestroyCallback> MovableOnDestroyCallbackHolder; |
52 | 56 |
53 class WallpaperManagerBrowserTest; | 57 class WallpaperManagerBrowserTest; |
54 class UserImage; | |
55 | 58 |
56 // Name of wallpaper sequence token. | 59 // Name of wallpaper sequence token. |
57 extern const char kWallpaperSequenceTokenName[]; | 60 extern const char kWallpaperSequenceTokenName[]; |
58 | 61 |
59 // File path suffices of resized small or large wallpaper. | 62 // File path suffices of resized small or large wallpaper. |
60 // TODO(bshe): Use the same sub folder system as custom wallpapers use. | 63 // TODO(bshe): Use the same sub folder system as custom wallpapers use. |
61 // crbug.com/174928 | 64 // crbug.com/174928 |
62 extern const char kSmallWallpaperSuffix[]; | 65 extern const char kSmallWallpaperSuffix[]; |
63 extern const char kLargeWallpaperSuffix[]; | 66 extern const char kLargeWallpaperSuffix[]; |
64 | 67 |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 const std::string& user_id, | 378 const std::string& user_id, |
376 const WallpaperInfo& info, | 379 const WallpaperInfo& info, |
377 const base::FilePath& wallpaper_path, | 380 const base::FilePath& wallpaper_path, |
378 bool update_wallpaper, | 381 bool update_wallpaper, |
379 MovableOnDestroyCallbackHolder on_finish, | 382 MovableOnDestroyCallbackHolder on_finish, |
380 base::WeakPtr<WallpaperManager> weak_ptr); | 383 base::WeakPtr<WallpaperManager> weak_ptr); |
381 | 384 |
382 // Resize and save customized default wallpaper. | 385 // Resize and save customized default wallpaper. |
383 static void ResizeCustomizedDefaultWallpaper( | 386 static void ResizeCustomizedDefaultWallpaper( |
384 scoped_ptr<gfx::ImageSkia> image, | 387 scoped_ptr<gfx::ImageSkia> image, |
385 const UserImage::RawImage& raw_image, | 388 const user_manager::UserImage::RawImage& raw_image, |
386 const CustomizedWallpaperRescaledFiles* rescaled_files, | 389 const CustomizedWallpaperRescaledFiles* rescaled_files, |
387 bool* success, | 390 bool* success, |
388 gfx::ImageSkia* small_wallpaper_image, | 391 gfx::ImageSkia* small_wallpaper_image, |
389 gfx::ImageSkia* large_wallpaper_image); | 392 gfx::ImageSkia* large_wallpaper_image); |
390 | 393 |
391 // Initialize wallpaper for the specified user to default and saves this | 394 // Initialize wallpaper for the specified user to default and saves this |
392 // settings in local state. | 395 // settings in local state. |
393 void InitInitialUserWallpaper(const std::string& user_id, bool is_persistent); | 396 void InitInitialUserWallpaper(const std::string& user_id, bool is_persistent); |
394 | 397 |
395 // Set wallpaper to |user_image| controlled by policy. (Takes a UserImage | 398 // Set wallpaper to |user_image| controlled by policy. (Takes a UserImage |
396 // because that's the callback interface provided by UserImageLoader.) | 399 // because that's the callback interface provided by UserImageLoader.) |
397 void SetPolicyControlledWallpaper(const std::string& user_id, | 400 void SetPolicyControlledWallpaper(const std::string& user_id, |
398 const UserImage& user_image); | 401 const user_manager::UserImage& user_image); |
399 | 402 |
400 // Gets encoded wallpaper from cache. Returns true if success. | 403 // Gets encoded wallpaper from cache. Returns true if success. |
401 bool GetWallpaperFromCache(const std::string& user_id, gfx::ImageSkia* image); | 404 bool GetWallpaperFromCache(const std::string& user_id, gfx::ImageSkia* image); |
402 | 405 |
403 // The number of wallpapers have loaded. For test only. | 406 // The number of wallpapers have loaded. For test only. |
404 int loaded_wallpapers() const { return loaded_wallpapers_; } | 407 int loaded_wallpapers() const { return loaded_wallpapers_; } |
405 | 408 |
406 // Cache some (or all) logged in users' wallpapers to memory at login | 409 // Cache some (or all) logged in users' wallpapers to memory at login |
407 // screen. It should not compete with first wallpaper loading when boot | 410 // screen. It should not compete with first wallpaper loading when boot |
408 // up/initialize login WebUI page. | 411 // up/initialize login WebUI page. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 bool GetUserWallpaperInfo(const std::string& user_id, | 462 bool GetUserWallpaperInfo(const std::string& user_id, |
460 WallpaperInfo* info) const; | 463 WallpaperInfo* info) const; |
461 | 464 |
462 // Sets wallpaper to the decoded wallpaper if |update_wallpaper| is true. | 465 // Sets wallpaper to the decoded wallpaper if |update_wallpaper| is true. |
463 // Otherwise, cache wallpaper to memory if not logged in. (Takes a UserImage | 466 // Otherwise, cache wallpaper to memory if not logged in. (Takes a UserImage |
464 // because that's the callback interface provided by UserImageLoader.) | 467 // because that's the callback interface provided by UserImageLoader.) |
465 void OnWallpaperDecoded(const std::string& user_id, | 468 void OnWallpaperDecoded(const std::string& user_id, |
466 ash::WallpaperLayout layout, | 469 ash::WallpaperLayout layout, |
467 bool update_wallpaper, | 470 bool update_wallpaper, |
468 MovableOnDestroyCallbackHolder on_finish, | 471 MovableOnDestroyCallbackHolder on_finish, |
469 const UserImage& user_image); | 472 const user_manager::UserImage& user_image); |
470 | 473 |
471 // Creates new PendingWallpaper request (or updates currently pending). | 474 // Creates new PendingWallpaper request (or updates currently pending). |
472 void ScheduleSetUserWallpaper(const std::string& user_id, bool delayed); | 475 void ScheduleSetUserWallpaper(const std::string& user_id, bool delayed); |
473 | 476 |
474 // Sets wallpaper to default. | 477 // Sets wallpaper to default. |
475 void DoSetDefaultWallpaper( | 478 void DoSetDefaultWallpaper( |
476 const std::string& user_id, | 479 const std::string& user_id, |
477 MovableOnDestroyCallbackHolder on_finish); | 480 MovableOnDestroyCallbackHolder on_finish); |
478 | 481 |
479 // Starts to load wallpaper at |wallpaper_path|. If |wallpaper_path| is the | 482 // Starts to load wallpaper at |wallpaper_path|. If |wallpaper_path| is the |
(...skipping 28 matching lines...) Expand all Loading... |
508 // This is called after we check that supplied default wallpaper files exist. | 511 // This is called after we check that supplied default wallpaper files exist. |
509 void SetCustomizedDefaultWallpaperAfterCheck( | 512 void SetCustomizedDefaultWallpaperAfterCheck( |
510 const GURL& wallpaper_url, | 513 const GURL& wallpaper_url, |
511 const base::FilePath& downloaded_file, | 514 const base::FilePath& downloaded_file, |
512 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files); | 515 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files); |
513 | 516 |
514 // Starts rescaling of customized wallpaper. | 517 // Starts rescaling of customized wallpaper. |
515 void OnCustomizedDefaultWallpaperDecoded( | 518 void OnCustomizedDefaultWallpaperDecoded( |
516 const GURL& wallpaper_url, | 519 const GURL& wallpaper_url, |
517 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | 520 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, |
518 const UserImage& user_image); | 521 const user_manager::UserImage& user_image); |
519 | 522 |
520 // Check the result of ResizeCustomizedDefaultWallpaper and finally | 523 // Check the result of ResizeCustomizedDefaultWallpaper and finally |
521 // apply Customized Default Wallpaper. | 524 // apply Customized Default Wallpaper. |
522 void OnCustomizedDefaultWallpaperResized( | 525 void OnCustomizedDefaultWallpaperResized( |
523 const GURL& wallpaper_url, | 526 const GURL& wallpaper_url, |
524 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | 527 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, |
525 scoped_ptr<bool> success, | 528 scoped_ptr<bool> success, |
526 scoped_ptr<gfx::ImageSkia> small_wallpaper_image, | 529 scoped_ptr<gfx::ImageSkia> small_wallpaper_image, |
527 scoped_ptr<gfx::ImageSkia> large_wallpaper_image); | 530 scoped_ptr<gfx::ImageSkia> large_wallpaper_image); |
528 | 531 |
529 // Init |*default_*_wallpaper_file_| from given command line and | 532 // Init |*default_*_wallpaper_file_| from given command line and |
530 // clear |default_wallpaper_image_|. | 533 // clear |default_wallpaper_image_|. |
531 void SetDefaultWallpaperPathsFromCommandLine(base::CommandLine* command_line); | 534 void SetDefaultWallpaperPathsFromCommandLine(base::CommandLine* command_line); |
532 | 535 |
533 // Sets wallpaper to decoded default. | 536 // Sets wallpaper to decoded default. |
534 void OnDefaultWallpaperDecoded(const base::FilePath& path, | 537 void OnDefaultWallpaperDecoded(const base::FilePath& path, |
535 const ash::WallpaperLayout layout, | 538 const ash::WallpaperLayout layout, |
536 scoped_ptr<UserImage>* result, | 539 scoped_ptr<user_manager::UserImage>* result, |
537 MovableOnDestroyCallbackHolder on_finish, | 540 MovableOnDestroyCallbackHolder on_finish, |
538 const UserImage& user_image); | 541 const user_manager::UserImage& user_image); |
539 | 542 |
540 // Start decoding given default wallpaper. | 543 // Start decoding given default wallpaper. |
541 void StartLoadAndSetDefaultWallpaper(const base::FilePath& path, | 544 void StartLoadAndSetDefaultWallpaper( |
542 const ash::WallpaperLayout layout, | 545 const base::FilePath& path, |
543 MovableOnDestroyCallbackHolder on_finish, | 546 const ash::WallpaperLayout layout, |
544 scoped_ptr<UserImage>* result_out); | 547 MovableOnDestroyCallbackHolder on_finish, |
| 548 scoped_ptr<user_manager::UserImage>* result_out); |
545 | 549 |
546 // Returns wallpaper subdirectory name for current resolution. | 550 // Returns wallpaper subdirectory name for current resolution. |
547 const char* GetCustomWallpaperSubdirForCurrentResolution(); | 551 const char* GetCustomWallpaperSubdirForCurrentResolution(); |
548 | 552 |
549 // Init default_wallpaper_image_ with 1x1 image of default color. | 553 // Init default_wallpaper_image_ with 1x1 image of default color. |
550 void CreateSolidDefaultWallpaper(); | 554 void CreateSolidDefaultWallpaper(); |
551 | 555 |
552 // The number of loaded wallpapers. | 556 // The number of loaded wallpapers. |
553 int loaded_wallpapers_; | 557 int loaded_wallpapers_; |
554 | 558 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList; | 609 typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList; |
606 PendingList loading_; | 610 PendingList loading_; |
607 | 611 |
608 base::FilePath default_small_wallpaper_file_; | 612 base::FilePath default_small_wallpaper_file_; |
609 base::FilePath default_large_wallpaper_file_; | 613 base::FilePath default_large_wallpaper_file_; |
610 | 614 |
611 base::FilePath guest_small_wallpaper_file_; | 615 base::FilePath guest_small_wallpaper_file_; |
612 base::FilePath guest_large_wallpaper_file_; | 616 base::FilePath guest_large_wallpaper_file_; |
613 | 617 |
614 // Current decoded default image is stored in cache. | 618 // Current decoded default image is stored in cache. |
615 scoped_ptr<UserImage> default_wallpaper_image_; | 619 scoped_ptr<user_manager::UserImage> default_wallpaper_image_; |
616 | 620 |
617 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); | 621 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); |
618 }; | 622 }; |
619 | 623 |
620 } // namespace chromeos | 624 } // namespace chromeos |
621 | 625 |
622 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ | 626 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ |
OLD | NEW |