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

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: just rebase 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 //
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()); 179 LOG(ERROR) << "User images is not in safe format";
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; 180 return false;
178 } 181 }
179 182
180 if (!encoded_image->size() || 183 const user_manager::UserImage::Bytes& image_bytes = user_image.image_bytes();
184 if (image_bytes.empty() ||
181 base::WriteFile(image_path, 185 base::WriteFile(image_path,
182 reinterpret_cast<const char*>(&(*encoded_image)[0]), 186 reinterpret_cast<const char*>(image_bytes.data()),
183 encoded_image->size()) == -1) { 187 image_bytes.size()) == -1) {
184 LOG(ERROR) << "Failed to save image to file."; 188 LOG(ERROR) << "Failed to save image to file.";
185 return false; 189 return false;
186 } 190 }
187 191
188 return true; 192 return true;
189 } 193 }
190 194
191 } // namespace 195 } // namespace
192 196
193 // static 197 // static
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 } 1029 }
1026 1030
1027 bool UserImageManagerImpl::IsUserLoggedInAndHasGaiaAccount() const { 1031 bool UserImageManagerImpl::IsUserLoggedInAndHasGaiaAccount() const {
1028 const user_manager::User* user = GetUser(); 1032 const user_manager::User* user = GetUser();
1029 if (!user) 1033 if (!user)
1030 return false; 1034 return false;
1031 return user->is_logged_in() && user->HasGaiaAccount(); 1035 return user->is_logged_in() && user->HasGaiaAccount();
1032 } 1036 }
1033 1037
1034 } // namespace chromeos 1038 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698