Index: chrome/browser/image_decoder.cc |
diff --git a/chrome/browser/image_decoder.cc b/chrome/browser/image_decoder.cc |
index 8c9fb605304a7427472a003b2f9cc2d5184424a9..f77a8c61b0ddbd93deab1b0c713bba74d15a4734 100644 |
--- a/chrome/browser/image_decoder.cc |
+++ b/chrome/browser/image_decoder.cc |
@@ -8,9 +8,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; |
@@ -215,15 +219,26 @@ void ImageDecoder::DecodeImageInSandbox( |
it->second->SetStarted(); |
} |
- 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 ? |
+ services::IMAGE_CODEC_ROBUST_JPEG : |
+ services::IMAGE_CODEC_DEFAULT, |
+ shrink_to_fit, |
+ base::Bind(&ImageDecoder::OnDecodeImageDone, |
+ 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; |
+ } |
} |
} |
@@ -252,9 +267,20 @@ void ImageDecoder::StartBatchMode() { |
utility_process_host_ = |
UtilityProcessHost::Create(this, base::MessageLoopProxy::current().get()) |
->AsWeakPtr(); |
- if (!utility_process_host_->StartBatchMode()) { |
- utility_process_host_.reset(); |
- return; |
+ if (switches::MojoUtilityServicesEnabled()) { |
+ decoder_.reset(); |
+ if (!utility_process_host_->StartMojoMode()) { |
+ utility_process_host_.reset(); |
Sam McNally
2015/04/08 08:09:00
3 space indent?
Anand Mistry (off Chromium)
2015/04/09 05:25:03
Done.
|
+ return; |
+ } |
+ content::ServiceRegistry* service_registry = |
+ utility_process_host_->GetServiceRegistry(); |
+ service_registry->ConnectToRemoteService(&decoder_); |
+ } else { |
+ if (!utility_process_host_->StartBatchMode()) { |
+ utility_process_host_.reset(); |
+ return; |
+ } |
} |
batch_mode_timer_.Start( |
FROM_HERE, base::TimeDelta::FromSeconds(kBatchModeTimeoutSeconds), |
@@ -269,8 +295,10 @@ void ImageDecoder::StopBatchMode() { |
} |
if (utility_process_host_) { |
- utility_process_host_->EndBatchMode(); |
+ if (!switches::MojoUtilityServicesEnabled()) |
+ utility_process_host_->EndBatchMode(); |
utility_process_host_.reset(); |
+ decoder_.reset(); |
} |
batch_mode_timer_.Stop(); |
@@ -354,6 +382,18 @@ void ImageDecoder::OnDecodeImageFailed(int request_id) { |
job->NotifyDecodeFailed(); |
} |
+void ImageDecoder::OnDecodeImageDone(int request_id, skia::BitmapPtr image) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ if (image) { |
+ SkBitmap bitmap = image.To<SkBitmap>(); |
+ if (!bitmap.empty()) { |
+ OnDecodeImageSucceeded(bitmap, request_id); |
+ return; |
+ } |
+ } |
+ OnDecodeImageFailed(request_id); |
+} |
+ |
void ImageDecoder::RemoveJob(const scoped_refptr<Job>& job) { |
base::AutoLock lock(map_lock_); |
for (auto it = image_request_id_map_.begin(); |