Chromium Code Reviews| 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 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 5 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 6 | 6 |
| 7 #include <numeric> | 7 #include <numeric> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/ash_constants.h" | 10 #include "ash/ash_constants.h" |
| 11 #include "ash/ash_switches.h" | 11 #include "ash/ash_switches.h" |
| 12 #include "ash/desktop_background/desktop_background_controller.h" | 12 #include "ash/desktop_background/desktop_background_controller.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "base/bind.h" | |
| 14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 15 #include "base/debug/trace_event.h" | 16 #include "base/debug/trace_event.h" |
| 16 #include "base/file_util.h" | 17 #include "base/file_util.h" |
| 17 #include "base/files/file_enumerator.h" | 18 #include "base/files/file_enumerator.h" |
| 18 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
| 19 #include "base/logging.h" | 20 #include "base/logging.h" |
| 20 #include "base/metrics/histogram.h" | 21 #include "base/metrics/histogram.h" |
| 21 #include "base/path_service.h" | 22 #include "base/path_service.h" |
| 22 #include "base/prefs/pref_registry_simple.h" | 23 #include "base/prefs/pref_registry_simple.h" |
| 23 #include "base/prefs/pref_service.h" | 24 #include "base/prefs/pref_service.h" |
| 24 #include "base/prefs/scoped_user_pref_update.h" | 25 #include "base/prefs/scoped_user_pref_update.h" |
| 25 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
| 26 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
| 27 #include "base/strings/stringprintf.h" | 28 #include "base/strings/stringprintf.h" |
| 28 #include "base/sys_info.h" | 29 #include "base/sys_info.h" |
| 29 #include "base/threading/worker_pool.h" | 30 #include "base/threading/worker_pool.h" |
| 30 #include "base/time/time.h" | 31 #include "base/time/time.h" |
| 31 #include "base/values.h" | 32 #include "base/values.h" |
| 32 #include "chrome/browser/browser_process.h" | 33 #include "chrome/browser/browser_process.h" |
| 33 #include "chrome/browser/chrome_notification_types.h" | 34 #include "chrome/browser/chrome_notification_types.h" |
| 34 #include "chrome/browser/chromeos/customization_document.h" | 35 #include "chrome/browser/chromeos/customization_document.h" |
| 35 #include "chrome/browser/chromeos/login/startup_utils.h" | 36 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 36 #include "chrome/browser/chromeos/login/users/user_manager.h" | 37 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 37 #include "chrome/browser/chromeos/login/wizard_controller.h" | 38 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 38 #include "chrome/browser/chromeos/settings/cros_settings.h" | 39 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 39 #include "chrome/common/chrome_paths.h" | 40 #include "chrome/common/chrome_paths.h" |
| 40 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
| 41 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
| 42 #include "chromeos/chromeos_switches.h" | 43 #include "chromeos/chromeos_switches.h" |
| 44 #include "chromeos/cryptohome/async_method_caller.h" | |
| 43 #include "chromeos/dbus/dbus_thread_manager.h" | 45 #include "chromeos/dbus/dbus_thread_manager.h" |
| 44 #include "chromeos/login/user_names.h" | 46 #include "chromeos/login/user_names.h" |
| 45 #include "components/user_manager/user.h" | 47 #include "components/user_manager/user.h" |
| 46 #include "components/user_manager/user_image/user_image.h" | 48 #include "components/user_manager/user_image/user_image.h" |
| 47 #include "components/user_manager/user_type.h" | 49 #include "components/user_manager/user_type.h" |
| 48 #include "content/public/browser/browser_thread.h" | 50 #include "content/public/browser/browser_thread.h" |
| 49 #include "content/public/browser/notification_service.h" | 51 #include "content/public/browser/notification_service.h" |
| 50 #include "third_party/skia/include/core/SkColor.h" | 52 #include "third_party/skia/include/core/SkColor.h" |
| 51 #include "ui/gfx/codec/jpeg_codec.h" | 53 #include "ui/gfx/codec/jpeg_codec.h" |
| 52 #include "ui/gfx/image/image_skia_operations.h" | 54 #include "ui/gfx/image/image_skia_operations.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 // Whether DesktopBackgroundController should start with customized default | 142 // Whether DesktopBackgroundController should start with customized default |
| 141 // wallpaper in WallpaperManager::InitializeWallpaper() or not. | 143 // wallpaper in WallpaperManager::InitializeWallpaper() or not. |
| 142 bool ShouldUseCustomizedDefaultWallpaper() { | 144 bool ShouldUseCustomizedDefaultWallpaper() { |
| 143 PrefService* pref_service = g_browser_process->local_state(); | 145 PrefService* pref_service = g_browser_process->local_state(); |
| 144 | 146 |
| 145 return !(pref_service->FindPreference( | 147 return !(pref_service->FindPreference( |
| 146 prefs::kCustomizationDefaultWallpaperURL) | 148 prefs::kCustomizationDefaultWallpaperURL) |
| 147 ->IsDefaultValue()); | 149 ->IsDefaultValue()); |
| 148 } | 150 } |
| 149 | 151 |
| 150 // Deletes everything else except |path| in the same directory. | |
| 151 void DeleteAllExcept(const base::FilePath& path) { | |
| 152 base::FilePath dir = path.DirName(); | |
| 153 if (base::DirectoryExists(dir)) { | |
| 154 base::FileEnumerator files(dir, false, base::FileEnumerator::FILES); | |
| 155 for (base::FilePath current = files.Next(); !current.empty(); | |
| 156 current = files.Next()) { | |
| 157 if (current != path) | |
| 158 base::DeleteFile(current, false); | |
| 159 } | |
| 160 } | |
| 161 } | |
| 162 | |
| 163 // Deletes a list of wallpaper files in |file_list|. | 152 // Deletes a list of wallpaper files in |file_list|. |
| 164 void DeleteWallpaperInList(const std::vector<base::FilePath>& file_list) { | 153 void DeleteWallpaperInList(const std::vector<base::FilePath>& file_list) { |
| 165 for (std::vector<base::FilePath>::const_iterator it = file_list.begin(); | 154 for (std::vector<base::FilePath>::const_iterator it = file_list.begin(); |
| 166 it != file_list.end(); ++it) { | 155 it != file_list.end(); ++it) { |
| 167 base::FilePath path = *it; | 156 base::FilePath path = *it; |
| 168 // Some users may still have legacy wallpapers with png extension. We need | 157 // Some users may still have legacy wallpapers with png extension. We need |
| 169 // to delete these wallpapers too. | 158 // to delete these wallpapers too. |
| 170 if (!base::DeleteFile(path, true) && | 159 if (!base::DeleteFile(path, true) && |
| 171 !base::DeleteFile(path.AddExtension(".png"), false)) { | 160 !base::DeleteFile(path.AddExtension(".png"), false)) { |
| 172 LOG(ERROR) << "Failed to remove user wallpaper at " << path.value(); | 161 LOG(ERROR) << "Failed to remove user wallpaper at " << path.value(); |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 837 | 826 |
| 838 void WallpaperManager::SetPolicyControlledWallpaper( | 827 void WallpaperManager::SetPolicyControlledWallpaper( |
| 839 const std::string& user_id, | 828 const std::string& user_id, |
| 840 const user_manager::UserImage& user_image) { | 829 const user_manager::UserImage& user_image) { |
| 841 const user_manager::User* user = | 830 const user_manager::User* user = |
| 842 chromeos::UserManager::Get()->FindUser(user_id); | 831 chromeos::UserManager::Get()->FindUser(user_id); |
| 843 if (!user) { | 832 if (!user) { |
| 844 NOTREACHED() << "Unknown user."; | 833 NOTREACHED() << "Unknown user."; |
| 845 return; | 834 return; |
| 846 } | 835 } |
| 836 | |
| 837 if (user->username_hash().empty()) { | |
| 838 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( | |
| 839 user_id, | |
| 840 base::Bind(&WallpaperManager::SetCustomWallpaperOnSanitizedUsername, | |
| 841 weak_factory_.GetWeakPtr(), | |
| 842 user_id, | |
| 843 user_image.image(), | |
| 844 true /* update wallpaper */)); | |
| 845 } else { | |
| 846 SetCustomWallpaper(user_id, | |
| 847 user->username_hash(), | |
| 848 "policy-controlled.jpeg", | |
| 849 ash::WALLPAPER_LAYOUT_CENTER_CROPPED, | |
| 850 user_manager::User::POLICY, | |
| 851 user_image.image(), | |
| 852 true /* update wallpaper */); | |
| 853 } | |
| 854 } | |
| 855 | |
| 856 void WallpaperManager::SetCustomWallpaperOnSanitizedUsername( | |
| 857 const std::string& user_id, | |
| 858 const gfx::ImageSkia& image, | |
| 859 bool update_wallpaper, | |
| 860 bool cryptohome_success, | |
| 861 const std::string& user_id_hash) { | |
| 862 if (!cryptohome_success) | |
| 863 return; | |
| 847 SetCustomWallpaper(user_id, | 864 SetCustomWallpaper(user_id, |
| 848 user->username_hash(), | 865 user_id_hash, |
| 849 "policy-controlled.jpeg", | 866 "policy-controlled.jpeg", |
| 850 ash::WALLPAPER_LAYOUT_CENTER_CROPPED, | 867 ash::WALLPAPER_LAYOUT_CENTER_CROPPED, |
| 851 user_manager::User::POLICY, | 868 user_manager::User::POLICY, |
| 852 user_image.image(), | 869 image, |
| 853 true /* update wallpaper */); | 870 update_wallpaper); |
| 854 } | 871 } |
| 855 | 872 |
| 856 void WallpaperManager::SetCustomWallpaper( | 873 void WallpaperManager::SetCustomWallpaper( |
| 857 const std::string& user_id, | 874 const std::string& user_id, |
| 858 const std::string& user_id_hash, | 875 const std::string& user_id_hash, |
| 859 const std::string& file, | 876 const std::string& file, |
| 860 ash::WallpaperLayout layout, | 877 ash::WallpaperLayout layout, |
| 861 user_manager::User::WallpaperType type, | 878 user_manager::User::WallpaperType type, |
| 862 const gfx::ImageSkia& image, | 879 const gfx::ImageSkia& image, |
| 863 bool update_wallpaper) { | 880 bool update_wallpaper) { |
| 864 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 881 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 865 DCHECK(UserManager::Get()->IsUserLoggedIn()); | |
| 866 | 882 |
| 867 // There is no visible background in kiosk mode. | 883 // There is no visible background in kiosk mode. |
| 868 if (UserManager::Get()->IsLoggedInAsKioskApp()) | 884 if (UserManager::Get()->IsLoggedInAsKioskApp()) |
| 869 return; | 885 return; |
| 870 | 886 |
| 871 // Don't allow custom wallpapers while policy is in effect. | 887 // Don't allow custom wallpapers while policy is in effect. |
| 872 if (type != user_manager::User::POLICY && IsPolicyControlled(user_id)) | 888 if (type != user_manager::User::POLICY && IsPolicyControlled(user_id)) |
| 873 return; | 889 return; |
| 874 | 890 |
| 875 base::FilePath wallpaper_path = | 891 base::FilePath wallpaper_path = |
| 876 GetCustomWallpaperPath(kOriginalWallpaperSubDir, user_id_hash, file); | 892 GetCustomWallpaperPath(kOriginalWallpaperSubDir, user_id_hash, file); |
| 877 | 893 |
| 878 // If decoded wallpaper is empty, we have probably failed to decode the file. | 894 // If decoded wallpaper is empty, we have probably failed to decode the file. |
| 879 // Use default wallpaper in this case. | 895 // Use default wallpaper in this case. |
| 880 if (image.isNull()) { | 896 if (image.isNull()) { |
| 881 SetDefaultWallpaperDelayed(user_id); | 897 SetDefaultWallpaperDelayed(user_id); |
| 882 return; | 898 return; |
| 883 } | 899 } |
| 884 | 900 |
| 901 const user_manager::User *user = UserManager::Get()->FindUser(user_id); | |
| 902 CHECK(user); | |
| 885 bool is_persistent = | 903 bool is_persistent = |
| 886 !UserManager::Get()->IsUserNonCryptohomeDataEphemeral(user_id); | 904 !UserManager::Get()->IsUserNonCryptohomeDataEphemeral(user_id) || |
| 905 (type == user_manager::User::POLICY && | |
| 906 user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT); | |
| 887 | 907 |
| 888 WallpaperInfo wallpaper_info = { | 908 WallpaperInfo wallpaper_info = { |
| 889 wallpaper_path.value(), | 909 wallpaper_path.value(), |
| 890 layout, | 910 layout, |
| 891 type, | 911 type, |
| 892 // Date field is not used. | 912 // Date field is not used. |
| 893 base::Time::Now().LocalMidnight() | 913 base::Time::Now().LocalMidnight() |
| 894 }; | 914 }; |
| 895 if (is_persistent) { | 915 if (is_persistent) { |
| 896 image.EnsureRepsForSupportedScales(); | 916 image.EnsureRepsForSupportedScales(); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 992 int index) { | 1012 int index) { |
| 993 UMA_HISTOGRAM_ENUMERATION( | 1013 UMA_HISTOGRAM_ENUMERATION( |
| 994 "Ash.Wallpaper.Type", type, user_manager::User::WALLPAPER_TYPE_COUNT); | 1014 "Ash.Wallpaper.Type", type, user_manager::User::WALLPAPER_TYPE_COUNT); |
| 995 } | 1015 } |
| 996 | 1016 |
| 997 // static | 1017 // static |
| 998 void WallpaperManager::SaveCustomWallpaper(const std::string& user_id_hash, | 1018 void WallpaperManager::SaveCustomWallpaper(const std::string& user_id_hash, |
| 999 const base::FilePath& original_path, | 1019 const base::FilePath& original_path, |
| 1000 ash::WallpaperLayout layout, | 1020 ash::WallpaperLayout layout, |
| 1001 scoped_ptr<gfx::ImageSkia> image) { | 1021 scoped_ptr<gfx::ImageSkia> image) { |
| 1022 base::DeleteFile( | |
| 1023 GetCustomWallpaperDir(kOriginalWallpaperSubDir).Append(user_id_hash), | |
| 1024 true); | |
|
Alexander Alekseev
2014/08/01 19:25:45
nit: /* recursive */
Thiemo Nagel
2014/08/04 08:34:09
Done.
| |
| 1025 base::DeleteFile( | |
| 1026 GetCustomWallpaperDir(kSmallWallpaperSubDir).Append(user_id_hash), true); | |
| 1027 base::DeleteFile( | |
| 1028 GetCustomWallpaperDir(kLargeWallpaperSubDir).Append(user_id_hash), true); | |
| 1002 EnsureCustomWallpaperDirectories(user_id_hash); | 1029 EnsureCustomWallpaperDirectories(user_id_hash); |
| 1003 std::string file_name = original_path.BaseName().value(); | 1030 std::string file_name = original_path.BaseName().value(); |
| 1004 base::FilePath small_wallpaper_path = | 1031 base::FilePath small_wallpaper_path = |
| 1005 GetCustomWallpaperPath(kSmallWallpaperSubDir, user_id_hash, file_name); | 1032 GetCustomWallpaperPath(kSmallWallpaperSubDir, user_id_hash, file_name); |
| 1006 base::FilePath large_wallpaper_path = | 1033 base::FilePath large_wallpaper_path = |
| 1007 GetCustomWallpaperPath(kLargeWallpaperSubDir, user_id_hash, file_name); | 1034 GetCustomWallpaperPath(kLargeWallpaperSubDir, user_id_hash, file_name); |
| 1008 | 1035 |
| 1009 // Re-encode orginal file to jpeg format and saves the result in case that | 1036 // Re-encode orginal file to jpeg format and saves the result in case that |
| 1010 // resized wallpaper is not generated (i.e. chrome shutdown before resized | 1037 // resized wallpaper is not generated (i.e. chrome shutdown before resized |
| 1011 // wallpaper is saved). | 1038 // wallpaper is saved). |
| 1012 ResizeAndSaveWallpaper(*image, | 1039 ResizeAndSaveWallpaper(*image, |
| 1013 original_path, | 1040 original_path, |
| 1014 ash::WALLPAPER_LAYOUT_STRETCH, | 1041 ash::WALLPAPER_LAYOUT_STRETCH, |
| 1015 image->width(), | 1042 image->width(), |
| 1016 image->height(), | 1043 image->height(), |
| 1017 NULL); | 1044 NULL); |
| 1018 DeleteAllExcept(original_path); | |
| 1019 | |
| 1020 ResizeAndSaveWallpaper(*image, | 1045 ResizeAndSaveWallpaper(*image, |
| 1021 small_wallpaper_path, | 1046 small_wallpaper_path, |
| 1022 layout, | 1047 layout, |
| 1023 kSmallWallpaperMaxWidth, | 1048 kSmallWallpaperMaxWidth, |
| 1024 kSmallWallpaperMaxHeight, | 1049 kSmallWallpaperMaxHeight, |
| 1025 NULL); | 1050 NULL); |
| 1026 DeleteAllExcept(small_wallpaper_path); | |
| 1027 ResizeAndSaveWallpaper(*image, | 1051 ResizeAndSaveWallpaper(*image, |
| 1028 large_wallpaper_path, | 1052 large_wallpaper_path, |
| 1029 layout, | 1053 layout, |
| 1030 kLargeWallpaperMaxWidth, | 1054 kLargeWallpaperMaxWidth, |
| 1031 kLargeWallpaperMaxHeight, | 1055 kLargeWallpaperMaxHeight, |
| 1032 NULL); | 1056 NULL); |
| 1033 DeleteAllExcept(large_wallpaper_path); | |
| 1034 } | 1057 } |
| 1035 | 1058 |
| 1036 // static | 1059 // static |
| 1037 void WallpaperManager::MoveCustomWallpapersOnWorker( | 1060 void WallpaperManager::MoveCustomWallpapersOnWorker( |
| 1038 const std::string& user_id, | 1061 const std::string& user_id, |
| 1039 const std::string& user_id_hash, | 1062 const std::string& user_id_hash, |
| 1040 base::WeakPtr<WallpaperManager> weak_ptr) { | 1063 base::WeakPtr<WallpaperManager> weak_ptr) { |
| 1041 | 1064 |
| 1042 if (MoveCustomWallpaperDirectory( | 1065 if (MoveCustomWallpaperDirectory( |
| 1043 kOriginalWallpaperSubDir, user_id, user_id_hash)) { | 1066 kOriginalWallpaperSubDir, user_id, user_id_hash)) { |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1913 void WallpaperManager::CreateSolidDefaultWallpaper() { | 1936 void WallpaperManager::CreateSolidDefaultWallpaper() { |
| 1914 loaded_wallpapers_++; | 1937 loaded_wallpapers_++; |
| 1915 SkBitmap bitmap; | 1938 SkBitmap bitmap; |
| 1916 bitmap.allocN32Pixels(1, 1); | 1939 bitmap.allocN32Pixels(1, 1); |
| 1917 bitmap.eraseColor(kDefaultWallpaperColor); | 1940 bitmap.eraseColor(kDefaultWallpaperColor); |
| 1918 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 1941 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 1919 default_wallpaper_image_.reset(new user_manager::UserImage(image)); | 1942 default_wallpaper_image_.reset(new user_manager::UserImage(image)); |
| 1920 } | 1943 } |
| 1921 | 1944 |
| 1922 } // namespace chromeos | 1945 } // namespace chromeos |
| OLD | NEW |