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

Unified Diff: chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.cc

Issue 1748423005: Crop the user-specified profile image for WebUI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.cc
diff --git a/chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.cc b/chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.cc
index d702cabe9fe867553816bd5f33ca0e47a6a48e67..9d48c4d6ee4875274877a4d92a7a859fdee69e37 100644
--- a/chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.cc
+++ b/chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.cc
@@ -150,23 +150,27 @@ int ImageIndexToHistogramIndex(int image_index) {
bool SaveImage(const user_manager::UserImage& user_image,
const base::FilePath& image_path) {
- user_manager::UserImage safe_image;
- const user_manager::UserImage::Bytes* encoded_image = NULL;
+ // This should always be true, because of the following reasons:
+ //
+ // 1) Profile image from Google account -> UserImage is created with
+ // CreateAndEncode() that generates safe bytes representation.
+ // 2) Profile image from user-specified image -> The bytes representation
+ // is regenerated after the original image is decoded and cropped.
+ // 3) Profile image from policy (via OnExternalDataFetched()) -> JPEG is
+ // only allowed and ROBUST_JPEG_CODEC is used.
+ //
+ // However, check the value just in case because an unsafe image should
+ // never be saved.
if (!user_image.is_safe_format()) {
- safe_image = user_manager::UserImage::CreateAndEncode(user_image.image());
- encoded_image = &safe_image.image_bytes();
- UMA_HISTOGRAM_MEMORY_KB("UserImage.RecodedJpegSize", encoded_image->size());
- } else if (user_image.has_image_bytes()) {
- encoded_image = &user_image.image_bytes();
- } else {
- NOTREACHED() << "image data bytes missing.";
+ LOG(ERROR) << "User image is not in safe format";
return false;
}
- if (!encoded_image->size() ||
+ const user_manager::UserImage::Bytes& image_bytes = user_image.image_bytes();
+ if (image_bytes.empty() ||
base::WriteFile(image_path,
- reinterpret_cast<const char*>(&(*encoded_image)[0]),
- encoded_image->size()) == -1) {
+ reinterpret_cast<const char*>(image_bytes.data()),
+ image_bytes.size()) == -1) {
LOG(ERROR) << "Failed to save image to file.";
return false;
}
« no previous file with comments | « chrome/browser/chromeos/login/users/avatar/user_image_loader.cc ('k') | components/user_manager/user_image/user_image.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698