OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 // Names of nodes with info about wallpaper in |kUserWallpapersProperties| | 63 // Names of nodes with info about wallpaper in |kUserWallpapersProperties| |
64 // dictionary. | 64 // dictionary. |
65 const char kNewWallpaperDateNodeName[] = "date"; | 65 const char kNewWallpaperDateNodeName[] = "date"; |
66 const char kNewWallpaperLayoutNodeName[] = "layout"; | 66 const char kNewWallpaperLayoutNodeName[] = "layout"; |
67 const char kNewWallpaperFileNodeName[] = "file"; | 67 const char kNewWallpaperFileNodeName[] = "file"; |
68 const char kNewWallpaperTypeNodeName[] = "type"; | 68 const char kNewWallpaperTypeNodeName[] = "type"; |
69 | 69 |
70 // File path suffix of the original custom wallpaper. | 70 // File path suffix of the original custom wallpaper. |
71 const char kOriginalCustomWallpaperSuffix[] = "_wallpaper"; | 71 const char kOriginalCustomWallpaperSuffix[] = "_wallpaper"; |
72 | 72 |
73 gfx::ImageSkia GetWallpaperThumbnail(const gfx::ImageSkia& wallpaper) { | |
74 gfx::ImageSkia thumbnail = gfx::ImageSkiaOperations::CreateResizedImage( | |
75 wallpaper, | |
76 skia::ImageOperations::RESIZE_LANCZOS3, | |
77 gfx::Size(kThumbnailWidth, kThumbnailHeight)); | |
78 | |
79 thumbnail.MakeThreadSafe(); | |
80 return thumbnail; | |
81 } | |
82 | |
83 // For our scaling ratios we need to round positive numbers. | 73 // For our scaling ratios we need to round positive numbers. |
84 int RoundPositive(double x) { | 74 int RoundPositive(double x) { |
85 return static_cast<int>(floor(x + 0.5)); | 75 return static_cast<int>(floor(x + 0.5)); |
86 } | 76 } |
87 | 77 |
88 } // namespace | 78 } // namespace |
89 | 79 |
90 namespace chromeos { | 80 namespace chromeos { |
91 | 81 |
92 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; | 82 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 kSmallWallpaperSuffix : kLargeWallpaperSuffix; | 177 kSmallWallpaperSuffix : kLargeWallpaperSuffix; |
188 | 178 |
189 std::string filename = base::StringPrintf("%s_wallpaper%s", | 179 std::string filename = base::StringPrintf("%s_wallpaper%s", |
190 username.c_str(), | 180 username.c_str(), |
191 suffix); | 181 suffix); |
192 FilePath user_data_dir; | 182 FilePath user_data_dir; |
193 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 183 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
194 return user_data_dir.AppendASCII(filename); | 184 return user_data_dir.AppendASCII(filename); |
195 } | 185 } |
196 | 186 |
197 gfx::ImageSkia WallpaperManager::GetCustomWallpaperThumbnail( | |
198 const std::string& email) { | |
199 CustomWallpaperMap::const_iterator it = | |
200 custom_wallpaper_thumbnail_cache_.find(email); | |
201 if (it != custom_wallpaper_thumbnail_cache_.end()) | |
202 return (*it).second; | |
203 else | |
204 return gfx::ImageSkia(); | |
205 } | |
206 | |
207 bool WallpaperManager::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) { | 187 bool WallpaperManager::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) { |
208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
209 | 189 |
210 if (UserManager::Get()->IsLoggedInAsStub()) { | 190 if (UserManager::Get()->IsLoggedInAsStub()) { |
211 info->file = current_user_wallpaper_info_.file = ""; | 191 info->file = current_user_wallpaper_info_.file = ""; |
212 info->layout = current_user_wallpaper_info_.layout = | 192 info->layout = current_user_wallpaper_info_.layout = |
213 ash::WALLPAPER_LAYOUT_CENTER_CROPPED; | 193 ash::WALLPAPER_LAYOUT_CENTER_CROPPED; |
214 info->type = current_user_wallpaper_info_.type = User::DEFAULT; | 194 info->type = current_user_wallpaper_info_.type = User::DEFAULT; |
215 return true; | 195 return true; |
216 } | 196 } |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 task_runner_->PostTask(FROM_HERE, | 607 task_runner_->PostTask(FROM_HERE, |
628 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, | 608 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, |
629 base::Unretained(this), email, info, wallpaper_path, | 609 base::Unretained(this), email, info, wallpaper_path, |
630 false /* do not update wallpaper */)); | 610 false /* do not update wallpaper */)); |
631 return; | 611 return; |
632 } | 612 } |
633 LoadWallpaper(email, info, false /* do not update wallpaper */); | 613 LoadWallpaper(email, info, false /* do not update wallpaper */); |
634 } | 614 } |
635 } | 615 } |
636 | 616 |
637 void WallpaperManager::CacheThumbnail(const std::string& email, | |
638 scoped_ptr<gfx::ImageSkia> wallpaper) { | |
639 DCHECK(BrowserThread::GetBlockingPool()-> | |
640 IsRunningSequenceOnCurrentThread(sequence_token_)); | |
641 custom_wallpaper_thumbnail_cache_[email] = | |
642 GetWallpaperThumbnail(*wallpaper.get()); | |
643 } | |
644 | |
645 void WallpaperManager::ClearObsoleteWallpaperPrefs() { | 617 void WallpaperManager::ClearObsoleteWallpaperPrefs() { |
646 PrefService* prefs = g_browser_process->local_state(); | 618 PrefService* prefs = g_browser_process->local_state(); |
647 DictionaryPrefUpdate wallpaper_properties_pref(prefs, | 619 DictionaryPrefUpdate wallpaper_properties_pref(prefs, |
648 kUserWallpapersProperties); | 620 kUserWallpapersProperties); |
649 wallpaper_properties_pref->Clear(); | 621 wallpaper_properties_pref->Clear(); |
650 DictionaryPrefUpdate wallpapers_pref(prefs, kUserWallpapers); | 622 DictionaryPrefUpdate wallpapers_pref(prefs, kUserWallpapers); |
651 wallpapers_pref->Clear(); | 623 wallpapers_pref->Clear(); |
652 } | 624 } |
653 | 625 |
654 void WallpaperManager::DeleteWallpaperInList( | 626 void WallpaperManager::DeleteWallpaperInList( |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 &date_string) && | 736 &date_string) && |
765 base::StringToInt64(date_string, &val))) | 737 base::StringToInt64(date_string, &val))) |
766 val = 0; | 738 val = 0; |
767 info->date = base::Time::FromInternalValue(val); | 739 info->date = base::Time::FromInternalValue(val); |
768 return true; | 740 return true; |
769 } | 741 } |
770 | 742 |
771 return false; | 743 return false; |
772 } | 744 } |
773 | 745 |
774 void WallpaperManager::GenerateUserWallpaperThumbnail( | |
775 const std::string& email, | |
776 User::WallpaperType type, | |
777 const gfx::ImageSkia& wallpaper) { | |
778 DCHECK(BrowserThread::GetBlockingPool()-> | |
779 IsRunningSequenceOnCurrentThread(sequence_token_)); | |
780 custom_wallpaper_thumbnail_cache_[email] = GetWallpaperThumbnail(wallpaper); | |
781 } | |
782 | |
783 void WallpaperManager::GetCustomWallpaperInternal( | 746 void WallpaperManager::GetCustomWallpaperInternal( |
784 const std::string& email, | 747 const std::string& email, |
785 const WallpaperInfo& info, | 748 const WallpaperInfo& info, |
786 const FilePath& wallpaper_path, | 749 const FilePath& wallpaper_path, |
787 bool update_wallpaper) { | 750 bool update_wallpaper) { |
788 DCHECK(BrowserThread::GetBlockingPool()-> | 751 DCHECK(BrowserThread::GetBlockingPool()-> |
789 IsRunningSequenceOnCurrentThread(sequence_token_)); | 752 IsRunningSequenceOnCurrentThread(sequence_token_)); |
790 std::string file_name = wallpaper_path.BaseName().value(); | 753 std::string file_name = wallpaper_path.BaseName().value(); |
791 | 754 |
792 if (!file_util::PathExists(wallpaper_path)) { | 755 if (!file_util::PathExists(wallpaper_path)) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 ash::WALLPAPER_LAYOUT_CENTER_CROPPED, | 792 ash::WALLPAPER_LAYOUT_CENTER_CROPPED, |
830 User::DEFAULT, | 793 User::DEFAULT, |
831 base::Time::Now().LocalMidnight() | 794 base::Time::Now().LocalMidnight() |
832 }; | 795 }; |
833 SetUserWallpaperInfo(email, info, true); | 796 SetUserWallpaperInfo(email, info, true); |
834 | 797 |
835 if (update_wallpaper) | 798 if (update_wallpaper) |
836 SetDefaultWallpaper(); | 799 SetDefaultWallpaper(); |
837 return; | 800 return; |
838 } | 801 } |
839 // Generate all reps before passing to another thread. | |
840 wallpaper.image().EnsureRepsForSupportedScaleFactors(); | |
841 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy()); | |
842 | |
843 task_runner_->PostTask(FROM_HERE, | |
844 base::Bind(&WallpaperManager::CacheThumbnail, | |
845 base::Unretained(this), email, | |
846 base::Passed(&deep_copy))); | |
847 | 802 |
848 // Only cache user wallpaper at login screen. | 803 // Only cache user wallpaper at login screen. |
849 if (!UserManager::Get()->IsUserLoggedIn()) { | 804 if (!UserManager::Get()->IsUserLoggedIn()) { |
850 wallpaper_cache_.insert(std::make_pair(email, wallpaper.image())); | 805 wallpaper_cache_.insert(std::make_pair(email, wallpaper.image())); |
851 } | 806 } |
852 if (update_wallpaper) { | 807 if (update_wallpaper) { |
853 ash::Shell::GetInstance()->desktop_background_controller()-> | 808 ash::Shell::GetInstance()->desktop_background_controller()-> |
854 SetCustomWallpaper(wallpaper.image(), layout); | 809 SetCustomWallpaper(wallpaper.image(), layout); |
855 } | 810 } |
856 } | 811 } |
857 | 812 |
858 void WallpaperManager::ProcessCustomWallpaper( | 813 void WallpaperManager::ProcessCustomWallpaper( |
859 const std::string& email, | 814 const std::string& email, |
860 bool persistent, | 815 bool persistent, |
861 const WallpaperInfo& info, | 816 const WallpaperInfo& info, |
862 scoped_ptr<gfx::ImageSkia> image, | 817 scoped_ptr<gfx::ImageSkia> image, |
863 const UserImage::RawImage& raw_image) { | 818 const UserImage::RawImage& raw_image) { |
864 DCHECK(BrowserThread::GetBlockingPool()-> | 819 DCHECK(BrowserThread::GetBlockingPool()-> |
865 IsRunningSequenceOnCurrentThread(sequence_token_)); | 820 IsRunningSequenceOnCurrentThread(sequence_token_)); |
866 UserImage wallpaper(*image.get(), raw_image); | 821 UserImage wallpaper(*image.get(), raw_image); |
867 GenerateUserWallpaperThumbnail(email, info.type, wallpaper.image()); | |
868 if (persistent) | 822 if (persistent) |
869 SaveCustomWallpaper(email, FilePath(info.file), info.layout, wallpaper); | 823 SaveCustomWallpaper(email, FilePath(info.file), info.layout, wallpaper); |
870 } | 824 } |
871 | 825 |
872 void WallpaperManager::SaveCustomWallpaper(const std::string& email, | 826 void WallpaperManager::SaveCustomWallpaper(const std::string& email, |
873 const FilePath& path, | 827 const FilePath& path, |
874 ash::WallpaperLayout layout, | 828 ash::WallpaperLayout layout, |
875 const UserImage& wallpaper) { | 829 const UserImage& wallpaper) { |
876 FilePath small_wallpaper_path = GetWallpaperPathForUser(email, true); | 830 FilePath small_wallpaper_path = GetWallpaperPathForUser(email, true); |
877 // Delete previous saved wallpapers. | 831 // Delete previous saved wallpapers. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 FROM_HERE, | 905 FROM_HERE, |
952 base::Bind(&WallpaperManager::StartLoad, | 906 base::Bind(&WallpaperManager::StartLoad, |
953 base::Unretained(this), | 907 base::Unretained(this), |
954 email, | 908 email, |
955 info, | 909 info, |
956 update_wallpaper, | 910 update_wallpaper, |
957 valid_path)); | 911 valid_path)); |
958 } | 912 } |
959 | 913 |
960 } // chromeos | 914 } // chromeos |
OLD | NEW |