| Index: chrome/browser/image_decoder.cc
|
| diff --git a/chrome/browser/image_decoder.cc b/chrome/browser/image_decoder.cc
|
| index 2f9e83b7ab8953f41eb2d5a4bfc091e8f7e81ce7..82638381e858835dc4776a18312ce9f093aeefce 100644
|
| --- a/chrome/browser/image_decoder.cc
|
| +++ b/chrome/browser/image_decoder.cc
|
| @@ -6,9 +6,13 @@
|
|
|
| #include "base/bind.h"
|
| #include "chrome/browser/browser_process.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| #include "chrome/common/chrome_utility_messages.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/utility_process_host.h"
|
| +#include "content/public/common/service_registry.h"
|
| +#include "services/image_decoder/public/interfaces/image_decoder.mojom.h"
|
| +#include "skia/public/type_converters.h"
|
|
|
| using content::BrowserThread;
|
| using content::UtilityProcessHost;
|
| @@ -66,16 +70,56 @@ void ImageDecoder::OnDecodeImageFailed() {
|
| delegate_->OnDecodeImageFailed(this);
|
| }
|
|
|
| +void ImageDecoder::OnDecodeImageDone(bool success,
|
| + skia::ImagePtr image) {
|
| + LOG(INFO) << "ImageDecoder::OnDecodeImageDone: " << success;
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + if (delegate_) {
|
| + if (success && image) {
|
| + SkBitmap bitmap = image.To<SkBitmap>();
|
| + task_runner_->PostTask(FROM_HERE,
|
| + base::Bind(&ImageDecoder::OnDecodeImageSucceeded,
|
| + this,
|
| + bitmap));
|
| + } else {
|
| + task_runner_->PostTask(FROM_HERE,
|
| + base::Bind(&ImageDecoder::OnDecodeImageFailed,
|
| + this));
|
| + }
|
| + }
|
| + decoder_.reset();
|
| +}
|
| +
|
| void ImageDecoder::DecodeImageInSandbox(
|
| const std::vector<unsigned char>& image_data) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| UtilityProcessHost* utility_process_host;
|
| utility_process_host = UtilityProcessHost::Create(this, task_runner_.get());
|
| - if (image_codec_ == ROBUST_JPEG_CODEC) {
|
| - utility_process_host->Send(
|
| - new ChromeUtilityMsg_RobustJPEGDecodeImage(image_data));
|
| +
|
| + if (switches::MojoUtilityServicesEnabled()) {
|
| + LOG(INFO) << "ImageDecoder::DecodeImageInSandbox using Mojo";
|
| + if (!utility_process_host->StartMojoMode()) {
|
| + OnDecodeImageDone(false, nullptr);
|
| + return;
|
| + }
|
| + content::ServiceRegistry* service_registry =
|
| + utility_process_host->GetServiceRegistry();
|
| + service_registry->ConnectToRemoteService(&decoder_);
|
| +
|
| + decoder_->DecodeImage(mojo::Array<uint8_t>::From(image_data),
|
| + image_codec_ == ROBUST_JPEG_CODEC ?
|
| + services::image_decoder::IMAGE_CODEC_ROBUST_JPEG :
|
| + services::image_decoder::IMAGE_CODEC_DEFAULT,
|
| + shrink_to_fit_,
|
| + base::Bind(&ImageDecoder::OnDecodeImageDone, this));
|
| } else {
|
| - utility_process_host->Send(
|
| - new ChromeUtilityMsg_DecodeImage(image_data, shrink_to_fit_));
|
| + LOG(INFO) << "ImageDecoder::DecodeImageInSandbox using Chrome IPC";
|
| + if (image_codec_ == ROBUST_JPEG_CODEC) {
|
| + utility_process_host->Send(
|
| + new ChromeUtilityMsg_RobustJPEGDecodeImage(image_data));
|
| + } else {
|
| + utility_process_host->Send(
|
| + new ChromeUtilityMsg_DecodeImage(image_data, shrink_to_fit_));
|
| + }
|
| }
|
| }
|
|
|