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

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

Issue 2220433002: ChromeOS: fix crash in HashWallpaperFilesIdStr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: AddOnSystemSaltReady() should immediately run callback if system salt is ready. Created 4 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 | « no previous file | chromeos/cryptohome/system_salt_getter.h » ('j') | 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 <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/common/ash_constants.h" 12 #include "ash/common/ash_constants.h"
13 #include "ash/common/ash_switches.h" 13 #include "ash/common/ash_switches.h"
14 #include "ash/desktop_background/desktop_background_controller.h" 14 #include "ash/desktop_background/desktop_background_controller.h"
15 #include "ash/shell.h" 15 #include "ash/shell.h"
16 #include "ash/sysui/public/interfaces/wallpaper.mojom.h" 16 #include "ash/sysui/public/interfaces/wallpaper.mojom.h"
17 #include "base/bind.h" 17 #include "base/bind.h"
18 #include "base/bind_helpers.h"
18 #include "base/command_line.h" 19 #include "base/command_line.h"
19 #include "base/files/file_enumerator.h" 20 #include "base/files/file_enumerator.h"
20 #include "base/files/file_path.h" 21 #include "base/files/file_path.h"
21 #include "base/files/file_util.h" 22 #include "base/files/file_util.h"
22 #include "base/logging.h" 23 #include "base/logging.h"
23 #include "base/macros.h" 24 #include "base/macros.h"
24 #include "base/metrics/histogram.h" 25 #include "base/metrics/histogram.h"
25 #include "base/path_service.h" 26 #include "base/path_service.h"
26 #include "base/sha1.h" 27 #include "base/sha1.h"
27 #include "base/strings/string_number_conversions.h" 28 #include "base/strings/string_number_conversions.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 ::tolower); 164 ::tolower);
164 std::vector<uint8_t> data = *salt; 165 std::vector<uint8_t> data = *salt;
165 std::copy(files_id_unhashed.begin(), files_id_unhashed.end(), 166 std::copy(files_id_unhashed.begin(), files_id_unhashed.end(),
166 std::back_inserter(data)); 167 std::back_inserter(data));
167 base::SHA1HashBytes(data.data(), data.size(), binmd); 168 base::SHA1HashBytes(data.data(), data.size(), binmd);
168 std::string result = base::HexEncode(binmd, sizeof(binmd)); 169 std::string result = base::HexEncode(binmd, sizeof(binmd));
169 std::transform(result.begin(), result.end(), result.begin(), ::tolower); 170 std::transform(result.begin(), result.end(), result.begin(), ::tolower);
170 return wallpaper::WallpaperFilesId::FromString(result); 171 return wallpaper::WallpaperFilesId::FromString(result);
171 } 172 }
172 173
174 // Returns true if HashWallpaperFilesIdStr will not assert().
175 bool CanGetFilesId() {
176 return SystemSaltGetter::Get()->GetRawSalt();
177 }
178
179 // Call |closure| when HashWallpaperFilesIdStr will not assert().
180 void CallWhenCanGetFilesId(const base::Closure& closure) {
181 SystemSaltGetter::Get()->AddOnSystemSaltReady(closure);
182 }
183
173 void SetKnownUserWallpaperFilesId( 184 void SetKnownUserWallpaperFilesId(
174 const AccountId& account_id, 185 const AccountId& account_id,
175 const wallpaper::WallpaperFilesId& wallpaper_files_id) { 186 const wallpaper::WallpaperFilesId& wallpaper_files_id) {
176 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId, 187 user_manager::known_user::SetStringPref(account_id, kWallpaperFilesId,
177 wallpaper_files_id.id()); 188 wallpaper_files_id.id());
178 } 189 }
179 190
180 ash::sysui::mojom::WallpaperLayout WallpaperLayoutToMojo( 191 ash::sysui::mojom::WallpaperLayout WallpaperLayoutToMojo(
181 wallpaper::WallpaperLayout layout) { 192 wallpaper::WallpaperLayout layout) {
182 switch (layout) { 193 switch (layout) {
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 } 885 }
875 } 886 }
876 887
877 if (loading_.empty()) 888 if (loading_.empty())
878 FOR_EACH_OBSERVER(Observer, observers_, OnPendingListEmptyForTesting()); 889 FOR_EACH_OBSERVER(Observer, observers_, OnPendingListEmptyForTesting());
879 } 890 }
880 891
881 void WallpaperManager::SetPolicyControlledWallpaper( 892 void WallpaperManager::SetPolicyControlledWallpaper(
882 const AccountId& account_id, 893 const AccountId& account_id,
883 std::unique_ptr<user_manager::UserImage> user_image) { 894 std::unique_ptr<user_manager::UserImage> user_image) {
895 if (!CanGetFilesId()) {
896 CallWhenCanGetFilesId(
897 base::Bind(&WallpaperManager::SetPolicyControlledWallpaper,
898 weak_factory_.GetWeakPtr(), account_id,
899 base::Passed(std::move(user_image))));
900 return;
901 }
902
884 const wallpaper::WallpaperFilesId wallpaper_files_id = GetFilesId(account_id); 903 const wallpaper::WallpaperFilesId wallpaper_files_id = GetFilesId(account_id);
885 904
886 if (!wallpaper_files_id.is_valid()) 905 if (!wallpaper_files_id.is_valid())
887 LOG(FATAL) << "Wallpaper flies id if invalid!"; 906 LOG(FATAL) << "Wallpaper flies id if invalid!";
888 907
889 SetCustomWallpaper(account_id, wallpaper_files_id, "policy-controlled.jpeg", 908 SetCustomWallpaper(account_id, wallpaper_files_id, "policy-controlled.jpeg",
890 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED, 909 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED,
891 user_manager::User::POLICY, user_image->image(), 910 user_manager::User::POLICY, user_image->image(),
892 true /* update wallpaper */); 911 true /* update wallpaper */);
893 } 912 }
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 &stored_value)) { 1185 &stored_value)) {
1167 return wallpaper::WallpaperFilesId::FromString(stored_value); 1186 return wallpaper::WallpaperFilesId::FromString(stored_value);
1168 } 1187 }
1169 const std::string& old_id = account_id.GetUserEmail(); // Migrated 1188 const std::string& old_id = account_id.GetUserEmail(); // Migrated
1170 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id); 1189 const wallpaper::WallpaperFilesId files_id = HashWallpaperFilesIdStr(old_id);
1171 SetKnownUserWallpaperFilesId(account_id, files_id); 1190 SetKnownUserWallpaperFilesId(account_id, files_id);
1172 return files_id; 1191 return files_id;
1173 } 1192 }
1174 1193
1175 } // namespace chromeos 1194 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chromeos/cryptohome/system_salt_getter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698