Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 return default_user_image::kHistogramImageFromCamera; | 143 return default_user_image::kHistogramImageFromCamera; |
| 144 case user_manager::User::USER_IMAGE_PROFILE: | 144 case user_manager::User::USER_IMAGE_PROFILE: |
| 145 return default_user_image::kHistogramImageFromProfile; | 145 return default_user_image::kHistogramImageFromProfile; |
| 146 default: | 146 default: |
| 147 return image_index; | 147 return image_index; |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 | 150 |
| 151 bool SaveImage(const user_manager::UserImage& user_image, | 151 bool SaveImage(const user_manager::UserImage& user_image, |
| 152 const base::FilePath& image_path) { | 152 const base::FilePath& image_path) { |
| 153 user_manager::UserImage safe_image; | 153 // This should always be true, because of the following reasons: |
| 154 const user_manager::UserImage::Bytes* encoded_image = NULL; | 154 // |
| 155 // 1) Profile image from Google account -> UserImage is created with | |
| 156 // CreateAndEncode() that generates safe bytes representation. | |
| 157 // 2) Profile image from user-specified image -> The bytes representation | |
| 158 // is regenerated after the original image is decoded and cropped. | |
| 159 // 3) Profile image from policy (via OnExternalDataFetched()) -> JPEG is | |
| 160 // only allowed and ROBUST_JPEG_CODEC is used. | |
| 161 // | |
| 162 // However, check the value just in case because an unsafe image should | |
| 163 // never be saved. | |
| 155 if (!user_image.is_safe_format()) { | 164 if (!user_image.is_safe_format()) { |
| 156 safe_image = user_manager::UserImage::CreateAndEncode(user_image.image()); | 165 LOG(ERROR) << "User images is not in safe format"; |
|
achuithb
2016/03/10 23:02:10
User image is not in a safe format
satorux1
2016/03/11 02:03:37
Good catch. Done.
| |
| 157 encoded_image = &safe_image.image_bytes(); | |
| 158 UMA_HISTOGRAM_MEMORY_KB("UserImage.RecodedJpegSize", encoded_image->size()); | |
| 159 } else if (user_image.has_image_bytes()) { | |
| 160 encoded_image = &user_image.image_bytes(); | |
| 161 } else { | |
| 162 NOTREACHED() << "image data bytes missing."; | |
| 163 return false; | 166 return false; |
| 164 } | 167 } |
| 165 | 168 |
| 166 if (!encoded_image->size() || | 169 const user_manager::UserImage::Bytes& image_bytes = user_image.image_bytes(); |
| 170 if (image_bytes.empty() || | |
| 167 base::WriteFile(image_path, | 171 base::WriteFile(image_path, |
| 168 reinterpret_cast<const char*>(&(*encoded_image)[0]), | 172 reinterpret_cast<const char*>(image_bytes.data()), |
|
achuithb
2016/03/10 23:02:10
is reinterpret_cast still necessary? Or does unsig
satorux1
2016/03/11 02:03:37
It's needed. Otherwise we'll get
../../chrome/bro
| |
| 169 encoded_image->size()) == -1) { | 173 image_bytes.size()) == -1) { |
| 170 LOG(ERROR) << "Failed to save image to file."; | 174 LOG(ERROR) << "Failed to save image to file."; |
| 171 return false; | 175 return false; |
| 172 } | 176 } |
| 173 | 177 |
| 174 return true; | 178 return true; |
| 175 } | 179 } |
| 176 | 180 |
| 177 } // namespace | 181 } // namespace |
| 178 | 182 |
| 179 const char UserImageManagerImpl::kUserImageProperties[] = "user_image_info"; | 183 const char UserImageManagerImpl::kUserImageProperties[] = "user_image_info"; |
| (...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 929 } | 933 } |
| 930 | 934 |
| 931 bool UserImageManagerImpl::IsUserLoggedInAndHasGaiaAccount() const { | 935 bool UserImageManagerImpl::IsUserLoggedInAndHasGaiaAccount() const { |
| 932 const user_manager::User* user = GetUser(); | 936 const user_manager::User* user = GetUser(); |
| 933 if (!user) | 937 if (!user) |
| 934 return false; | 938 return false; |
| 935 return user->is_logged_in() && user->HasGaiaAccount(); | 939 return user->is_logged_in() && user->HasGaiaAccount(); |
| 936 } | 940 } |
| 937 | 941 |
| 938 } // namespace chromeos | 942 } // namespace chromeos |
| OLD | NEW |