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 #include "chrome/browser/chromeos/login/wallpaper_manager.h" | 5 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
6 | 6 |
7 #include <numeric> | 7 #include <numeric> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
25 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
26 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
27 #include "base/threading/worker_pool.h" | 27 #include "base/threading/worker_pool.h" |
28 #include "base/time/time.h" | 28 #include "base/time/time.h" |
29 #include "base/values.h" | 29 #include "base/values.h" |
30 #include "chrome/browser/browser_process.h" | 30 #include "chrome/browser/browser_process.h" |
31 #include "chrome/browser/chrome_notification_types.h" | 31 #include "chrome/browser/chrome_notification_types.h" |
32 #include "chrome/browser/chromeos/login/startup_utils.h" | 32 #include "chrome/browser/chromeos/login/startup_utils.h" |
33 #include "chrome/browser/chromeos/login/user.h" | 33 #include "chrome/browser/chromeos/login/user.h" |
34 #include "chrome/browser/chromeos/login/user_image.h" | |
34 #include "chrome/browser/chromeos/login/user_manager.h" | 35 #include "chrome/browser/chromeos/login/user_manager.h" |
35 #include "chrome/browser/chromeos/login/wizard_controller.h" | 36 #include "chrome/browser/chromeos/login/wizard_controller.h" |
36 #include "chrome/browser/chromeos/settings/cros_settings.h" | 37 #include "chrome/browser/chromeos/settings/cros_settings.h" |
37 #include "chrome/common/chrome_paths.h" | 38 #include "chrome/common/chrome_paths.h" |
38 #include "chrome/common/chrome_switches.h" | 39 #include "chrome/common/chrome_switches.h" |
39 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
40 #include "chromeos/chromeos_switches.h" | 41 #include "chromeos/chromeos_switches.h" |
41 #include "chromeos/dbus/dbus_thread_manager.h" | 42 #include "chromeos/dbus/dbus_thread_manager.h" |
42 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
43 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
68 // A dictionary pref that maps usernames to wallpaper properties. | 69 // A dictionary pref that maps usernames to wallpaper properties. |
69 const char kUserWallpapersProperties[] = "UserWallpapersProperties"; | 70 const char kUserWallpapersProperties[] = "UserWallpapersProperties"; |
70 | 71 |
71 // Names of nodes with info about wallpaper in |kUserWallpapersProperties| | 72 // Names of nodes with info about wallpaper in |kUserWallpapersProperties| |
72 // dictionary. | 73 // dictionary. |
73 const char kNewWallpaperDateNodeName[] = "date"; | 74 const char kNewWallpaperDateNodeName[] = "date"; |
74 const char kNewWallpaperLayoutNodeName[] = "layout"; | 75 const char kNewWallpaperLayoutNodeName[] = "layout"; |
75 const char kNewWallpaperFileNodeName[] = "file"; | 76 const char kNewWallpaperFileNodeName[] = "file"; |
76 const char kNewWallpaperTypeNodeName[] = "type"; | 77 const char kNewWallpaperTypeNodeName[] = "type"; |
77 | 78 |
78 // File path suffix of the original custom wallpaper. | |
79 const char kOriginalCustomWallpaperSuffix[] = "_wallpaper"; | |
80 | |
81 // Maximum number of wallpapers cached by CacheUsersWallpapers(). | 79 // Maximum number of wallpapers cached by CacheUsersWallpapers(). |
82 const int kMaxWallpapersToCache = 3; | 80 const int kMaxWallpapersToCache = 3; |
83 | 81 |
84 // Maximum number of entries in WallpaperManager::last_load_times_ . | 82 // Maximum number of entries in WallpaperManager::last_load_times_ . |
85 const size_t kLastLoadsStatsMsMaxSize = 4; | 83 const size_t kLastLoadsStatsMsMaxSize = 4; |
86 | 84 |
87 // Minimum delay between wallpaper loads, milliseconds. | 85 // Minimum delay between wallpaper loads, milliseconds. |
88 const unsigned kLoadMinDelayMs = 50; | 86 const unsigned kLoadMinDelayMs = 50; |
89 | 87 |
90 // Default wallpaper load delay, milliseconds. | 88 // Default wallpaper load delay, milliseconds. |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 } | 408 } |
411 | 409 |
412 base::FilePath WallpaperManager::GetCustomWallpaperPath( | 410 base::FilePath WallpaperManager::GetCustomWallpaperPath( |
413 const char* sub_dir, | 411 const char* sub_dir, |
414 const std::string& user_id_hash, | 412 const std::string& user_id_hash, |
415 const std::string& file) const { | 413 const std::string& file) const { |
416 base::FilePath custom_wallpaper_path = GetCustomWallpaperDir(sub_dir); | 414 base::FilePath custom_wallpaper_path = GetCustomWallpaperDir(sub_dir); |
417 return custom_wallpaper_path.Append(user_id_hash).Append(file); | 415 return custom_wallpaper_path.Append(user_id_hash).Append(file); |
418 } | 416 } |
419 | 417 |
420 base::FilePath WallpaperManager::GetOriginalWallpaperPathForUser( | |
421 const std::string& user_id) { | |
422 std::string filename = user_id + kOriginalCustomWallpaperSuffix; | |
423 base::FilePath user_data_dir; | |
424 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | |
425 return user_data_dir.AppendASCII(filename); | |
426 } | |
427 | |
428 bool WallpaperManager::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) { | 418 bool WallpaperManager::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) { |
429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
430 | 420 |
431 if (UserManager::Get()->IsLoggedInAsStub()) { | 421 if (UserManager::Get()->IsLoggedInAsStub()) { |
432 info->file = current_user_wallpaper_info_.file = ""; | 422 info->file = current_user_wallpaper_info_.file = ""; |
433 info->layout = current_user_wallpaper_info_.layout = | 423 info->layout = current_user_wallpaper_info_.layout = |
434 ash::WALLPAPER_LAYOUT_CENTER_CROPPED; | 424 ash::WALLPAPER_LAYOUT_CENTER_CROPPED; |
435 info->type = current_user_wallpaper_info_.type = User::DEFAULT; | 425 info->type = current_user_wallpaper_info_.type = User::DEFAULT; |
426 info->date = current_user_wallpaper_info_.date = | |
427 base::Time::Now().LocalMidnight(); | |
436 return true; | 428 return true; |
437 } | 429 } |
438 | 430 |
439 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(), | 431 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(), |
440 info); | 432 info); |
441 } | 433 } |
442 | 434 |
443 void WallpaperManager::InitializeWallpaper() { | 435 void WallpaperManager::InitializeWallpaper() { |
444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
445 UserManager* user_manager = UserManager::Get(); | 437 UserManager* user_manager = UserManager::Get(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
521 WallpaperInfo info; | 513 WallpaperInfo info; |
522 GetUserWallpaperInfo(user_id, &info); | 514 GetUserWallpaperInfo(user_id, &info); |
523 PrefService* prefs = g_browser_process->local_state(); | 515 PrefService* prefs = g_browser_process->local_state(); |
524 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs, | 516 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs, |
525 prefs::kUsersWallpaperInfo); | 517 prefs::kUsersWallpaperInfo); |
526 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(user_id, NULL); | 518 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(user_id, NULL); |
527 DeleteUserWallpapers(user_id, info.file); | 519 DeleteUserWallpapers(user_id, info.file); |
528 } | 520 } |
529 | 521 |
530 bool WallpaperManager::ResizeWallpaper( | 522 bool WallpaperManager::ResizeWallpaper( |
531 const UserImage& wallpaper, | 523 const gfx::ImageSkia& wallpaper, |
532 ash::WallpaperLayout layout, | 524 ash::WallpaperLayout layout, |
533 int preferred_width, | 525 int preferred_width, |
534 int preferred_height, | 526 int preferred_height, |
535 scoped_refptr<base::RefCountedBytes>* output, | 527 scoped_refptr<base::RefCountedBytes>* output, |
536 gfx::ImageSkia* output_skia) const { | 528 gfx::ImageSkia* output_skia) const { |
537 DCHECK(BrowserThread::GetBlockingPool()-> | 529 DCHECK(BrowserThread::GetBlockingPool()-> |
538 IsRunningSequenceOnCurrentThread(sequence_token_)); | 530 IsRunningSequenceOnCurrentThread(sequence_token_)); |
539 int width = wallpaper.image().width(); | 531 int width = wallpaper.width(); |
540 int height = wallpaper.image().height(); | 532 int height = wallpaper.height(); |
541 int resized_width; | 533 int resized_width; |
542 int resized_height; | 534 int resized_height; |
543 *output = new base::RefCountedBytes(); | 535 *output = new base::RefCountedBytes(); |
544 | 536 |
545 if (layout == ash::WALLPAPER_LAYOUT_CENTER_CROPPED) { | 537 if (layout == ash::WALLPAPER_LAYOUT_CENTER_CROPPED) { |
546 // Do not resize custom wallpaper if it is smaller than preferred size. | 538 // Do not resize custom wallpaper if it is smaller than preferred size. |
547 if (!(width > preferred_width && height > preferred_height)) | 539 if (!(width > preferred_width && height > preferred_height)) |
548 return false; | 540 return false; |
549 | 541 |
550 double horizontal_ratio = static_cast<double>(preferred_width) / width; | 542 double horizontal_ratio = static_cast<double>(preferred_width) / width; |
551 double vertical_ratio = static_cast<double>(preferred_height) / height; | 543 double vertical_ratio = static_cast<double>(preferred_height) / height; |
552 if (vertical_ratio > horizontal_ratio) { | 544 if (vertical_ratio > horizontal_ratio) { |
553 resized_width = | 545 resized_width = |
554 RoundPositive(static_cast<double>(width) * vertical_ratio); | 546 RoundPositive(static_cast<double>(width) * vertical_ratio); |
555 resized_height = preferred_height; | 547 resized_height = preferred_height; |
556 } else { | 548 } else { |
557 resized_width = preferred_width; | 549 resized_width = preferred_width; |
558 resized_height = | 550 resized_height = |
559 RoundPositive(static_cast<double>(height) * horizontal_ratio); | 551 RoundPositive(static_cast<double>(height) * horizontal_ratio); |
560 } | 552 } |
561 } else if (layout == ash::WALLPAPER_LAYOUT_STRETCH) { | 553 } else if (layout == ash::WALLPAPER_LAYOUT_STRETCH) { |
562 resized_width = preferred_width; | 554 resized_width = preferred_width; |
563 resized_height = preferred_height; | 555 resized_height = preferred_height; |
564 } else { | 556 } else { |
565 resized_width = width; | 557 resized_width = width; |
566 resized_height = height; | 558 resized_height = height; |
567 } | 559 } |
568 | 560 |
569 gfx::ImageSkia resized_image = gfx::ImageSkiaOperations::CreateResizedImage( | 561 gfx::ImageSkia resized_image = gfx::ImageSkiaOperations::CreateResizedImage( |
570 wallpaper.image(), | 562 wallpaper, |
571 skia::ImageOperations::RESIZE_LANCZOS3, | 563 skia::ImageOperations::RESIZE_LANCZOS3, |
572 gfx::Size(resized_width, resized_height)); | 564 gfx::Size(resized_width, resized_height)); |
573 | 565 |
574 SkBitmap image = *(resized_image.bitmap()); | 566 SkBitmap image = *(resized_image.bitmap()); |
575 SkAutoLockPixels lock_input(image); | 567 SkAutoLockPixels lock_input(image); |
576 gfx::JPEGCodec::Encode( | 568 gfx::JPEGCodec::Encode( |
577 reinterpret_cast<unsigned char*>(image.getAddr32(0, 0)), | 569 reinterpret_cast<unsigned char*>(image.getAddr32(0, 0)), |
578 gfx::JPEGCodec::FORMAT_SkBitmap, | 570 gfx::JPEGCodec::FORMAT_SkBitmap, |
579 image.width(), | 571 image.width(), |
580 image.height(), | 572 image.height(), |
581 image.width() * image.bytesPerPixel(), | 573 image.width() * image.bytesPerPixel(), |
582 kDefaultEncodingQuality, &(*output)->data()); | 574 kDefaultEncodingQuality, &(*output)->data()); |
583 | 575 |
584 if (output_skia) { | 576 if (output_skia) { |
585 resized_image.MakeThreadSafe(); | 577 resized_image.MakeThreadSafe(); |
586 *output_skia = resized_image; | 578 *output_skia = resized_image; |
587 } | 579 } |
588 | 580 |
589 return true; | 581 return true; |
590 } | 582 } |
591 | 583 |
592 bool WallpaperManager::ResizeAndSaveWallpaper( | 584 bool WallpaperManager::ResizeAndSaveWallpaper( |
593 const UserImage& wallpaper, | 585 const gfx::ImageSkia& wallpaper, |
594 const base::FilePath& path, | 586 const base::FilePath& path, |
595 ash::WallpaperLayout layout, | 587 ash::WallpaperLayout layout, |
596 int preferred_width, | 588 int preferred_width, |
597 int preferred_height, | 589 int preferred_height, |
598 gfx::ImageSkia* result_out) const { | 590 gfx::ImageSkia* result_out) const { |
599 if (layout == ash::WALLPAPER_LAYOUT_CENTER) { | 591 if (layout == ash::WALLPAPER_LAYOUT_CENTER) { |
600 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. | 592 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. |
601 if (base::PathExists(path)) | 593 if (base::PathExists(path)) |
602 base::DeleteFile(path, false); | 594 base::DeleteFile(path, false); |
603 return false; | 595 return false; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
671 const User *user = chromeos::UserManager::Get()->FindUser(user_id); | 663 const User *user = chromeos::UserManager::Get()->FindUser(user_id); |
672 if (!user) { | 664 if (!user) { |
673 NOTREACHED() << "Unknown user."; | 665 NOTREACHED() << "Unknown user."; |
674 return; | 666 return; |
675 } | 667 } |
676 SetCustomWallpaper(user_id, | 668 SetCustomWallpaper(user_id, |
677 user->username_hash(), | 669 user->username_hash(), |
678 "policy-controlled.jpeg", | 670 "policy-controlled.jpeg", |
679 ash::WALLPAPER_LAYOUT_CENTER_CROPPED, | 671 ash::WALLPAPER_LAYOUT_CENTER_CROPPED, |
680 User::POLICY, | 672 User::POLICY, |
681 wallpaper, | 673 wallpaper.image(), |
682 true /* update wallpaper */); | 674 true /* update wallpaper */); |
683 } | 675 } |
684 | 676 |
685 void WallpaperManager::SetCustomWallpaper(const std::string& user_id, | 677 void WallpaperManager::SetCustomWallpaper(const std::string& user_id, |
686 const std::string& user_id_hash, | 678 const std::string& user_id_hash, |
687 const std::string& file, | 679 const std::string& file, |
688 ash::WallpaperLayout layout, | 680 ash::WallpaperLayout layout, |
689 User::WallpaperType type, | 681 User::WallpaperType type, |
690 const UserImage& wallpaper, | 682 const gfx::ImageSkia& wallpaper, |
691 bool update_wallpaper) { | 683 bool update_wallpaper) { |
692 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 684 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
693 DCHECK(UserManager::Get()->IsUserLoggedIn()); | 685 DCHECK(UserManager::Get()->IsUserLoggedIn()); |
694 | 686 |
695 // There is no visible background in kiosk mode. | 687 // There is no visible background in kiosk mode. |
696 if (UserManager::Get()->IsLoggedInAsKioskApp()) | 688 if (UserManager::Get()->IsLoggedInAsKioskApp()) |
697 return; | 689 return; |
698 | 690 |
699 // Don't allow custom wallpapers while policy is in effect. | 691 // Don't allow custom wallpapers while policy is in effect. |
700 if (type != User::POLICY && IsPolicyControlled(user_id)) | 692 if (type != User::POLICY && IsPolicyControlled(user_id)) |
701 return; | 693 return; |
702 | 694 |
703 base::FilePath wallpaper_path = | 695 base::FilePath wallpaper_path = |
704 GetCustomWallpaperPath(kOriginalWallpaperSubDir, user_id_hash, file); | 696 GetCustomWallpaperPath(kOriginalWallpaperSubDir, user_id_hash, file); |
705 | 697 |
706 // If decoded wallpaper is empty, we have probably failed to decode the file. | 698 // If decoded wallpaper is empty, we have probably failed to decode the file. |
707 // Use default wallpaper in this case. | 699 // Use default wallpaper in this case. |
708 if (wallpaper.image().isNull()) { | 700 if (wallpaper.isNull()) { |
709 SetDefaultWallpaperDelayed(user_id); | 701 SetDefaultWallpaperDelayed(user_id); |
710 return; | 702 return; |
711 } | 703 } |
712 | 704 |
713 bool is_persistent = | 705 bool is_persistent = |
714 !UserManager::Get()->IsUserNonCryptohomeDataEphemeral(user_id); | 706 !UserManager::Get()->IsUserNonCryptohomeDataEphemeral(user_id); |
715 | 707 |
716 wallpaper.image().EnsureRepsForSupportedScales(); | |
717 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy()); | |
718 | |
719 WallpaperInfo wallpaper_info = { | 708 WallpaperInfo wallpaper_info = { |
720 wallpaper_path.value(), | 709 wallpaper_path.value(), |
721 layout, | 710 layout, |
722 type, | 711 type, |
723 // Date field is not used. | 712 // Date field is not used. |
724 base::Time::Now().LocalMidnight() | 713 base::Time::Now().LocalMidnight() |
725 }; | 714 }; |
726 // Block shutdown on this task. Otherwise, we may lose the custom wallpaper | 715 if (is_persistent) { |
727 // that the user selected. | 716 wallpaper.EnsureRepsForSupportedScales(); |
728 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = | 717 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.DeepCopy()); |
729 BrowserThread::GetBlockingPool()-> | 718 // Block shutdown on this task. Otherwise, we may lose the custom wallpaper |
730 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, | 719 // that the user selected. |
731 base::SequencedWorkerPool::BLOCK_SHUTDOWN); | 720 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = |
732 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. | 721 BrowserThread::GetBlockingPool()-> |
733 blocking_task_runner->PostTask(FROM_HERE, | 722 GetSequencedTaskRunnerWithShutdownBehavior( |
734 base::Bind(&WallpaperManager::ProcessCustomWallpaper, | 723 sequence_token_, base::SequencedWorkerPool::BLOCK_SHUTDOWN); |
735 base::Unretained(this), | 724 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. |
736 user_id_hash, | 725 blocking_task_runner->PostTask( |
737 is_persistent, | 726 FROM_HERE, |
738 wallpaper_info, | 727 base::Bind(&WallpaperManager::SaveCustomWallpaper, |
739 base::Passed(&deep_copy), | 728 base::Unretained(this), |
740 wallpaper.raw_image())); | 729 user_id_hash, |
730 base::FilePath(wallpaper_info.file), | |
731 wallpaper_info.layout, | |
732 base::Passed(&deep_copy))); | |
oshima
2014/04/22 00:13:47
I think deep_copy.Pass() is better now.
Thiemo Nagel
2014/04/23 17:14:06
I have tried that before. Using deep_copy.Pass()
oshima
2014/04/23 17:34:23
Didn't you pass &deep_copy.Pass() instead of deep_
Thiemo Nagel
2014/04/23 17:44:38
Neither works. In the case of deep_copy.Pass(), t
| |
733 } | |
741 | 734 |
742 std::string relative_path = base::FilePath(user_id_hash).Append(file).value(); | 735 std::string relative_path = base::FilePath(user_id_hash).Append(file).value(); |
743 // User's custom wallpaper path is determined by relative path and the | 736 // User's custom wallpaper path is determined by relative path and the |
744 // appropriate wallpaper resolution in GetCustomWallpaperInternal. | 737 // appropriate wallpaper resolution in GetCustomWallpaperInternal. |
745 WallpaperInfo info = { | 738 WallpaperInfo info = { |
746 relative_path, | 739 relative_path, |
747 layout, | 740 layout, |
748 type, | 741 type, |
749 base::Time::Now().LocalMidnight() | 742 base::Time::Now().LocalMidnight() |
750 }; | 743 }; |
751 SetUserWallpaperInfo(user_id, info, is_persistent); | 744 SetUserWallpaperInfo(user_id, info, is_persistent); |
752 if (update_wallpaper) { | 745 if (update_wallpaper) { |
753 GetPendingWallpaper(user_id, false) | 746 GetPendingWallpaper(user_id, false) |
754 ->ResetSetWallpaperImage(wallpaper.image(), info); | 747 ->ResetSetWallpaperImage(wallpaper, info); |
755 } | 748 } |
756 | 749 |
757 if (UserManager::IsMultipleProfilesAllowed()) | 750 if (UserManager::IsMultipleProfilesAllowed()) |
758 wallpaper_cache_[user_id] = wallpaper.image(); | 751 wallpaper_cache_[user_id] = wallpaper; |
759 } | 752 } |
760 | 753 |
761 void WallpaperManager::SetDefaultWallpaperNow(const std::string& user_id) { | 754 void WallpaperManager::SetDefaultWallpaperNow(const std::string& user_id) { |
762 GetPendingWallpaper(user_id, false)->ResetSetDefaultWallpaper(); | 755 GetPendingWallpaper(user_id, false)->ResetSetDefaultWallpaper(); |
763 } | 756 } |
764 | 757 |
765 void WallpaperManager::SetDefaultWallpaperDelayed(const std::string& user_id) { | 758 void WallpaperManager::SetDefaultWallpaperDelayed(const std::string& user_id) { |
766 GetPendingWallpaper(user_id, true)->ResetSetDefaultWallpaper(); | 759 GetPendingWallpaper(user_id, true)->ResetSetDefaultWallpaper(); |
767 } | 760 } |
768 | 761 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
843 | 836 |
844 base::DictionaryValue* wallpaper_info_dict = new base::DictionaryValue(); | 837 base::DictionaryValue* wallpaper_info_dict = new base::DictionaryValue(); |
845 wallpaper_info_dict->SetString(kNewWallpaperDateNodeName, | 838 wallpaper_info_dict->SetString(kNewWallpaperDateNodeName, |
846 base::Int64ToString(info.date.ToInternalValue())); | 839 base::Int64ToString(info.date.ToInternalValue())); |
847 wallpaper_info_dict->SetString(kNewWallpaperFileNodeName, info.file); | 840 wallpaper_info_dict->SetString(kNewWallpaperFileNodeName, info.file); |
848 wallpaper_info_dict->SetInteger(kNewWallpaperLayoutNodeName, info.layout); | 841 wallpaper_info_dict->SetInteger(kNewWallpaperLayoutNodeName, info.layout); |
849 wallpaper_info_dict->SetInteger(kNewWallpaperTypeNodeName, info.type); | 842 wallpaper_info_dict->SetInteger(kNewWallpaperTypeNodeName, info.type); |
850 wallpaper_update->SetWithoutPathExpansion(user_id, wallpaper_info_dict); | 843 wallpaper_update->SetWithoutPathExpansion(user_id, wallpaper_info_dict); |
851 } | 844 } |
852 | 845 |
853 void WallpaperManager::SetLastSelectedUser( | |
Nikita (slow)
2014/04/18 09:28:19
I guess this was previously used for tests, maybe
| |
854 const std::string& last_selected_user) { | |
855 last_selected_user_ = last_selected_user; | |
856 } | |
857 | |
858 void WallpaperManager::SetUserWallpaperDelayed(const std::string& user_id) { | 846 void WallpaperManager::SetUserWallpaperDelayed(const std::string& user_id) { |
859 ScheduleSetUserWallpaper(user_id, true); | 847 ScheduleSetUserWallpaper(user_id, true); |
860 } | 848 } |
861 | 849 |
862 void WallpaperManager::SetUserWallpaperNow(const std::string& user_id) { | 850 void WallpaperManager::SetUserWallpaperNow(const std::string& user_id) { |
863 ScheduleSetUserWallpaper(user_id, false); | 851 ScheduleSetUserWallpaper(user_id, false); |
864 } | 852 } |
865 | 853 |
866 void WallpaperManager::ScheduleSetUserWallpaper(const std::string& user_id, | 854 void WallpaperManager::ScheduleSetUserWallpaper(const std::string& user_id, |
867 bool delayed) { | 855 bool delayed) { |
868 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 856 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
869 // Some unit tests come here without a UserManager or without a pref system. | 857 // Some unit tests come here without a UserManager or without a pref system. |
870 if (!UserManager::IsInitialized() || !g_browser_process->local_state()) | 858 if (!UserManager::IsInitialized() || !g_browser_process->local_state()) |
871 return; | 859 return; |
872 // There is no visible background in kiosk mode. | 860 // There is no visible background in kiosk mode. |
873 if (UserManager::Get()->IsLoggedInAsKioskApp()) | 861 if (UserManager::Get()->IsLoggedInAsKioskApp()) |
874 return; | 862 return; |
875 // Guest user, regular user in ephemeral mode, or kiosk app. | 863 // Guest user, regular user in ephemeral mode, or kiosk app. |
876 const User* user = UserManager::Get()->FindUser(user_id); | 864 const User* user = UserManager::Get()->FindUser(user_id); |
877 if (UserManager::Get()->IsUserNonCryptohomeDataEphemeral(user_id) || | 865 if (UserManager::Get()->IsUserNonCryptohomeDataEphemeral(user_id) || |
878 (user != NULL && user->GetType() == User::USER_TYPE_KIOSK_APP)) { | 866 (user != NULL && user->GetType() == User::USER_TYPE_KIOSK_APP)) { |
879 InitInitialUserWallpaper(user_id, false); | 867 InitInitialUserWallpaper(user_id, false); |
880 GetPendingWallpaper(user_id, delayed)->ResetSetDefaultWallpaper(); | 868 GetPendingWallpaper(user_id, delayed)->ResetSetDefaultWallpaper(); |
881 return; | 869 return; |
882 } | 870 } |
883 | 871 |
884 if (!UserManager::Get()->IsKnownUser(user_id)) | 872 if (!UserManager::Get()->IsKnownUser(user_id)) |
885 return; | 873 return; |
886 | 874 |
887 SetLastSelectedUser(user_id); | 875 last_selected_user_ = user_id; |
888 | 876 |
889 WallpaperInfo info; | 877 WallpaperInfo info; |
890 | 878 |
891 if (!GetUserWallpaperInfo(user_id, &info)) { | 879 if (!GetUserWallpaperInfo(user_id, &info)) { |
892 InitInitialUserWallpaper(user_id, true); | 880 InitInitialUserWallpaper(user_id, true); |
893 GetUserWallpaperInfo(user_id, &info); | 881 GetUserWallpaperInfo(user_id, &info); |
894 } | 882 } |
895 | 883 |
896 gfx::ImageSkia user_wallpaper; | 884 gfx::ImageSkia user_wallpaper; |
897 current_user_wallpaper_info_ = info; | 885 current_user_wallpaper_info_ = info; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1041 | 1029 |
1042 void WallpaperManager::ClearObsoleteWallpaperPrefs() { | 1030 void WallpaperManager::ClearObsoleteWallpaperPrefs() { |
1043 PrefService* prefs = g_browser_process->local_state(); | 1031 PrefService* prefs = g_browser_process->local_state(); |
1044 DictionaryPrefUpdate wallpaper_properties_pref(prefs, | 1032 DictionaryPrefUpdate wallpaper_properties_pref(prefs, |
1045 kUserWallpapersProperties); | 1033 kUserWallpapersProperties); |
1046 wallpaper_properties_pref->Clear(); | 1034 wallpaper_properties_pref->Clear(); |
1047 DictionaryPrefUpdate wallpapers_pref(prefs, kUserWallpapers); | 1035 DictionaryPrefUpdate wallpapers_pref(prefs, kUserWallpapers); |
1048 wallpapers_pref->Clear(); | 1036 wallpapers_pref->Clear(); |
1049 } | 1037 } |
1050 | 1038 |
1039 // static | |
1051 void WallpaperManager::DeleteAllExcept(const base::FilePath& path) { | 1040 void WallpaperManager::DeleteAllExcept(const base::FilePath& path) { |
Nikita (slow)
2014/04/18 09:28:19
nit: This function seems to be used only in this f
Thiemo Nagel
2014/04/23 17:14:06
Done.
| |
1052 base::FilePath dir = path.DirName(); | 1041 base::FilePath dir = path.DirName(); |
1053 if (base::DirectoryExists(dir)) { | 1042 if (base::DirectoryExists(dir)) { |
1054 base::FileEnumerator files(dir, false, base::FileEnumerator::FILES); | 1043 base::FileEnumerator files(dir, false, base::FileEnumerator::FILES); |
1055 for (base::FilePath current = files.Next(); !current.empty(); | 1044 for (base::FilePath current = files.Next(); !current.empty(); |
1056 current = files.Next()) { | 1045 current = files.Next()) { |
1057 if (current != path) | 1046 if (current != path) |
1058 base::DeleteFile(current, false); | 1047 base::DeleteFile(current, false); |
1059 } | 1048 } |
1060 } | 1049 } |
1061 } | 1050 } |
1062 | 1051 |
1052 // static | |
1063 void WallpaperManager::DeleteWallpaperInList( | 1053 void WallpaperManager::DeleteWallpaperInList( |
Nikita (slow)
2014/04/18 09:28:19
nit: This function seems to be used only in this f
Thiemo Nagel
2014/04/23 17:14:06
Done.
| |
1064 const std::vector<base::FilePath>& file_list) { | 1054 const std::vector<base::FilePath>& file_list) { |
1065 for (std::vector<base::FilePath>::const_iterator it = file_list.begin(); | 1055 for (std::vector<base::FilePath>::const_iterator it = file_list.begin(); |
1066 it != file_list.end(); ++it) { | 1056 it != file_list.end(); ++it) { |
1067 base::FilePath path = *it; | 1057 base::FilePath path = *it; |
1068 // Some users may still have legacy wallpapers with png extension. We need | 1058 // Some users may still have legacy wallpapers with png extension. We need |
1069 // to delete these wallpapers too. | 1059 // to delete these wallpapers too. |
1070 if (!base::DeleteFile(path, true) && | 1060 if (!base::DeleteFile(path, true) && |
1071 !base::DeleteFile(path.AddExtension(".png"), false)) { | 1061 !base::DeleteFile(path.AddExtension(".png"), false)) { |
1072 LOG(ERROR) << "Failed to remove user wallpaper at " << path.value(); | 1062 LOG(ERROR) << "Failed to remove user wallpaper at " << path.value(); |
1073 } | 1063 } |
(...skipping 25 matching lines...) Expand all Loading... | |
1099 | 1089 |
1100 // Remove original user wallpaper. | 1090 // Remove original user wallpaper. |
1101 wallpaper_path = GetCustomWallpaperDir(kOriginalWallpaperSubDir); | 1091 wallpaper_path = GetCustomWallpaperDir(kOriginalWallpaperSubDir); |
1102 file_to_remove.push_back(wallpaper_path.Append(user_id)); | 1092 file_to_remove.push_back(wallpaper_path.Append(user_id)); |
1103 wallpaper_path = wallpaper_path.Append(path_to_file); | 1093 wallpaper_path = wallpaper_path.Append(path_to_file); |
1104 file_to_remove.push_back(wallpaper_path); | 1094 file_to_remove.push_back(wallpaper_path); |
1105 | 1095 |
1106 base::WorkerPool::PostTask( | 1096 base::WorkerPool::PostTask( |
1107 FROM_HERE, | 1097 FROM_HERE, |
1108 base::Bind(&WallpaperManager::DeleteWallpaperInList, | 1098 base::Bind(&WallpaperManager::DeleteWallpaperInList, |
1109 base::Unretained(this), | |
1110 file_to_remove), | 1099 file_to_remove), |
1111 false); | 1100 false); |
1112 } | 1101 } |
1113 | 1102 |
1103 // static | |
1114 void WallpaperManager::EnsureCustomWallpaperDirectories( | 1104 void WallpaperManager::EnsureCustomWallpaperDirectories( |
Nikita (slow)
2014/04/18 09:28:19
nit: This function seems to be used only in this f
Thiemo Nagel
2014/04/23 17:14:06
Done.
| |
1115 const std::string& user_id_hash) { | 1105 const std::string& user_id_hash) { |
1116 base::FilePath dir; | 1106 base::FilePath dir; |
1117 dir = GetCustomWallpaperDir(kSmallWallpaperSubDir); | 1107 dir = GetCustomWallpaperDir(kSmallWallpaperSubDir); |
1118 dir = dir.Append(user_id_hash); | 1108 dir = dir.Append(user_id_hash); |
1119 if (!base::PathExists(dir)) | 1109 if (!base::PathExists(dir)) |
1120 base::CreateDirectory(dir); | 1110 base::CreateDirectory(dir); |
1121 dir = GetCustomWallpaperDir(kLargeWallpaperSubDir); | 1111 dir = GetCustomWallpaperDir(kLargeWallpaperSubDir); |
1122 dir = dir.Append(user_id_hash); | 1112 dir = dir.Append(user_id_hash); |
1123 if (!base::PathExists(dir)) | 1113 if (!base::PathExists(dir)) |
1124 base::CreateDirectory(dir); | 1114 base::CreateDirectory(dir); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1389 wallpaper_cache_[user_id] = wallpaper.image(); | 1379 wallpaper_cache_[user_id] = wallpaper.image(); |
1390 } | 1380 } |
1391 | 1381 |
1392 if (update_wallpaper) { | 1382 if (update_wallpaper) { |
1393 ash::Shell::GetInstance() | 1383 ash::Shell::GetInstance() |
1394 ->desktop_background_controller() | 1384 ->desktop_background_controller() |
1395 ->SetWallpaperImage(wallpaper.image(), layout); | 1385 ->SetWallpaperImage(wallpaper.image(), layout); |
1396 } | 1386 } |
1397 } | 1387 } |
1398 | 1388 |
1399 void WallpaperManager::ProcessCustomWallpaper( | 1389 void WallpaperManager::SaveCustomWallpaper( |
1400 const std::string& user_id_hash, | 1390 const std::string& user_id_hash, |
1401 bool persistent, | 1391 const base::FilePath& original_path, |
1402 const WallpaperInfo& info, | 1392 ash::WallpaperLayout layout, |
1403 scoped_ptr<gfx::ImageSkia> image, | 1393 scoped_ptr<gfx::ImageSkia> wallpaper) const { |
1404 const UserImage::RawImage& raw_image) { | |
1405 DCHECK(BrowserThread::GetBlockingPool()-> | |
1406 IsRunningSequenceOnCurrentThread(sequence_token_)); | |
1407 UserImage wallpaper(*image.get(), raw_image); | |
1408 if (persistent) { | |
1409 SaveCustomWallpaper(user_id_hash, base::FilePath(info.file), info.layout, | |
1410 wallpaper); | |
1411 } | |
1412 } | |
1413 | |
1414 void WallpaperManager::SaveCustomWallpaper(const std::string& user_id_hash, | |
1415 const base::FilePath& original_path, | |
1416 ash::WallpaperLayout layout, | |
1417 const UserImage& wallpaper) { | |
1418 DCHECK(BrowserThread::GetBlockingPool()-> | 1394 DCHECK(BrowserThread::GetBlockingPool()-> |
1419 IsRunningSequenceOnCurrentThread(sequence_token_)); | 1395 IsRunningSequenceOnCurrentThread(sequence_token_)); |
1420 EnsureCustomWallpaperDirectories(user_id_hash); | 1396 EnsureCustomWallpaperDirectories(user_id_hash); |
1421 std::string file_name = original_path.BaseName().value(); | 1397 std::string file_name = original_path.BaseName().value(); |
1422 base::FilePath small_wallpaper_path = | 1398 base::FilePath small_wallpaper_path = |
1423 GetCustomWallpaperPath(kSmallWallpaperSubDir, user_id_hash, file_name); | 1399 GetCustomWallpaperPath(kSmallWallpaperSubDir, user_id_hash, file_name); |
1424 base::FilePath large_wallpaper_path = | 1400 base::FilePath large_wallpaper_path = |
1425 GetCustomWallpaperPath(kLargeWallpaperSubDir, user_id_hash, file_name); | 1401 GetCustomWallpaperPath(kLargeWallpaperSubDir, user_id_hash, file_name); |
1426 | 1402 |
1427 // Re-encode orginal file to jpeg format and saves the result in case that | 1403 // Re-encode orginal file to jpeg format and saves the result in case that |
1428 // resized wallpaper is not generated (i.e. chrome shutdown before resized | 1404 // resized wallpaper is not generated (i.e. chrome shutdown before resized |
1429 // wallpaper is saved). | 1405 // wallpaper is saved). |
1430 ResizeAndSaveWallpaper(wallpaper, | 1406 ResizeAndSaveWallpaper(*wallpaper, |
1431 original_path, | 1407 original_path, |
1432 ash::WALLPAPER_LAYOUT_STRETCH, | 1408 ash::WALLPAPER_LAYOUT_STRETCH, |
1433 wallpaper.image().width(), | 1409 wallpaper->width(), |
1434 wallpaper.image().height(), | 1410 wallpaper->height(), |
1435 NULL); | 1411 NULL); |
1436 DeleteAllExcept(original_path); | 1412 DeleteAllExcept(original_path); |
1437 | 1413 |
1438 ResizeAndSaveWallpaper(wallpaper, | 1414 ResizeAndSaveWallpaper(*wallpaper, |
1439 small_wallpaper_path, | 1415 small_wallpaper_path, |
1440 layout, | 1416 layout, |
1441 kSmallWallpaperMaxWidth, | 1417 kSmallWallpaperMaxWidth, |
1442 kSmallWallpaperMaxHeight, | 1418 kSmallWallpaperMaxHeight, |
1443 NULL); | 1419 NULL); |
1444 DeleteAllExcept(small_wallpaper_path); | 1420 DeleteAllExcept(small_wallpaper_path); |
1445 ResizeAndSaveWallpaper(wallpaper, | 1421 ResizeAndSaveWallpaper(*wallpaper, |
1446 large_wallpaper_path, | 1422 large_wallpaper_path, |
1447 layout, | 1423 layout, |
1448 kLargeWallpaperMaxWidth, | 1424 kLargeWallpaperMaxWidth, |
1449 kLargeWallpaperMaxHeight, | 1425 kLargeWallpaperMaxHeight, |
1450 NULL); | 1426 NULL); |
1451 DeleteAllExcept(large_wallpaper_path); | 1427 DeleteAllExcept(large_wallpaper_path); |
1452 } | 1428 } |
1453 | 1429 |
1454 void WallpaperManager::RecordUma(User::WallpaperType type, int index) const { | 1430 void WallpaperManager::RecordUma(User::WallpaperType type, int index) const { |
1455 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type, | 1431 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1574 base::Passed(on_finish.Pass()))); | 1550 base::Passed(on_finish.Pass()))); |
1575 } | 1551 } |
1576 | 1552 |
1577 const char* WallpaperManager::GetCustomWallpaperSubdirForCurrentResolution() { | 1553 const char* WallpaperManager::GetCustomWallpaperSubdirForCurrentResolution() { |
1578 WallpaperResolution resolution = GetAppropriateResolution(); | 1554 WallpaperResolution resolution = GetAppropriateResolution(); |
1579 return resolution == WALLPAPER_RESOLUTION_SMALL ? kSmallWallpaperSubDir | 1555 return resolution == WALLPAPER_RESOLUTION_SMALL ? kSmallWallpaperSubDir |
1580 : kLargeWallpaperSubDir; | 1556 : kLargeWallpaperSubDir; |
1581 } | 1557 } |
1582 | 1558 |
1583 } // namespace chromeos | 1559 } // namespace chromeos |
OLD | NEW |