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 "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 scoped_ptr<UserImage> result(new UserImage(image, *image_bytes)); |
|
hashimoto
2016/03/15 08:39:27
This line still copies image bytes.
satorux1
2016/03/16 02:01:30
Added a TODO comment.
| |
| 47 result.MarkAsSafe(); | 47 result->MarkAsSafe(); |
| 48 return result; | 48 return result; |
| 49 } | 49 } |
| 50 return UserImage(image); | 50 return make_scoped_ptr(new UserImage(image)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 UserImage::UserImage() | 53 UserImage::UserImage() |
| 54 : has_image_bytes_(false), | 54 : has_image_bytes_(false), |
| 55 is_safe_format_(false) { | 55 is_safe_format_(false) { |
| 56 } | 56 } |
| 57 | 57 |
| 58 UserImage::UserImage(const gfx::ImageSkia& image) | 58 UserImage::UserImage(const gfx::ImageSkia& image) |
| 59 : image_(image), | 59 : image_(image), |
| 60 has_image_bytes_(false), | 60 has_image_bytes_(false), |
| 61 is_safe_format_(false) { | 61 is_safe_format_(false) { |
| 62 } | 62 } |
| 63 | 63 |
| 64 UserImage::UserImage(const gfx::ImageSkia& image, | 64 UserImage::UserImage(const gfx::ImageSkia& image, |
| 65 const Bytes& image_bytes) | 65 const Bytes& image_bytes) |
| 66 : image_(image), | 66 : image_(image), |
| 67 has_image_bytes_(false), | 67 has_image_bytes_(false), |
| 68 is_safe_format_(false) { | 68 is_safe_format_(false) { |
| 69 has_image_bytes_ = true; | 69 has_image_bytes_ = true; |
| 70 image_bytes_ = image_bytes; | 70 image_bytes_ = image_bytes; |
| 71 } | 71 } |
| 72 | 72 |
| 73 UserImage::~UserImage() {} | 73 UserImage::~UserImage() {} |
| 74 | 74 |
| 75 void UserImage::MarkAsSafe() { | 75 void UserImage::MarkAsSafe() { |
| 76 is_safe_format_ = true; | 76 is_safe_format_ = true; |
| 77 } | 77 } |
| 78 | 78 |
| 79 } // namespace user_manager | 79 } // namespace user_manager |
| OLD | NEW |