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

Unified Diff: chrome/utility/chrome_content_utility_client.cc

Issue 865543002: WIP: Browser image decoding using Mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup and add DecodeImageBase64. Created 5 years, 11 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
« no previous file with comments | « chrome/utility/chrome_content_utility_client.h ('k') | chrome/utility/extensions/extensions_handler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 25a744455b2a2a8978f1b0dc63202c2b09140588..1c0ca91f5997342cddd917a9e91f7c5a8974441b 100644
--- a/chrome/utility/chrome_content_utility_client.cc
+++ b/chrome/utility/chrome_content_utility_client.cc
@@ -9,12 +9,15 @@
#include "base/json/json_reader.h"
#include "base/memory/ref_counted.h"
#include "base/time/time.h"
+#include "content/child/child_process.h"
#include "chrome/common/chrome_utility_messages.h"
#include "chrome/common/safe_browsing/zip_analyzer.h"
#include "chrome/utility/chrome_content_utility_ipc_whitelist.h"
+#include "chrome/utility/image_decoder_impl.h"
#include "chrome/utility/utility_message_handler.h"
#include "content/public/child/image_decoder_utils.h"
#include "content/public/common/content_switches.h"
+#include "content/public/common/service_registry.h"
#include "content/public/utility/utility_thread.h"
#include "courgette/courgette.h"
#include "courgette/third_party/bsdiff.h"
@@ -129,9 +132,6 @@ bool ChromeContentUtilityClient::OnMessageReceived(
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message)
- IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage)
- IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage,
- OnRobustJPEGDecodeImage)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff,
OnPatchFileBsdiff)
@@ -160,6 +160,19 @@ bool ChromeContentUtilityClient::OnMessageReceived(
return handled;
}
+static void CreateImageDecoder(
+ mojo::InterfaceRequest<content::ImageDecoder> request) {
+ // TODO(amistry): Single process mode.
+ content::ChildProcess::current()->AddRefProcess();
+ mojo::BindToRequest(new content::ImageDecoderImpl, &request);
+}
+
+void ChromeContentUtilityClient::RegisterMojoServices(
+ content::ServiceRegistry* registry) {
+ registry->AddService<content::ImageDecoder>(base::Bind(
+ CreateImageDecoder));
+}
+
// static
void ChromeContentUtilityClient::PreSandboxStartup() {
#if defined(ENABLE_EXTENSIONS)
@@ -178,56 +191,6 @@ void ChromeContentUtilityClient::PreSandboxStartup() {
#endif // ENABLE_MDNS
}
-// static
-SkBitmap ChromeContentUtilityClient::DecodeImage(
- const std::vector<unsigned char>& encoded_data, bool shrink_to_fit) {
- SkBitmap 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){
- SkBitmap decoded_image = DecodeImage(encoded_data, shrink_to_fit);
-
- if (decoded_image.empty()) {
- Send(new ChromeUtilityHostMsg_DecodeImage_Failed());
- } else {
- Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(decoded_image));
- }
- ReleaseProcessIfNeeded();
-}
-
-void ChromeContentUtilityClient::OnDecodeImage(
- const std::vector<unsigned char>& encoded_data, bool shrink_to_fit) {
- DecodeImageAndSend(encoded_data, shrink_to_fit);
-}
-
#if defined(OS_CHROMEOS)
void ChromeContentUtilityClient::OnCreateZipFile(
const base::FilePath& src_dir,
@@ -260,24 +223,6 @@ void ChromeContentUtilityClient::OnCreateZipFile(
}
#endif // defined(OS_CHROMEOS)
-void ChromeContentUtilityClient::OnRobustJPEGDecodeImage(
- const std::vector<unsigned char>& encoded_data) {
- // Our robust jpeg decoding is using IJG libjpeg.
- if (gfx::JPEGCodec::JpegLibraryVariant() == gfx::JPEGCodec::IJG_LIBJPEG &&
- !encoded_data.empty()) {
- scoped_ptr<SkBitmap> decoded_image(gfx::JPEGCodec::Decode(
- &encoded_data[0], encoded_data.size()));
- if (!decoded_image.get() || decoded_image->empty()) {
- Send(new ChromeUtilityHostMsg_DecodeImage_Failed());
- } else {
- Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(*decoded_image));
- }
- } else {
- Send(new ChromeUtilityHostMsg_DecodeImage_Failed());
- }
- ReleaseProcessIfNeeded();
-}
-
void ChromeContentUtilityClient::OnParseJSON(const std::string& json) {
int error_code;
std::string error;
« no previous file with comments | « chrome/utility/chrome_content_utility_client.h ('k') | chrome/utility/extensions/extensions_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698