summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorsatorux <satorux@chromium.org>2016-03-10 21:13:04 -0800
committerCommit bot <commit-bot@chromium.org>2016-03-11 05:14:44 +0000
commit5820ae933247dc363ba3ae51220acd64ba3488b0 (patch)
treef8030a8e614e48293b59e3fd0d96aaf851fc18ad /components
parentdbdf20c9eec45a535156daf94b94db89ace868f5 (diff)
downloadchromium_src-5820ae933247dc363ba3ae51220acd64ba3488b0.zip
chromium_src-5820ae933247dc363ba3ae51220acd64ba3488b0.tar.gz
chromium_src-5820ae933247dc363ba3ae51220acd64ba3488b0.tar.bz2
Crop the user-specified profile image for WebUI
This patch fixes a bug where the user-specified profile image wasn't cropped for WebUI thus the image was displayed weirdly in the lock screen and the settings. The root cause of the problem was that the original image data bytes (not cropped, and can be big) were used for WebUI. Along the way, get rid of UserImage.RecodedJpegSize UMA because it's not defined in tools/metrics/histograms/histograms.xml BUG=590630 TEST=follow steps in the bug Review URL: https://codereview.chromium.org/1748423005 Cr-Commit-Position: refs/heads/master@{#380512}
Diffstat (limited to 'components')
-rw-r--r--components/user_manager/user_image/user_image.cc45
-rw-r--r--components/user_manager/user_image/user_image.h4
2 files changed, 29 insertions, 20 deletions
diff --git a/components/user_manager/user_image/user_image.cc b/components/user_manager/user_image/user_image.cc
index af37983..10cd448 100644
--- a/components/user_manager/user_image/user_image.cc
+++ b/components/user_manager/user_image/user_image.cc
@@ -15,30 +15,35 @@ namespace {
// Default quality for encoding user images.
const int kDefaultEncodingQuality = 90;
-bool EncodeImageSkia(const gfx::ImageSkia& image,
- UserImage::Bytes* output) {
- TRACE_EVENT2("oobe", "EncodeImageSkia",
- "width", image.width(), "height", image.height());
- if (image.isNull())
- return false;
- const SkBitmap& bitmap = *image.bitmap();
- SkAutoLockPixels lock_image(bitmap);
- return 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);
-}
-
} // namespace
// static
+scoped_ptr<UserImage::Bytes> UserImage::Encode(const SkBitmap& bitmap) {
+ TRACE_EVENT2("oobe", "UserImage::Encode",
+ "width", bitmap.width(), "height", bitmap.height());
+ SkAutoLockPixels lock_bitmap(bitmap);
+ scoped_ptr<Bytes> output(new Bytes);
+ 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;
+ } else {
+ return nullptr;
+ }
+}
+
+// static
UserImage UserImage::CreateAndEncode(const gfx::ImageSkia& image) {
- Bytes image_bytes;
- if (EncodeImageSkia(image, &image_bytes)) {
- UserImage result(image, image_bytes);
+ if (image.isNull())
+ return UserImage();
+
+ scoped_ptr<Bytes> image_bytes = Encode(*image.bitmap());
+ if (image_bytes) {
+ UserImage result(image, *image_bytes);
result.MarkAsSafe();
return result;
}
diff --git a/components/user_manager/user_image/user_image.h b/components/user_manager/user_image/user_image.h
index 6397096..d6621be 100644
--- a/components/user_manager/user_image/user_image.h
+++ b/components/user_manager/user_image/user_image.h
@@ -24,6 +24,10 @@ class USER_MANAGER_EXPORT UserImage {
// TODO(ivankr): replace with RefCountedMemory to prevent copying.
typedef std::vector<unsigned char> Bytes;
+ // Encodes the given bitmap to bytes representation for WebUI. Returns null
+ // on failure.
+ static scoped_ptr<Bytes> Encode(const SkBitmap& bitmap);
+
// Creates a new instance from a given still frame and tries to encode it
// to bytes representation for WebUI.
// TODO(ivankr): remove eventually.