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 <stdint.h> | 7 #include <stdint.h> |
8 #include <numeric> | 8 #include <numeric> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "ash/ash_constants.h" | 12 #include "ash/ash_constants.h" |
13 #include "ash/ash_switches.h" | 13 #include "ash/ash_switches.h" |
14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/files/file_enumerator.h" | 17 #include "base/files/file_enumerator.h" |
18 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
19 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
21 #include "base/macros.h" | 21 #include "base/macros.h" |
22 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
23 #include "base/path_service.h" | 23 #include "base/path_service.h" |
24 #include "base/sha1.h" | |
25 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
26 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
27 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
28 #include "base/sys_info.h" | 27 #include "base/sys_info.h" |
29 #include "base/threading/worker_pool.h" | 28 #include "base/threading/worker_pool.h" |
30 #include "base/time/time.h" | 29 #include "base/time/time.h" |
31 #include "base/trace_event/trace_event.h" | 30 #include "base/trace_event/trace_event.h" |
32 #include "base/values.h" | 31 #include "base/values.h" |
33 #include "chrome/browser/browser_process.h" | 32 #include "chrome/browser/browser_process.h" |
34 #include "chrome/browser/chrome_notification_types.h" | 33 #include "chrome/browser/chrome_notification_types.h" |
35 #include "chrome/browser/chromeos/customization/customization_document.h" | 34 #include "chrome/browser/chromeos/customization/customization_document.h" |
36 #include "chrome/browser/chromeos/login/startup_utils.h" | 35 #include "chrome/browser/chromeos/login/startup_utils.h" |
37 #include "chrome/browser/chromeos/login/wizard_controller.h" | 36 #include "chrome/browser/chromeos/login/wizard_controller.h" |
38 #include "chrome/browser/chromeos/settings/cros_settings.h" | 37 #include "chrome/browser/chromeos/settings/cros_settings.h" |
39 #include "chrome/common/chrome_paths.h" | 38 #include "chrome/common/chrome_paths.h" |
40 #include "chrome/common/chrome_switches.h" | 39 #include "chrome/common/chrome_switches.h" |
41 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
42 #include "chromeos/chromeos_switches.h" | 41 #include "chromeos/chromeos_switches.h" |
43 #include "chromeos/cryptohome/system_salt_getter.h" | 42 #include "chromeos/cryptohome/async_method_caller.h" |
| 43 #include "chromeos/cryptohome/cryptohome_parameters.h" |
44 #include "chromeos/dbus/dbus_thread_manager.h" | 44 #include "chromeos/dbus/dbus_thread_manager.h" |
45 #include "chromeos/login/user_names.h" | 45 #include "chromeos/login/user_names.h" |
46 #include "components/prefs/pref_registry_simple.h" | 46 #include "components/prefs/pref_registry_simple.h" |
47 #include "components/prefs/pref_service.h" | 47 #include "components/prefs/pref_service.h" |
48 #include "components/prefs/scoped_user_pref_update.h" | 48 #include "components/prefs/scoped_user_pref_update.h" |
49 #include "components/signin/core/account_id/account_id.h" | 49 #include "components/signin/core/account_id/account_id.h" |
50 #include "components/user_manager/known_user.h" | 50 #include "components/user_manager/known_user.h" |
51 #include "components/user_manager/user.h" | 51 #include "components/user_manager/user.h" |
52 #include "components/user_manager/user_image/user_image.h" | 52 #include "components/user_manager/user_image/user_image.h" |
53 #include "components/user_manager/user_manager.h" | 53 #include "components/user_manager/user_manager.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 ++it, ++i) { | 122 ++it, ++i) { |
123 if ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT) { | 123 if ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT) { |
124 index = i; | 124 index = i; |
125 break; | 125 break; |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 return index; | 129 return index; |
130 } | 130 } |
131 | 131 |
132 // This has once been copied from | 132 cryptohome::Identification GetUnhashedSourceForWallpaperFilesId( |
133 // brillo::cryptohome::home::SanitizeUserName(username) to be used for | 133 const user_manager::User& user) { |
134 // wallpaper identification purpose only. | 134 const AccountId& account_id = user.GetAccountId(); |
135 // | 135 const std::string& old_id = account_id.GetUserEmail(); // Migrated |
136 // Historic note: We need some way to identify users wallpaper files in | 136 return cryptohome::Identification::FromString(old_id); |
137 // the device filesystem. Historically User::username_hash() was used for this | 137 } |
138 // purpose, but it has two caveats: | |
139 // 1. username_hash() is defined only after user has logged in. | |
140 // 2. If cryptohome identifier changes, username_hash() will also change, | |
141 // and we may loose user => wallpaper files mapping at that point. | |
142 // So this function gives WallpaperManager independent hashing method to break | |
143 // this dependency. | |
144 // | |
145 wallpaper::WallpaperFilesId HashWallpaperFilesIdStr( | |
146 const std::string& files_id_unhashed) { | |
147 SystemSaltGetter* salt_getter = SystemSaltGetter::Get(); | |
148 DCHECK(salt_getter); | |
149 | 138 |
150 // System salt must be defined at this point. | 139 wallpaper::WallpaperFilesId GetKnownUserWallpaperFilesId( |
151 const SystemSaltGetter::RawSalt* salt = salt_getter->GetRawSalt(); | 140 const user_manager::User& user) { |
152 if (!salt) | 141 const AccountId& account_id = user.GetAccountId(); |
153 LOG(FATAL) << "WallpaperManager HashWallpaperFilesIdStr(): no salt!"; | 142 std::string stored_value; |
154 | 143 if (user_manager::known_user::GetStringPref(account_id, kWallpaperFilesId, |
155 unsigned char binmd[base::kSHA1Length]; | 144 &stored_value)) { |
156 std::string lowercase(files_id_unhashed); | 145 return wallpaper::WallpaperFilesId::FromString(stored_value); |
157 std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(), | 146 } |
158 ::tolower); | 147 return wallpaper::WallpaperFilesId::FromString(user.username_hash()); |
159 std::vector<uint8_t> data = *salt; | |
160 std::copy(files_id_unhashed.begin(), files_id_unhashed.end(), | |
161 std::back_inserter(data)); | |
162 base::SHA1HashBytes(data.data(), data.size(), binmd); | |
163 std::string result = base::HexEncode(binmd, sizeof(binmd)); | |
164 std::transform(result.begin(), result.end(), result.begin(), ::tolower); | |
165 return wallpaper::WallpaperFilesId::FromString(result); | |
166 } | 148 } |
167 | 149 |
168 void SetKnownUserWallpaperFilesId( | 150 void SetKnownUserWallpaperFilesId( |
169 const AccountId& account_id, | 151 const AccountId& account_id, |
170 const wallpaper::WallpaperFilesId& wallpaper_files_id) { | 152 const wallpaper::WallpaperFilesId& wallpaper_files_id) { |
171 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, | 153 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, |
172 wallpaper_files_id.id()); | 154 wallpaper_files_id.id()); |
173 } | 155 } |
174 | 156 |
175 } // namespace | 157 } // namespace |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 } | 821 } |
840 } | 822 } |
841 | 823 |
842 if (loading_.empty()) | 824 if (loading_.empty()) |
843 FOR_EACH_OBSERVER(Observer, observers_, OnPendingListEmptyForTesting()); | 825 FOR_EACH_OBSERVER(Observer, observers_, OnPendingListEmptyForTesting()); |
844 } | 826 } |
845 | 827 |
846 void WallpaperManager::SetPolicyControlledWallpaper( | 828 void WallpaperManager::SetPolicyControlledWallpaper( |
847 const AccountId& account_id, | 829 const AccountId& account_id, |
848 std::unique_ptr<user_manager::UserImage> user_image) { | 830 std::unique_ptr<user_manager::UserImage> user_image) { |
849 const wallpaper::WallpaperFilesId wallpaper_files_id = GetFilesId(account_id); | 831 const user_manager::User* user = |
| 832 user_manager::UserManager::Get()->FindUser(account_id); |
| 833 if (!user) { |
| 834 NOTREACHED() << "Unknown user."; |
| 835 return; |
| 836 } |
850 | 837 |
851 if (!wallpaper_files_id.is_valid()) | 838 const wallpaper::WallpaperFilesId wallpaper_files_id = |
852 LOG(FATAL) << "Wallpaper flies id if invalid!"; | 839 GetKnownUserWallpaperFilesId(*user); |
| 840 if (!wallpaper_files_id.is_valid()) { |
| 841 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( |
| 842 GetUnhashedSourceForWallpaperFilesId(*user), |
| 843 base::Bind(&WallpaperManager::SetCustomWallpaperOnSanitizedUsername, |
| 844 weak_factory_.GetWeakPtr(), account_id, user_image->image(), |
| 845 true /* update wallpaper */)); |
| 846 } else { |
| 847 SetCustomWallpaper(account_id, wallpaper_files_id, "policy-controlled.jpeg", |
| 848 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED, |
| 849 user_manager::User::POLICY, user_image->image(), |
| 850 true /* update wallpaper */); |
| 851 } |
| 852 } |
853 | 853 |
| 854 void WallpaperManager::SetCustomWallpaperOnSanitizedUsername( |
| 855 const AccountId& account_id, |
| 856 const gfx::ImageSkia& image, |
| 857 bool update_wallpaper, |
| 858 bool cryptohome_success, |
| 859 const std::string& wallpaper_files_id_str) { |
| 860 if (!cryptohome_success) |
| 861 return; |
| 862 const wallpaper::WallpaperFilesId wallpaper_files_id = |
| 863 wallpaper::WallpaperFilesId::FromString(wallpaper_files_id_str); |
| 864 SetKnownUserWallpaperFilesId(account_id, wallpaper_files_id); |
854 SetCustomWallpaper(account_id, wallpaper_files_id, "policy-controlled.jpeg", | 865 SetCustomWallpaper(account_id, wallpaper_files_id, "policy-controlled.jpeg", |
855 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED, | 866 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED, |
856 user_manager::User::POLICY, user_image->image(), | 867 user_manager::User::POLICY, image, update_wallpaper); |
857 true /* update wallpaper */); | |
858 } | 868 } |
859 | 869 |
860 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { | 870 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { |
861 if (user_manager::UserManager::Get()->IsUserLoggedIn()) | 871 if (user_manager::UserManager::Get()->IsUserLoggedIn()) |
862 return; | 872 return; |
863 | 873 |
864 bool disable_boot_animation = | 874 bool disable_boot_animation = |
865 GetCommandLine()->HasSwitch(switches::kDisableBootAnimation); | 875 GetCommandLine()->HasSwitch(switches::kDisableBootAnimation); |
866 bool show_users = true; | 876 bool show_users = true; |
867 bool result = CrosSettings::Get()->GetBoolean( | 877 bool result = CrosSettings::Get()->GetBoolean( |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1122 default_wallpaper_image_->set_file_path(default_large_wallpaper_file); | 1132 default_wallpaper_image_->set_file_path(default_large_wallpaper_file); |
1123 } | 1133 } |
1124 } | 1134 } |
1125 | 1135 |
1126 if (need_update_screen) { | 1136 if (need_update_screen) { |
1127 DoSetDefaultWallpaper(EmptyAccountId(), MovableOnDestroyCallbackHolder()); | 1137 DoSetDefaultWallpaper(EmptyAccountId(), MovableOnDestroyCallbackHolder()); |
1128 } | 1138 } |
1129 } | 1139 } |
1130 | 1140 |
1131 wallpaper::WallpaperFilesId WallpaperManager::GetFilesId( | 1141 wallpaper::WallpaperFilesId WallpaperManager::GetFilesId( |
1132 const AccountId& account_id) const { | 1142 const user_manager::User& user) const { |
1133 std::string stored_value; | 1143 return GetKnownUserWallpaperFilesId(user); |
1134 if (user_manager::known_user::GetStringPref(account_id, kWallpaperFilesId, | |
1135 &stored_value)) { | |
1136 return wallpaper::WallpaperFilesId::FromString(stored_value); | |
1137 } | |
1138 const std::string& old_id = account_id.GetUserEmail(); // Migrated | |
1139 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); | |
1140 SetKnownUserWallpaperFilesId(account_id, files_id); | |
1141 return files_id; | |
1142 } | 1144 } |
1143 | 1145 |
1144 } // namespace chromeos | 1146 } // namespace chromeos |
OLD | NEW |