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

Side by Side 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: 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 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/avatar/user_image_manager_impl.h" 5 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 return default_user_image::kHistogramImageFromCamera; 157 return default_user_image::kHistogramImageFromCamera;
158 case user_manager::User::USER_IMAGE_PROFILE: 158 case user_manager::User::USER_IMAGE_PROFILE:
159 return default_user_image::kHistogramImageFromProfile; 159 return default_user_image::kHistogramImageFromProfile;
160 default: 160 default:
161 return image_index; 161 return image_index;
162 } 162 }
163 } 163 }
164 164
165 bool SaveImage(const user_manager::UserImage& user_image, 165 bool SaveImage(const user_manager::UserImage& user_image,
166 const base::FilePath& image_path) { 166 const base::FilePath& image_path) {
167 user_manager::UserImage safe_image; 167 // This should always be true, because of the following reasons:
168 const user_manager::UserImage::Bytes* encoded_image = NULL; 168 //
169 // 1) Profile image from Google account -> UserImage is created with
170 // CreateAndEncode() that generates safe bytes representation.
171 // 2) Profile image from user-specified image -> The bytes representation
172 // is regenerated after the original image is decoded and cropped.
173 // 3) Profile image from policy (via OnExternalDataFetched()) -> JPEG is
174 // only allowed and ROBUST_JPEG_CODEC is used.
175 DCHECK(user_image.is_safe_format());
hashimoto 2016/03/02 07:33:58 Instead of DCHECK, shouldn't we have LOG(ERROR) wh
satorux1 2016/03/02 08:23:51 Done.
176 // However, check the value just in case because an unsafe image should
177 // never be saved.
169 if (!user_image.is_safe_format()) { 178 if (!user_image.is_safe_format()) {
170 safe_image = user_manager::UserImage::CreateAndEncode(user_image.image());
171 encoded_image = &safe_image.image_bytes();
172 UMA_HISTOGRAM_MEMORY_KB("UserImage.RecodedJpegSize", encoded_image->size());
173 } else if (user_image.has_image_bytes()) {
174 encoded_image = &user_image.image_bytes();
175 } else {
176 NOTREACHED() << "image data bytes missing.";
177 return false; 179 return false;
178 } 180 }
179 181
180 if (!encoded_image->size() || 182 const user_manager::UserImage::Bytes& image_bytes = user_image.image_bytes();
183 if (!image_bytes.size() ||
hashimoto 2016/03/02 07:33:58 nit: image_bytes.empty()?
satorux1 2016/03/02 08:23:51 Done.
181 base::WriteFile(image_path, 184 base::WriteFile(image_path,
182 reinterpret_cast<const char*>(&(*encoded_image)[0]), 185 reinterpret_cast<const char*>(&image_bytes[0]),
hashimoto 2016/03/02 07:33:58 &image_bytes[0] -> image_bytes.data()? nit: I'm n
satorux1 2016/03/02 08:23:51 Done
183 encoded_image->size()) == -1) { 186 image_bytes.size()) == -1) {
184 LOG(ERROR) << "Failed to save image to file."; 187 LOG(ERROR) << "Failed to save image to file.";
185 return false; 188 return false;
186 } 189 }
187 190
188 return true; 191 return true;
189 } 192 }
190 193
191 } // namespace 194 } // namespace
192 195
193 // static 196 // static
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 } 1028 }
1026 1029
1027 bool UserImageManagerImpl::IsUserLoggedInAndHasGaiaAccount() const { 1030 bool UserImageManagerImpl::IsUserLoggedInAndHasGaiaAccount() const {
1028 const user_manager::User* user = GetUser(); 1031 const user_manager::User* user = GetUser();
1029 if (!user) 1032 if (!user)
1030 return false; 1033 return false;
1031 return user->is_logged_in() && user->HasGaiaAccount(); 1034 return user->is_logged_in() && user->HasGaiaAccount();
1032 } 1035 }
1033 1036
1034 } // namespace chromeos 1037 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698