Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(607)

Side by Side Diff: chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.cc

Issue 422243002: Ensure public account policy wallpaper is stored in correct place. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Alexander's comment. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 /* recursive */);
1025 base::DeleteFile(
1026 GetCustomWallpaperDir(kSmallWallpaperSubDir).Append(user_id_hash),
1027 true /* recursive */);
1028 base::DeleteFile(
1029 GetCustomWallpaperDir(kLargeWallpaperSubDir).Append(user_id_hash),
1030 true /* recursive */);
1002 EnsureCustomWallpaperDirectories(user_id_hash); 1031 EnsureCustomWallpaperDirectories(user_id_hash);
1003 std::string file_name = original_path.BaseName().value(); 1032 std::string file_name = original_path.BaseName().value();
1004 base::FilePath small_wallpaper_path = 1033 base::FilePath small_wallpaper_path =
1005 GetCustomWallpaperPath(kSmallWallpaperSubDir, user_id_hash, file_name); 1034 GetCustomWallpaperPath(kSmallWallpaperSubDir, user_id_hash, file_name);
1006 base::FilePath large_wallpaper_path = 1035 base::FilePath large_wallpaper_path =
1007 GetCustomWallpaperPath(kLargeWallpaperSubDir, user_id_hash, file_name); 1036 GetCustomWallpaperPath(kLargeWallpaperSubDir, user_id_hash, file_name);
1008 1037
1009 // Re-encode orginal file to jpeg format and saves the result in case that 1038 // 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 1039 // resized wallpaper is not generated (i.e. chrome shutdown before resized
1011 // wallpaper is saved). 1040 // wallpaper is saved).
1012 ResizeAndSaveWallpaper(*image, 1041 ResizeAndSaveWallpaper(*image,
1013 original_path, 1042 original_path,
1014 ash::WALLPAPER_LAYOUT_STRETCH, 1043 ash::WALLPAPER_LAYOUT_STRETCH,
1015 image->width(), 1044 image->width(),
1016 image->height(), 1045 image->height(),
1017 NULL); 1046 NULL);
1018 DeleteAllExcept(original_path);
1019
1020 ResizeAndSaveWallpaper(*image, 1047 ResizeAndSaveWallpaper(*image,
1021 small_wallpaper_path, 1048 small_wallpaper_path,
1022 layout, 1049 layout,
1023 kSmallWallpaperMaxWidth, 1050 kSmallWallpaperMaxWidth,
1024 kSmallWallpaperMaxHeight, 1051 kSmallWallpaperMaxHeight,
1025 NULL); 1052 NULL);
1026 DeleteAllExcept(small_wallpaper_path);
1027 ResizeAndSaveWallpaper(*image, 1053 ResizeAndSaveWallpaper(*image,
1028 large_wallpaper_path, 1054 large_wallpaper_path,
1029 layout, 1055 layout,
1030 kLargeWallpaperMaxWidth, 1056 kLargeWallpaperMaxWidth,
1031 kLargeWallpaperMaxHeight, 1057 kLargeWallpaperMaxHeight,
1032 NULL); 1058 NULL);
1033 DeleteAllExcept(large_wallpaper_path);
1034 } 1059 }
1035 1060
1036 // static 1061 // static
1037 void WallpaperManager::MoveCustomWallpapersOnWorker( 1062 void WallpaperManager::MoveCustomWallpapersOnWorker(
1038 const std::string& user_id, 1063 const std::string& user_id,
1039 const std::string& user_id_hash, 1064 const std::string& user_id_hash,
1040 base::WeakPtr<WallpaperManager> weak_ptr) { 1065 base::WeakPtr<WallpaperManager> weak_ptr) {
1041 1066
1042 if (MoveCustomWallpaperDirectory( 1067 if (MoveCustomWallpaperDirectory(
1043 kOriginalWallpaperSubDir, user_id, user_id_hash)) { 1068 kOriginalWallpaperSubDir, user_id, user_id_hash)) {
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
1913 void WallpaperManager::CreateSolidDefaultWallpaper() { 1938 void WallpaperManager::CreateSolidDefaultWallpaper() {
1914 loaded_wallpapers_++; 1939 loaded_wallpapers_++;
1915 SkBitmap bitmap; 1940 SkBitmap bitmap;
1916 bitmap.allocN32Pixels(1, 1); 1941 bitmap.allocN32Pixels(1, 1);
1917 bitmap.eraseColor(kDefaultWallpaperColor); 1942 bitmap.eraseColor(kDefaultWallpaperColor);
1918 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 1943 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
1919 default_wallpaper_image_.reset(new user_manager::UserImage(image)); 1944 default_wallpaper_image_.reset(new user_manager::UserImage(image));
1920 } 1945 }
1921 1946
1922 } // namespace chromeos 1947 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698