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" | |
24 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
25 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
26 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
27 #include "base/sys_info.h" | 28 #include "base/sys_info.h" |
28 #include "base/threading/worker_pool.h" | 29 #include "base/threading/worker_pool.h" |
29 #include "base/time/time.h" | 30 #include "base/time/time.h" |
30 #include "base/trace_event/trace_event.h" | 31 #include "base/trace_event/trace_event.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/customization_document.h" | 35 #include "chrome/browser/chromeos/customization/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/wizard_controller.h" | 37 #include "chrome/browser/chromeos/login/wizard_controller.h" |
37 #include "chrome/browser/chromeos/settings/cros_settings.h" | 38 #include "chrome/browser/chromeos/settings/cros_settings.h" |
38 #include "chrome/common/chrome_paths.h" | 39 #include "chrome/common/chrome_paths.h" |
39 #include "chrome/common/chrome_switches.h" | 40 #include "chrome/common/chrome_switches.h" |
40 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
41 #include "chromeos/chromeos_switches.h" | 42 #include "chromeos/chromeos_switches.h" |
42 #include "chromeos/cryptohome/async_method_caller.h" | 43 #include "chromeos/cryptohome/system_salt_getter.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 cryptohome::Identification GetUnhashedSourceForWallpaperFilesId( | 132 // This has once been copied from |
133 const user_manager::User& user) { | 133 // brillo::cryptohome::home::SanitizeUserName(username) to be used for |
134 const AccountId& account_id = user.GetAccountId(); | 134 // wallpaper identification purpose only. |
bshe
2016/04/13 20:00:19
nit: perhaps also document why do we want to copy
Alexander Alekseev
2016/04/14 03:37:29
Done.
| |
135 const std::string& old_id = account_id.GetUserEmail(); // Migrated | 135 wallpaper::WallpaperFilesId HashWallpaperFilesIdStr( |
136 return cryptohome::Identification::FromString(old_id); | 136 const std::string& files_id_unhashed) { |
137 } | 137 SystemSaltGetter* salt_getter = SystemSaltGetter::Get(); |
138 DCHECK(salt_getter); | |
139 const SystemSaltGetter::RawSalt* salt = salt_getter->GetRawSalt(); | |
140 if (!salt) | |
141 LOG(FATAL) << "WallpaperManager HashWallpaperFilesIdStr(): no salt!"; | |
138 | 142 |
139 wallpaper::WallpaperFilesId GetKnownUserWallpaperFilesId( | 143 unsigned char binmd[base::kSHA1Length]; |
140 const user_manager::User& user) { | 144 std::string lowercase(files_id_unhashed); |
141 const AccountId& account_id = user.GetAccountId(); | 145 std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(), |
142 std::string stored_value; | 146 ::tolower); |
143 if (user_manager::known_user::GetStringPref(account_id, kWallpaperFilesId, | 147 std::vector<uint8_t> data = *salt; |
144 &stored_value)) { | 148 std::copy(files_id_unhashed.begin(), files_id_unhashed.end(), |
145 return wallpaper::WallpaperFilesId::FromString(stored_value); | 149 std::back_inserter(data)); |
146 } | 150 base::SHA1HashBytes(data.data(), data.size(), binmd); |
147 return wallpaper::WallpaperFilesId::FromString(user.username_hash()); | 151 std::string result = base::HexEncode(binmd, sizeof(binmd)); |
152 std::transform(result.begin(), result.end(), result.begin(), ::tolower); | |
153 return wallpaper::WallpaperFilesId::FromString(result); | |
148 } | 154 } |
149 | 155 |
150 void SetKnownUserWallpaperFilesId( | 156 void SetKnownUserWallpaperFilesId( |
151 const AccountId& account_id, | 157 const AccountId& account_id, |
152 const wallpaper::WallpaperFilesId& wallpaper_files_id) { | 158 const wallpaper::WallpaperFilesId& wallpaper_files_id) { |
153 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, | 159 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, |
154 wallpaper_files_id.id()); | 160 wallpaper_files_id.id()); |
155 } | 161 } |
156 | 162 |
163 wallpaper::WallpaperFilesId GetWallpaperFilesId(const AccountId& account_id) { | |
164 std::string stored_value; | |
165 if (user_manager::known_user::GetStringPref(account_id, kWallpaperFilesId, | |
166 &stored_value)) { | |
167 return wallpaper::WallpaperFilesId::FromString(stored_value); | |
168 } | |
169 const std::string& old_id = account_id.GetUserEmail(); // Migrated | |
170 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); | |
171 SetKnownUserWallpaperFilesId(account_id, files_id); | |
172 return files_id; | |
173 } | |
174 | |
157 } // namespace | 175 } // namespace |
158 | 176 |
159 // This is "wallpaper either scheduled to load, or loading right now". | 177 // This is "wallpaper either scheduled to load, or loading right now". |
160 // | 178 // |
161 // While enqueued, it defines moment in the future, when it will be loaded. | 179 // While enqueued, it defines moment in the future, when it will be loaded. |
162 // Enqueued but not started request might be updated by subsequent load | 180 // Enqueued but not started request might be updated by subsequent load |
163 // request. Therefore it's created empty, and updated being enqueued. | 181 // request. Therefore it's created empty, and updated being enqueued. |
164 // | 182 // |
165 // PendingWallpaper is owned by WallpaperManager, but reference to this object | 183 // PendingWallpaper is owned by WallpaperManager, but reference to this object |
166 // is passed to other threads by PostTask() calls, therefore it is | 184 // is passed to other threads by PostTask() calls, therefore it is |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
821 } | 839 } |
822 } | 840 } |
823 | 841 |
824 if (loading_.empty()) | 842 if (loading_.empty()) |
825 FOR_EACH_OBSERVER(Observer, observers_, OnPendingListEmptyForTesting()); | 843 FOR_EACH_OBSERVER(Observer, observers_, OnPendingListEmptyForTesting()); |
826 } | 844 } |
827 | 845 |
828 void WallpaperManager::SetPolicyControlledWallpaper( | 846 void WallpaperManager::SetPolicyControlledWallpaper( |
829 const AccountId& account_id, | 847 const AccountId& account_id, |
830 std::unique_ptr<user_manager::UserImage> user_image) { | 848 std::unique_ptr<user_manager::UserImage> user_image) { |
831 const user_manager::User* user = | 849 const wallpaper::WallpaperFilesId wallpaper_files_id = |
832 user_manager::UserManager::Get()->FindUser(account_id); | 850 GetWallpaperFilesId(account_id); |
833 if (!user) { | 851 if (!wallpaper_files_id.is_valid()) |
834 NOTREACHED() << "Unknown user."; | 852 LOG(FATAL) << "Wallpaper flies id if invalid!"; |
835 return; | |
836 } | |
837 | 853 |
838 const wallpaper::WallpaperFilesId wallpaper_files_id = | |
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 | |
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); | |
865 SetCustomWallpaper(account_id, wallpaper_files_id, "policy-controlled.jpeg", | 854 SetCustomWallpaper(account_id, wallpaper_files_id, "policy-controlled.jpeg", |
866 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED, | 855 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED, |
867 user_manager::User::POLICY, image, update_wallpaper); | 856 user_manager::User::POLICY, user_image->image(), |
857 true /* update wallpaper */); | |
868 } | 858 } |
869 | 859 |
870 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { | 860 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { |
871 if (user_manager::UserManager::Get()->IsUserLoggedIn()) | 861 if (user_manager::UserManager::Get()->IsUserLoggedIn()) |
872 return; | 862 return; |
873 | 863 |
874 bool disable_boot_animation = | 864 bool disable_boot_animation = |
875 GetCommandLine()->HasSwitch(switches::kDisableBootAnimation); | 865 GetCommandLine()->HasSwitch(switches::kDisableBootAnimation); |
876 bool show_users = true; | 866 bool show_users = true; |
877 bool result = CrosSettings::Get()->GetBoolean( | 867 bool result = CrosSettings::Get()->GetBoolean( |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1132 default_wallpaper_image_->set_file_path(default_large_wallpaper_file); | 1122 default_wallpaper_image_->set_file_path(default_large_wallpaper_file); |
1133 } | 1123 } |
1134 } | 1124 } |
1135 | 1125 |
1136 if (need_update_screen) { | 1126 if (need_update_screen) { |
1137 DoSetDefaultWallpaper(EmptyAccountId(), MovableOnDestroyCallbackHolder()); | 1127 DoSetDefaultWallpaper(EmptyAccountId(), MovableOnDestroyCallbackHolder()); |
1138 } | 1128 } |
1139 } | 1129 } |
1140 | 1130 |
1141 wallpaper::WallpaperFilesId WallpaperManager::GetFilesId( | 1131 wallpaper::WallpaperFilesId WallpaperManager::GetFilesId( |
1142 const user_manager::User& user) const { | 1132 const AccountId& account_id) const { |
bshe
2016/04/13 20:00:19
nit: consider move the implementation of GetWallpa
Alexander Alekseev
2016/04/14 03:37:29
Done.
| |
1143 return GetKnownUserWallpaperFilesId(user); | 1133 return GetWallpaperFilesId(account_id); |
1144 } | 1134 } |
1145 | 1135 |
1146 } // namespace chromeos | 1136 } // namespace chromeos |
OLD | NEW |