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

Unified Diff: chrome/utility/chrome_content_utility_client.cc

Issue 1844103004: Convert the utility process image decoder into a Mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 8 months 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: chrome/utility/chrome_content_utility_client.cc
diff --git a/chrome/utility/chrome_content_utility_client.cc b/chrome/utility/chrome_content_utility_client.cc
index e7f7ac2098be7a38265617dbefbac450528b94fc..7465af01959246f36c36d3360e62185c266f2458 100644
--- a/chrome/utility/chrome_content_utility_client.cc
+++ b/chrome/utility/chrome_content_utility_client.cc
@@ -16,6 +16,7 @@
#include "chrome/common/safe_browsing/zip_analyzer.h"
#include "chrome/common/safe_browsing/zip_analyzer_results.h"
#include "chrome/utility/chrome_content_utility_ipc_whitelist.h"
+#include "chrome/utility/image_decoder_impl.h"
#include "chrome/utility/safe_json_parser_handler.h"
#include "chrome/utility/utility_message_handler.h"
#include "content/public/child/image_decoder_utils.h"
@@ -25,16 +26,9 @@
#include "courgette/courgette.h"
#include "courgette/third_party/bsdiff.h"
#include "ipc/ipc_channel.h"
-#include "skia/ext/image_operations.h"
-#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/zlib/google/zip.h"
#include "ui/gfx/geometry/size.h"
-#if defined(OS_CHROMEOS)
-#include "ui/gfx/chromeos/codec/jpeg_codec_robust_slow.h"
-#include "ui/gfx/codec/png_codec.h"
-#endif
-
#if !defined(OS_ANDROID)
#include "chrome/common/resource_usage_reporter.mojom.h"
#include "chrome/utility/profile_import_handler.h"
@@ -109,10 +103,12 @@ void CreateResourceUsageReporter(
}
#endif // OS_ANDROID
-} // namespace
+void CreateImageDecoder(mojo::InterfaceRequest<mojom::ImageDecoder> request) {
+ content::UtilityThread::Get()->EnsureBlinkInitialized();
+ new ImageDecoderImpl(std::move(request));
+}
-int64_t ChromeContentUtilityClient::max_ipc_message_size_ =
- IPC::Channel::kMaximumMessageSize;
+} // namespace
ChromeContentUtilityClient::ChromeContentUtilityClient()
: filter_messages_(false) {
@@ -161,13 +157,6 @@ bool ChromeContentUtilityClient::OnMessageReceived(
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message)
- IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage)
-#if defined(OS_CHROMEOS)
- IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage,
- OnRobustJPEGDecodeImage)
- IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustPNGDecodeImage,
- OnRobustPNGDecodeImage)
-#endif // defined(OS_CHROMEOS)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff,
OnPatchFileBsdiff)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileCourgette,
@@ -212,6 +201,7 @@ void ChromeContentUtilityClient::RegisterMojoServices(
registry->AddService<ResourceUsageReporter>(
base::Bind(CreateResourceUsageReporter));
#endif
+ registry->AddService(base::Bind(&CreateImageDecoder));
}
void ChromeContentUtilityClient::AddHandler(
@@ -226,66 +216,6 @@ void ChromeContentUtilityClient::PreSandboxStartup() {
#endif
}
-// static
-SkBitmap ChromeContentUtilityClient::DecodeImage(
- const std::vector<unsigned char>& encoded_data, bool shrink_to_fit) {
- SkBitmap decoded_image;
- if (encoded_data.empty())
- return decoded_image;
-
- decoded_image = content::DecodeImage(&encoded_data[0],
- gfx::Size(),
- encoded_data.size());
-
- int64_t struct_size = sizeof(ChromeUtilityHostMsg_DecodeImage_Succeeded);
- int64_t image_size = decoded_image.computeSize64();
- int halves = 0;
- while (struct_size + (image_size >> 2*halves) > max_ipc_message_size_)
- halves++;
- if (halves) {
- if (shrink_to_fit) {
- // If decoded image is too large for IPC message, shrink it by halves.
- // This prevents quality loss, and should never overshrink on displays
- // smaller than 3600x2400.
- // TODO (Issue 416916): Instead of shrinking, return via shared memory
- decoded_image = skia::ImageOperations::Resize(
- decoded_image, skia::ImageOperations::RESIZE_LANCZOS3,
- decoded_image.width() >> halves, decoded_image.height() >> halves);
- } else {
- // Image too big for IPC message, but caller didn't request resize;
- // pre-delete image so DecodeImageAndSend() will send an error.
- decoded_image.reset();
- LOG(ERROR) << "Decoded image too large for IPC message";
- }
- }
-
- return decoded_image;
-}
-
-// static
-void ChromeContentUtilityClient::DecodeImageAndSend(
- const std::vector<unsigned char>& encoded_data,
- bool shrink_to_fit,
- int request_id) {
- SkBitmap decoded_image = DecodeImage(encoded_data, shrink_to_fit);
-
- if (decoded_image.empty()) {
- Send(new ChromeUtilityHostMsg_DecodeImage_Failed(request_id));
- } else {
- Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(decoded_image,
- request_id));
- }
- ReleaseProcessIfNeeded();
-}
-
-void ChromeContentUtilityClient::OnDecodeImage(
- const std::vector<unsigned char>& encoded_data,
- bool shrink_to_fit,
- int request_id) {
- content::UtilityThread::Get()->EnsureBlinkInitialized();
- DecodeImageAndSend(encoded_data, shrink_to_fit, request_id);
-}
-
#if defined(OS_CHROMEOS)
void ChromeContentUtilityClient::OnCreateZipFile(
const base::FilePath& src_dir,
@@ -318,47 +248,6 @@ void ChromeContentUtilityClient::OnCreateZipFile(
}
#endif // defined(OS_CHROMEOS)
-#if defined(OS_CHROMEOS)
-void ChromeContentUtilityClient::OnRobustJPEGDecodeImage(
- const std::vector<unsigned char>& encoded_data,
- int request_id) {
- // Our robust jpeg decoding is using IJG libjpeg.
- if (!encoded_data.empty()) {
- scoped_ptr<SkBitmap> decoded_image(gfx::JPEGCodecRobustSlow::Decode(
- &encoded_data[0], encoded_data.size()));
- if (!decoded_image.get() || decoded_image->empty()) {
- Send(new ChromeUtilityHostMsg_DecodeImage_Failed(request_id));
- } else {
- Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(*decoded_image,
- request_id));
- }
- } else {
- Send(new ChromeUtilityHostMsg_DecodeImage_Failed(request_id));
- }
- ReleaseProcessIfNeeded();
-}
-
-void ChromeContentUtilityClient::OnRobustPNGDecodeImage(
- const std::vector<unsigned char>& encoded_data,
- int request_id) {
- // Our robust PNG decoding is using libpng.
- if (!encoded_data.empty()) {
- SkBitmap decoded_image;
- if (gfx::PNGCodec::Decode(encoded_data.data(),
- encoded_data.size(),
- &decoded_image)) {
- Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(decoded_image,
- request_id));
- } else {
- Send(new ChromeUtilityHostMsg_DecodeImage_Failed(request_id));
- }
- } else {
- Send(new ChromeUtilityHostMsg_DecodeImage_Failed(request_id));
- }
- ReleaseProcessIfNeeded();
-}
-#endif // defined(OS_CHROMEOS)
-
void ChromeContentUtilityClient::OnPatchFileBsdiff(
const base::FilePath& input_file,
const base::FilePath& patch_file,
« no previous file with comments | « chrome/utility/chrome_content_utility_client.h ('k') | chrome/utility/chrome_content_utility_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698