Chromium Code Reviews| Index: chrome/browser/image_decoder.cc |
| diff --git a/chrome/browser/image_decoder.cc b/chrome/browser/image_decoder.cc |
| index 2f9e83b7ab8953f41eb2d5a4bfc091e8f7e81ce7..f04e34650d3fd3739320556f6d99e4c712f3db0c 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,58 @@ void ImageDecoder::OnDecodeImageFailed() { |
| delegate_->OnDecodeImageFailed(this); |
| } |
| +void ImageDecoder::OnDecodeImageDone(bool success, skia::BitmapPtr image) { |
|
sky
2015/04/01 15:00:45
Order doesn't match header.
Anand Mistry (off Chromium)
2015/04/02 04:29:45
You mean ordering of functions? Fixed that.
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + decoder_.reset(); |
| + if (delegate_ && success && image) { |
| + SkBitmap bitmap = image.To<SkBitmap>(); |
| + if (!bitmap.empty()) { |
| + task_runner_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&ImageDecoder::OnDecodeImageSucceeded, this, bitmap)); |
| + return; |
| + } |
| + } |
| + task_runner_->PostTask(FROM_HERE, |
| + base::Bind(&ImageDecoder::OnDecodeImageFailed, this)); |
| +} |
| + |
| +void ImageDecoder::OnConnectionError() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + // Destroys the local Mojo endpoint, which releases Mojo's references to this |
| + // object from the DecodeImage callback. Also, we need to make sure this is |
| + // destroyed on the IO thread since Mojo is thread-hostile. |
| + 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()) { |
| + if (!utility_process_host->StartMojoMode()) { |
| + OnDecodeImageDone(false, nullptr); |
| + return; |
| + } |
| + content::ServiceRegistry* service_registry = |
| + utility_process_host->GetServiceRegistry(); |
| + service_registry->ConnectToRemoteService(&decoder_); |
| + decoder_.set_error_handler(this); |
| + |
| + decoder_->DecodeImage( |
| + mojo::Array<uint8_t>::From(image_data), |
| + image_codec_ == ROBUST_JPEG_CODEC ? services::IMAGE_CODEC_ROBUST_JPEG |
| + : services::IMAGE_CODEC_DEFAULT, |
| + shrink_to_fit_, base::Bind(&ImageDecoder::OnDecodeImageDone, this)); |
| } else { |
| - utility_process_host->Send( |
| - new ChromeUtilityMsg_DecodeImage(image_data, shrink_to_fit_)); |
| + 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_)); |
| + } |
| } |
| } |