| Index: chrome/browser/image_decoder.cc
|
| diff --git a/chrome/browser/image_decoder.cc b/chrome/browser/image_decoder.cc
|
| index c3973a5ac843fbe3709120efc63cf9935bbbb710..3dba8ea2e2f50295ab00a90df0ce5bbb12af6290 100644
|
| --- a/chrome/browser/image_decoder.cc
|
| +++ b/chrome/browser/image_decoder.cc
|
| @@ -5,12 +5,17 @@
|
| #include "chrome/browser/image_decoder.h"
|
|
|
| #include "base/bind.h"
|
| +#include "base/callback.h"
|
| #include "base/thread_task_runner_handle.h"
|
| #include "chrome/browser/browser_process.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| #include "chrome/common/chrome_utility_messages.h"
|
| #include "chrome/grit/generated_resources.h"
|
| +#include "components/image_decoder/public/interfaces/image_decoder.mojom.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/utility_process_host.h"
|
| +#include "content/public/common/service_registry.h"
|
| +#include "skia/public/type_converters.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
|
|
| using content::BrowserThread;
|
| @@ -25,6 +30,21 @@ base::LazyInstance<ImageDecoder>::Leaky g_decoder = LAZY_INSTANCE_INITIALIZER;
|
| // batch mode.
|
| const int kBatchModeTimeoutSeconds = 5;
|
|
|
| +void OnDecodeImageDone(
|
| + base::Callback<void(int)> fail_callback,
|
| + base::Callback<void(const SkBitmap&, int)> success_callback,
|
| + int request_id, skia::BitmapPtr image) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + if (image) {
|
| + SkBitmap bitmap = image->To<SkBitmap>();
|
| + if (!bitmap.empty()) {
|
| + success_callback.Run(bitmap, request_id);
|
| + return;
|
| + }
|
| + }
|
| + fail_callback.Run(request_id);
|
| +}
|
| +
|
| } // namespace
|
|
|
| ImageDecoder::ImageDecoder()
|
| @@ -133,15 +153,28 @@ void ImageDecoder::DecodeImageInSandbox(
|
| }
|
| batch_mode_timer_->Reset();
|
|
|
| - switch (image_codec) {
|
| - case ROBUST_JPEG_CODEC:
|
| - utility_process_host_->Send(new ChromeUtilityMsg_RobustJPEGDecodeImage(
|
| - image_data, request_id));
|
| - break;
|
| - case DEFAULT_CODEC:
|
| - utility_process_host_->Send(new ChromeUtilityMsg_DecodeImage(
|
| - image_data, shrink_to_fit, request_id));
|
| - break;
|
| + if (switches::MojoUtilityServicesEnabled()) {
|
| + (*decoder_)->DecodeImage(
|
| + mojo::Array<uint8_t>::From(image_data),
|
| + image_codec == ROBUST_JPEG_CODEC
|
| + ? image_decoder::IMAGE_CODEC_ROBUST_JPEG
|
| + : image_decoder::IMAGE_CODEC_DEFAULT,
|
| + shrink_to_fit,
|
| + base::Bind(&OnDecodeImageDone,
|
| + base::Bind(&ImageDecoder::OnDecodeImageFailed, this),
|
| + base::Bind(&ImageDecoder::OnDecodeImageSucceeded, this),
|
| + request_id));
|
| + } else {
|
| + switch (image_codec) {
|
| + case ROBUST_JPEG_CODEC:
|
| + utility_process_host_->Send(
|
| + new ChromeUtilityMsg_RobustJPEGDecodeImage(image_data, request_id));
|
| + break;
|
| + case DEFAULT_CODEC:
|
| + utility_process_host_->Send(new ChromeUtilityMsg_DecodeImage(
|
| + image_data, shrink_to_fit, request_id));
|
| + break;
|
| + }
|
| }
|
| }
|
|
|
| @@ -164,16 +197,34 @@ void ImageDecoder::StartBatchMode() {
|
| ->AsWeakPtr();
|
| utility_process_host_->SetName(l10n_util::GetStringUTF16(
|
| IDS_UTILITY_PROCESS_IMAGE_DECODER_NAME));
|
| - if (!utility_process_host_->StartBatchMode()) {
|
| - utility_process_host_.reset();
|
| - return;
|
| + if (switches::MojoUtilityServicesEnabled()) {
|
| + decoder_.reset(new image_decoder::ImageDecoderPtr);
|
| + if (!utility_process_host_->StartMojoMode()) {
|
| + utility_process_host_.reset();
|
| + return;
|
| + }
|
| + content::ServiceRegistry* service_registry =
|
| + utility_process_host_->GetServiceRegistry();
|
| + service_registry->ConnectToRemoteService(decoder_.get());
|
| + } else {
|
| + if (!utility_process_host_->StartBatchMode()) {
|
| + utility_process_host_.reset();
|
| + return;
|
| + }
|
| }
|
| }
|
|
|
| void ImageDecoder::StopBatchMode() {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| if (utility_process_host_) {
|
| - utility_process_host_->EndBatchMode();
|
| + if (switches::MojoUtilityServicesEnabled()) {
|
| + // In Mojo, the utility process needs to be explicitly shut down by
|
| + // deleting the host.
|
| + delete utility_process_host_.get();
|
| + decoder_.reset();
|
| + } else {
|
| + utility_process_host_->EndBatchMode();
|
| + }
|
| utility_process_host_.reset();
|
| }
|
|
|
|
|