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

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

Issue 1886653002: Remove WallpaperManager dependency on Cryptohome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix rebase (raw_salt_ is now properly set). Created 4 years, 8 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
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 <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
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.
135 const std::string& old_id = account_id.GetUserEmail(); // Migrated 135 //
136 return cryptohome::Identification::FromString(old_id); 136 // Historic note: We need some way to identify users wallpaper files in
137 } 137 // the device filesystem. Historically User::username_hash() was used for this
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);
138 149
139 wallpaper::WallpaperFilesId GetKnownUserWallpaperFilesId( 150 // System salt must be defined at this point.
140 const user_manager::User& user) { 151 const SystemSaltGetter::RawSalt* salt = salt_getter->GetRawSalt();
141 const AccountId& account_id = user.GetAccountId(); 152 if (!salt)
142 std::string stored_value; 153 LOG(FATAL) << "WallpaperManager HashWallpaperFilesIdStr(): no salt!";
143 if (user_manager::known_user::GetStringPref(account_id, kWallpaperFilesId, 154
144 &stored_value)) { 155 unsigned char binmd[base::kSHA1Length];
145 return wallpaper::WallpaperFilesId::FromString(stored_value); 156 std::string lowercase(files_id_unhashed);
146 } 157 std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(),
147 return wallpaper::WallpaperFilesId::FromString(user.username_hash()); 158 ::tolower);
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);
148 } 166 }
149 167
150 void SetKnownUserWallpaperFilesId( 168 void SetKnownUserWallpaperFilesId(
151 const AccountId& account_id, 169 const AccountId& account_id,
152 const wallpaper::WallpaperFilesId& wallpaper_files_id) { 170 const wallpaper::WallpaperFilesId& wallpaper_files_id) {
153 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, 171 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId,
154 wallpaper_files_id.id()); 172 wallpaper_files_id.id());
155 } 173 }
156 174
157 } // namespace 175 } // namespace
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = GetFilesId(account_id);
832 user_manager::UserManager::Get()->FindUser(account_id);
833 if (!user) {
834 NOTREACHED() << "Unknown user.";
835 return;
836 }
837 850
838 const wallpaper::WallpaperFilesId wallpaper_files_id = 851 if (!wallpaper_files_id.is_valid())
839 GetKnownUserWallpaperFilesId(*user); 852 LOG(FATAL) << "Wallpaper flies id if invalid!";
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);
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
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 {
1143 return GetKnownUserWallpaperFilesId(user); 1133 std::string stored_value;
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;
1144 } 1142 }
1145 1143
1146 } // namespace chromeos 1144 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698