| 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 "components/user_manager/user_image/user_image.h" | 5 #include "components/user_manager/user_image/user_image.h" |
| 6 | 6 |
| 7 #include "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
| 8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
| 9 #include "ui/gfx/codec/jpeg_codec.h" | 9 #include "ui/gfx/codec/jpeg_codec.h" |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 bitmap.height(), | 30 bitmap.height(), |
| 31 bitmap.width() * bitmap.bytesPerPixel(), | 31 bitmap.width() * bitmap.bytesPerPixel(), |
| 32 kDefaultEncodingQuality, output.get())) { | 32 kDefaultEncodingQuality, output.get())) { |
| 33 return output; | 33 return output; |
| 34 } else { | 34 } else { |
| 35 return nullptr; | 35 return nullptr; |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 // static | 39 // static |
| 40 UserImage UserImage::CreateAndEncode(const gfx::ImageSkia& image) { | 40 scoped_ptr<UserImage> UserImage::CreateAndEncode(const gfx::ImageSkia& image) { |
| 41 if (image.isNull()) | 41 if (image.isNull()) |
| 42 return UserImage(); | 42 return make_scoped_ptr(new UserImage); |
| 43 | 43 |
| 44 scoped_ptr<Bytes> image_bytes = Encode(*image.bitmap()); | 44 scoped_ptr<Bytes> image_bytes = Encode(*image.bitmap()); |
| 45 if (image_bytes) { | 45 if (image_bytes) { |
| 46 UserImage result(image, *image_bytes); | 46 // TODO(crbug.com/593251): Remove the data copy via |image_bytes|. |
| 47 result.MarkAsSafe(); | 47 scoped_ptr<UserImage> result(new UserImage(image, *image_bytes)); |
| 48 result->MarkAsSafe(); |
| 48 return result; | 49 return result; |
| 49 } | 50 } |
| 50 return UserImage(image); | 51 return make_scoped_ptr(new UserImage(image)); |
| 51 } | 52 } |
| 52 | 53 |
| 53 UserImage::UserImage() | 54 UserImage::UserImage() |
| 54 : has_image_bytes_(false), | 55 : has_image_bytes_(false), |
| 55 is_safe_format_(false) { | 56 is_safe_format_(false) { |
| 56 } | 57 } |
| 57 | 58 |
| 58 UserImage::UserImage(const gfx::ImageSkia& image) | 59 UserImage::UserImage(const gfx::ImageSkia& image) |
| 59 : image_(image), | 60 : image_(image), |
| 60 has_image_bytes_(false), | 61 has_image_bytes_(false), |
| 61 is_safe_format_(false) { | 62 is_safe_format_(false) { |
| 62 } | 63 } |
| 63 | 64 |
| 64 UserImage::UserImage(const gfx::ImageSkia& image, | 65 UserImage::UserImage(const gfx::ImageSkia& image, |
| 65 const Bytes& image_bytes) | 66 const Bytes& image_bytes) |
| 66 : image_(image), | 67 : image_(image), |
| 67 has_image_bytes_(false), | 68 has_image_bytes_(false), |
| 68 is_safe_format_(false) { | 69 is_safe_format_(false) { |
| 69 has_image_bytes_ = true; | 70 has_image_bytes_ = true; |
| 70 image_bytes_ = image_bytes; | 71 image_bytes_ = image_bytes; |
| 71 } | 72 } |
| 72 | 73 |
| 73 UserImage::~UserImage() {} | 74 UserImage::~UserImage() {} |
| 74 | 75 |
| 75 void UserImage::MarkAsSafe() { | 76 void UserImage::MarkAsSafe() { |
| 76 is_safe_format_ = true; | 77 is_safe_format_ = true; |
| 77 } | 78 } |
| 78 | 79 |
| 79 } // namespace user_manager | 80 } // namespace user_manager |
| OLD | NEW |