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

Unified Diff: components/user_manager/user_image/user_image.cc

Issue 2517053004: Use base::RefCountedBytes in user_manager::UserImage (Closed)
Patch Set: Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: components/user_manager/user_image/user_image.cc
diff --git a/components/user_manager/user_image/user_image.cc b/components/user_manager/user_image/user_image.cc
index c06c847405f5d0f7f15215edea62cf0519c75a9a..8a7f4143fde82e1e96ab932cc85315e780b5c866 100644
--- a/components/user_manager/user_image/user_image.cc
+++ b/components/user_manager/user_image/user_image.cc
@@ -19,19 +19,20 @@ const int kDefaultEncodingQuality = 90;
} // namespace
// static
-std::unique_ptr<UserImage::Bytes> UserImage::Encode(const SkBitmap& bitmap) {
+scoped_refptr<base::RefCountedBytes> UserImage::Encode(
+ const SkBitmap& bitmap) {
TRACE_EVENT2("oobe", "UserImage::Encode",
"width", bitmap.width(), "height", bitmap.height());
SkAutoLockPixels lock_bitmap(bitmap);
- std::unique_ptr<Bytes> output(new Bytes);
+ std::vector<unsigned char> output;
if (gfx::JPEGCodec::Encode(
reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)),
gfx::JPEGCodec::FORMAT_SkBitmap,
bitmap.width(),
bitmap.height(),
bitmap.width() * bitmap.bytesPerPixel(),
- kDefaultEncodingQuality, output.get())) {
- return output;
+ kDefaultEncodingQuality, &output)) {
+ return base::RefCountedBytes::TakeVector(&output);
} else {
return nullptr;
}
@@ -43,10 +44,9 @@ std::unique_ptr<UserImage> UserImage::CreateAndEncode(
if (image.isNull())
return base::WrapUnique(new UserImage);
- std::unique_ptr<Bytes> image_bytes = Encode(*image.bitmap());
+ scoped_refptr<base::RefCountedBytes> image_bytes = Encode(*image.bitmap());
if (image_bytes) {
- // TODO(crbug.com/593251): Remove the data copy via |image_bytes|.
- std::unique_ptr<UserImage> result(new UserImage(image, *image_bytes));
+ std::unique_ptr<UserImage> result(new UserImage(image, image_bytes));
result->MarkAsSafe();
return result;
}
@@ -54,23 +54,19 @@ std::unique_ptr<UserImage> UserImage::CreateAndEncode(
}
UserImage::UserImage()
- : has_image_bytes_(false),
- is_safe_format_(false) {
+ : is_safe_format_(false) {
achuithb 2016/11/22 21:16:54 Move this to header since you're here?
satorux1 2016/11/24 02:13:40 Maybe it's short enough to be in .h file, but I'd
achuithb 2016/11/28 09:01:10 Maybe there's a misunderstanding - I meant the var
satorux1 2016/11/28 23:09:16 My bad. Didn't know about the c++11 guideline. Fix
}
UserImage::UserImage(const gfx::ImageSkia& image)
: image_(image),
- has_image_bytes_(false),
is_safe_format_(false) {
}
UserImage::UserImage(const gfx::ImageSkia& image,
- const Bytes& image_bytes)
+ scoped_refptr<base::RefCountedBytes> image_bytes)
: image_(image),
- has_image_bytes_(false),
+ image_bytes_(image_bytes),
is_safe_format_(false) {
achuithb 2016/11/22 21:16:54 ditto
satorux1 2016/11/24 02:13:40 ditto
- has_image_bytes_ = true;
- image_bytes_ = image_bytes;
}
UserImage::~UserImage() {}

Powered by Google App Engine
This is Rietveld 408576698